ricecoder_providers/provider/
mod.rs1use async_trait::async_trait;
4
5use crate::error::ProviderError;
6use crate::models::{ChatRequest, ChatResponse, ModelInfo};
7
8pub mod manager;
9pub mod registry;
10
11pub use manager::ProviderManager;
12pub use registry::ProviderRegistry;
13
14pub type ChatStream =
16 Box<dyn futures::Stream<Item = Result<ChatResponse, ProviderError>> + Send + Unpin>;
17
18#[async_trait]
20pub trait Provider: Send + Sync {
21 fn id(&self) -> &str;
23
24 fn name(&self) -> &str;
26
27 fn models(&self) -> Vec<ModelInfo>;
29
30 async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError>;
32
33 async fn chat_stream(&self, request: ChatRequest) -> Result<ChatStream, ProviderError>;
35
36 fn count_tokens(&self, content: &str, model: &str) -> Result<usize, ProviderError>;
38
39 async fn health_check(&self) -> Result<bool, ProviderError>;
41}