File size: 685 Bytes
130d5b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# tools/string_tool.py
from langchain.tools import BaseTool

class StringTool(BaseTool):
    """

    Операции над строками: реверс текста по префиксу 'reverse:'.

    """
    name: str = "string_tool"
    description: str = "Реверсирует часть строки после 'reverse:'."

    def _run(self, text: str) -> str:
        if text.lower().startswith('reverse:'):
            s = text[len('reverse:'):].strip()
            return s[::-1]
        return f"Неизвестная операция: {text}"

    async def _arun(self, text: str) -> str:
        raise NotImplementedError("Async not supported.")