You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
850 B
27 lines
850 B
|
|
from typing import Callable, Dict, Any, List |
|
|
|
class ToolRegistry: |
|
_tools = [] |
|
|
|
@classmethod |
|
def register(cls, name: str, description: str, parameters: Dict[str, Any] = None): |
|
def decorator(func: Callable): |
|
cls._tools.append({ |
|
"type": "function", |
|
"function": { |
|
"name": name, |
|
"description": description, |
|
"parameters": parameters or {} |
|
} |
|
}) |
|
# No need for the wrapper since we're not adding any extra logic |
|
return func |
|
return decorator |
|
|
|
@classmethod |
|
def get_tools(cls, tools: list = None) -> List[Dict[str, Any]]: |
|
if tools: |
|
return [tool for tool in cls._tools if tool['function']['name'] in tools] |
|
else: |
|
return cls._tools |