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 fn new(active: impl Into<CompactString>) -> Self
pub fn new(active: impl Into<CompactString>) -> Self
Create an empty manager with the given active model name.
Use add_provider() or add_model() to populate.
Sourcepub async fn from_providers(
active: CompactString,
providers: &BTreeMap<CompactString, ProviderDef>,
) -> Result<Self>
pub async fn from_providers( active: CompactString, providers: &BTreeMap<CompactString, ProviderDef>, ) -> Result<Self>
Build a manager from a map of provider definitions and an active model.
Iterates each provider def, building a Provider instance per model
in its models list.
Sourcepub fn add_provider(
&self,
name: impl Into<CompactString>,
provider: Provider,
) -> Result<()>
pub fn add_provider( &self, name: impl Into<CompactString>, provider: Provider, ) -> Result<()>
Add a pre-built provider directly (e.g. local models from registry).
Sourcepub async fn add_def(&self, def: &ProviderDef) -> Result<()>
pub async fn add_def(&self, def: &ProviderDef) -> Result<()>
Add all models from a provider definition. Builds a Provider per model.
Sourcepub fn active_model_name(&self) -> Result<CompactString>
pub fn active_model_name(&self) -> Result<CompactString>
Get the model name of the active provider (also its key).
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 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) -> Result<Vec<ProviderEntry>>
pub fn list(&self) -> Result<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.
Uses the static map in wcore::model::default_context_limit.