use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum Provider {
Anthropic,
OpenAI,
Gemini,
Other,
}
impl Provider {
pub fn from_name(name: &str) -> Self {
match name {
"anthropic" => Self::Anthropic,
"openai" => Self::OpenAI,
"gemini" => Self::Gemini,
_ => Self::Other,
}
}
pub fn parse_strict(name: &str) -> Option<Self> {
match name {
"anthropic" => Some(Self::Anthropic),
"openai" => Some(Self::OpenAI),
"gemini" => Some(Self::Gemini),
_ => None,
}
}
pub fn infer_from_model(model: &str) -> Option<Self> {
let lower = model.to_lowercase();
if lower.starts_with("claude-") {
return Some(Self::Anthropic);
}
if lower.starts_with("gpt-") || lower.starts_with("chatgpt-") {
return Some(Self::OpenAI);
}
if lower.starts_with("gemini-") {
return Some(Self::Gemini);
}
None
}
pub fn as_str(&self) -> &'static str {
match self {
Self::Anthropic => "anthropic",
Self::OpenAI => "openai",
Self::Gemini => "gemini",
Self::Other => "other",
}
}
pub const ALL_CONCRETE: &'static [Provider] =
&[Provider::Anthropic, Provider::OpenAI, Provider::Gemini];
}