1use potato_head::Provider;
2use serde::Serialize;
3
4pub trait ProviderSettings {
5 fn api_key(&self) -> &str;
6 fn api_url(&self) -> &str;
7 fn is_configured(&self) -> bool {
8 !self.api_key().is_empty() && !self.api_url().is_empty()
9 }
10}
11
12#[derive(Debug, Clone, Serialize)]
13pub struct OpenAISettings {
14 pub api_key: String,
15 pub api_url: String,
16}
17
18impl ProviderSettings for OpenAISettings {
19 fn api_key(&self) -> &str {
20 &self.api_key
21 }
22 fn api_url(&self) -> &str {
23 &self.api_url
24 }
25}
26
27impl Default for OpenAISettings {
28 fn default() -> Self {
29 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| "".to_string());
30 let env_api_url = std::env::var("OPENAI_API_URL").ok();
31 let api_url = env_api_url.unwrap_or_else(|| Provider::OpenAI.url().to_string());
32 Self { api_key, api_url }
33 }
34}
35
36#[derive(Debug, Clone, Serialize)]
37pub struct GeminiSettings {
38 pub api_key: String,
39 pub api_url: String,
40}
41
42impl ProviderSettings for GeminiSettings {
43 fn api_key(&self) -> &str {
44 &self.api_key
45 }
46 fn api_url(&self) -> &str {
47 &self.api_url
48 }
49}
50
51impl Default for GeminiSettings {
52 fn default() -> Self {
53 let api_key = std::env::var("GEMINI_API_KEY").unwrap_or_else(|_| "".to_string());
54 let env_api_url = std::env::var("GEMINI_API_URL").ok();
55 let api_url = env_api_url.unwrap_or_else(|| Provider::Gemini.url().to_string());
56 Self { api_key, api_url }
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Default)]
61pub struct LLMSettings {
62 pub openai_settings: OpenAISettings,
63 pub gemini_settings: GeminiSettings,
64}
65
66impl LLMSettings {
67 pub fn is_configured(&self) -> bool {
69 self.openai_settings.is_configured() || self.gemini_settings.is_configured()
70 }
71}