CustomProviderBuilder

Struct CustomProviderBuilder 

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

Builder for OpenAI-compatible custom providers without editing the Provider enum.

This builder allows you to create a ChatProvider for any service that exposes an OpenAI-compatible API, even if it’s not natively supported by the library.

§Example

// Create a provider for a hypothetical service "MyService"
let my_provider = CustomProviderBuilder::new("MyService")
    .with_base_url("https://api.myservice.com/v1")
    .with_api_key_env("MY_SERVICE_API_KEY")
    .with_default_chat_model("my-model-v1")
    .build_provider()?;

// Inject it into the client
let client = AiClientBuilder::new(Provider::OpenAI) // Enum ignored
    .with_strategy(my_provider)
    .build()?;

Implementations§

Source§

impl CustomProviderBuilder

Source

pub fn new(name: impl Into<String>) -> Self

Create a new builder with the human-readable provider name.

Source

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

Set the base URL (required) for the custom provider.

Source

pub fn with_api_key_env(self, env_var: &str) -> Self

Override the environment variable used to fetch the API key at runtime.

Source

pub fn with_api_key(self, api_key: impl Into<String>) -> Self

Inject a literal API key instead of relying on environment variables.

Source

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

Override the default chat model used for simple helpers.

Source

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

Override the default multimodal model (optional).

Source

pub fn with_chat_endpoint(self, endpoint: &str) -> Self

Override the chat completion endpoint (default: /chat/completions).

Source

pub fn with_upload_endpoint(self, endpoint: Option<&str>) -> Self

Override the upload endpoint (default: /v1/files).

Source

pub fn with_models_endpoint(self, endpoint: Option<&str>) -> Self

Override the models endpoint (default: /models).

Source

pub fn with_headers<I, K, V>(self, headers: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Merge custom HTTP headers (e.g., vendor-specific auth scopes).

Source

pub fn with_transport(self, transport: DynHttpTransportRef) -> Self

Provide a pre-built transport (shared client, proxy, custom TLS, etc.).

Source

pub fn build_provider(self) -> Result<Box<dyn ChatProvider>, AiLibError>

Build a boxed ChatProvider that can be passed to AiClientBuilder::with_strategy.

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,