Skip to main content

rs_agent/models/
mod.rs

1use async_trait::async_trait;
2
3use crate::error::{AgentError, Result};
4use crate::types::{File, GenerationChunk, GenerationResponse, Message};
5use futures::stream::BoxStream;
6
7/// LLM model interface
8#[async_trait]
9pub trait LLM: Send + Sync {
10    /// Generates a response from the model
11    async fn generate(
12        &self,
13        messages: Vec<Message>,
14        files: Option<Vec<File>>,
15    ) -> Result<GenerationResponse>;
16
17    /// Generates a streaming response from the model
18    async fn stream_generate(
19        &self,
20        _messages: Vec<Message>,
21        _files: Option<Vec<File>>,
22    ) -> Result<BoxStream<'static, Result<GenerationChunk>>> {
23        Err(AgentError::ModelError(
24            "Streaming not implemented for this provider".into(),
25        ))
26    }
27
28    /// Returns the model name
29    fn model_name(&self) -> &str;
30}
31
32// LLM provider implementations
33#[cfg(feature = "gemini")]
34pub mod gemini;
35
36#[cfg(feature = "ollama")]
37pub mod ollama;
38
39#[cfg(feature = "anthropic")]
40pub mod anthropic;
41
42#[cfg(feature = "openai")]
43pub mod openai;
44
45// Re-export providers
46#[cfg(feature = "gemini")]
47pub use gemini::GeminiLLM;
48
49#[cfg(feature = "ollama")]
50pub use ollama::OllamaLLM;
51
52#[cfg(feature = "anthropic")]
53pub use anthropic::AnthropicLLM;
54
55#[cfg(feature = "openai")]
56pub use openai::OpenAILLM;