Skip to content

Commit 4845f53

Browse files
committed
Add reasoning effort support for HuggingChat
- to `apps/browser/src/content-scripts/send-prompt-content-script/chatbots/hugging-chat.ts` add reasoning effort: low, medium, high [Pasted text] - in case of `apps/browser/src/content-scripts/send-prompt-content-script/chatbots/hugging-chat.ts`, if no reasoning effort is selected option 'default' should be selected (it's in the dropdown above 'low') ├── apps │ └── browser │ └── src │ └── content-scripts │ └── send-prompt-content-script │ └── chatbots │ ├── ai-studio.ts │ ├── arena.ts │ ├── chatgpt.ts │ ├── claude.ts │ ├── copilot.ts │ ├── deepseek.ts │ ├── doubao.ts │ ├── gemini.ts │ ├── github-copilot.ts │ ├── grok.ts │ ├── hugging-chat.ts │ ├── index.ts │ ├── kimi.ts │ ├── meta.ts │ ├── mistral.ts │ ├── open-webui.ts │ ├── openrouter.ts │ ├── qwen.ts │ ├── together.ts │ ├── yuanbao.ts │ └── z-ai.ts └── packages └── shared └── src └── constants └── chatbots.ts
1 parent 5ffa0a3 commit 4845f53

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/hugging-chat.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,83 @@ export const hugging_chat: Chatbot = {
99
wait_until_ready: async () => {
1010
await new Promise((resolve) => setTimeout(resolve, 500))
1111
},
12+
set_reasoning_effort: async (chat) => {
13+
const effort_button = document.querySelector(
14+
'button[aria-label="Select thinking effort"]'
15+
) as HTMLButtonElement
16+
17+
if (!effort_button) {
18+
if (chat.reasoning_effort) {
19+
report_initialization_error({
20+
function_name: 'hugging_chat.set_reasoning_effort',
21+
log_message: 'Thinking effort button not found'
22+
})
23+
}
24+
return
25+
}
26+
27+
const reasoning_effort = chat.reasoning_effort || 'default'
28+
29+
if (
30+
effort_button.textContent
31+
?.trim()
32+
.toLowerCase()
33+
.includes(reasoning_effort.toLowerCase())
34+
) {
35+
return
36+
}
37+
38+
effort_button.click()
39+
await new Promise((r) => requestAnimationFrame(r))
40+
41+
const menu = await new Promise<Element | null>((resolve) => {
42+
let attempts = 0
43+
const check = () => {
44+
attempts++
45+
const el = document.querySelector('div[data-dropdown-menu-content]')
46+
if (el) {
47+
resolve(el)
48+
} else if (attempts > 50) {
49+
resolve(null)
50+
} else {
51+
setTimeout(check, 100)
52+
}
53+
}
54+
check()
55+
})
56+
57+
if (!menu) {
58+
report_initialization_error({
59+
function_name: 'hugging_chat.set_reasoning_effort',
60+
log_message: 'Reasoning effort menu not found'
61+
})
62+
return
63+
}
64+
65+
const options = Array.from(menu.querySelectorAll('div[role="menuitem"]'))
66+
let found = false
67+
for (const option of options) {
68+
if (
69+
option.textContent?.trim().toLowerCase() ==
70+
reasoning_effort.toLowerCase()
71+
) {
72+
;(option as HTMLElement).click()
73+
found = true
74+
break
75+
}
76+
}
77+
78+
if (!found) {
79+
report_initialization_error({
80+
function_name: 'hugging_chat.set_reasoning_effort',
81+
log_message: `Reasoning effort option "${reasoning_effort}" not found`
82+
})
83+
document.dispatchEvent(
84+
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
85+
)
86+
}
87+
await new Promise((resolve) => setTimeout(resolve, 250))
88+
},
1289
set_model: async (chat) => {
1390
const model = chat.model
1491
if (!model) return

‎packages/shared/src/constants/chatbots.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export const CHATBOTS = {
112112
} as Chatbot,
113113
HuggingChat: {
114114
url: 'https://huggingface.co/chat/',
115-
supports_user_provided_model: true
115+
supports_user_provided_model: true,
116+
supports_reasoning_effort: true,
117+
supported_reasoning_efforts: ['Low', 'Medium', 'High']
116118
} as Chatbot,
117119
Kimi: {
118120
url: 'https://www.kimi.com/'

0 commit comments

Comments
 (0)