Skip to main content

ProviderManager

Struct ProviderManager 

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

Manages a set of named providers with an active selection.

All methods that read or mutate the inner state acquire the RwLock. active() returns a clone of the current Provider — callers do not hold the lock while performing LLM calls.

Implementations§

Source§

impl ProviderManager

Source

pub fn new(active: impl Into<CompactString>) -> Self

Create an empty manager with the given active model name.

Use add_provider() or add_config() to populate.

Source

pub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>

Create a manager from a list of remote provider configs.

The first element becomes the active provider. Returns an error if the slice is empty, any config fails validation, or any provider fails to build.

Source

pub fn add_provider( &self, name: impl Into<CompactString>, provider: Provider, ) -> Result<()>

Add a pre-built provider directly (e.g. local models from registry).

Source

pub async fn add_config(&self, config: &ProviderConfig) -> Result<()>

Add a remote provider from config. Validates and builds it.

Source

pub fn active(&self) -> Result<Provider>

Get a clone of the active provider.

Source

pub fn active_model_name(&self) -> Result<CompactString>

Get the model name of the active provider (also its key).

Source

pub fn switch(&self, model: &str) -> Result<()>

Switch to a different provider by model name. Returns an error if the name is not found.

Source

pub fn remove(&self, model: &str) -> Result<()>

Remove a provider by model name. Fails if the provider is currently active.

Source

pub fn list(&self) -> Result<Vec<ProviderEntry>>

List all providers with their active status.

Source

pub async fn wait_until_ready(&self) -> Result<()>

Wait until the active provider is ready.

No-op for remote providers. For local providers, blocks until the model finishes loading.

Source

pub fn context_limit(&self, model: &str) -> usize

Resolve the context limit for a model.

Resolution chain: provider reports limit → static map → 8192 default. Falls back to the static default if the lock is poisoned.

Trait Implementations§

Source§

impl Clone for ProviderManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProviderManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Model for ProviderManager

Source§

async fn send(&self, request: &Request) -> Result<Response>

Send a chat completion request.
Source§

fn stream( &self, request: Request, ) -> impl Stream<Item = Result<StreamChunk>> + Send

Stream a chat completion response.
Source§

fn context_limit(&self, model: &str) -> usize

Resolve the context limit for a model name. Read more
Source§

fn active_model(&self) -> CompactString

Get the active/default model name.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

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
Source§

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

Source§

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
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