from typing import List, Dict, Any from langchain.tools import BaseTool class StringUtilitiesTool(BaseTool): name = "string_utilities" description = "Fournit des utilitaires pour manipuler les chaînes de caractères" def _run(self, text: str, operation: str) -> str: """Effectue une opération sur une chaîne de caractères""" try: if operation == "reverse": return text[::-1] elif operation == "uppercase": return text.upper() elif operation == "lowercase": return text.lower() elif operation == "capitalize": return text.capitalize() elif operation == "title": return text.title() elif operation == "strip": return text.strip() elif operation == "split": return str(text.split()) elif operation == "join": return " ".join(text.split()) else: return f"Opération non supportée: {operation}. Opérations disponibles: reverse, uppercase, lowercase, capitalize, title, strip, split, join" except Exception as e: return f"Erreur lors de la manipulation de la chaîne: {str(e)}" async def _arun(self, text: str, operation: str) -> str: """Version asynchrone de l'outil""" return self._run(text, operation)