Skip to content

Commit 0fa746f

Browse files
authored
fix: Add client-side modelName mapping for backward compatibility (#2604)
* add mapping * adjust import location * compare name first
1 parent e25efa8 commit 0fa746f

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

crates/chat-cli/src/cli/chat/cli/model.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,27 @@ fn get_fallback_models() -> Vec<ModelInfo> {
196196
context_window_tokens: 200_000,
197197
},
198198
ModelInfo {
199-
model_name: Some("claude-4-sonnet".to_string()),
200-
model_id: "claude-4-sonnet".to_string(),
199+
model_name: Some("claude-sonnet-4".to_string()),
200+
model_id: "claude-sonnet-4".to_string(),
201201
context_window_tokens: 200_000,
202202
},
203203
]
204204
}
205+
206+
pub fn normalize_model_name(name: &str) -> &str {
207+
match name {
208+
"claude-4-sonnet" => "claude-sonnet-4",
209+
// can add more mapping for backward compatibility
210+
_ => name,
211+
}
212+
}
213+
214+
pub fn find_model<'a>(models: &'a [ModelInfo], name: &str) -> Option<&'a ModelInfo> {
215+
let normalized = normalize_model_name(name);
216+
models.iter().find(|m| {
217+
m.model_name
218+
.as_deref()
219+
.is_some_and(|n| n.eq_ignore_ascii_case(normalized))
220+
|| m.model_id.eq_ignore_ascii_case(normalized)
221+
})
222+
}

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ use crate::auth::AuthError;
133133
use crate::auth::builder_id::is_idc_user;
134134
use crate::cli::agent::Agents;
135135
use crate::cli::chat::cli::SlashCommand;
136+
use crate::cli::chat::cli::model::find_model;
136137
use crate::cli::chat::cli::prompts::{
137138
GetPromptError,
138139
PromptsSubcommand,
@@ -315,13 +316,7 @@ impl ChatArgs {
315316
// Otherwise, CLI will use a default model when starting chat
316317
let (models, default_model_opt) = get_available_models(os).await?;
317318
let model_id: Option<String> = if let Some(requested) = self.model.as_ref() {
318-
let requested_lower = requested.to_lowercase();
319-
if let Some(m) = models.iter().find(|m| {
320-
m.model_name
321-
.as_deref()
322-
.is_some_and(|n| n.eq_ignore_ascii_case(&requested_lower))
323-
|| m.model_id.eq_ignore_ascii_case(&requested_lower)
324-
}) {
319+
if let Some(m) = find_model(&models, requested) {
325320
Some(m.model_id.clone())
326321
} else {
327322
let available = models
@@ -332,14 +327,9 @@ impl ChatArgs {
332327
bail!("Model '{}' does not exist. Available models: {}", requested, available);
333328
}
334329
} else if let Some(saved) = os.database.settings.get_string(Setting::ChatDefaultModel) {
335-
if let Some(m) = models.iter().find(|m| {
336-
m.model_name.as_deref().is_some_and(|n| n.eq_ignore_ascii_case(&saved))
337-
|| m.model_id.eq_ignore_ascii_case(&saved)
338-
}) {
339-
Some(m.model_id.clone())
340-
} else {
341-
Some(default_model_opt.model_id.clone())
342-
}
330+
find_model(&models, &saved)
331+
.map(|m| m.model_id.clone())
332+
.or(Some(default_model_opt.model_id.clone()))
343333
} else {
344334
Some(default_model_opt.model_id.clone())
345335
};

0 commit comments

Comments
 (0)