Skip to main content

Model

Trait Model 

Source
pub trait Model: Send + Sync {
    // Required methods
    fn chat<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [ChatMessage],
        config: &'life2 ModelConfig,
        callback: Option<StreamCallback>,
    ) -> Pin<Box<dyn Future<Output = Result<ModelResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn capabilities(&self) -> &ModelCapabilities;
    fn name(&self) -> &str;

    // Provided method
    fn list_models<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Core trait that all model adapters implement.

chat() streams typed StreamEvents (text, reasoning, tool calls, completion) through the optional callback and returns a final ModelResponse. Adapters own the translation between provider-native stream shapes and the typed event surface — see OllamaAdapter::chat for the reference impl.

Required Methods§

Source

fn chat<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [ChatMessage], config: &'life2 ModelConfig, callback: Option<StreamCallback>, ) -> Pin<Box<dyn Future<Output = Result<ModelResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send a chat conversation to the model. If a callback is supplied the adapter streams typed events; otherwise it does a single blocking request and returns the response.

Source

fn capabilities(&self) -> &ModelCapabilities

Capabilities advertised by this model — does it support tools, vision, what reasoning controls, max context. Adapters return a ModelCapabilities populated at construction time.

Source

fn name(&self) -> &str

Get the model identifier (e.g., “ollama/tinyllama”)

Provided Methods§

Source

fn list_models<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List available models from this backend.

Default impl returns Unsupported — appropriate for providers that have no /models endpoint (Anthropic, raw Bedrock). Ollama and OpenAI-compatible adapters override.

Implementors§