use std::str::FromStr;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Capabilities {
pub chat: bool,
pub tools: bool,
pub streaming: bool,
pub vision: bool,
pub system_prompt: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ProviderKind {
Openai,
Anthropic,
Deepseek,
Gemini,
Cohere,
Ollama,
Groq,
Perplexity,
Xai,
}
impl ProviderKind {
pub fn all() -> &'static [ProviderKind] {
&[
ProviderKind::Openai,
ProviderKind::Anthropic,
ProviderKind::Deepseek,
ProviderKind::Gemini,
ProviderKind::Cohere,
ProviderKind::Ollama,
ProviderKind::Groq,
ProviderKind::Perplexity,
ProviderKind::Xai,
]
}
pub fn as_str(&self) -> &'static str {
match self {
ProviderKind::Openai => "openai",
ProviderKind::Anthropic => "anthropic",
ProviderKind::Deepseek => "deepseek",
ProviderKind::Gemini => "gemini",
ProviderKind::Cohere => "cohere",
ProviderKind::Ollama => "ollama",
ProviderKind::Groq => "groq",
ProviderKind::Perplexity => "perplexity",
ProviderKind::Xai => "xai",
}
}
}
impl FromStr for ProviderKind {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"openai" => Ok(ProviderKind::Openai),
"anthropic" => Ok(ProviderKind::Anthropic),
"deepseek" => Ok(ProviderKind::Deepseek),
"gemini" => Ok(ProviderKind::Gemini),
"cohere" => Ok(ProviderKind::Cohere),
"ollama" => Ok(ProviderKind::Ollama),
"groq" => Ok(ProviderKind::Groq),
"perplexity" => Ok(ProviderKind::Perplexity),
"xai" => Ok(ProviderKind::Xai),
other => Err(format!("unknown provider: {other}")),
}
}
}
#[cfg(feature = "clap")]
impl clap::ValueEnum for ProviderKind {
fn value_variants<'a>() -> &'a [Self] {
Self::all()
}
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
Some(clap::builder::PossibleValue::new(self.as_str()))
}
}
impl From<ProviderKind> for Capabilities {
fn from(kind: ProviderKind) -> Self {
match kind {
ProviderKind::Openai => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: true,
system_prompt: true,
},
ProviderKind::Anthropic => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: true,
system_prompt: true,
},
ProviderKind::Deepseek => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: false,
system_prompt: true,
},
ProviderKind::Gemini => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: true,
system_prompt: true,
},
ProviderKind::Cohere => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: false,
system_prompt: true,
},
ProviderKind::Ollama => Capabilities {
chat: true,
tools: false,
streaming: true,
vision: false,
system_prompt: true,
},
ProviderKind::Groq => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: false,
system_prompt: true,
},
ProviderKind::Perplexity => Capabilities {
chat: true,
tools: false,
streaming: true,
vision: false,
system_prompt: true,
},
ProviderKind::Xai => Capabilities {
chat: true,
tools: true,
streaming: true,
vision: false,
system_prompt: true,
},
}
}
}