Spaces:
Runtime error
Runtime error
Download team_framework/load_tools.py from airsltd/base-teams: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/airsltd/base-teams/resolve/main/team_framework/load_tools.py
- Command line
-
hf download hf://spaces/airsltd/base-teams/team_framework/load_tools.py
-
curl -L -o load_tools.py https://huggingface.co/spaces/airsltd/base-teams/resolve/main/team_framework/load_tools.py
1.27 kB
| import importlib | |
| def load_tools_from_array(arr:list): | |
| ret = {} | |
| for item in arr: | |
| # 构建正确的模块路径,使用 __name__ 动态获取当前模块的父路径(此处正好为团队名称),并加上 .tools 子目录和工具名称 | |
| # parent_module_path = '.'.join(__name__.split('.')[:-1]) | |
| # module_path = f'{parent_module_path}.tools.{item}' | |
| module_path = f'teams.get_weather.tools.{item}' | |
| try: | |
| module = importlib.import_module(module_path) | |
| # 函数名预期与工具名称相同 | |
| func = getattr(module, item) | |
| ret[item] = func | |
| print(f"成功从模块 '{module_path}' 导入函数 '{item}'") | |
| except ImportError as e: | |
| print(f"导入模块 {module_path} 时出错: {e}") | |
| except AttributeError as e: | |
| print(f"在模块 {module_path} 中找不到函数 '{item}': {e}") | |
| return ret | |
| # def load_tools_from_db(): | |
| # tool_arr = ["get_weather", "get_current_time"] | |
| # return load_tools_from_array(tool_arr) | |
| def load_tools(tools_dict:dict): | |
| print("\n\n\n######## load_tools\ntools_dict: ", tools_dict) | |
| # load_tools_from_array(tools_dict) | |
| return load_tools_from_array(tools_dict) | |
| return tools_dict |