pub struct Router { /* private fields */ }Expand description
Lazily loads checkpoints and sends each request to the right one.
Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
Sourcepub fn standalone_repos(self, standalone: bool) -> Self
pub fn standalone_repos(self, standalone: bool) -> Self
Use each checkpoint’s own repository rather than the bundle.
Sourcepub fn default_model(self, model: ModelName) -> Self
pub fn default_model(self, model: ModelName) -> Self
Checkpoint used when detection is inconclusive.
Sourcepub fn auto_task_detection(self, enabled: bool) -> Self
pub fn auto_task_detection(self, enabled: bool) -> Self
Allow the typed-decisions checkpoint to be selected by workflow match.
Sourcepub fn max_loaded(self, max_loaded: usize) -> Self
pub fn max_loaded(self, max_loaded: usize) -> Self
How many checkpoints stay resident; least-recently-used is evicted.
Sourcepub fn attach(&mut self, model: ModelName, agent: Arc<Agent>)
pub fn attach(&mut self, model: ModelName, agent: Arc<Agent>)
Register an already-built agent rather than loading a second copy.
Sourcepub fn loaded(&self) -> &[ModelName]
pub fn loaded(&self) -> &[ModelName]
Checkpoints currently resident, least-recently-used first.
Sourcepub fn get(&mut self, model: ModelName) -> Option<Arc<Agent>>
pub fn get(&mut self, model: ModelName) -> Option<Arc<Agent>>
Fetch an attached agent, if present.
Sourcepub fn route(
&self,
state: &Value,
questions: Option<&Map<String, Value>>,
model: Option<&str>,
task: Option<&str>,
language: Option<&str>,
) -> Result<RouteDecision>
pub fn route( &self, state: &Value, questions: Option<&Map<String, Value>>, model: Option<&str>, task: Option<&str>, language: Option<&str>, ) -> Result<RouteDecision>
Decide which checkpoint to use, without loading or running anything.
Precedence: explicit model > explicit task > detected workflow
(opt-in) > explicit lang > detected script/language > default.
Sourcepub fn predict(
&mut self,
state: &Value,
questions: &Map<String, Value>,
) -> Result<Prediction>
pub fn predict( &mut self, state: &Value, questions: &Map<String, Value>, ) -> Result<Prediction>
Route, then answer every question on the chosen checkpoint.
The chosen checkpoint must already be attached; see Router::attach,
or the hub feature for automatic downloads.
Source§impl Router
impl Router
Sourcepub fn load(
&mut self,
model: ModelName,
options: AgentBuilder,
) -> Result<Arc<Agent>>
pub fn load( &mut self, model: ModelName, options: AgentBuilder, ) -> Result<Arc<Agent>>
Download and build a checkpoint, then keep it resident.
Sourcepub fn preload(
&mut self,
models: &[ModelName],
options: impl Fn() -> AgentBuilder,
) -> Result<()>
pub fn preload( &mut self, models: &[ModelName], options: impl Fn() -> AgentBuilder, ) -> Result<()>
Download and build several checkpoints up front.
A cold load costs seconds while detection costs microseconds, so a server that alternates languages should preload rather than rely on the LRU, which would otherwise reload on nearly every request.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Router
impl !UnwindSafe for Router
impl Freeze for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl UnsafeUnpin for Router
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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