pub struct AiClientBuilder { /* private fields */ }Expand description
AI client builder with progressive custom configuration
Implementations§
Source§impl AiClientBuilder
impl AiClientBuilder
Sourcepub fn with_base_url(self, base_url: &str) -> Self
pub fn with_base_url(self, base_url: &str) -> Self
Set custom base URL
Sourcepub fn with_proxy(self, proxy_url: Option<&str>) -> Self
pub fn with_proxy(self, proxy_url: Option<&str>) -> Self
Set custom proxy URL
Sourcepub fn without_proxy(self) -> Self
pub fn without_proxy(self) -> Self
Explicitly disable proxy usage
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set custom timeout duration
Sourcepub fn with_pool_config(self, max_idle: usize, idle_timeout: Duration) -> Self
pub fn with_pool_config(self, max_idle: usize, idle_timeout: Duration) -> Self
Set connection pool configuration
Sourcepub fn with_metrics(self, metrics: Arc<dyn Metrics>) -> Self
pub fn with_metrics(self, metrics: Arc<dyn Metrics>) -> Self
Set custom metrics implementation
Sourcepub fn with_default_chat_model(self, model: &str) -> Self
pub fn with_default_chat_model(self, model: &str) -> Self
Set default chat model for the client
Sourcepub fn with_default_multimodal_model(self, model: &str) -> Self
pub fn with_default_multimodal_model(self, model: &str) -> Self
Set default multimodal model for the client
Sourcepub fn with_model_resolver(self, resolver: Arc<ModelResolver>) -> Self
pub fn with_model_resolver(self, resolver: Arc<ModelResolver>) -> Self
Inject a custom model resolver (advanced usage).
Sourcepub fn with_smart_defaults(self) -> Self
pub fn with_smart_defaults(self) -> Self
Enable smart defaults for resilience features
Sourcepub fn for_production(self) -> Self
pub fn for_production(self) -> Self
Configure for production environment
Sourcepub fn for_development(self) -> Self
pub fn for_development(self) -> Self
Configure for development environment
Sourcepub fn build_provider(self) -> Result<Box<dyn ChatProvider>, AiLibError>
pub fn build_provider(self) -> Result<Box<dyn ChatProvider>, AiLibError>
Build and return a boxed ChatProvider according to the current builder configuration.
If a custom strategy was provided via with_strategy, it will be returned directly.
Sourcepub fn with_max_concurrency(self, max_concurrent_requests: usize) -> Self
pub fn with_max_concurrency(self, max_concurrent_requests: usize) -> Self
Configure a simple max concurrent requests backpressure guard
Sourcepub fn with_resilience_config(self, config: ResilienceConfig) -> Self
pub fn with_resilience_config(self, config: ResilienceConfig) -> Self
Set custom resilience configuration
Sourcepub fn with_strategy(self, strategy: Box<dyn ChatProvider>) -> Self
pub fn with_strategy(self, strategy: Box<dyn ChatProvider>) -> Self
Provide a custom provider strategy (boxed ChatProvider)
This allows injecting a fully custom implementation of ChatProvider,
bypassing the standard provider factory logic.
§Example
// Create a custom strategy (e.g., manually built RoundRobin)
let strategy = RoundRobinProvider::new(vec![])?;
let client = AiClientBuilder::new(Provider::OpenAI) // Provider enum ignored here
.with_strategy(Box::new(strategy))
.build()?;Sourcepub fn with_round_robin_strategy<I>(
self,
providers: I,
) -> Result<Self, AiLibError>
pub fn with_round_robin_strategy<I>( self, providers: I, ) -> Result<Self, AiLibError>
Compose a round-robin strategy from the provided providers.
This method takes a collection of boxed ChatProvider instances and wraps them
in a RoundRobinProvider.
§Example
let p1 = AiClientBuilder::new(Provider::OpenAI).build_provider()?;
let p2 = AiClientBuilder::new(Provider::Anthropic).build_provider()?;
let client = AiClientBuilder::new(Provider::OpenAI)
.with_round_robin_strategy(vec![p1, p2])?
.build()?;Sourcepub fn with_failover_strategy<I>(self, providers: I) -> Result<Self, AiLibError>
pub fn with_failover_strategy<I>(self, providers: I) -> Result<Self, AiLibError>
Compose a failover strategy from the provided providers.
Sourcepub fn with_round_robin_chain(
self,
providers: Vec<Provider>,
) -> Result<Self, AiLibError>
pub fn with_round_robin_chain( self, providers: Vec<Provider>, ) -> Result<Self, AiLibError>
Compose a round-robin strategy from built-in Provider variants.
Sourcepub fn with_failover_chain(
self,
providers: Vec<Provider>,
) -> Result<Self, AiLibError>
pub fn with_failover_chain( self, providers: Vec<Provider>, ) -> Result<Self, AiLibError>
Compose a failover strategy from built-in Provider variants.
Sourcepub fn with_round_robin_builder(
self,
builder: RoutingStrategyBuilder,
) -> Result<Self, AiLibError>
pub fn with_round_robin_builder( self, builder: RoutingStrategyBuilder, ) -> Result<Self, AiLibError>
Use RoutingStrategyBuilder to configure a round-robin strategy inline.
Sourcepub fn with_failover_builder(
self,
builder: RoutingStrategyBuilder,
) -> Result<Self, AiLibError>
pub fn with_failover_builder( self, builder: RoutingStrategyBuilder, ) -> Result<Self, AiLibError>
Use RoutingStrategyBuilder to configure a failover strategy inline.
Sourcepub fn build(self) -> Result<AiClient, AiLibError>
pub fn build(self) -> Result<AiClient, AiLibError>
Build AiClient instance