pub trait ProviderFactory: Sized {
// Required methods
fn from_env() -> impl Future<Output = LlmResult<Self>> + Send;
fn with_model(self, model: &str) -> Self;
}Expand description
Factory trait for constructing model providers from environment configuration.
This trait is separate from StreamingModelProvider because construction methods require Sized, which is incompatible with trait objects (Box<dyn StreamingModelProvider>). By splitting the factory methods into their own trait, the provider trait remains object-safe.
§Methods
-
async from_env() -> Result<Self>– Create a provider from environment variables (e.g.ANTHROPIC_API_KEY,OPENAI_API_KEY). ReturnsLlmError::MissingApiKeyif the required variable is not set. -
with_model(self, model: &str) -> Self– Set or override the model for this provider. Returnsselffor builder-style chaining.
§Example
use llm::{ProviderFactory, StreamingModelProvider};
use llm::providers::anthropic::AnthropicProvider;
let provider = AnthropicProvider::from_env().await
.expect("ANTHROPIC_API_KEY must be set")
.with_model("claude-sonnet-4-5-20250929");
println!("Using: {}", provider.display_name());Required Methods§
Sourcefn from_env() -> impl Future<Output = LlmResult<Self>> + Send
fn from_env() -> impl Future<Output = LlmResult<Self>> + Send
Create provider from environment variables and default configuration
Sourcefn with_model(self, model: &str) -> Self
fn with_model(self, model: &str) -> Self
Set or update the model for this provider (builder pattern)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.