pub struct LLMConfig {
pub provider: Box<dyn ProviderConfig>,
pub default_params: DefaultLLMParams,
}Expand description
System-wide LLM configuration.
Combines a provider-specific configuration with default model parameters.
This is the primary config type used to create a UnifiedLLMClient.
§Example
use multi_llm::{LLMConfig, AnthropicConfig, DefaultLLMParams};
let config = LLMConfig {
provider: Box::new(AnthropicConfig {
api_key: Some("sk-ant-...".to_string()),
default_model: "claude-3-5-sonnet-20241022".to_string(),
..Default::default()
}),
default_params: DefaultLLMParams {
temperature: 0.7,
max_tokens: 4096,
..Default::default()
},
};§From Environment
Use from_env() to load from environment variables:
AI_PROVIDER: Provider name (“anthropic”, “openai”, “ollama”, “lmstudio”)- Provider-specific vars (e.g.,
ANTHROPIC_API_KEY,OPENAI_API_KEY)
Fields§
§provider: Box<dyn ProviderConfig>The provider-specific configuration.
Contains API keys, endpoints, model selection, and provider features.
default_params: DefaultLLMParamsDefault parameters for LLM requests.
Applied to all requests unless overridden by RequestConfig.
Implementations§
Source§impl LLMConfig
impl LLMConfig
Sourcepub fn create_provider(
provider_name: &str,
api_key: Option<String>,
base_url: Option<String>,
model: Option<String>,
) -> LlmResult<Self>
pub fn create_provider( provider_name: &str, api_key: Option<String>, base_url: Option<String>, model: Option<String>, ) -> LlmResult<Self>
Create configuration for a specific provider with generic parameters This is the main factory method for creating provider configurations
§Errors
Returns LlmError::UnsupportedProvider if the provider name is not recognized.
Supported providers are: “anthropic”, “openai”, “lmstudio”.
Returns LlmError::ConfigurationError if:
- API key format validation fails
- Provider-specific configuration validation fails
- Required fields for the provider are missing
Sourcepub fn from_env() -> LlmResult<Self>
pub fn from_env() -> LlmResult<Self>
Load configuration from environment variables for the specified provider This is the ONLY method that should access environment variables
§Errors
Returns LlmError::ConfigurationError if:
- Required environment variables are missing
- Environment variable values are invalid or malformed
- Provider configuration validation fails
Returns LlmError::UnsupportedProvider if the AI_PROVIDER environment variable
contains an unrecognized provider name.