Trait ModelProvider
pub trait ModelProvider:
Send
+ Sync
+ Attributable {
Show 26 methods
// Required method
fn chat_with_system<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system_prompt: Option<&'life1 str>,
message: &'life2 str,
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait;
// Provided methods
fn has_stable_request_identity(&self, _model: &str) -> bool { ... }
fn capabilities(&self) -> ProviderCapabilities { ... }
fn capabilities_for_model(&self, _model: &str) -> ProviderCapabilities { ... }
fn vision_limited_by(&self, _model: &str) -> Option<String> { ... }
fn has_mixed_native_tool_support_for_model(&self, _model: &str) -> bool { ... }
fn default_temperature(&self) -> f64 { ... }
fn default_max_tokens(&self) -> u32 { ... }
fn default_timeout_secs(&self) -> u64 { ... }
fn default_base_url(&self) -> Option<&str> { ... }
fn default_wire_api(&self) -> &str { ... }
fn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload { ... }
fn simple_chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 str,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn list_models_with_pricing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn chat_with_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: ChatRequest<'life1>,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn supports_native_tools(&self) -> bool { ... }
fn supports_vision(&self) -> bool { ... }
fn warmup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn chat_with_tools<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
_tools: &'life2 [Value],
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn supports_streaming(&self) -> bool { ... }
fn supports_streaming_tool_events(&self) -> bool { ... }
fn stream_chat_with_system(
&self,
_system_prompt: Option<&str>,
_message: &str,
_model: &str,
_temperature: Option<f64>,
_options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>> { ... }
fn stream_chat_with_history(
&self,
messages: &[ChatMessage],
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>> { ... }
fn stream_chat(
&self,
request: ChatRequest<'_>,
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, StreamError>> + Send>> { ... }
}Required Methods§
Sourcefn chat_with_system<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system_prompt: Option<&'life1 str>,
message: &'life2 str,
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn chat_with_system<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system_prompt: Option<&'life1 str>,
message: &'life2 str,
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
One-shot chat with optional system prompt. See simple_chat for
the temperature contract.
Provided Methods§
Sourcefn has_stable_request_identity(&self, _model: &str) -> bool
fn has_stable_request_identity(&self, _model: &str) -> bool
Whether repeated requests for model are dispatched to one stable
provider/model identity.
The default is deliberately unstable. Known leaf providers are marked stable at their construction choke point; composite and out-of-tree providers must opt in only when they can prove one concrete dispatch identity. Callers use this fact to fail closed for identity-sensitive behavior such as persistent full-response caching.
Sourcefn capabilities(&self) -> ProviderCapabilities
fn capabilities(&self) -> ProviderCapabilities
Query model_provider capabilities.
Sourcefn capabilities_for_model(&self, _model: &str) -> ProviderCapabilities
fn capabilities_for_model(&self, _model: &str) -> ProviderCapabilities
Query the effective capabilities for the model that will be dispatched.
Most providers have one capability set for every model and inherit this default. Composite providers override it when the model selects a route or when failover can reach children with different capabilities.
Sourcefn vision_limited_by(&self, _model: &str) -> Option<String>
fn vision_limited_by(&self, _model: &str) -> Option<String>
Name the entry that forced vision to false on this provider’s
Self::capabilities_for_model, for providers that aggregate several
named entries (e.g. a primary plus configured fallbacks) into one
capability set. Returns None when this provider is not such an
aggregate, or when nothing about it limits vision for model.
Sourcefn has_mixed_native_tool_support_for_model(&self, _model: &str) -> bool
fn has_mixed_native_tool_support_for_model(&self, _model: &str) -> bool
Whether the selected request can reach both native-tool and text-only candidates.
Ordinary providers are homogeneous and inherit false. Composite
providers override this so callers that must select one tool protocol
before dispatch can reject an incompatible strict configuration.
Sourcefn default_temperature(&self) -> f64
fn default_temperature(&self) -> f64
Family-preferred temperature default. Override per family. Documented
for introspection only; never use to convert None into a wire value.
Sourcefn default_max_tokens(&self) -> u32
fn default_max_tokens(&self) -> u32
Max output tokens used when the caller / config doesn’t set one.
Sourcefn default_timeout_secs(&self) -> u64
fn default_timeout_secs(&self) -> u64
HTTP timeout (seconds) used when the caller / config doesn’t set one.
Sourcefn default_base_url(&self) -> Option<&str>
fn default_base_url(&self) -> Option<&str>
Canonical public API endpoint, when there is one. Returned as a
string slice so model_provider impls can serve from const &'static strs
without allocations. None = model_provider has no universal endpoint
(local model_providers, auth-less CLIs, user-BYO endpoints).
Sourcefn default_wire_api(&self) -> &str
fn default_wire_api(&self) -> &str
Wire protocol variant. Either "responses" (OpenAI Codex-style) or
"chat_completions" (everything else). Providers override to their
native format.
Sourcefn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload
fn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload
Convert tool specifications to provider-native format.
Sourcefn simple_chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 str,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn simple_chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 str,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Simple one-shot chat (single user message, no explicit system prompt).
temperature == None means the field is omitted on the wire.
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Sourcefn list_models_with_pricing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn list_models_with_pricing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Fetch the list of available models with pricing data for this
model_provider. Default delegates to list_models and returns no
pricing. Concrete providers that receive pricing from their /models
endpoint override this to return enriched data.
Sourcefn chat_with_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn chat_with_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Multi-turn conversation. See simple_chat for the temperature
contract.
Sourcefn chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: ChatRequest<'life1>,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: ChatRequest<'life1>,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Structured chat API for agent loop callers. See simple_chat for
the temperature contract.
Sourcefn supports_native_tools(&self) -> bool
fn supports_native_tools(&self) -> bool
Whether model_provider supports native tool calls over API.
Sourcefn supports_vision(&self) -> bool
fn supports_vision(&self) -> bool
Whether model_provider supports multimodal vision input.
Sourcefn warmup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn warmup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Warm up the HTTP connection pool.
Sourcefn chat_with_tools<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
_tools: &'life2 [Value],
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn chat_with_tools<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
_tools: &'life2 [Value],
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Chat with tool definitions for native function calling support.
See simple_chat for the temperature contract.
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Whether model_provider supports streaming responses.
Sourcefn supports_streaming_tool_events(&self) -> bool
fn supports_streaming_tool_events(&self) -> bool
Whether model_provider can emit structured tool-call stream events.
Sourcefn stream_chat_with_system(
&self,
_system_prompt: Option<&str>,
_message: &str,
_model: &str,
_temperature: Option<f64>,
_options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>>
fn stream_chat_with_system( &self, _system_prompt: Option<&str>, _message: &str, _model: &str, _temperature: Option<f64>, _options: StreamOptions, ) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>>
Streaming chat with optional system prompt. See simple_chat for
the temperature contract.
Sourcefn stream_chat_with_history(
&self,
messages: &[ChatMessage],
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>>
fn stream_chat_with_history( &self, messages: &[ChatMessage], model: &str, temperature: Option<f64>, options: StreamOptions, ) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, StreamError>> + Send>>
Streaming chat with history. See simple_chat for the temperature
contract.
Sourcefn stream_chat(
&self,
request: ChatRequest<'_>,
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, StreamError>> + Send>>
fn stream_chat( &self, request: ChatRequest<'_>, model: &str, temperature: Option<f64>, options: StreamOptions, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, StreamError>> + Send>>
Structured streaming chat interface. See simple_chat for the
temperature contract.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> ModelProvider for Arc<T>where
T: ModelProvider + ?Sized,
Blanket implementation: Arc<T> delegates all ModelProvider methods to T.
This eliminates the need for manual impl ModelProvider for Arc<MyModelProvider>
boilerplate in test and production code.
impl<T> ModelProvider for Arc<T>where
T: ModelProvider + ?Sized,
Blanket implementation: Arc<T> delegates all ModelProvider methods to T.
This eliminates the need for manual impl ModelProvider for Arc<MyModelProvider>
boilerplate in test and production code.