final_exam / tools /string_tool.py
VinogradovAI's picture
Upload 16 files
130d5b3 verified
Raw History Blame
685 Bytes
# 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.")