pub mod config;
pub mod gemini;
#[cfg(test)]
pub mod mock;
pub mod types;
use async_trait::async_trait;
use crate::{
error::Result,
messages::Message,
model::ModelConfig,
providers::types::ChatResponse
};
#[async_trait]
pub trait Provider: Send + Sync + std::fmt::Debug {
type Config: Send + Sync + std::fmt::Debug;
fn new(config: Self::Config) -> Self;
fn get_base_url(&self) -> &str;
fn get_predefined_models(&self) -> Result<Vec<String>>;
async fn chat(
&self,
model_config: ModelConfig,
message: Message,
chat_history: Vec<Message>,
) -> Result<ChatResponse>;
async fn prompt(
&self,
model_config: ModelConfig,
prompt: String,
) -> Result<ChatResponse>;
fn name(&self) -> &'static str;
fn supports_streaming(&self) -> bool {
false
}
fn supports_tools(&self) -> bool {
false
}
}
#[async_trait]
pub trait ProviderExt: Send + Sync + std::fmt::Debug {
async fn chat(
&self,
model_config: ModelConfig,
message: Message,
chat_history: Vec<Message>,
) -> Result<ChatResponse>;
async fn prompt(&self, model_config: ModelConfig, prompt: String) -> Result<ChatResponse>;
fn get_base_url(&self) -> &str;
fn get_predefined_models(&self) -> Result<Vec<String>>;
fn name(&self) -> &'static str;
fn supports_streaming(&self) -> bool {
false
}
fn supports_tools(&self) -> bool {
false
}
}
#[async_trait]
impl<T> ProviderExt for T
where
T: Provider + Send + Sync + std::fmt::Debug + 'static,
{
async fn chat(
&self,
model_config: ModelConfig,
message: Message,
chat_history: Vec<Message>,
) -> Result<ChatResponse> {
Provider::chat(self, model_config, message, chat_history).await
}
async fn prompt(&self, model_config: ModelConfig, prompt: String) -> Result<ChatResponse> {
Provider::prompt(self, model_config, prompt).await
}
fn get_base_url(&self) -> &str {
Provider::get_base_url(self)
}
fn get_predefined_models(&self) -> Result<Vec<String>> {
Provider::get_predefined_models(self)
}
fn name(&self) -> &'static str {
Provider::name(self)
}
fn supports_streaming(&self) -> bool {
Provider::supports_streaming(self)
}
fn supports_tools(&self) -> bool {
Provider::supports_tools(self)
}
}