Spaces:
Runtime error
Runtime error
Download src/tools_registry.py from Gwenn-LR/Final_Assignment_Gaia: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/Gwenn-LR/Final_Assignment_Gaia/resolve/main/src/tools_registry.py
- Command line
-
hf download hf://spaces/Gwenn-LR/Final_Assignment_Gaia/src/tools_registry.py
-
curl -L -o tools_registry.py https://huggingface.co/spaces/Gwenn-LR/Final_Assignment_Gaia/resolve/main/src/tools_registry.py
1.32 kB
| from typing import Any, Callable | |
| from functools import wraps | |
| import inspect | |
| import smolagents.default_tools | |
| from smolagents._function_type_hints_utils import get_json_schema | |
| SMOLAGENT_DEFAULT_TOOLS_OLLAMA_MAPPING = { | |
| smolagent_tool.name: { | |
| "type": "function", | |
| "function": { | |
| "name": smolagent_tool.name, | |
| "description": smolagent_tool.description, | |
| "parameters": {"type": "object", "properties": smolagent_tool.inputs}, | |
| "required": list(smolagent_tool.inputs.keys()), | |
| }, | |
| } | |
| for smolagent_tool in [ | |
| class_element | |
| for _, class_element in inspect.getmembers( | |
| smolagents.default_tools, inspect.isclass | |
| ) | |
| if ("Tool" in str(class_element)) and (getattr(class_element, "name", None)) | |
| ] | |
| } | |
| class ToolsRegistry: | |
| _tools: dict[str, Any] = SMOLAGENT_DEFAULT_TOOLS_OLLAMA_MAPPING | |
| def register(cls): | |
| def decorator(func: Callable): | |
| cls._tools.update({func.__name__: get_json_schema(func)}) | |
| def wrapper(*args, **kwargs): | |
| return func(*args, **kwargs) | |
| return wrapper | |
| return decorator | |
| def get_all_tools(cls) -> list[dict[str, Any]]: | |
| return cls._tools | |