VinogradovAI's picture
Update tools/string_tool.py
0a78ac3 verified
raw
history blame contribute delete
793 Bytes
# tools/string_tool.py
from langchain.tools import BaseTool
class StringTool(BaseTool):
"""
Операции над строками: реверс текста по префиксу 'reverse:'.
"""
name: str = "string_tool"
description: str = "Apply string transformations: reverse text, case conversion, substring extraction, regex matching. Use for puzzles like reversed sentences, odd-even indexing, or any explicit string manipulation."
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.")