pub struct ModelRouter { /* private fields */ }Expand description
Smart request router: selects the best model endpoint for a request.
Wraps a ModelRegistry and adds routing logic including fallback to
the default model, context-length awareness, and OpenAI-compatible
model listing.
Implementations§
Source§impl ModelRouter
impl ModelRouter
Sourcepub fn new(registry: ModelRegistry) -> Self
pub fn new(registry: ModelRegistry) -> Self
Create a new router backed by the given registry.
Sourcepub fn route(
&self,
requested_model: Option<&str>,
) -> Result<&ModelEndpoint, RoutingError>
pub fn route( &self, requested_model: Option<&str>, ) -> Result<&ModelEndpoint, RoutingError>
Route a request: resolve model_id from the request.
Falls back to the default model if requested_model is None.
Returns an error if the resolved endpoint is not in a Ready state.
Sourcepub fn route_for_context(
&self,
requested_model: Option<&str>,
required_context: usize,
) -> Result<&ModelEndpoint, RoutingError>
pub fn route_for_context( &self, requested_model: Option<&str>, required_context: usize, ) -> Result<&ModelEndpoint, RoutingError>
Route with context-length awareness: pick a model that can accommodate the required context length.
If a specific model is requested, validates it has sufficient context. If no model is specified, finds the default model that fits, or falls back to any available model with sufficient context capacity.
Sourcepub fn models_list(&self) -> Vec<ModelListEntry>
pub fn models_list(&self) -> Vec<ModelListEntry>
OpenAI-compatible /v1/models list.
Returns an entry for every available endpoint in the registry.
Sourcepub fn registry(&self) -> &ModelRegistry
pub fn registry(&self) -> &ModelRegistry
Immutable access to the underlying registry.
Sourcepub fn registry_mut(&mut self) -> &mut ModelRegistry
pub fn registry_mut(&mut self) -> &mut ModelRegistry
Mutable access to the underlying registry.
Auto Trait Implementations§
impl Freeze for ModelRouter
impl RefUnwindSafe for ModelRouter
impl Send for ModelRouter
impl Sync for ModelRouter
impl Unpin for ModelRouter
impl UnsafeUnpin for ModelRouter
impl UnwindSafe for ModelRouter
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