use async_trait::async_trait;
use super::config::ModelConfig;
use super::error::Result;
use super::types::{ChatMessage, ModelResponse, StreamCallback};
#[async_trait]
pub trait Model: Send + Sync {
async fn chat(
&self,
messages: &[ChatMessage],
config: &ModelConfig,
stream_callback: Option<StreamCallback>,
) -> Result<ModelResponse>;
fn name(&self) -> &str;
fn is_local(&self) -> bool;
async fn health_check(&self) -> Result<()>;
async fn list_models(&self) -> Result<Vec<String>>;
async fn has_model(&self, model_name: &str) -> Result<bool> {
let models = self.list_models().await?;
Ok(models.iter().any(|m| {
m == model_name
|| m.starts_with(&format!("{}:", model_name))
|| model_name.starts_with(&format!("{}:", m))
}))
}
fn capabilities(&self) -> ModelCapabilities {
ModelCapabilities::default()
}
}
#[derive(Debug, Clone)]
pub struct ModelCapabilities {
pub max_context_length: usize,
pub supports_streaming: bool,
pub supports_functions: bool,
pub supports_vision: bool,
}
impl Default for ModelCapabilities {
fn default() -> Self {
Self {
max_context_length: 4096,
supports_streaming: true,
supports_functions: false,
supports_vision: false,
}
}
}