tooluniverse.utils module

tooluniverse.utils.download_from_hf(tool_config)[source]
tooluniverse.utils.get_md5(input_str)[source]
tooluniverse.utils.get_user_cache_dir()[source]

Return a cross-platform user cache directory for ToolUniverse.

macOS: ~/Library/Caches/ToolUniverse Linux: $XDG_CACHE_HOME or ~/.cache/tooluniverse Windows: %LOCALAPPDATA%ToolUniverseCache

tooluniverse.utils.yaml_to_dict(yaml_file_path)[source]

Convert a YAML file to a dictionary.

Parameters:

yaml_file_path (str) – Path to the YAML file.

Returns:

Dictionary representation of the YAML file content.

Return type:

dict

tooluniverse.utils.read_json_list(file_path)[source]

Reads a list of JSON objects from a file.

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)[source]
tooluniverse.utils.evaluate_function_call_from_toolbox(toolbox, function_call)[source]
tooluniverse.utils.compare_function_calls(pred_function_call, gt_function_call, compare_arguments=True, compare_value=True)[source]
tooluniverse.utils.extract_function_call_json(lst, return_message=False, verbose=True, format='llama')[source]
tooluniverse.utils.format_error_response(error, tool_name=None, context=None)[source]

Format error responses in a consistent structure.

This function ensures all error responses follow the same format for better error handling and debugging.

Parameters:
  • error (Exception) – The error that occurred

  • tool_name (str, optional) – Name of the tool that failed

  • context (Dict[str, Any], optional) – Additional context about the error

Returns:

Standardized error response

Return type:

Dict[str, Any]

tooluniverse.utils.get_parameter_schema(tool_config)[source]

Get parameter schema from tool configuration.

Parameters:

tool_config (Dict[str, Any]) – Tool configuration dictionary

Returns:

Parameter schema dictionary

Return type:

Dict[str, Any]

tooluniverse.utils.validate_query(query)[source]

Validate a query dictionary for required fields and structure.

Parameters:

query (Dict[str, Any]) – The query dictionary to validate

Returns:

True if query is valid, False otherwise

Return type:

bool

tooluniverse.utils.normalize_gene_symbol(gene_symbol)[source]

Normalize a gene symbol to standard format.

Parameters:

gene_symbol (str) – The gene symbol to normalize

Returns:

Normalized gene symbol

Return type:

str

tooluniverse.utils.format_api_response(response_data, format_type='json')[source]

Format API response data into a standardized format.

Parameters:
  • response_data (Any) – The response data to format

  • format_type (str) – The desired output format (‘json’, ‘pretty’, ‘minimal’)

Returns:

Formatted response

Return type:

Union[str, Dict[str, Any]]

tooluniverse.utils.validate_hook_config(config)[source]

Validate hook configuration for correctness and completeness.

This function checks that the hook configuration contains all required fields and that the structure is valid for the hook system.

Parameters:

config (Dict[str, Any]) – Hook configuration to validate

Returns:

True if configuration is valid, False otherwise

Return type:

bool

tooluniverse.utils.validate_hook_conditions(conditions)[source]

Validate hook trigger conditions.

This function checks that the hook conditions are properly structured and contain valid operators and thresholds.

Parameters:

conditions (Dict[str, Any]) – Hook conditions to validate

Returns:

True if conditions are valid, False otherwise

Return type:

bool