use async_trait::async_trait;
use futures::stream::BoxStream;
use crate::{
ChatCompletionChunk, ChatCompletionRequest, ChatCompletionResponse, EmbeddingsRequest,
EmbeddingsResponse, ModelInfo, ModelPricing, ProviderError, RequestContext,
};
#[async_trait]
pub trait Provider: Send + Sync {
fn id(&self) -> &'static str;
fn models(&self) -> Vec<ModelInfo>;
fn pricing(&self, model: &str) -> Option<ModelPricing>;
fn fee_multiplier(&self) -> f64 {
1.0
}
async fn chat_completion(
&self,
req: ChatCompletionRequest,
ctx: &RequestContext,
) -> Result<ChatCompletionResponse, ProviderError>;
async fn chat_completion_stream(
&self,
req: ChatCompletionRequest,
ctx: &RequestContext,
) -> Result<BoxStream<'static, Result<ChatCompletionChunk, ProviderError>>, ProviderError>;
async fn embeddings(
&self,
_req: EmbeddingsRequest,
_ctx: &RequestContext,
) -> Result<EmbeddingsResponse, ProviderError> {
Err(ProviderError::Unsupported(format!(
"{} does not support embeddings",
self.id()
)))
}
async fn health_check(&self) -> Result<(), ProviderError> {
Ok(())
}
}