Skip to main content

RoutingTextModel

Struct RoutingTextModel 

Source
pub struct RoutingTextModel { /* private fields */ }
Expand description

Dispatches by Prompt::tier to the adapter a venture configured for that tier, so venture code holds one Arc<dyn TextModel> and never matches on the tier or the vendor itself (ADR 0002). The router lives above the adapters, in core — the same place RoutingPush does, and for the same reason (ADR 0015).

This is the seam that lets a venture put drafting on one vendor and an independent judge on another without either module knowing.

A tier with no adapter is TextModelError::NotConfigured — deliberately not TextModelError::Rejected: nothing is wrong with the prompt, the venture simply did not wire that tier.

The router also enforces capability agreement (issue #665): a prompt that carries Prompt::tools is refused with TextModelError::Unsupported before a tier that does not report Capability::Tools for that tier is called, so a venture can assert once at compose time — router.supports(ModelTier::Strong, Capability::Tools) — that the tier it routed tools to can carry them. RoutingTextModel::supports answers for the single routed tier: the adapter wired for tier, or false when that tier is unwired. It is deliberately not an aggregate over every wired tier: a prompt goes to exactly one tier, so what matters is that tier’s answer, and a strong-tier judge that cannot carry tools must not make a fast-tier drafting model look incapable.

The same agreement covers images (issue #628): a prompt carrying a Part::Image is refused with TextModelError::Unsupported before a tier that does not report Capability::Images is called, and an over-limit prompt by Prompt::check_images before the tier is looked up at all.

Implementations§

Source§

impl RoutingTextModel

Source

pub fn new() -> Self

A router with no adapters: every tier is NotConfigured.

Source

pub fn fast(self, model: Arc<dyn TextModel>) -> Self

The adapter for ModelTier::Fast.

Source

pub fn strong(self, model: Arc<dyn TextModel>) -> Self

The adapter for ModelTier::Strong.

Source

pub fn route_for(&self, tier: ModelTier) -> Option<&Arc<dyn TextModel>>

The adapter that serves tier, if one is configured.

Trait Implementations§

Source§

impl Clone for RoutingTextModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoutingTextModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RoutingTextModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TextModel for RoutingTextModel

Source§

fn stream<'a>( &'a self, prompt: &'a Prompt, ) -> BoxStream<'a, Result<TextDelta, TextModelError>>

Forwards to the routed tier’s own stream — a native stream is not flattened through a buffered complete, or the router would turn every native stream into one round trip. The pre-flight refusals are the router’s own (routed), so an unwired tier, an over-limit prompt or a capability the tier lacks fails with the same error complete gives, as the stream’s first item.

Source§

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 Prompt, ) -> Pin<Box<dyn Future<Output = Result<Completion, TextModelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Completes prompt. Read more
Source§

fn supports(&self, tier: ModelTier, capability: Capability) -> bool

Whether this adapter can do capability for a prompt routed to tier. Defaults to false: a model that has not opted in is refused a tools-bearing prompt by RoutingTextModel and run_tool_loop before it is ever called, rather than sent a request it would silently drop the tools from. An adapter that carries Capability::Tools or Capability::Images overrides this to answer true for it. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<M> TextModelChunkedExt for M
where M: TextModel + ?Sized,

Source§

fn complete_chunked<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, max_chars: usize, prompt: impl for<'a> FnMut(usize, usize, &'a str) -> Prompt + Send + 'async_trait, ) -> Pin<Box<dyn Future<Output = Result<String, TextModelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, M: 'async_trait,

Completes text in chunks of at most max_chars chars: splits it with split_text_chunks, calls TextModel::complete once per chunk — sequentially, in order, chunk n asked only after n−1 answered — and reassembles the answers with reassemble_text_chunks. Read more
Source§

impl<M> TextModelExt for M
where M: TextModel + ?Sized,

Source§

fn complete_json<'life0, 'life1, 'async_trait>( &'life0 self, prompt: Prompt, schema: &'life1 Schema, ) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, M: 'async_trait,

Completes prompt and returns a value that conforms to schema. Read more
Source§

fn complete_as<'life0, 'async_trait, T>( &'life0 self, prompt: Prompt, ) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, T: JsonSchema + DeserializeOwned + Send + 'async_trait, M: 'async_trait,

Completes prompt and deserializes the conforming value into T, using T’s own schema (schema_for) as the constraint — the typed form of TextModelExt::complete_json. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more