pub mod capabilities;
pub mod client;
pub mod conversions;
pub mod extensions;
pub mod language_model;
pub mod settings;
use crate::core::DynamicModel;
use crate::core::capabilities::ModelName;
use crate::core::utils::validate_base_url;
use crate::error::Error;
use crate::providers::anthropic::client::AnthropicOptions;
use crate::providers::anthropic::settings::AnthropicProviderSettings;
use serde::Serialize;
pub const ANTHROPIC_API_VERSION: &str = "2023-06-01";
#[derive(Debug, Serialize, Clone)]
pub struct Anthropic<M: ModelName> {
pub settings: AnthropicProviderSettings,
options: AnthropicOptions,
_phantom: std::marker::PhantomData<M>,
}
impl<M: ModelName> Anthropic<M> {
pub fn builder() -> AnthropicBuilder<M> {
AnthropicBuilder::default()
}
}
impl Anthropic<DynamicModel> {
pub fn model_name(name: impl Into<String>) -> Self {
let settings = AnthropicProviderSettings::default();
let options = AnthropicOptions::builder()
.model(name.into())
.build()
.unwrap();
Anthropic {
settings,
options,
_phantom: std::marker::PhantomData,
}
}
}
impl<M: ModelName> Default for Anthropic<M> {
fn default() -> Self {
let settings = AnthropicProviderSettings::default();
let options = AnthropicOptions::builder()
.model(M::MODEL_NAME.to_string())
.build()
.unwrap();
Self {
settings,
options,
_phantom: std::marker::PhantomData,
}
}
}
pub struct AnthropicBuilder<M: ModelName> {
settings: AnthropicProviderSettings,
options: AnthropicOptions,
_phantom: std::marker::PhantomData<M>,
}
impl<M: ModelName> Default for AnthropicBuilder<M> {
fn default() -> Self {
let settings = AnthropicProviderSettings::default();
let options = AnthropicOptions::builder()
.model(M::MODEL_NAME.to_string())
.build()
.unwrap();
Self {
settings,
options,
_phantom: std::marker::PhantomData,
}
}
}
impl AnthropicBuilder<DynamicModel> {
pub fn model_name(mut self, model_name: impl Into<String>) -> Self {
self.options.model = model_name.into();
self
}
}
impl<M: ModelName> AnthropicBuilder<M> {
pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
self.settings.base_url = base_url.into();
self
}
pub fn api_key(mut self, api_key: impl Into<String>) -> Self {
self.settings.api_key = api_key.into();
self
}
pub fn provider_name(mut self, provider_name: impl Into<String>) -> Self {
self.settings.provider_name = provider_name.into();
self
}
pub fn path(mut self, path: impl Into<String>) -> Self {
self.settings.path = Some(path.into());
self
}
pub fn build(self) -> Result<Anthropic<M>, Error> {
let base_url = validate_base_url(&self.settings.base_url)?;
if self.settings.api_key.is_empty() {
return Err(Error::MissingField("api_key".to_string()));
}
Ok(Anthropic {
settings: AnthropicProviderSettings {
base_url,
..self.settings
},
options: self.options,
_phantom: std::marker::PhantomData,
})
}
}
pub use capabilities::*;