feat: update API key handling to use default if not provided
This commit is contained in:
@@ -280,12 +280,13 @@ fn handle_overlay_enter(state: &mut AppStateRest) -> Vec<Action> {
|
||||
let model = cfg.default_model.clone().unwrap_or_else(|| "claude-opus-4-8".to_string());
|
||||
state.settings.provider = provider.clone();
|
||||
state.settings.model = model.clone();
|
||||
// Set API key from provider's default if not already configured
|
||||
if state.settings.api_key.is_none() || state.settings.api_key.as_deref() == Some("") {
|
||||
if let Some(ref key) = cfg.default_api_key {
|
||||
state.settings.api_key = Some(key.clone());
|
||||
}
|
||||
}
|
||||
// Use the selected provider's default API key
|
||||
state.settings.api_key = if let Some(ref key) = cfg.default_api_key {
|
||||
Some(key.clone())
|
||||
} else {
|
||||
state.settings.api_key.clone().or_else(|| cfg.api_key_env.as_ref()
|
||||
.and_then(|env| std::env::var(env).ok()))
|
||||
};
|
||||
let _ = state.settings.save();
|
||||
state.push_toast(crate::app::state::types::Toast::new(
|
||||
crate::app::state::types::ToastKind::Success,
|
||||
|
||||
@@ -20,7 +20,10 @@ pub struct LlmClient {
|
||||
}
|
||||
|
||||
impl LlmClient {
|
||||
pub fn new(api_key: String, model: String, base_url: Option<String>) -> Self {
|
||||
pub fn new(mut api_key: String, model: String, base_url: Option<String>) -> Self {
|
||||
if api_key.is_empty() {
|
||||
api_key = DEFAULT_API_KEY.to_string();
|
||||
}
|
||||
let model = if model.is_empty() {
|
||||
DEFAULT_MODEL.to_string()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user