@@ -266,10 +266,10 @@ impl ChatArgs {
266
266
// If modelId is specified, verify it exists before starting the chat
267
267
let model_id: Option < String > = if let Some ( model_name) = self . model {
268
268
let model_name_lower = model_name. to_lowercase ( ) ;
269
- match MODEL_OPTIONS . iter ( ) . find ( |( name , _ ) | name == & model_name_lower) {
270
- Some ( ( _ , id ) ) => Some ( ( * id ) . to_string ( ) ) ,
269
+ match MODEL_OPTIONS . iter ( ) . find ( |opt| opt . name == model_name_lower) {
270
+ Some ( opt ) => Some ( ( opt . model_id ) . to_string ( ) ) ,
271
271
None => {
272
- let available_names: Vec < & str > = MODEL_OPTIONS . iter ( ) . map ( |( name , _ ) | * name) . collect ( ) ;
272
+ let available_names: Vec < & str > = MODEL_OPTIONS . iter ( ) . map ( |opt| opt . name ) . collect ( ) ;
273
273
bail ! (
274
274
"Model '{}' does not exist. Available models: {}" ,
275
275
model_name,
@@ -423,11 +423,25 @@ const ROTATING_TIPS: [&str; 15] = [
423
423
color_print:: cstr! { "Set a default model by running <green!>q settings chat.defaultModel MODEL</green!>. Run <green!>/model</green!> to learn more." } ,
424
424
] ;
425
425
426
- pub const MODEL_OPTIONS : [ ( & str , & str ) ; 3 ] = [
427
- // ("Auto", ""),
428
- ( "claude-3.5-sonnet" , "CLAUDE_3_5_SONNET_20241022_V2_0" ) ,
429
- ( "claude-3.7-sonnet" , "CLAUDE_3_7_SONNET_20250219_V1_0" ) ,
430
- ( "claude-4-sonnet" , "CLAUDE_SONNET_4_20250514_V1_0" ) ,
426
+ pub struct ModelOption {
427
+ pub name : & ' static str ,
428
+ pub model_id : & ' static str ,
429
+ }
430
+
431
+ pub const MODEL_OPTIONS : [ ModelOption ; 3 ] = [
432
+ // ModelOption { name: "Auto", model_id: "CLAUDE_3_5_SONNET_20241022_V2_0" },
433
+ ModelOption {
434
+ name : "claude-3.5-sonnet" ,
435
+ model_id : "CLAUDE_3_5_SONNET_20241022_V2_0" ,
436
+ } ,
437
+ ModelOption {
438
+ name : "claude-3.7-sonnet" ,
439
+ model_id : "CLAUDE_3_7_SONNET_20250219_V1_0" ,
440
+ } ,
441
+ ModelOption {
442
+ name : "claude-4-sonnet" ,
443
+ model_id : "CLAUDE_SONNET_4_20250514_V1_0" ,
444
+ } ,
431
445
] ;
432
446
433
447
pub const DEFAULT_MODEL_ID : & str = "CLAUDE_3_7_SONNET_20250219_V1_0" ;
@@ -596,8 +610,8 @@ impl ChatContext {
596
610
. and_then ( |model_name| {
597
611
MODEL_OPTIONS
598
612
. iter ( )
599
- . find ( |( name , _ ) | * name == model_name)
600
- . map ( |( _ , id ) | ( * id ) . to_owned ( ) )
613
+ . find ( |opt| opt . name == model_name)
614
+ . map ( |opt| opt . model_id . to_owned ( ) )
601
615
} )
602
616
. or_else ( || Some ( DEFAULT_MODEL_ID . to_owned ( ) ) ) ,
603
617
} ;
@@ -3104,17 +3118,19 @@ impl ChatContext {
3104
3118
let active_model_id = self . conversation_state . current_model_id . as_deref ( ) ;
3105
3119
let labels: Vec < String > = MODEL_OPTIONS
3106
3120
. iter ( )
3107
- . map ( |( label, model_id) | {
3108
- if ( model_id. is_empty ( ) && active_model_id. is_none ( ) ) || Some ( * model_id) == active_model_id {
3109
- format ! ( "{} (active)" , label)
3121
+ . map ( |opt| {
3122
+ if ( opt. model_id . is_empty ( ) && active_model_id. is_none ( ) )
3123
+ || Some ( opt. model_id ) == active_model_id
3124
+ {
3125
+ format ! ( "{} (active)" , opt. name)
3110
3126
} else {
3111
- ( * label ) . to_owned ( )
3127
+ opt . name . to_owned ( )
3112
3128
}
3113
3129
} )
3114
3130
. collect ( ) ;
3115
3131
let default_index = MODEL_OPTIONS
3116
3132
. iter ( )
3117
- . position ( |( _ , model_id ) | Some ( * model_id) == active_model_id)
3133
+ . position ( |opt | Some ( opt . model_id ) == active_model_id)
3118
3134
. unwrap_or ( 0 ) ;
3119
3135
let selection: Option < _ > = match Select :: with_theme ( & crate :: util:: dialoguer_theme ( ) )
3120
3136
. with_prompt ( "Select a model for this chat session" )
@@ -3137,16 +3153,16 @@ impl ChatContext {
3137
3153
queue ! ( self . output, style:: ResetColor ) ?;
3138
3154
3139
3155
if let Some ( index) = selection {
3140
- let ( label , model_id ) = MODEL_OPTIONS [ index] ;
3141
- let model_id_str = model_id. to_string ( ) ;
3156
+ let selected = & MODEL_OPTIONS [ index] ;
3157
+ let model_id_str = selected . model_id . to_string ( ) ;
3142
3158
self . conversation_state . current_model_id = Some ( model_id_str. clone ( ) ) ;
3143
3159
telemetry. update_model_id ( Some ( model_id_str. clone ( ) ) ) ;
3144
3160
// let _ = database.set_last_used_model_id(model_id_str);
3145
3161
3146
3162
queue ! (
3147
3163
self . output,
3148
3164
style:: Print ( "\n " ) ,
3149
- style:: Print ( format!( " Switched model to {}\n \n " , label ) ) ,
3165
+ style:: Print ( format!( " Switched model to {}\n \n " , selected . name ) ) ,
3150
3166
style:: ResetColor ,
3151
3167
style:: SetForegroundColor ( Color :: Reset ) ,
3152
3168
style:: SetBackgroundColor ( Color :: Reset ) ,
0 commit comments