tftsr-devops_investigation/src-tauri/src/ai/provider.rs
Shaun Arman 74afb47eac
Some checks failed
Auto Tag / auto-tag (push) Successful in 3s
Test / rust-fmt-check (push) Successful in 58s
Release / build-macos-arm64 (push) Successful in 4m13s
Test / rust-clippy (push) Successful in 7m25s
Release / build-linux-amd64 (push) Has been cancelled
Release / build-windows-amd64 (push) Has been cancelled
Release / build-linux-arm64 (push) Has been cancelled
Test / rust-tests (push) Successful in 8m11s
Test / frontend-typecheck (push) Successful in 1m33s
Test / frontend-tests (push) Successful in 1m16s
fix: provider routing uses provider_type, Active badge, fmt
2026-03-31 08:05:13 -05:00

32 lines
1.0 KiB
Rust

use async_trait::async_trait;
use crate::ai::{ChatResponse, Message, ProviderInfo};
use crate::state::ProviderConfig;
#[async_trait]
pub trait Provider: Send + Sync {
fn name(&self) -> &str;
fn info(&self) -> ProviderInfo;
async fn chat(
&self,
messages: Vec<Message>,
config: &ProviderConfig,
) -> anyhow::Result<ChatResponse>;
}
pub fn create_provider(config: &ProviderConfig) -> Box<dyn Provider> {
// Match on provider_type (the kind), falling back to name for legacy configs
let kind = if config.provider_type.is_empty() {
config.name.as_str()
} else {
config.provider_type.as_str()
};
match kind {
"anthropic" => Box::new(crate::ai::anthropic::AnthropicProvider),
"gemini" => Box::new(crate::ai::gemini::GeminiProvider),
"mistral" => Box::new(crate::ai::mistral::MistralProvider),
"ollama" => Box::new(crate::ai::ollama::OllamaProvider),
_ => Box::new(crate::ai::openai::OpenAiProvider), // default: OpenAI-compatible
}
}