Skip to content

Commit edee849

Browse files
committed
add mapping
1 parent e25efa8 commit edee849

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,26 @@ 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+
[name, normalized].iter().any(|n| {
218+
m.model_id.eq_ignore_ascii_case(n) || m.model_name.as_deref().is_some_and(|mn| mn.eq_ignore_ascii_case(n))
219+
})
220+
})
221+
}

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod server_messenger;
1616
mod skim_integration;
1717
mod token_counter;
1818
pub mod tool_manager;
19+
use crate::cli::chat::cli::model::find_model;
1920
pub mod tools;
2021
pub mod util;
2122
use std::borrow::Cow;
@@ -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)