use std::pin::Pin;
use async_trait::async_trait;
use futures_util::Stream;
use crate::error::ProviderError;
use crate::provider::{
ChatRequest, ChatResponse, ChatStreamEvent, EmbeddingRequest, EmbeddingResponse,
ProviderCapabilities, ProviderId,
};
pub type ProviderResult<T> = std::result::Result<T, ProviderError>;
pub type ChatStream = Pin<Box<dyn Stream<Item = ProviderResult<ChatStreamEvent>> + Send + 'static>>;
#[async_trait]
pub trait ChatProvider: Send + Sync {
fn id(&self) -> ProviderId;
fn capabilities(&self) -> ProviderCapabilities;
async fn complete(&self, request: ChatRequest) -> ProviderResult<ChatResponse>;
async fn stream(&self, request: ChatRequest) -> ProviderResult<ChatStream> {
let _ = request;
Err(ProviderError::Unsupported {
provider: self.id(),
feature: "chat_stream".to_owned(),
})
}
}
#[async_trait]
pub trait EmbeddingProvider: Send + Sync {
fn id(&self) -> ProviderId;
fn capabilities(&self) -> ProviderCapabilities;
async fn embed(&self, request: EmbeddingRequest) -> ProviderResult<EmbeddingResponse>;
}