Spaces:
Sleeping
Sleeping
File size: 1,413 Bytes
1397957 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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
|