pub struct ModelProviderParser { /* private fields */ }Expand description
Parses "provider:model" strings into live StreamingModelProvider instances.
This is the primary entry point for creating providers from user-supplied model specifications at runtime. It handles provider lookup, credential loading, and model configuration in one step.
§Format
- Single provider –
"anthropic:claude-sonnet-4-5-20250929"or"ollama:llama3.2" - Multiple providers –
"anthropic:claude-sonnet-4-5-20250929,openai:gpt-4o"creates anAlloyedModelProviderthat cycles between them.
§Built-in providers
Default::default() registers all built-in providers: anthropic, openai, openrouter, gemini, ollama, llamacpp, deepseek, moonshot, zai, and (with feature flags) bedrock and codex.
§Custom providers
Register additional providers with with_provider (for types implementing ProviderFactory) or with_openai_provider (for OpenAI-compatible APIs).
§Example
use llm::parser::ModelProviderParser;
use llm::StreamingModelProvider;
let parser = ModelProviderParser::default();
let (provider, model) = parser.parse("ollama:llama3.2").await.unwrap();
println!("Provider: {}", provider.display_name());
println!("Model: {model}");Implementations§
Source§impl ModelProviderParser
impl ModelProviderParser
Sourcepub fn new(factories: HashMap<String, CreateProviderFn>) -> Self
pub fn new(factories: HashMap<String, CreateProviderFn>) -> Self
Create a new parser with custom provider factories
Source§impl ModelProviderParser
impl ModelProviderParser
pub fn with_provider<P: ProviderFactory + StreamingModelProvider + 'static>( self, name: impl Into<String>, ) -> Self
pub fn with_openai_provider( self, name: impl Into<String>, config: &'static ProviderConfig, ) -> Self
Sourcepub async fn create_provider(
&self,
model: &LlmModel,
) -> Result<Box<dyn StreamingModelProvider>>
pub async fn create_provider( &self, model: &LlmModel, ) -> Result<Box<dyn StreamingModelProvider>>
Create a provider from a typed LlmModel
Sourcepub async fn parse(
&self,
models_str: &str,
) -> Result<(Box<dyn StreamingModelProvider>, LlmModel)>
pub async fn parse( &self, models_str: &str, ) -> Result<(Box<dyn StreamingModelProvider>, LlmModel)>
Parse a model specification string and create a provider instance.
Returns both the provider and an LlmModel describing the identity
of the first (or only) provider in the spec.
§Format
"provider:model"- Single provider (e.g., “anthropic:claude-3.5-sonnet”)"provider1:model1,provider2:model2"- Multiple providers create anAlloyedModelProvider
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModelProviderParser
impl !RefUnwindSafe for ModelProviderParser
impl Send for ModelProviderParser
impl Sync for ModelProviderParser
impl Unpin for ModelProviderParser
impl UnsafeUnpin for ModelProviderParser
impl !UnwindSafe for ModelProviderParser
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> 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