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
impl ProviderManager
Sourcepub async fn from_configs(
configs: &[ProviderConfig],
) -> Result<ProviderManager, Error>
pub async fn from_configs( configs: &[ProviderConfig], ) -> Result<ProviderManager, Error>
Create a new manager from a list of 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.
Sourcepub fn single(config: ProviderConfig, provider: Provider) -> ProviderManager
pub fn single(config: ProviderConfig, provider: Provider) -> ProviderManager
Create a manager with a single provider.
Sourcepub fn active_model(&self) -> CompactString
pub fn active_model(&self) -> CompactString
Get the model name of the active provider (also its key).
Sourcepub fn active_config(&self) -> ProviderConfig
pub fn active_config(&self) -> ProviderConfig
Get a clone of the active provider’s config.
Sourcepub fn switch(&self, model: &str) -> Result<(), Error>
pub fn switch(&self, model: &str) -> Result<(), Error>
Switch to a different provider by model name. Returns an error if the name is not found.
Sourcepub async fn add(&self, config: &ProviderConfig) -> Result<(), Error>
pub async fn add(&self, config: &ProviderConfig) -> Result<(), Error>
Add a new provider. Validates config first. Replaces any existing provider with the same model name.
Sourcepub fn remove(&self, model: &str) -> Result<(), Error>
pub fn remove(&self, model: &str) -> Result<(), Error>
Remove a provider by model name. Fails if the provider is currently active.
Sourcepub fn list(&self) -> Vec<ProviderEntry>
pub fn list(&self) -> Vec<ProviderEntry>
List all providers with their active status.
Sourcepub fn context_limit(&self, model: &str) -> usize
pub fn context_limit(&self, model: &str) -> usize
Resolve the context limit for a model.
Resolution chain: provider reports limit → static map → 8192 default.
Trait Implementations§
Source§impl Clone for ProviderManager
impl Clone for ProviderManager
Source§fn clone(&self) -> ProviderManager
fn clone(&self) -> ProviderManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProviderManager
impl Debug for ProviderManager
Source§impl Model for ProviderManager
impl Model for ProviderManager
Source§async fn send(&self, request: &Request) -> Result<Response, Error>
async fn send(&self, request: &Request) -> Result<Response, Error>
Source§fn stream(
&self,
request: Request,
) -> impl Stream<Item = Result<StreamChunk, Error>> + Send
fn stream( &self, request: Request, ) -> impl Stream<Item = Result<StreamChunk, Error>> + Send
Source§fn context_limit(&self, model: &str) -> usize
fn context_limit(&self, model: &str) -> usize
Source§fn active_model(&self) -> CompactString
fn active_model(&self) -> CompactString
Auto Trait Implementations§
impl Freeze for ProviderManager
impl RefUnwindSafe for ProviderManager
impl Send for ProviderManager
impl Sync for ProviderManager
impl Unpin for ProviderManager
impl UnsafeUnpin for ProviderManager
impl UnwindSafe for ProviderManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more