@@ -79,6 +79,7 @@ const create_separator = async (params: {
7979const create_preset = async ( params : {
8080 panel_provider : PanelProvider
8181 insertion_index ?: number
82+ chatbot : keyof typeof CHATBOTS
8283} ) => {
8384 const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
8485 const presets_config_key = params . panel_provider . get_presets_config_key ( )
@@ -93,10 +94,11 @@ const create_preset = async (params: {
9394
9495 const new_preset : ConfigPresetFormat = {
9596 name : new_name ,
96- chatbot : 'AI Studio' ,
97- model : Object . keys ( CHATBOTS [ 'AI Studio' ] . models ?? { } ) [ 0 ] ,
98- temperature : 0.5 ,
99- systemInstructions : CHATBOTS [ 'AI Studio' ] . default_system_instructions
97+ chatbot : params . chatbot ,
98+ model : Object . keys ( CHATBOTS [ params . chatbot ] . models ?? { } ) [ 0 ] ,
99+ systemInstructions : CHATBOTS [ params . chatbot ] . supports_system_instructions
100+ ? CHATBOTS [ params . chatbot ] . default_system_instructions
101+ : undefined
100102 }
101103
102104 const updated_presets = [ ...current_presets ]
@@ -182,38 +184,96 @@ export const handle_create_preset_group_or_separator = async (
182184 insertion_index = 0
183185 }
184186
185- const quickPick = vscode . window . createQuickPick ( )
186- quickPick . items = [
187- { label : ITEM_NAME_PRESET } ,
188- { label : ITEM_NAME_GROUP } ,
189- { label : ITEM_NAME_SEPARATOR }
190- ]
191- quickPick . title = 'Item Types'
192- quickPick . placeholder = 'What would you like to create?'
193- quickPick . buttons = [
194- {
195- iconPath : new vscode . ThemeIcon ( 'close' ) ,
196- tooltip : 'Close'
197- }
198- ]
199-
200- quickPick . onDidTriggerButton ( ( ) => {
201- quickPick . hide ( )
202- } )
203-
204- quickPick . onDidAccept ( async ( ) => {
205- const selection = quickPick . selectedItems [ 0 ] ?. label
206- quickPick . hide ( )
207-
208- if ( selection == ITEM_NAME_GROUP ) {
209- await create_group ( { panel_provider, insertion_index } )
210- } else if ( selection == ITEM_NAME_SEPARATOR ) {
211- await create_separator ( { panel_provider, insertion_index } )
212- } else if ( selection == ITEM_NAME_PRESET ) {
213- await create_preset ( { panel_provider, insertion_index } )
214- }
215- } )
187+ const show_item_types_menu = ( ) => {
188+ const quickPick = vscode . window . createQuickPick ( )
189+ quickPick . items = [
190+ { label : ITEM_NAME_PRESET } ,
191+ { label : ITEM_NAME_GROUP } ,
192+ { label : ITEM_NAME_SEPARATOR }
193+ ]
194+ quickPick . title = 'Item Types'
195+ quickPick . placeholder = 'What would you like to create?'
196+ quickPick . buttons = [
197+ {
198+ iconPath : new vscode . ThemeIcon ( 'close' ) ,
199+ tooltip : 'Close'
200+ }
201+ ]
202+
203+ quickPick . onDidTriggerButton ( ( ) => {
204+ quickPick . hide ( )
205+ } )
206+
207+ quickPick . onDidAccept ( async ( ) => {
208+ const selection = quickPick . selectedItems [ 0 ] ?. label
209+ quickPick . hide ( )
210+
211+ if ( selection == ITEM_NAME_GROUP ) {
212+ await create_group ( { panel_provider, insertion_index } )
213+ } else if ( selection == ITEM_NAME_SEPARATOR ) {
214+ await create_separator ( { panel_provider, insertion_index } )
215+ } else if ( selection == ITEM_NAME_PRESET ) {
216+ show_chatbots_menu ( )
217+ }
218+ } )
219+
220+ quickPick . onDidHide ( ( ) => quickPick . dispose ( ) )
221+ quickPick . show ( )
222+ }
223+
224+ const show_chatbots_menu = ( ) => {
225+ const chatbots = Object . entries ( CHATBOTS )
226+ const items : vscode . QuickPickItem [ ] = chatbots . map (
227+ ( [ chatbot , { url } ] ) => ( {
228+ label : chatbot ,
229+ description :
230+ chatbot == 'Open WebUI'
231+ ? 'localhost'
232+ : url . replace ( / ^ h t t p s ? : \/ \/ / , '' ) . split ( '/' ) [ 0 ]
233+ } )
234+ )
235+
236+ const quick_pick = vscode . window . createQuickPick ( )
237+ quick_pick . items = items
238+ quick_pick . title = 'Chatbots'
239+ quick_pick . placeholder = 'Choose a chatbot for the new preset'
240+ quick_pick . buttons = [ vscode . QuickInputButtons . Back ]
241+
242+ let is_handled = false
243+ const disposables : vscode . Disposable [ ] = [ ]
244+
245+ disposables . push (
246+ quick_pick . onDidTriggerButton ( ( button ) => {
247+ if ( button === vscode . QuickInputButtons . Back ) {
248+ is_handled = true
249+ quick_pick . hide ( )
250+ show_item_types_menu ( )
251+ }
252+ } ) ,
253+ quick_pick . onDidAccept ( async ( ) => {
254+ is_handled = true
255+ const selected_chatbot = quick_pick . selectedItems [ 0 ]
256+ ?. label as keyof typeof CHATBOTS
257+ quick_pick . hide ( )
258+ if ( selected_chatbot ) {
259+ await create_preset ( {
260+ panel_provider,
261+ insertion_index,
262+ chatbot : selected_chatbot
263+ } )
264+ }
265+ } ) ,
266+ quick_pick . onDidHide ( ( ) => {
267+ if ( ! is_handled ) {
268+ show_item_types_menu ( )
269+ }
270+ disposables . forEach ( ( d ) => d . dispose ( ) )
271+ quick_pick . dispose ( )
272+ } )
273+ )
274+
275+ quick_pick . show ( )
276+ }
216277
217- quickPick . onDidHide ( ( ) => quickPick . dispose ( ) )
218- quickPick . show ( )
278+ show_item_types_menu ( )
219279}
0 commit comments