AiClientBuilder

Struct AiClientBuilder 

Source
pub struct AiClientBuilder { /* private fields */ }
Expand description

AI client builder with progressive custom configuration

Implementations§

Source§

impl AiClientBuilder

Source

pub fn new(provider: Provider) -> Self

Create a new builder instance

Source

pub fn with_base_url(self, base_url: &str) -> Self

Set custom base URL

Source

pub fn with_proxy(self, proxy_url: Option<&str>) -> Self

Set custom proxy URL

Source

pub fn without_proxy(self) -> Self

Explicitly disable proxy usage

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Set custom timeout duration

Source

pub fn with_pool_config(self, max_idle: usize, idle_timeout: Duration) -> Self

Set connection pool configuration

Source

pub fn with_metrics(self, metrics: Arc<dyn Metrics>) -> Self

Set custom metrics implementation

Source

pub fn with_default_chat_model(self, model: &str) -> Self

Set default chat model for the client

Source

pub fn with_default_multimodal_model(self, model: &str) -> Self

Set default multimodal model for the client

Source

pub fn with_model_resolver(self, resolver: Arc<ModelResolver>) -> Self

Inject a custom model resolver (advanced usage).

Source

pub fn with_smart_defaults(self) -> Self

Enable smart defaults for resilience features

Source

pub fn for_production(self) -> Self

Configure for production environment

Source

pub fn for_development(self) -> Self

Configure for development environment

Source

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.

Source

pub fn with_max_concurrency(self, max_concurrent_requests: usize) -> Self

Configure a simple max concurrent requests backpressure guard

Source

pub fn with_resilience_config(self, config: ResilienceConfig) -> Self

Set custom resilience configuration

Source

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()?;
Source

pub fn with_round_robin_strategy<I>( self, providers: I, ) -> Result<Self, AiLibError>
where I: IntoIterator<Item = Box<dyn ChatProvider>>,

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()?;
Source

pub fn with_failover_strategy<I>(self, providers: I) -> Result<Self, AiLibError>
where I: IntoIterator<Item = Box<dyn ChatProvider>>,

Compose a failover strategy from the provided providers.

Source

pub fn with_round_robin_chain( self, providers: Vec<Provider>, ) -> Result<Self, AiLibError>

Compose a round-robin strategy from built-in Provider variants.

Source

pub fn with_failover_chain( self, providers: Vec<Provider>, ) -> Result<Self, AiLibError>

Compose a failover strategy from built-in Provider variants.

Source

pub fn with_round_robin_builder( self, builder: RoutingStrategyBuilder, ) -> Result<Self, AiLibError>

Use RoutingStrategyBuilder to configure a round-robin strategy inline.

Source

pub fn with_failover_builder( self, builder: RoutingStrategyBuilder, ) -> Result<Self, AiLibError>

Use RoutingStrategyBuilder to configure a failover strategy inline.

Source

pub fn build(self) -> Result<AiClient, AiLibError>

Build AiClient instance

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,