Spaces:
Sleeping
Sleeping
Download tools/string_tool.py from olcapone/final_exam: direct link, hf CLI and curl.
- Browser
- Download file 685 Bytes
-
https://huggingface.co/spaces/olcapone/final_exam/resolve/75e2fa36d5dfc8a7cd201daacc44b54881b6ca3a/tools/string_tool.py
- Command line
-
hf download hf://spaces/olcapone/final_exam@75e2fa36d5dfc8a7cd201daacc44b54881b6ca3a/tools/string_tool.py
-
curl -L -o string_tool.py https://huggingface.co/spaces/olcapone/final_exam/resolve/75e2fa36d5dfc8a7cd201daacc44b54881b6ca3a/tools/string_tool.py
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.") | |