use async_trait::async_trait;
use crate::error::LlmResult;
use crate::stream::ChatStream;
use crate::types::{ChatRequest, ChatResponse, EmbedRequest, EmbedResponse};
use crate::usage::CostEstimate;
#[async_trait]
pub trait LlmProvider: Send + Sync + 'static {
async fn chat(&self, req: ChatRequest) -> LlmResult<ChatResponse>;
async fn chat_stream(&self, req: ChatRequest) -> LlmResult<ChatStream>;
async fn embed(&self, req: EmbedRequest) -> LlmResult<EmbedResponse>;
fn name(&self) -> &'static str;
fn model(&self) -> &str;
fn estimate_cost(&self, _req: &ChatRequest) -> Option<CostEstimate> {
None
}
}
#[async_trait]
impl<T: LlmProvider + ?Sized> LlmProvider for std::sync::Arc<T> {
async fn chat(&self, req: ChatRequest) -> LlmResult<ChatResponse> {
(**self).chat(req).await
}
async fn chat_stream(&self, req: ChatRequest) -> LlmResult<ChatStream> {
(**self).chat_stream(req).await
}
async fn embed(&self, req: EmbedRequest) -> LlmResult<EmbedResponse> {
(**self).embed(req).await
}
fn name(&self) -> &'static str {
(**self).name()
}
fn model(&self) -> &str {
(**self).model()
}
fn estimate_cost(&self, req: &ChatRequest) -> Option<CostEstimate> {
(**self).estimate_cost(req)
}
}