tooluniverse.utils 模块¶
- tooluniverse.utils.get_user_cache_dir()[源代码]¶
返回一个适用于ToolUniverse的跨平台用户缓存目录。
macOS:~/Library/Caches/ToolUniverse Linux:$XDG_CACHE_HOME 或 ~/.cache/tooluniverse Windows:%LOCALAPPDATA%ToolUniverseCache
- tooluniverse.utils.yaml_to_dict(yaml_file_path)[源代码]¶
将 YAML 文件转换为字典。
- 参数:
yaml_file_path (
str) – YAML 文件的路径。
- 返回值
- dict or None: Dictionary representation of the YAML file content,
or None if the file is not found or has YAML errors.
- tooluniverse.utils.read_json_list(file_path)[源代码]¶
从文件中读取 JSON 对象列表。
Parameters file_path (str): The path to the JSON file.
Returns list: A list of dictionaries containing the JSON objects.
- tooluniverse.utils.compare_function_calls(pred_function_call, gt_function_call, compare_arguments=True, compare_value=True)[源代码]¶
- tooluniverse.utils.extract_function_call_json(lst, return_message=False, verbose=True, format='llama')[源代码]¶
- tooluniverse.utils.format_error_response(error, tool_name=None, context=None)[源代码]¶
将格式错误响应统一为一致的结构。
此功能确保所有错误响应遵循统一格式,以便更好地进行错误处理和调试。
- 参数:
error (
Exception) – 发生的错误tool_name (
str, optional) – 失败工具的名称context (
Dict[str, Any], optional) – 错误的附加上下文
- 返回值
Dict[str, Any]: Standardized error response
- tooluniverse.utils.get_parameter_schema(tool_config)[源代码]¶
从工具配置中获取参数模式。
- 参数:
tool_config (
Dict[str, Any]) – Tool configuration dictionary
- 返回值
Dict[str, Any]: Parameter schema dictionary
- tooluniverse.utils.validate_query(query)[源代码]¶
验证查询字典的必填字段和结构。
- 参数:
query (
Dict[str, Any]) – 用于验证的查询字典
- 返回值
bool: True if query is valid, False otherwise
- tooluniverse.utils.normalize_gene_symbol(gene_symbol)[源代码]¶
将基因符号规范化为标准格式。
- 参数:
gene_symbol (
str) – 用于标准化的基因符号
- 返回值
str: Normalized gene symbol
- tooluniverse.utils.format_api_response(response_data, format_type='json')[源代码]¶
将 API 响应数据格式化为标准化格式。
- 参数:
response_data (
Any) – 响应数据的格式format_type (
str) – 所需的输出格式(’json’、’pretty’、’minimal’)
- 返回值
Union[str, Dict[str, Any]]: Formatted response