rust_agent/models/
chat.rs

1// Chat model interface and related structure definitions
2use anyhow::Error;
3use crate::models::message::{ChatMessage, TokenUsage};
4
5// Simplified chat completion structure
6pub struct ChatCompletion {
7    pub message: ChatMessage,
8    pub usage: Option<TokenUsage>,
9    pub model_name: String,
10}
11
12// Chat model interface
13pub trait ChatModel: Send + Sync {
14    // Basic model information
15    fn model_name(&self) -> Option<&str> {
16        None
17    }
18
19    // Model base URL
20    fn base_url(&self) -> String {
21        "https://api.openai.com/v1".to_string()
22    }
23    
24    // Core method: handle chat messages
25    fn invoke(&self, messages: Vec<ChatMessage>) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<ChatCompletion, Error>> + Send + '_>> {
26        let _messages = messages;
27        Box::pin(async move {
28            Err(Error::msg("The model does not implement the invoke method"))
29        })
30    }
31}