@@ -12,6 +12,82 @@ export const hugging_chat: Chatbot = {
1212 wait_until_ready : async ( ) => {
1313 await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
1414 } ,
15+ set_model : async ( model ?: string ) => {
16+ if ( ! model ) return
17+
18+ const model_picker_button = document . querySelector (
19+ 'form + div > a'
20+ ) as HTMLAnchorElement
21+ if ( ! model_picker_button ) {
22+ report_initialization_error ( {
23+ function_name : 'hugging_chat.set_model' ,
24+ log_message : 'Model picker button not found' ,
25+ alert_message : InitializationError . UNABLE_TO_SET_MODEL
26+ } )
27+ return
28+ }
29+
30+ model_picker_button . click ( )
31+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
32+
33+ const dialog = await new Promise < Element | null > ( ( resolve ) => {
34+ const check = ( ) => {
35+ const el = document . querySelector ( 'div[role="dialog"]' )
36+ if ( el ) {
37+ resolve ( el )
38+ } else {
39+ setTimeout ( check , 100 )
40+ }
41+ }
42+ check ( )
43+ } )
44+
45+ if ( ! dialog ) {
46+ report_initialization_error ( {
47+ function_name : 'hugging_chat.set_model' ,
48+ log_message : 'Model picker dialog not found' ,
49+ alert_message : InitializationError . UNABLE_TO_SET_MODEL
50+ } )
51+ return
52+ }
53+
54+ const model_button = dialog . querySelector (
55+ `button[data-model-id="${ model } "]`
56+ ) as HTMLButtonElement
57+
58+ if ( ! model_button ) {
59+ report_initialization_error ( {
60+ function_name : 'hugging_chat.set_model' ,
61+ log_message : `Model button for "${ model } " not found` ,
62+ alert_message : InitializationError . UNABLE_TO_SET_MODEL
63+ } )
64+
65+ const close_button = dialog . querySelector ( 'button' ) as HTMLButtonElement
66+ if ( close_button ) {
67+ close_button . click ( )
68+ }
69+ return
70+ }
71+
72+ model_button . click ( )
73+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
74+
75+ const activate_button = dialog . querySelector (
76+ 'button[name="Activate model"]'
77+ ) as HTMLButtonElement
78+
79+ if ( ! activate_button ) {
80+ report_initialization_error ( {
81+ function_name : 'hugging_chat.set_model' ,
82+ log_message : 'Activate model button not found' ,
83+ alert_message : InitializationError . UNABLE_TO_SET_MODEL
84+ } )
85+ return
86+ }
87+
88+ activate_button . click ( )
89+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
90+ } ,
1591 inject_apply_response_button : (
1692 client_id : number ,
1793 raw_instructions ?: string ,
@@ -43,7 +119,7 @@ export const hugging_chat: Chatbot = {
43119 }
44120
45121 observe_for_responses ( {
46- chatbot_name : 'Hugging Chat ' ,
122+ chatbot_name : 'HuggingChat ' ,
47123 is_generating : ( ) =>
48124 ! ! document . querySelector ( 'button.stop-generating-btn' ) ,
49125 footer_selector : 'div[data-message-role="assistant"] > div:nth-child(3)' ,
0 commit comments