use crate::prelude::*;
pub const LMSTUDIO_HOST: &str = "http://localhost:1234";
pub const OPENAI_HOST: &str = "https://api.openai.com";
pub const CEREBRAS_HOST: &str = "https://api.cerebras.ai";
pub const OPENROUTER_HOST: &str = "https://openrouter.ai/api";
pub const PERPLEXITY_HOST: &str = "https://api.perplexity.ai";
pub const ANTHROPIC_HOST: &str = "https://api.anthropic.com";
pub const VOYAGE_HOST: &str = "https://api.voyageai.com";
pub const GOOGLE_HOST: &str = "https://generativelanguage.googleapis.com";
#[derive(Clone, Debug, Display, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ApiKind {
OpenAI,
Anthropic,
Google,
LmStudio,
ChatGpt,
Gemini,
Cerebras,
OpenRouter,
Perplexity,
Claude,
Voyage,
}
impl ApiKind {
pub fn is_openai(&self) -> bool {
!self.is_anthropic() && !self.is_google()
}
pub fn is_anthropic(&self) -> bool {
matches!(self, Self::Anthropic | Self::Claude)
}
pub fn is_google(&self) -> bool {
matches!(self, Self::Google | Self::Gemini)
}
pub fn is_lmstudio(&self) -> bool {
matches!(self, Self::LmStudio)
}
pub fn host(&self) -> &'static str {
match *self {
Self::OpenAI | Self::ChatGpt => OPENAI_HOST,
Self::Anthropic | Self::Claude => ANTHROPIC_HOST,
Self::Google | Self::Gemini => GOOGLE_HOST,
Self::LmStudio => LMSTUDIO_HOST,
Self::Cerebras => CEREBRAS_HOST,
Self::OpenRouter => OPENROUTER_HOST,
Self::Perplexity => PERPLEXITY_HOST,
Self::Voyage => VOYAGE_HOST,
}
}
pub fn completions_path(&self, model: &str) -> String {
if self.is_google() {
str!("v1beta/models/{}:streamGenerateContent?alt=sse", model)
} else if self.is_anthropic() {
str!("v1/messages")
} else {
str!("v1/chat/completions")
}
}
pub fn embeddings_path(&self, model: &str) -> String {
if self.is_google() {
str!("v1beta/models/{}:embedContent", model)
} else {
str!("v1/embeddings")
}
}
}
impl Default for ApiKind {
fn default() -> Self {
Self::OpenAI
}
}