tooluniverse.utils 模块

tooluniverse.utils.download_from_hf(tool_config)[源代码]
tooluniverse.utils.get_md5(input_str)[源代码]

Return the hexadecimal MD5 digest of the given string.

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.evaluate_function_call(tool_definition, function_call)[源代码]
tooluniverse.utils.evaluate_function_call_from_toolbox(toolbox, function_call)[源代码]
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

tooluniverse.utils.validate_hook_config(config)[源代码]

验证钩子配置的正确性和完整性。

此函数检查挂钩配置是否包含所有必需字段,并确保其结构符合挂钩系统的要求。

参数:

config (Dict[str, Any]) – 挂钩配置以进行验证

返回值

bool: True if configuration is valid, False otherwise

tooluniverse.utils.validate_hook_conditions(conditions)[源代码]

验证钩子触发条件。

此函数用于检查钩子条件的结构是否正确,并确保包含有效的运算符和阈值。

参数:

conditions (Dict[str, Any]) – 挂钩条件进行验证

返回值

bool: True if conditions are valid, False otherwise