@@ -141,7 +141,7 @@ class ActionProvider {
141141 }
142142 console . log ( res ) ;
143143 const successmessage = this . createChatBotMessage (
144- "Chatbot initialized successfully." ,
144+ "Chatbot initialized successfully. By default, GPT-4o-mini model is being used. To change chatbot's model, please type model and press enter. " ,
145145 Math . floor ( Math . random ( ) * 65536 ) ,
146146 {
147147 loading : true ,
@@ -154,6 +154,95 @@ class ActionProvider {
154154 } ) ;
155155 } ;
156156
157+ handleModelSelection = ( initRequired : boolean ) : void => {
158+ console . log ( "Initialization required:" , initRequired ) ;
159+ if ( initRequired ) {
160+ const message = this . createChatBotMessage (
161+ "Chatbot not initialized. To initialize the chatbot, please type init and press enter." ,
162+ Math . floor ( Math . random ( ) * 65536 ) ,
163+ {
164+ loading : true ,
165+ terminateLoading : true ,
166+ role : "assistant" ,
167+ } ,
168+ ) ;
169+ this . addMessageToState ( message ) ;
170+ } else {
171+ this . addModelSelectionToState ( ) ;
172+ const message = this . createChatBotMessage (
173+ `Type one of these available options and press enter:\n\n` +
174+ `1. \`gpt-4o\` : GPT-4 Omni (fastest, multimodal, best for general use)\n\n` +
175+ `2. \`gpt-4o-mini\` : Lighter version of GPT-4o (efficient for most tasks)\n\n` +
176+ `3. \`gpt-4-turbo\` : GPT-4 Turbo (older but solid performance)\n\n` +
177+ `4. \`gpt-3.5-turbo\` : GPT-3.5 Turbo (cheaper, good for lightweight tasks)\n\n` +
178+ `5. \`gpt-3.5-turbo-16k\` : Like above but with 16k context window\n\n` +
179+ `By default, GPT-4o-mini will be used if any invalid option is entered.` ,
180+ Math . floor ( Math . random ( ) * 65536 ) ,
181+ {
182+ loading : true ,
183+ terminateLoading : true ,
184+ role : "assistant" ,
185+ } ,
186+ ) ;
187+ this . addMessageToState ( message ) ;
188+ }
189+ } ;
190+
191+ handleModelConfirmation = ( model_name : string | null , accessToken : string ) : void => {
192+ const validModels : Record < string , string > = {
193+ "1" : "gpt-4o" ,
194+ "2" : "gpt-4o-mini" ,
195+ "3" : "gpt-4-turbo" ,
196+ "4" : "gpt-3.5-turbo" ,
197+ "5" : "gpt-3.5-turbo-16k" ,
198+ "gpt-4o" : "gpt-4o" ,
199+ "gpt-4o-mini" : "gpt-4o-mini" ,
200+ "gpt-4-turbo" : "gpt-4-turbo" ,
201+ "gpt-3.5-turbo" : "gpt-3.5-turbo" ,
202+ "gpt-3.5-turbo-16k" : "gpt-3.5-turbo-16k"
203+ } ;
204+ const selectedModel = model_name ?. trim ( ) ;
205+ const modelToUse = selectedModel && validModels [ selectedModel ] ? validModels [ selectedModel ] : null ;
206+
207+ const modelUrl = APIService . CHATBOT_SERVICE + "genai/model" ;
208+ superagent
209+ . post ( modelUrl )
210+ . send ( { model_name : modelToUse } )
211+ . set ( "Accept" , "application/json" )
212+ . set ( "Content-Type" , "application/json" )
213+ . set ( "Authorization" , `Bearer ${ accessToken } ` )
214+ . end ( ( err , res ) => {
215+ if ( err ) {
216+ console . log ( err ) ;
217+ const errormessage = this . createChatBotMessage (
218+ "Failed to set model. Please try again." ,
219+ Math . floor ( Math . random ( ) * 65536 ) ,
220+ {
221+ loading : true ,
222+ terminateLoading : true ,
223+ role : "assistant" ,
224+ } ,
225+ ) ;
226+ this . addMessageToState ( errormessage ) ;
227+ return ;
228+ }
229+
230+ console . log ( res ) ;
231+ const currentModel = res . body ?. model_used || modelToUse ;
232+ const successmessage = this . createChatBotMessage (
233+ `Model has been successfully set to ${ currentModel } . You can now start chatting.` ,
234+ Math . floor ( Math . random ( ) * 65536 ) ,
235+ {
236+ loading : true ,
237+ terminateLoading : true ,
238+ role : "assistant" ,
239+ } ,
240+ ) ;
241+ this . addMessageToState ( successmessage ) ;
242+ this . addModelConfirmationToState ( ) ;
243+ } ) ;
244+ } ;
245+
157246 handleChat = ( message : string , accessToken : string ) : void => {
158247 const chatUrl = APIService . CHATBOT_SERVICE + "genai/ask" ;
159248 console . log ( "Chat message:" , message ) ;
@@ -223,7 +312,7 @@ class ActionProvider {
223312 this . addMessageToState ( message ) ;
224313 } else {
225314 const message = this . createChatBotMessage (
226- "Chat with the bot and exploit it." ,
315+ "Chat with the bot and exploit it. To change chatbot's model, please type model and press enter. " ,
227316 Math . floor ( Math . random ( ) * 65536 ) ,
228317 {
229318 loading : true ,
@@ -303,6 +392,20 @@ class ActionProvider {
303392 } ) ) ;
304393 } ;
305394
395+ addModelSelectionToState = ( ) : void => {
396+ this . setState ( ( state ) => ( {
397+ ...state ,
398+ modelSelection : true ,
399+ } ) ) ;
400+ } ;
401+
402+ addModelConfirmationToState = ( ) : void => {
403+ this . setState ( ( state ) => ( {
404+ ...state ,
405+ modelSelection : false ,
406+ } ) ) ;
407+ } ;
408+
306409 clearMessages = ( ) : void => {
307410 this . setState ( ( state ) => ( {
308411 ...state ,
0 commit comments