ExLLM.Adapters.Shared.ConfigHelper (ex_llm v0.5.0)

View Source

Shared configuration management utilities for adapters.

Provides common functionality for retrieving configuration, API keys, and default models across all adapters.

Summary

Functions

Get the default model for an adapter, raising if not configured.

Get API key from config with environment variable fallback.

Get configuration for a specific adapter from the config provider.

Get the config provider from options with application default fallback.

Functions

ensure_default_model(adapter_name)

Get the default model for an adapter, raising if not configured.

Examples

iex> ConfigHelper.ensure_default_model(:openai)
"gpt-3.5-turbo"

get_api_key(config, env_var_name)

Get API key from config with environment variable fallback.

Examples

iex> ConfigHelper.get_api_key(%{api_key: "sk-123"}, "OPENAI_API_KEY")
"sk-123"

iex> ConfigHelper.get_api_key(%{}, "OPENAI_API_KEY")
"env-api-key"  # From environment

get_config(adapter_name, config_provider)

Get configuration for a specific adapter from the config provider.

Examples

iex> ConfigHelper.get_config(:anthropic, ExLLM.ConfigProvider.Env)
%{api_key: "sk-...", model: "claude-3-5-sonnet", ...}

get_config_provider(options)

Get the config provider from options with application default fallback.