use crate::prelude::*;
#[derive(Clone, Copy, Debug, Display, Serialize, Deserialize, Eq, PartialEq, Hash, Default)]
#[serde(rename_all = "lowercase")]
pub enum ApiKind {
#[default]
OpenAi,
Anthropic,
Google,
}
impl ApiKind {
pub fn is_openai(&self) -> bool {
matches!(self, Self::OpenAi)
}
pub fn is_anthropic(&self) -> bool {
matches!(self, Self::Anthropic)
}
pub fn is_google(&self) -> bool {
matches!(self, Self::Google)
}
pub fn default_host(&self) -> &'static str {
match self {
ApiKind::OpenAi => "https://api.openai.com/v1",
ApiKind::Anthropic => "https://api.anthropic.com/v1",
ApiKind::Google => "https://generativelanguage.googleapis.com/v1beta",
}
}
pub fn default_env_var(&self) -> Option<&'static str> {
match self {
ApiKind::OpenAi => Some("OPENAI_API_KEY"),
ApiKind::Anthropic => Some("ANTHROPIC_API_KEY"),
ApiKind::Google => Some("GEMINI_API_KEY"),
}
}
pub fn completions_path(&self, model: &str) -> String {
match self {
Self::Google => format!("v1beta/models/{}:streamGenerateContent?alt=sse", model),
Self::Anthropic => "v1/messages".to_string(),
Self::OpenAi => "v1/chat/completions".to_string(),
}
}
pub fn embeddings_path(&self, model: &str) -> String {
match self {
Self::Google => format!("v1beta/models/{}:embedContent", model),
Self::OpenAi | Self::Anthropic => "v1/embeddings".to_string(),
}
}
}