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<Self>
pub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>
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) -> Self
pub fn single(config: ProviderConfig, provider: Provider) -> Self
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<()>
pub fn switch(&self, model: &str) -> Result<()>
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<()>
pub async fn add(&self, config: &ProviderConfig) -> Result<()>
Add a new provider. Validates config first. Replaces any existing provider with the same model name.
Sourcepub fn remove(&self, model: &str) -> Result<()>
pub fn remove(&self, model: &str) -> Result<()>
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§impl Debug for ProviderManager
impl Debug for ProviderManager
Source§impl Model for ProviderManager
impl Model for ProviderManager
Source§fn stream(
&self,
request: Request,
) -> impl Stream<Item = Result<StreamChunk>> + Send
fn stream( &self, request: Request, ) -> impl Stream<Item = Result<StreamChunk>> + 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.