Skip to content

Commit df7b9b8

Browse files
committed
remove auto, add 4.0 & settings impl
1 parent 0cc1b7a commit df7b9b8

File tree

5 files changed

+75
-47
lines changed

5 files changed

+75
-47
lines changed

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

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,23 @@ const ROTATING_TIPS: [&str; 14] = [
234234

235235
const GREETING_BREAK_POINT: usize = 80;
236236

237-
const MODEL_OPTIONS: [(&str, &str); 3] = [
238-
("Auto", ""),
239-
("Claude Sonnet 3.7", "CLAUDE_3_7_SONNET_20250219_V1_0"),
240-
("Claude Sonnet 3.5", "CLAUDE_3_5_SONNET_20241022_V2_0"),
237+
pub const MODEL_OPTIONS: [(&str, &str, &str); 3] = [
238+
// ("Auto", ""),
239+
(
240+
"Claude Sonnet 3.5",
241+
"claude-3.5-sonnet",
242+
"CLAUDE_3_5_SONNET_20241022_V2_0",
243+
),
244+
(
245+
"Claude Sonnet 3.7",
246+
"claude-3.7-sonnet",
247+
"CLAUDE_3_7_SONNET_20250219_V1_0",
248+
),
249+
("Claude Sonnet 4.0", "claude-4-sonnet", "CLAUDE_SONNET_4_20250514_V1_0"),
241250
];
242251

252+
pub const DEFAULT_MODEL_ID: &str = "CLAUDE_3_7_SONNET_20250219_V1_0";
253+
243254
const POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands <em>•</em> <green!>ctrl + j</green!> new lines <em>•</em> <green!>ctrl + s</green!> fuzzy search</black!>"};
244255
const SMALL_SCREEN_POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands
245256
<green!>ctrl + j</green!> new lines
@@ -421,16 +432,10 @@ pub async fn chat(
421432

422433
// If modelId is specified, verify it exists before starting the chat
423434
let model_id: Option<String> = if let Some(model_name) = model_name {
424-
match MODEL_OPTIONS.iter().find(|(name, _)| *name == model_name) {
425-
Some((name, id)) => {
426-
if *name == "Auto" {
427-
None // Auto maps to None
428-
} else {
429-
Some(id.to_string())
430-
}
431-
},
435+
match MODEL_OPTIONS.iter().find(|(_, name, _)| *name == model_name) {
436+
Some((_, _, id)) => Some(id.to_string()),
432437
None => {
433-
let available_names: Vec<&str> = MODEL_OPTIONS.iter().map(|(name, _)| *name).collect();
438+
let available_names: Vec<&str> = MODEL_OPTIONS.iter().map(|(_, name, _)| *name).collect();
434439
bail!(
435440
"Model '{}' does not exist. Available models: {}",
436441
model_name,
@@ -442,6 +447,9 @@ pub async fn chat(
442447
None
443448
};
444449

450+
// if let Some(ref id) = model_id {
451+
// database.set_last_used_model_id(id.clone())?;
452+
// }
445453
let conversation_id = Alphanumeric.sample_string(&mut rand::rng(), 9);
446454
info!(?conversation_id, "Generated new conversation id");
447455
let (prompt_request_sender, prompt_request_receiver) = std::sync::mpsc::channel::<Option<String>>();
@@ -598,10 +606,16 @@ impl ChatContext {
598606
let mut existing_conversation = false;
599607
let valid_model_id = match model_id {
600608
Some(id) => Some(id),
601-
None => match database.get_last_used_model_id() {
602-
Ok(Some(id)) => Some(id),
603-
Ok(None) | Err(_) => database.settings.get_string(Setting::UserDefaultModel),
604-
},
609+
None => database
610+
.settings
611+
.get_string(Setting::ChatDefaultModel)
612+
.and_then(|model_name| {
613+
MODEL_OPTIONS
614+
.iter()
615+
.find(|(_, name, _)| *name == model_name)
616+
.map(|(_, _, id)| id.to_string())
617+
})
618+
.or_else(|| Some(DEFAULT_MODEL_ID.to_string())),
605619
};
606620
let conversation_state = if resume_conversation {
607621
let prior = std::env::current_dir()
@@ -3080,7 +3094,7 @@ impl ChatContext {
30803094
let active_model_id = self.conversation_state.current_model_id.as_deref();
30813095
let labels: Vec<String> = MODEL_OPTIONS
30823096
.iter()
3083-
.map(|(label, model_id)| {
3097+
.map(|(label, _, model_id)| {
30843098
if (model_id.is_empty() && active_model_id.is_none()) || Some(*model_id) == active_model_id {
30853099
format!("{} (active)", label)
30863100
} else {
@@ -3090,7 +3104,7 @@ impl ChatContext {
30903104
.collect();
30913105
let default_index = MODEL_OPTIONS
30923106
.iter()
3093-
.position(|(_, model_id)| Some(*model_id) == active_model_id)
3107+
.position(|(_, _, model_id)| Some(*model_id) == active_model_id)
30943108
.unwrap_or(0);
30953109
let selection: Option<_> = match Select::with_theme(&crate::util::dialoguer_theme())
30963110
.with_prompt("Select a model for this chat session")
@@ -3113,17 +3127,17 @@ impl ChatContext {
31133127
queue!(self.output, style::ResetColor)?;
31143128

31153129
if let Some(index) = selection {
3116-
let (label, model_id) = MODEL_OPTIONS[index];
3130+
let (label, _, model_id) = MODEL_OPTIONS[index];
31173131
let model_id_str = model_id.to_string();
31183132

31193133
if model_id == "" {
31203134
self.conversation_state.current_model_id = None;
31213135
telemetry.update_model_id(None);
3122-
let _ = database.unset_last_used_model_id();
3136+
// let _ = database.unset_last_used_model_id();
31233137
} else {
31243138
self.conversation_state.current_model_id = Some(model_id_str.clone());
31253139
telemetry.update_model_id(Some(model_id_str.clone()));
3126-
let _ = database.set_last_used_model_id(model_id_str);
3140+
// let _ = database.set_last_used_model_id(model_id_str);
31273141
}
31283142

31293143
queue!(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ use anstream::{
1616
eprintln,
1717
println,
1818
};
19-
pub use chat::ConversationState;
2019
use chat::cli::Chat;
20+
pub use chat::{
21+
ConversationState,
22+
DEFAULT_MODEL_ID,
23+
MODEL_OPTIONS,
24+
};
2125
use clap::{
2226
ArgAction,
2327
CommandFactory,

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const IDC_REGION_KEY: &str = "auth.idc.region";
6060
// We include this key to remove for backwards compatibility
6161
const CUSTOMIZATION_STATE_KEY: &str = "api.selectedCustomization";
6262
const ROTATING_TIP_KEY: &str = "chat.greeting.rotating_tips_current_index";
63-
const LAST_USED_MODEL_ID: &str = "lastUsedModelId";
63+
// const LAST_USED_MODEL_ID: &str = "lastUsedModelId";
6464

6565
const MIGRATIONS: &[Migration] = migrations![
6666
"000_migration_table",
@@ -308,20 +308,20 @@ impl Database {
308308
Ok(tip)
309309
}
310310

311-
/// Get the model id used for last conversation state.
312-
pub fn get_last_used_model_id(&self) -> Result<Option<String>, DatabaseError> {
313-
self.get_json_entry::<String>(Table::State, LAST_USED_MODEL_ID)
314-
}
311+
// /// Get the model id used for last conversation state.
312+
// pub fn get_last_used_model_id(&self) -> Result<Option<String>, DatabaseError> {
313+
// self.get_json_entry::<String>(Table::State, LAST_USED_MODEL_ID)
314+
// }
315315

316-
/// Set the model id used for last conversation state.
317-
pub fn set_last_used_model_id(&mut self, last_used_model_id: String) -> Result<usize, DatabaseError> {
318-
self.set_json_entry(Table::State, LAST_USED_MODEL_ID, last_used_model_id)
319-
}
316+
// /// Set the model id used for last conversation state.
317+
// pub fn set_last_used_model_id(&mut self, last_used_model_id: String) -> Result<usize,
318+
// DatabaseError> { self.set_json_entry(Table::State, LAST_USED_MODEL_ID,
319+
// last_used_model_id) }
320320

321-
/// UnsSet the model id used for last conversation state.
322-
pub fn unset_last_used_model_id(&mut self) -> Result<(), DatabaseError> {
323-
self.delete_entry(Table::State, LAST_USED_MODEL_ID)
324-
}
321+
// /// UnsSet the model id used for last conversation state.
322+
// pub fn unset_last_used_model_id(&mut self) -> Result<(), DatabaseError> {
323+
// self.delete_entry(Table::State, LAST_USED_MODEL_ID)
324+
// }
325325

326326
/// Get a chat conversation given a path to the conversation.
327327
pub fn get_conversation_by_path(

crates/chat-cli/src/database/settings.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum Setting {
3131
McpInitTimeout,
3232
McpNoInteractiveTimeout,
3333
McpLoadedBefore,
34-
UserDefaultModel,
34+
ChatDefaultModel,
3535
}
3636

3737
impl AsRef<str> for Setting {
@@ -51,7 +51,7 @@ impl AsRef<str> for Setting {
5151
Self::McpInitTimeout => "mcp.initTimeout",
5252
Self::McpNoInteractiveTimeout => "mcp.noInteractiveTimeout",
5353
Self::McpLoadedBefore => "mcp.loadedBefore",
54-
Self::UserDefaultModel => "chat.userDefaultModel",
54+
Self::ChatDefaultModel => "chat.defaultModel",
5555
}
5656
}
5757
}
@@ -81,7 +81,7 @@ impl TryFrom<&str> for Setting {
8181
"mcp.initTimeout" => Ok(Self::McpInitTimeout),
8282
"mcp.noInteractiveTimeout" => Ok(Self::McpNoInteractiveTimeout),
8383
"mcp.loadedBefore" => Ok(Self::McpLoadedBefore),
84-
"chat.userDefaultModel" => Ok(Self::UserDefaultModel),
84+
"chat.defaultModel" => Ok(Self::ChatDefaultModel),
8585
_ => Err(DatabaseError::InvalidSetting(value.to_string())),
8686
}
8787
}
@@ -200,13 +200,13 @@ mod test {
200200
assert_eq!(settings.get(Setting::OldClientId), None);
201201
assert_eq!(settings.get(Setting::ShareCodeWhispererContent), None);
202202
assert_eq!(settings.get(Setting::McpLoadedBefore), None);
203-
assert_eq!(settings.get(Setting::UserDefaultModel), None);
203+
assert_eq!(settings.get(Setting::ChatDefaultModel), None);
204204

205205
settings.set(Setting::TelemetryEnabled, true).await.unwrap();
206206
settings.set(Setting::OldClientId, "test").await.unwrap();
207207
settings.set(Setting::ShareCodeWhispererContent, false).await.unwrap();
208208
settings.set(Setting::McpLoadedBefore, true).await.unwrap();
209-
settings.set(Setting::UserDefaultModel, "model 1").await.unwrap();
209+
settings.set(Setting::ChatDefaultModel, "model 1").await.unwrap();
210210

211211
assert_eq!(settings.get(Setting::TelemetryEnabled), Some(&Value::Bool(true)));
212212
assert_eq!(
@@ -219,7 +219,7 @@ mod test {
219219
);
220220
assert_eq!(settings.get(Setting::McpLoadedBefore), Some(&Value::Bool(true)));
221221
assert_eq!(
222-
settings.get(Setting::UserDefaultModel),
222+
settings.get(Setting::ChatDefaultModel),
223223
Some(&Value::String("model 1".to_string()))
224224
);
225225

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ use uuid::{
5454
use crate::api_client::Client as CodewhispererClient;
5555
use crate::auth::builder_id::get_start_url_and_region;
5656
use crate::aws_common::app_name;
57-
use crate::cli::CliRootCommands;
57+
use crate::cli::{
58+
CliRootCommands,
59+
DEFAULT_MODEL_ID,
60+
MODEL_OPTIONS,
61+
};
5862
use crate::database::settings::Setting;
5963
use crate::database::{
6064
Database,
@@ -151,10 +155,16 @@ impl Clone for TelemetryThread {
151155

152156
impl TelemetryThread {
153157
pub async fn new(env: &Env, database: &mut Database) -> Result<Self, TelemetryError> {
154-
let model_id = match database.get_last_used_model_id() {
155-
Ok(Some(id)) => Some(id),
156-
Ok(None) | Err(_) => database.settings.get_string(Setting::UserDefaultModel),
157-
};
158+
let model_id = database
159+
.settings
160+
.get_string(Setting::ChatDefaultModel)
161+
.and_then(|model_name| {
162+
MODEL_OPTIONS
163+
.iter()
164+
.find(|(_, name, _)| *name == model_name)
165+
.map(|(_, _, id)| id.to_string())
166+
})
167+
.or_else(|| Some(DEFAULT_MODEL_ID.to_string()));
158168
let current_model_id = Arc::new(RwLock::new(model_id));
159169
let telemetry_client = TelemetryClient::new(env, database, current_model_id.clone()).await?;
160170
let (tx, mut rx) = mpsc::unbounded_channel();

0 commit comments

Comments
 (0)