pub struct ModelRouter { /* private fields */ }Expand description
Selects a model Adapter by a stable provider ID.
Implementations§
Source§impl ModelRouter
impl ModelRouter
Sourcepub fn new(id: impl Into<String>, provider: Arc<dyn Model>) -> Self
pub fn new(id: impl Into<String>, provider: Arc<dyn Model>) -> Self
Creates a router with its first provider.
Sourcepub fn register(
&mut self,
id: impl Into<String>,
provider: Arc<dyn Model>,
) -> Result<()>
pub fn register( &mut self, id: impl Into<String>, provider: Arc<dyn Model>, ) -> Result<()>
Registers another provider.
Sourcepub fn choices(
&self,
) -> impl DoubleEndedIterator<Item = &ModelChoice> + ExactSizeIterator + Clone
pub fn choices( &self, ) -> impl DoubleEndedIterator<Item = &ModelChoice> + ExactSizeIterator + Clone
Returns the selectable routes in frontend display order.
Sourcepub fn resolve_choice(
&self,
route: &str,
reasoning_effort: Option<&str>,
) -> Result<&ModelChoice>
pub fn resolve_choice( &self, route: &str, reasoning_effort: Option<&str>, ) -> Result<&ModelChoice>
Resolves one route and optional reasoning effort through the model catalog.
Sourcepub fn configure_choice(&mut self, choice: ModelChoice) -> Result<()>
pub fn configure_choice(&mut self, choice: ModelChoice) -> Result<()>
Replaces display metadata for one registered route.
Sourcepub fn default_provider(&self) -> &str
pub fn default_provider(&self) -> &str
Returns the default provider ID.
Sourcepub async fn respond(
&self,
provider: &str,
request: ModelRequest<'_>,
events: ModelEventSink,
) -> Result<ModelOutput>
pub async fn respond( &self, provider: &str, request: ModelRequest<'_>, events: ModelEventSink, ) -> Result<ModelOutput>
Streams one response through the selected provider.
Sourcepub fn compaction_endpoint(&self, provider: &str) -> Result<bool>
pub fn compaction_endpoint(&self, provider: &str) -> Result<bool>
Reports whether one route has a native compaction endpoint.
Sourcepub fn supports_image_input(&self, provider: &str) -> Result<bool>
pub fn supports_image_input(&self, provider: &str) -> Result<bool>
Reports whether one route accepts native image input.
Sourcepub fn tool_discovery(&self, provider: &str) -> Result<ToolDiscoveryMode>
pub fn tool_discovery(&self, provider: &str) -> Result<ToolDiscoveryMode>
Reports deferred-tool cache behavior for one route.
Sourcepub fn prompt_cache_capability(
&self,
provider: &str,
) -> Result<PromptCacheCapability>
pub fn prompt_cache_capability( &self, provider: &str, ) -> Result<PromptCacheCapability>
Reports prompt-cache support for one route.
Sourcepub fn pricing(&self, provider: &str) -> Result<Option<ModelPricing>>
pub fn pricing(&self, provider: &str) -> Result<Option<ModelPricing>>
Returns provider-owned pricing for one route when it is known.
Sourcepub fn estimated_cost_microusd(
&self,
provider: &str,
usage: &TokenUsage,
) -> Result<Option<u64>>
pub fn estimated_cost_microusd( &self, provider: &str, usage: &TokenUsage, ) -> Result<Option<u64>>
Estimates one completed request from provider-owned rates.
Sourcepub async fn compact(
&self,
provider: &str,
request: CompactRequest<'_>,
) -> Result<CompactOutput>
pub async fn compact( &self, provider: &str, request: CompactRequest<'_>, ) -> Result<CompactOutput>
Compacts context through the selected provider.