diff options
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs index 96a6849..989a060 100644 --- a/src/config.rs +++ b/src/config.rs | |||
| @@ -10,8 +10,13 @@ pub struct Config { | |||
| 10 | pub copyparty_url: String, | 10 | pub copyparty_url: String, |
| 11 | pub copyparty_url_upload: String, | 11 | pub copyparty_url_upload: String, |
| 12 | pub copyparty_password: Option<String>, | 12 | pub copyparty_password: Option<String>, |
| 13 | /// Deprecated – use llm_api_key instead | ||
| 13 | pub openrouter_api_key: Option<String>, | 14 | pub openrouter_api_key: Option<String>, |
| 15 | /// Deprecated – use llm_model instead | ||
| 14 | pub openrouter_model: Option<String>, | 16 | pub openrouter_model: Option<String>, |
| 17 | pub llm_api_key: Option<String>, | ||
| 18 | pub llm_model: Option<String>, | ||
| 19 | pub llm_api_url: String, | ||
| 15 | pub database_path: String, | 20 | pub database_path: String, |
| 16 | } | 21 | } |
| 17 | 22 | ||
| @@ -72,6 +77,24 @@ const ENV_VARS: &[EnvVar] = &[ | |||
| 72 | description: "OpenRouter model", | 77 | description: "OpenRouter model", |
| 73 | }, | 78 | }, |
| 74 | EnvVar { | 79 | EnvVar { |
| 80 | name: "LLM_API_KEY", | ||
| 81 | required: false, | ||
| 82 | default: None, | ||
| 83 | description: "LLM API key (takes priority over OPENROUTER_API_KEY)", | ||
| 84 | }, | ||
| 85 | EnvVar { | ||
| 86 | name: "LLM_MODEL", | ||
| 87 | required: false, | ||
| 88 | default: None, | ||
| 89 | description: "LLM model name (takes priority over OPENROUTER_MODEL)", | ||
| 90 | }, | ||
| 91 | EnvVar { | ||
| 92 | name: "LLM_API_URL", | ||
| 93 | required: false, | ||
| 94 | default: Some("https://openrouter.ai/api/v1/chat/completions"), | ||
| 95 | description: "LLM API full URL including /chat/completions path", | ||
| 96 | }, | ||
| 97 | EnvVar { | ||
| 75 | name: "SENATOR_DB_PATH", | 98 | name: "SENATOR_DB_PATH", |
| 76 | required: false, | 99 | required: false, |
| 77 | default: Some("data/senator.db"), | 100 | default: Some("data/senator.db"), |
| @@ -126,6 +149,19 @@ pub fn check_env_vars() { | |||
| 126 | 149 | ||
| 127 | impl Config { | 150 | impl Config { |
| 128 | pub fn from_env() -> Self { | 151 | pub fn from_env() -> Self { |
| 152 | let openrouter_api_key = env::var("OPENROUTER_API_KEY").ok(); | ||
| 153 | let openrouter_model = env::var("OPENROUTER_MODEL").ok(); | ||
| 154 | let llm_api_key = env::var("LLM_API_KEY").ok(); | ||
| 155 | let llm_model = env::var("LLM_MODEL").ok(); | ||
| 156 | |||
| 157 | // Warn about deprecated env vars (mirrors Python's BACKWARD_COMPAT_MSG) | ||
| 158 | if openrouter_api_key.is_some() && llm_api_key.is_none() { | ||
| 159 | tracing::warn!("OPENROUTER_API_KEY is deprecated. Use LLM_API_KEY instead."); | ||
| 160 | } | ||
| 161 | if openrouter_model.is_some() && llm_model.is_none() { | ||
| 162 | tracing::warn!("OPENROUTER_MODEL is deprecated. Use LLM_MODEL instead."); | ||
| 163 | } | ||
| 164 | |||
| 129 | Self { | 165 | Self { |
| 130 | token: env::var("TOKEN").expect("Missing TOKEN"), | 166 | token: env::var("TOKEN").expect("Missing TOKEN"), |
| 131 | status_channel_id: env::var("STATUS_CHANNEL_ID") | 167 | status_channel_id: env::var("STATUS_CHANNEL_ID") |
| @@ -137,9 +173,32 @@ impl Config { | |||
| 137 | copyparty_url_upload: env::var("COPYPARTY_URL_UPLOAD") | 173 | copyparty_url_upload: env::var("COPYPARTY_URL_UPLOAD") |
| 138 | .unwrap_or_else(|_| "http://localhost:3939".into()), | 174 | .unwrap_or_else(|_| "http://localhost:3939".into()), |
| 139 | copyparty_password: env::var("COPYPARTY_PASSWORD").ok(), | 175 | copyparty_password: env::var("COPYPARTY_PASSWORD").ok(), |
| 140 | openrouter_api_key: env::var("OPENROUTER_API_KEY").ok(), | 176 | openrouter_api_key, |
| 141 | openrouter_model: env::var("OPENROUTER_MODEL").ok(), | 177 | openrouter_model, |
| 178 | llm_api_key, | ||
| 179 | llm_model, | ||
| 180 | llm_api_url: env::var("LLM_API_URL") | ||
| 181 | .unwrap_or_else(|_| "https://openrouter.ai/api/v1/chat/completions".into()), | ||
| 142 | database_path: env::var("SENATOR_DB_PATH").unwrap_or_else(|_| "data/senator.db".into()), | 182 | database_path: env::var("SENATOR_DB_PATH").unwrap_or_else(|_| "data/senator.db".into()), |
| 143 | } | 183 | } |
| 144 | } | 184 | } |
| 185 | |||
| 186 | /// Resolve the effective LLM config: (api_url, api_key, model). | ||
| 187 | /// LLM_* vars take priority; falls back to OPENROUTER_* for backward compat. | ||
| 188 | pub fn resolve_llm(&self) -> (String, String, String) { | ||
| 189 | let api_url = self.llm_api_url.clone(); | ||
| 190 | let api_key = self | ||
| 191 | .llm_api_key | ||
| 192 | .clone() | ||
| 193 | .or_else(|| self.openrouter_api_key.clone()) | ||
| 194 | .unwrap_or_default(); | ||
| 195 | let model = self | ||
| 196 | .llm_model | ||
| 197 | .clone() | ||
| 198 | .or_else(|| self.openrouter_model.clone()) | ||
| 199 | .unwrap_or_else(|| { | ||
| 200 | "cognitivecomputations/dolphin-mistral-24b-venice-edition:free".into() | ||
| 201 | }); | ||
| 202 | (api_url, api_key, model) | ||
| 203 | } | ||
| 145 | } | 204 | } |
