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";
#[derive(Clone, Debug, Display, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ApiKind {
OpenAI,
Anthropic,
LmStudio,
ChatGpt,
Cerebras,
OpenRouter,
Perplexity,
Claude,
Voyage,
}
impl ApiKind {
pub fn is_openai_standart(&self) -> bool {
use ApiKind::*;
*self != Anthropic && *self != Claude
}
pub fn is_anthropic_standart(&self) -> bool {
use ApiKind::*;
*self == Anthropic || *self == Claude
}
pub fn host(&self) -> &'static str {
use ApiKind::*;
match *self {
OpenAI | ChatGpt => OPENAI_HOST,
Anthropic | Claude => ANTHROPIC_HOST,
LmStudio => LMSTUDIO_HOST,
Cerebras => CEREBRAS_HOST,
OpenRouter => OPENROUTER_HOST,
Perplexity => PERPLEXITY_HOST,
Voyage => VOYAGE_HOST,
}
}
pub fn completions(&self) -> &'static str {
if self.is_anthropic_standart() {
"v1/messages"
} else {
"v1/chat/completions"
}
}
pub fn embeddings(&self) -> &'static str {
"v1/embeddings"
}
pub fn completions_url(&self) -> String {
fmt!("{}/{}", self.host(), self.completions())
}
pub fn embeddings_url(&self) -> String {
fmt!("{}/{}", self.host(), self.embeddings())
}
pub fn custom_completions_url(&self, url: &str) -> String {
fmt!(
"{url}{}{}",
if url.ends_with("/") { "" } else { "/" },
self.completions()
)
}
pub fn custom_embeddings_url(&self, url: &str) -> String {
fmt!(
"{url}{}{}",
if url.ends_with("/") { "" } else { "/" },
self.embeddings()
)
}
}
impl Default for ApiKind {
fn default() -> Self {
Self::OpenAI
}
}