Jido.AI.Provider.Helpers (Jido AI v0.5.2)

View Source

Common helper functions for AI provider adapters.

This module centralizes functionality that would otherwise be duplicated across provider implementations, such as:

  • File path management for model caching
  • Reading from and writing to cache
  • Making API requests with proper authentication
  • Model name standardization across providers

Summary

Functions

Caches a single model to a file.

Extracts a model from different response formats.

Extracts models from different response formats.

Gets an API key from options or environment.

Gets the path to a specific model file for a provider.

Gets the path to the models file for a provider.

Merges model information from multiple providers.

Reads models from the cache file.

Standardizes a model name across providers by removing version numbers and dates. This helps match equivalent models from different providers.

Functions

cache_single_model(provider_path, model, model_data)

Caches a single model to a file.

extract_model_from_response(model)

Extracts a model from different response formats.

extract_models_from_response(models)

Extracts models from different response formats.

fetch_and_cache_models(provider, url, headers, provider_path, process_fn)

Fetches models from the API and caches them.

fetch_model_from_api(provider, url, headers, model, provider_path, process_fn, opts \\ [])

Fetches a specific model from the API and caches it.

fetch_model_from_cache(provider_path, model, opts, process_fn)

Fetches a model from the cache.

get_api_key(opts, env_var, keyring_key)

Gets an API key from options or environment.

get_model_file_path(provider_path, model)

Gets the path to a specific model file for a provider.

get_models_file_path(provider_path)

Gets the path to the models file for a provider.

merge_model_information(models)

Merges model information from multiple providers.

Parameters

  • models: List of model maps from different providers

Returns

  • A merged model map with combined information

read_models_from_cache(provider_path, process_fn)

Reads models from the cache file.

standardize_name(model)

Standardizes a model name across providers by removing version numbers and dates. This helps match equivalent models from different providers.

Examples

iex> standardize_name("claude-3.7-sonnet-20250219")
"claude-3.7-sonnet"
iex> standardize_name("gpt-4-0613")
"gpt-4"