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, xiaomi, zai, and (with feature flags) bedrock and codex.
§Custom providers
Register additional providers with with_generic_provider (for endpoints described by a ProviderConfig).
§Example
use llm::parser::ModelProviderParser;
use llm::{ProviderConnectionOverrides, StreamingModelProvider};
let parser = ModelProviderParser::default();
let (provider, model) = parser.parse("ollama:llama3.2", &ProviderConnectionOverrides::default()).await.unwrap();
println!("Provider: {}", provider.display_name());
println!("Model: {model}");Implementations§
Source§impl ModelProviderParser
impl ModelProviderParser
pub fn with_codex_provider(self, codex: CodexProvider) -> Self
pub fn with_generic_provider(self, config: &'static ProviderConfig) -> Self
Sourcepub async fn parse(
&self,
models_str: &str,
connections: &ProviderConnectionOverrides,
) -> Result<(Box<dyn StreamingModelProvider>, LlmModel)>
pub async fn parse( &self, models_str: &str, connections: &ProviderConnectionOverrides, ) -> 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 !RefUnwindSafe for ModelProviderParser
impl !UnwindSafe for ModelProviderParser
impl Freeze for ModelProviderParser
impl Send for ModelProviderParser
impl Sync for ModelProviderParser
impl Unpin for ModelProviderParser
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
Converts
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> ⓘ
Converts
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 moreCreates a shared type from an unshared type.