mod anthropic;
mod errors;
pub mod gemini;
mod openai;
pub use anthropic::AnthropicProtocol;
pub use errors::{ProtocolError, ProtocolResult};
pub use gemini::GeminiProtocol;
pub use openai::OpenAIProtocol;
use bamboo_domain::Message;
pub trait FromProvider<T>: Sized {
fn from_provider(value: T) -> ProtocolResult<Self>;
}
pub trait ToProvider<T>: Sized {
fn to_provider(&self) -> ProtocolResult<T>;
}
pub trait FromProviderBatch<T>: Sized {
fn from_provider_batch(values: Vec<T>) -> ProtocolResult<Vec<Self>>;
}
pub trait ToProviderBatch<T>: Sized {
fn to_provider_batch(&self) -> ProtocolResult<Vec<T>>;
}
impl FromProviderBatch<crate::llm::api::models::ChatMessage> for Message {
fn from_provider_batch(
values: Vec<crate::llm::api::models::ChatMessage>,
) -> ProtocolResult<Vec<Self>> {
values.into_iter().map(Self::from_provider).collect()
}
}
impl ToProviderBatch<crate::llm::api::models::ChatMessage> for Vec<Message> {
fn to_provider_batch(&self) -> ProtocolResult<Vec<crate::llm::api::models::ChatMessage>> {
self.iter().map(|msg| msg.to_provider()).collect()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_trait_bounds() {
fn assert_from_provider<T, U>()
where
T: FromProvider<U>,
{
}
fn assert_to_provider<T, U>()
where
T: ToProvider<U>,
{
}
assert_from_provider::<Message, crate::llm::api::models::ChatMessage>();
assert_to_provider::<Message, crate::llm::api::models::ChatMessage>();
}
}