Skip to main content

mermaid_cli/models/
traits.rs

1//! Core Model trait - the single interface for model interactions
2//!
3//! Adapters implement this trait directly. No intermediate layers.
4
5use async_trait::async_trait;
6
7use super::config::ModelConfig;
8use super::error::Result;
9use super::types::{ChatMessage, ModelResponse, StreamCallback};
10
11/// Core trait that all model adapters implement
12///
13/// This is the only abstraction layer between user code and model providers.
14#[async_trait]
15pub trait Model: Send + Sync {
16    /// Send a chat conversation to the model and get a response
17    async fn chat(
18        &self,
19        messages: &[ChatMessage],
20        config: &ModelConfig,
21        stream_callback: Option<StreamCallback>,
22    ) -> Result<ModelResponse>;
23
24    /// Get the model identifier (e.g., "ollama/tinyllama")
25    fn name(&self) -> &str;
26
27    /// List available models from this backend
28    async fn list_models(&self) -> Result<Vec<String>>;
29}