tooluniverse.utils module¶
- 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
dict: Dictionary representation of the YAML file content.
- 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.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 occurredtool_name (
str, optional) – Name of the tool that failedcontext (
Dict[str, Any], optional) – Additional context about the error
- Returns
Dict[str, Any]: Standardized error response
- tooluniverse.utils.get_parameter_schema(tool_config)[source]¶
Get parameter schema from tool configuration.
- Parameters:
tool_config (
Dict[str, Any]) – Tool configuration dictionary
- Returns
Dict[str, Any]: Parameter schema dictionary
- 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
bool: True if query is valid, False otherwise
- 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
str: Normalized gene symbol
- 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 formatformat_type (
str) – The desired output format (‘json’, ‘pretty’, ‘minimal’)
- Returns
Union[str, Dict[str, Any]]: Formatted response
- 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
bool: True if configuration is valid, False otherwise
- 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
bool: True if conditions are valid, False otherwise