Thinking Budget 2.5: Electric Googaloo

a95056db40aebef80a5258ca3df5833a39103e6e

Cohee <18619528+Cohee1207@users.noreply.github.com>

4 files changed, +97 -0Showing whitespace changes
public/css/toggle-dependent.css+4 -0
@@ -498,3 +498,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small {
498498#banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba {
499499 filter: brightness(0.5);
500500}
501+
502+#thinking_budget_controls:not(:has(#enable_thinking:checked)) .range-block:has(#thinking_budget) {
503+ filter: brightness(0.5);
504+}
public/index.html+26 -0
@@ -2034,6 +2034,32 @@
20342034 </span>
20352035 </div>
20362036 </div>
2037+ <div id="thinking_budget_container" data-source="makersuite">
2038+ <div id="thinking_budget_controls">
2039+ <div class="range-block">
2040+ <label for="enable_thinking" class="checkbox_label widthFreeExpand">
2041+ <input id="enable_thinking" type="checkbox" />
2042+ <span data-i18n="Enable thinking">Enable thinking</span>
2043+ </label>
2044+ <div class="toggle-description justifyLeft marginBot5" data-i18n="thinking_budget_desc">
2045+ Must be enabled for Thinking Budget to take effect.
2046+ </div>
2047+ </div>
2048+ <div class="range-block">
2049+ <div class="range-block-title" data-i18n="Thinking Budget (Tokens)">
2050+ Thinking Budget (tokens)
2051+ </div>
2052+ <div class="range-block-range-and-counter">
2053+ <div class="range-block-range">
2054+ <input id="thinking_budget" type="range" min="0" max="24576" step="1">
2055+ </div>
2056+ <div class="range-block-counter">
2057+ <input id="thinking_budget_counter" type="number" min="0" max="24576" step="1" data-for="thinking_budget">
2058+ </div>
2059+ </div>
2060+ </div>
2061+ </div>
2062+ </div>
20372063 <div class="range-block" data-source="deepseek,openrouter,custom,claude,xai">
20382064 <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand">
20392065 <input id="openai_show_thoughts" type="checkbox" />
public/scripts/openai.js+58 -0
@@ -165,6 +165,11 @@ const textCompletionModels = [
165165 'code-search-ada-code-001',
166166];
167167
168+// One more models list to maintain, yay
169+const thinkingBudgetModels = [
170+ 'gemini-2.5-flash-preview-04-17',
171+];
172+
168173let biasCache = undefined;
169174export let model_list = [];
170175
@@ -306,6 +311,8 @@ export const settingsToUpdate = {
306311 n: ['#n_openai', 'n', false],
307312 bypass_status_check: ['#openai_bypass_status_check', 'bypass_status_check', true],
308313 request_images: ['#openai_request_images', 'request_images', true],
314+ enable_thinking: ['#enable_thinking', 'enable_thinking', true],
315+ thinking_budget: ['#thinking_budget', 'thinking_budget', false],
309316};
310317
311318const default_settings = {
@@ -385,6 +392,8 @@ const default_settings = {
385392 reasoning_effort: 'medium',
386393 enable_web_search: false,
387394 request_images: false,
395+ enable_thinking: true,
396+ thinking_budget: 1000,
388397 seed: -1,
389398 n: 1,
390399};
@@ -466,6 +475,8 @@ const oai_settings = {
466475 reasoning_effort: 'medium',
467476 enable_web_search: false,
468477 request_images: false,
478+ enable_thinking: true,
479+ thinking_budget: 1000,
469480 seed: -1,
470481 n: 1,
471482};
@@ -2029,6 +2040,11 @@ async function sendOpenAIRequest(type, messages, signal) {
20292040 'custom_prompt_post_processing': oai_settings.custom_prompt_post_processing,
20302041 };
20312042
2043+ if (thinkingBudgetModels.includes(model)) {
2044+ generate_data['enable_thinking'] = oai_settings.enable_thinking;
2045+ generate_data['thinking_budget'] = oai_settings.thinking_budget;
2046+ }
2047+
20322048 if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) {
20332049 await ToolManager.registerFunctionToolsOpenAI(generate_data);
20342050 }
@@ -3284,6 +3300,8 @@ function loadOpenAISettings(data, settings) {
32843300 oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts;
32853301 oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort;
32863302 oai_settings.enable_web_search = settings.enable_web_search ?? default_settings.enable_web_search;
3303+ oai_settings.enable_thinking = settings.enable_thinking ?? default_settings.enable_thinking;
3304+ oai_settings.thinking_budget = settings.thinking_budget ?? default_settings.thinking_budget;
32873305 oai_settings.request_images = settings.request_images ?? default_settings.request_images;
32883306 oai_settings.seed = settings.seed ?? default_settings.seed;
32893307 oai_settings.n = settings.n ?? default_settings.n;
@@ -3419,6 +3437,10 @@ function loadOpenAISettings(data, settings) {
34193437 $('#openai_reasoning_effort').val(oai_settings.reasoning_effort);
34203438 $(`#openai_reasoning_effort option[value="${oai_settings.reasoning_effort}"]`).prop('selected', true);
34213439
3440+ $('#enable_thinking').prop('checked', oai_settings.enable_thinking);
3441+ $('#thinking_budget').val(oai_settings.thinking_budget);
3442+ $('#thinking_budget_counter').val(oai_settings.thinking_budget);
3443+
34223444 if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy;
34233445 $('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
34243446
@@ -3449,6 +3471,7 @@ function loadOpenAISettings(data, settings) {
34493471
34503472 setNamesBehaviorControls();
34513473 setContinuePostfixControls();
3474+ updateThinkingBudgetUI();
34523475
34533476 if (oai_settings.custom_prompt_post_processing === custom_prompt_post_processing_types.CLAUDE) {
34543477 oai_settings.custom_prompt_post_processing = custom_prompt_post_processing_types.MERGE;
@@ -3506,6 +3529,14 @@ function setContinuePostfixControls() {
35063529 $('#continue_postfix_display').text(checkedItemText);
35073530}
35083531
3532+/**
3533+ * Updates the visibility and state of the Thinking Budget controls.
3534+ */
3535+function updateThinkingBudgetUI() {
3536+ const modelSupportsControl = thinkingBudgetModels.includes(getChatCompletionModel());
3537+ $('#thinking_budget_controls').toggle(modelSupportsControl);
3538+}
3539+
35093540async function getStatusOpen() {
35103541 if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) {
35113542 let status;
@@ -3686,6 +3717,8 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
36863717 reasoning_effort: settings.reasoning_effort,
36873718 enable_web_search: settings.enable_web_search,
36883719 request_images: settings.request_images,
3720+ enable_thinking: settings.enable_thinking,
3721+ thinking_budget: settings.thinking_budget,
36893722 seed: settings.seed,
36903723 n: settings.n,
36913724 };
@@ -4716,6 +4749,7 @@ async function onModelChange() {
47164749
47174750 $('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max')));
47184751
4752+ updateThinkingBudgetUI();
47194753 saveSettingsDebounced();
47204754 eventSource.emit(event_types.CHATCOMPLETION_MODEL_CHANGED, value);
47214755}
@@ -5534,6 +5568,7 @@ export function initOpenAI() {
55345568 $('#chat_completion_source').on('change', function () {
55355569 oai_settings.chat_completion_source = String($(this).find(':selected').val());
55365570 toggleChatCompletionForms();
5571+ updateThinkingBudgetUI();
55375572 saveSettingsDebounced();
55385573 reconnectOpenAi();
55395574 forceCharacterEditorTokenize();
@@ -5719,6 +5754,29 @@ export function initOpenAI() {
57195754 saveSettingsDebounced();
57205755 });
57215756
5757+ $('#enable_thinking').on('input', function () {
5758+ oai_settings.enable_thinking = !!$(this).prop('checked');
5759+ updateThinkingBudgetUI();
5760+ saveSettingsDebounced();
5761+ });
5762+
5763+ $('#thinking_budget').on('input', function () {
5764+ oai_settings.thinking_budget = Number($(this).val());
5765+ $('#thinking_budget_counter').val(oai_settings.thinking_budget);
5766+ saveSettingsDebounced();
5767+ });
5768+
5769+ $('#thinking_budget_counter').on('input', function () {
5770+ let value = Number($(this).val());
5771+ const min = Number($('#thinking_budget').attr('min'));
5772+ const max = Number($('#thinking_budget').attr('max'));
5773+ value = Math.max(min, Math.min(max, value));
5774+ $(this).val(value);
5775+ oai_settings.thinking_budget = value;
5776+ $('#thinking_budget').val(value);
5777+ saveSettingsDebounced();
5778+ });
5779+
57225780 $('#openai_enable_web_search').on('input', function () {
57235781 oai_settings.enable_web_search = !!$(this).prop('checked');
57245782 calculateOpenRouterCost();
src/endpoints/backends/chat-completions.js+9 -0
@@ -412,6 +412,15 @@ async function sendMakerSuiteRequest(request, response) {
412412 tools.push({ function_declarations: functionDeclarations });
413413 }
414414
415+ if ('enable_thinking' in request.body && 'thinking_budget' in request.body) {
416+ const thinkingEnabled = Boolean(request.body.enable_thinking);
417+ const thinkingBudget = Number(request.body.thinking_budget);
418+
419+ if (thinkingEnabled) {
420+ generationConfig.thinkingConfig = { thinkingBudget: thinkingBudget };
421+ }
422+ }
423+
415424 let body = {
416425 contents: prompt.contents,
417426 safetySettings: safetySettings,