@@ -42,60 +42,66 @@ pub struct ModelArgs;
42
42
43
43
impl ModelArgs {
44
44
pub async fn execute ( self , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
45
- queue ! ( session. stderr, style:: Print ( "\n " ) ) ?;
46
- let active_model_id = session. conversation . model . as_deref ( ) ;
47
- let labels: Vec < String > = MODEL_OPTIONS
48
- . iter ( )
49
- . map ( |opt| {
50
- if ( opt. model_id . is_empty ( ) && active_model_id. is_none ( ) ) || Some ( opt. model_id ) == active_model_id {
51
- format ! ( "{} (active)" , opt. name)
52
- } else {
53
- opt. name . to_owned ( )
54
- }
55
- } )
56
- . collect ( ) ;
57
-
58
- let selection: Option < _ > = match Select :: with_theme ( & crate :: util:: dialoguer_theme ( ) )
59
- . with_prompt ( "Select a model for this chat session" )
60
- . items ( & labels)
61
- . default ( 0 )
62
- . interact_on_opt ( & dialoguer:: console:: Term :: stdout ( ) )
63
- {
64
- Ok ( sel) => {
65
- let _ = crossterm:: execute!(
66
- std:: io:: stdout( ) ,
67
- crossterm:: style:: SetForegroundColor ( crossterm:: style:: Color :: Magenta )
68
- ) ;
69
- sel
70
- } ,
71
- // Ctrl‑C -> Err(Interrupted)
72
- Err ( dialoguer:: Error :: IO ( ref e) ) if e. kind ( ) == std:: io:: ErrorKind :: Interrupted => None ,
73
- Err ( e) => return Err ( ChatError :: Custom ( format ! ( "Failed to choose model: {e}" ) . into ( ) ) ) ,
74
- } ;
45
+ Ok ( select_model ( session) ?. unwrap_or ( ChatState :: PromptUser {
46
+ skip_printing_tools : false ,
47
+ } ) )
48
+ }
49
+ }
75
50
76
- queue ! ( session. stderr, style:: ResetColor ) ?;
51
+ pub fn select_model ( session : & mut ChatSession ) -> Result < Option < ChatState > , ChatError > {
52
+ queue ! ( session. stderr, style:: Print ( "\n " ) ) ?;
53
+ let active_model_id = session. conversation . model . as_deref ( ) ;
54
+ let labels: Vec < String > = MODEL_OPTIONS
55
+ . iter ( )
56
+ . map ( |opt| {
57
+ if ( opt. model_id . is_empty ( ) && active_model_id. is_none ( ) ) || Some ( opt. model_id ) == active_model_id {
58
+ format ! ( "{} (active)" , opt. name)
59
+ } else {
60
+ opt. name . to_owned ( )
61
+ }
62
+ } )
63
+ . collect ( ) ;
77
64
78
- if let Some ( index) = selection {
79
- let selected = & MODEL_OPTIONS [ index] ;
80
- let model_id_str = selected. model_id . to_string ( ) ;
81
- session. conversation . model = Some ( model_id_str) ;
65
+ let selection: Option < _ > = match Select :: with_theme ( & crate :: util:: dialoguer_theme ( ) )
66
+ . with_prompt ( "Select a model for this chat session" )
67
+ . items ( & labels)
68
+ . default ( 0 )
69
+ . interact_on_opt ( & dialoguer:: console:: Term :: stdout ( ) )
70
+ {
71
+ Ok ( sel) => {
72
+ let _ = crossterm:: execute!(
73
+ std:: io:: stdout( ) ,
74
+ crossterm:: style:: SetForegroundColor ( crossterm:: style:: Color :: Magenta )
75
+ ) ;
76
+ sel
77
+ } ,
78
+ // Ctrl‑C -> Err(Interrupted)
79
+ Err ( dialoguer:: Error :: IO ( ref e) ) if e. kind ( ) == std:: io:: ErrorKind :: Interrupted => return Ok ( None ) ,
80
+ Err ( e) => return Err ( ChatError :: Custom ( format ! ( "Failed to choose model: {e}" ) . into ( ) ) ) ,
81
+ } ;
82
82
83
- queue ! (
84
- session. stderr,
85
- style:: Print ( "\n " ) ,
86
- style:: Print ( format!( " Using {}\n \n " , selected. name) ) ,
87
- style:: ResetColor ,
88
- style:: SetForegroundColor ( Color :: Reset ) ,
89
- style:: SetBackgroundColor ( Color :: Reset ) ,
90
- ) ?;
91
- }
83
+ queue ! ( session. stderr, style:: ResetColor ) ?;
92
84
93
- execute ! ( session. stderr, style:: ResetColor ) ?;
85
+ if let Some ( index) = selection {
86
+ let selected = & MODEL_OPTIONS [ index] ;
87
+ let model_id_str = selected. model_id . to_string ( ) ;
88
+ session. conversation . model = Some ( model_id_str) ;
94
89
95
- Ok ( ChatState :: PromptUser {
96
- skip_printing_tools : false ,
97
- } )
90
+ queue ! (
91
+ session. stderr,
92
+ style:: Print ( "\n " ) ,
93
+ style:: Print ( format!( " Using {}\n \n " , selected. name) ) ,
94
+ style:: ResetColor ,
95
+ style:: SetForegroundColor ( Color :: Reset ) ,
96
+ style:: SetBackgroundColor ( Color :: Reset ) ,
97
+ ) ?;
98
98
}
99
+
100
+ execute ! ( session. stderr, style:: ResetColor ) ?;
101
+
102
+ Ok ( Some ( ChatState :: PromptUser {
103
+ skip_printing_tools : false ,
104
+ } ) )
99
105
}
100
106
101
107
/// Returns Claude 3.7 for: Amazon IDC users, FRA region users
0 commit comments