ricecoder_providers/provider/
mod.rs

1//! Provider trait and registry
2
3use 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
14/// A stream of chat completion responses
15pub type ChatStream =
16    Box<dyn futures::Stream<Item = Result<ChatResponse, ProviderError>> + Send + Unpin>;
17
18/// Core trait that all providers must implement
19#[async_trait]
20pub trait Provider: Send + Sync {
21    /// Get the provider's unique identifier
22    fn id(&self) -> &str;
23
24    /// Get the provider's human-readable name
25    fn name(&self) -> &str;
26
27    /// Get the list of available models
28    fn models(&self) -> Vec<ModelInfo>;
29
30    /// Send a chat completion request
31    async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError>;
32
33    /// Stream a chat completion response
34    async fn chat_stream(&self, request: ChatRequest) -> Result<ChatStream, ProviderError>;
35
36    /// Count tokens for content
37    fn count_tokens(&self, content: &str, model: &str) -> Result<usize, ProviderError>;
38
39    /// Check if the provider is available and healthy
40    async fn health_check(&self) -> Result<bool, ProviderError>;
41}