From edee84983643e01f870321e95cb9e23965cf974c Mon Sep 17 00:00:00 2001 From: YIFAN LIU Date: Wed, 13 Aug 2025 14:40:11 -0700 Subject: [PATCH 1/3] add mapping --- crates/chat-cli/src/cli/chat/cli/model.rs | 21 +++++++++++++++++++-- crates/chat-cli/src/cli/chat/mod.rs | 20 +++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/chat-cli/src/cli/chat/cli/model.rs b/crates/chat-cli/src/cli/chat/cli/model.rs index 8d4dacd87d..2f9585ca42 100644 --- a/crates/chat-cli/src/cli/chat/cli/model.rs +++ b/crates/chat-cli/src/cli/chat/cli/model.rs @@ -196,9 +196,26 @@ fn get_fallback_models() -> Vec { context_window_tokens: 200_000, }, ModelInfo { - model_name: Some("claude-4-sonnet".to_string()), - model_id: "claude-4-sonnet".to_string(), + model_name: Some("claude-sonnet-4".to_string()), + model_id: "claude-sonnet-4".to_string(), context_window_tokens: 200_000, }, ] } + +pub fn normalize_model_name(name: &str) -> &str { + match name { + "claude-4-sonnet" => "claude-sonnet-4", + // can add more mapping for backward compatibility + _ => name, + } +} + +pub fn find_model<'a>(models: &'a [ModelInfo], name: &str) -> Option<&'a ModelInfo> { + let normalized = normalize_model_name(name); + models.iter().find(|m| { + [name, normalized].iter().any(|n| { + m.model_id.eq_ignore_ascii_case(n) || m.model_name.as_deref().is_some_and(|mn| mn.eq_ignore_ascii_case(n)) + }) + }) +} diff --git a/crates/chat-cli/src/cli/chat/mod.rs b/crates/chat-cli/src/cli/chat/mod.rs index 0941df73a3..56bf1fbb8f 100644 --- a/crates/chat-cli/src/cli/chat/mod.rs +++ b/crates/chat-cli/src/cli/chat/mod.rs @@ -16,6 +16,7 @@ mod server_messenger; mod skim_integration; mod token_counter; pub mod tool_manager; +use crate::cli::chat::cli::model::find_model; pub mod tools; pub mod util; use std::borrow::Cow; @@ -315,13 +316,7 @@ impl ChatArgs { // Otherwise, CLI will use a default model when starting chat let (models, default_model_opt) = get_available_models(os).await?; let model_id: Option = if let Some(requested) = self.model.as_ref() { - let requested_lower = requested.to_lowercase(); - if let Some(m) = models.iter().find(|m| { - m.model_name - .as_deref() - .is_some_and(|n| n.eq_ignore_ascii_case(&requested_lower)) - || m.model_id.eq_ignore_ascii_case(&requested_lower) - }) { + if let Some(m) = find_model(&models, requested) { Some(m.model_id.clone()) } else { let available = models @@ -332,14 +327,9 @@ impl ChatArgs { bail!("Model '{}' does not exist. Available models: {}", requested, available); } } else if let Some(saved) = os.database.settings.get_string(Setting::ChatDefaultModel) { - if let Some(m) = models.iter().find(|m| { - m.model_name.as_deref().is_some_and(|n| n.eq_ignore_ascii_case(&saved)) - || m.model_id.eq_ignore_ascii_case(&saved) - }) { - Some(m.model_id.clone()) - } else { - Some(default_model_opt.model_id.clone()) - } + find_model(&models, &saved) + .map(|m| m.model_id.clone()) + .or(Some(default_model_opt.model_id.clone())) } else { Some(default_model_opt.model_id.clone()) }; From f6c73f05b5b778d784b3dc6494b6f27789907a50 Mon Sep 17 00:00:00 2001 From: YIFAN LIU Date: Wed, 13 Aug 2025 15:41:37 -0700 Subject: [PATCH 2/3] adjust import location --- crates/chat-cli/src/cli/chat/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/chat-cli/src/cli/chat/mod.rs b/crates/chat-cli/src/cli/chat/mod.rs index 56bf1fbb8f..0d3b7b1d8c 100644 --- a/crates/chat-cli/src/cli/chat/mod.rs +++ b/crates/chat-cli/src/cli/chat/mod.rs @@ -16,7 +16,6 @@ mod server_messenger; mod skim_integration; mod token_counter; pub mod tool_manager; -use crate::cli::chat::cli::model::find_model; pub mod tools; pub mod util; use std::borrow::Cow; @@ -134,6 +133,7 @@ use crate::auth::AuthError; use crate::auth::builder_id::is_idc_user; use crate::cli::agent::Agents; use crate::cli::chat::cli::SlashCommand; +use crate::cli::chat::cli::model::find_model; use crate::cli::chat::cli::prompts::{ GetPromptError, PromptsSubcommand, From 03d5d2dfe7be82775fc40857e3168906b62288c6 Mon Sep 17 00:00:00 2001 From: YIFAN LIU Date: Wed, 13 Aug 2025 15:49:27 -0700 Subject: [PATCH 3/3] compare name first --- crates/chat-cli/src/cli/chat/cli/model.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/chat-cli/src/cli/chat/cli/model.rs b/crates/chat-cli/src/cli/chat/cli/model.rs index 2f9585ca42..91d1f507b5 100644 --- a/crates/chat-cli/src/cli/chat/cli/model.rs +++ b/crates/chat-cli/src/cli/chat/cli/model.rs @@ -214,8 +214,9 @@ pub fn normalize_model_name(name: &str) -> &str { pub fn find_model<'a>(models: &'a [ModelInfo], name: &str) -> Option<&'a ModelInfo> { let normalized = normalize_model_name(name); models.iter().find(|m| { - [name, normalized].iter().any(|n| { - m.model_id.eq_ignore_ascii_case(n) || m.model_name.as_deref().is_some_and(|mn| mn.eq_ignore_ascii_case(n)) - }) + m.model_name + .as_deref() + .is_some_and(|n| n.eq_ignore_ascii_case(normalized)) + || m.model_id.eq_ignore_ascii_case(normalized) }) }