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,
        stream_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 name(&self) -> &str;
    fn is_local(&self) -> bool;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    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;

    // Provided methods
    fn has_model<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model_name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn capabilities(&self) -> ModelCapabilities { ... }
}
Expand description

Core trait that all model adapters implement

This is the only abstraction layer between user code and model providers.

Required Methods§

Source

fn chat<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [ChatMessage], config: &'life2 ModelConfig, stream_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 and get a response

Source

fn name(&self) -> &str

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

Source

fn is_local(&self) -> bool

Check if this is a local model (no external API calls)

Source

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

Check if the model backend is available and healthy

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

Provided Methods§

Source

fn has_model<'life0, 'life1, 'async_trait>( &'life0 self, model_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a specific model is available

Source

fn capabilities(&self) -> ModelCapabilities

Get model capabilities

Implementors§