Skip to main content

Model

Trait Model 

Source
pub trait Model: Sized + Clone {
    // Required methods
    fn send(
        &self,
        request: &Request,
    ) -> impl Future<Output = Result<Response>> + Send;
    fn stream(
        &self,
        request: Request,
    ) -> impl Stream<Item = Result<StreamChunk>> + Send;
    fn active_model(&self) -> CompactString;

    // Provided method
    fn context_limit(&self, model: &str) -> usize { ... }
}
Expand description

Unified LLM provider trait.

Abstracts any LLM provider — single-backend (DeepSeek, Claude) or multi-model registry (ProviderManager). All implementations take &Request directly; no associated config type.

Constructors are inherent methods on each provider — never called polymorphically.

Required Methods§

Source

fn send( &self, request: &Request, ) -> impl Future<Output = Result<Response>> + Send

Send a chat completion request.

Source

fn stream( &self, request: Request, ) -> impl Stream<Item = Result<StreamChunk>> + Send

Stream a chat completion response.

Source

fn active_model(&self) -> CompactString

Get the active/default model name.

Provided Methods§

Source

fn context_limit(&self, model: &str) -> usize

Resolve the context limit for a model name.

Default implementation uses the static prefix-matching map.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Model for ()

() as a no-op Model for testing (panics on send/stream).

Source§

async fn send(&self, _request: &Request) -> Result<Response>

Source§

fn stream( &self, _request: Request, ) -> impl Stream<Item = Result<StreamChunk>> + Send

Source§

fn context_limit(&self, _model: &str) -> usize

Source§

fn active_model(&self) -> CompactString

Implementors§