Spaces:
Paused
Paused
Download src/opencode_api/tool/registry.py from AUXteam/opencode-api: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/AUXteam/opencode-api/resolve/bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/tool/registry.py
- Command line
-
hf download hf://spaces/AUXteam/opencode-api@bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/tool/registry.py
-
curl -L -o registry.py https://huggingface.co/spaces/AUXteam/opencode-api/resolve/bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/tool/registry.py
1.41 kB
| from typing import Dict, Any, List, Optional | |
| from .tool import BaseTool | |
| import os | |
| import importlib.util | |
| class ToolRegistry: | |
| """๋๊ตฌ ๋ ์ง์คํธ๋ฆฌ - ๋๊ตฌ ๋ฑ๋ก ๋ฐ ๊ด๋ฆฌ""" | |
| def __init__(self): | |
| self._tools: Dict[str, BaseTool] = {} | |
| def register(self, tool: BaseTool) -> None: | |
| """๋๊ตฌ ๋ฑ๋ก""" | |
| self._tools[tool.id] = tool | |
| def get(self, tool_id: str) -> Optional[BaseTool]: | |
| """๋๊ตฌ ID๋ก ์กฐํ""" | |
| return self._tools.get(tool_id) | |
| def list(self) -> List[BaseTool]: | |
| """๋ฑ๋ก๋ ๋ชจ๋ ๋๊ตฌ ๋ชฉ๋ก ๋ฐํ""" | |
| return list(self._tools.values()) | |
| def get_schema(self) -> List[Dict[str, Any]]: | |
| """๋ชจ๋ ๋๊ตฌ์ ์คํค๋ง ๋ฐํ""" | |
| return [tool.get_schema() for tool in self._tools.values()] | |
| def load_from_directory(self, path: str) -> None: | |
| """ | |
| ๋๋ ํ ๋ฆฌ์์ ๋๊ตฌ๋ฅผ ๋์ ์ผ๋ก ๋ก๋ | |
| (๋์ค์ ๊ตฌํ ๊ฐ๋ฅ - ํ๋ฌ๊ทธ์ธ ์์คํ ) | |
| """ | |
| if not os.path.exists(path): | |
| raise ValueError(f"Directory not found: {path}") | |
| # ํฅํ ๊ตฌํ: .py ํ์ผ์ ์ค์บํ๊ณ BaseTool ์๋ธํด๋์ค๋ฅผ ์ฐพ์ ์๋ ๋ฑ๋ก | |
| # ํ์ฌ๋ placeholder | |
| pass | |
| # ์ ์ญ ์ฑ๊ธํค ์ธ์คํด์ค | |
| _registry = ToolRegistry() | |
| def get_registry() -> ToolRegistry: | |
| """์ ์ญ ๋ ์ง์คํธ๋ฆฌ ์ธ์คํด์ค ๋ฐํ""" | |
| return _registry | |