@@ -20,7 +20,11 @@ export const gemini: Chatbot = {
2020 } )
2121 } ,
2222 set_model : async ( model ?: string ) => {
23- if ( model && CHATBOTS [ 'Gemini' ] . models && model in CHATBOTS [ 'Gemini' ] . models ) {
23+ if (
24+ model &&
25+ CHATBOTS [ 'Gemini' ] . models &&
26+ model in CHATBOTS [ 'Gemini' ] . models
27+ ) {
2428 const model_selector_trigger = document . querySelector (
2529 'bard-mode-switcher button'
2630 ) as HTMLButtonElement
@@ -32,7 +36,7 @@ export const gemini: Chatbot = {
3236 return
3337 }
3438
35- const model_label = ( CHATBOTS [ 'Gemini' ] . models as any ) [ model ] . label
39+ const model_label = CHATBOTS [ 'Gemini' ] . models [ model ] . label
3640 if ( model_selector_trigger . textContent == model_label ) {
3741 return
3842 }
@@ -50,16 +54,24 @@ export const gemini: Chatbot = {
5054 return
5155 }
5256 const model_options = Array . from ( menu_content . querySelectorAll ( 'button' ) )
57+ const target_data_test_id = model_label . toLowerCase ( )
58+ let found = false
5359 for ( const option of model_options ) {
54- const name_element = option . querySelector (
55- '.title-and-description > span:first-child'
56- )
57- if ( name_element && name_element . textContent ?. trim ( ) == model_label ) {
58- ; ( option as HTMLElement ) . click ( )
59- await new Promise ( ( r ) => requestAnimationFrame ( r ) )
60+ if (
61+ option . getAttribute ( 'data-test-id' ) ?. includes ( target_data_test_id )
62+ ) {
63+ option . click ( )
64+ found = true
6065 break
6166 }
6267 }
68+ if ( ! found ) {
69+ report_initialization_error ( {
70+ function_name : 'set_model' ,
71+ log_message : `Model option for "${ model_label } " not found`
72+ } )
73+ }
74+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
6375 }
6476 } ,
6577 set_options : async ( options ?: string [ ] ) => {
0 commit comments