Thinking Budget 2.5: Electric Googaloo
| @@ -498,3 +498,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small { | |||
| 498 | #banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba { | 498 | #banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba { |
| 499 | filter: brightness(0.5); | 499 | filter: brightness(0.5); |
| 500 | } | 500 | } |
| 501 | |||
| 502 | #thinking_budget_controls:not(:has(#enable_thinking:checked)) .range-block:has(#thinking_budget) { | ||
| 503 | filter: brightness(0.5); | ||
| 504 | } | ||
| @@ -2034,6 +2034,32 @@ | |||
| 2034 | </span> | 2034 | </span> |
| 2035 | </div> | 2035 | </div> |
| 2036 | </div> | 2036 | </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> | ||
| 2037 | <div class="range-block" data-source="deepseek,openrouter,custom,claude,xai"> | 2063 | <div class="range-block" data-source="deepseek,openrouter,custom,claude,xai"> |
| 2038 | <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand"> | 2064 | <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand"> |
| 2039 | <input id="openai_show_thoughts" type="checkbox" /> | 2065 | <input id="openai_show_thoughts" type="checkbox" /> |
| @@ -165,6 +165,11 @@ const textCompletionModels = [ | |||
| 165 | 'code-search-ada-code-001', | 165 | 'code-search-ada-code-001', |
| 166 | ]; | 166 | ]; |
| 167 | 167 | ||
| 168 | // One more models list to maintain, yay | ||
| 169 | const thinkingBudgetModels = [ | ||
| 170 | 'gemini-2.5-flash-preview-04-17', | ||
| 171 | ]; | ||
| 172 | |||
| 168 | let biasCache = undefined; | 173 | let biasCache = undefined; |
| 169 | export let model_list = []; | 174 | export let model_list = []; |
| 170 | 175 | ||
| @@ -306,6 +311,8 @@ export const settingsToUpdate = { | |||
| 306 | n: ['#n_openai', 'n', false], | 311 | n: ['#n_openai', 'n', false], |
| 307 | bypass_status_check: ['#openai_bypass_status_check', 'bypass_status_check', true], | 312 | bypass_status_check: ['#openai_bypass_status_check', 'bypass_status_check', true], |
| 308 | request_images: ['#openai_request_images', 'request_images', true], | 313 | request_images: ['#openai_request_images', 'request_images', true], |
| 314 | enable_thinking: ['#enable_thinking', 'enable_thinking', true], | ||
| 315 | thinking_budget: ['#thinking_budget', 'thinking_budget', false], | ||
| 309 | }; | 316 | }; |
| 310 | 317 | ||
| 311 | const default_settings = { | 318 | const default_settings = { |
| @@ -385,6 +392,8 @@ const default_settings = { | |||
| 385 | reasoning_effort: 'medium', | 392 | reasoning_effort: 'medium', |
| 386 | enable_web_search: false, | 393 | enable_web_search: false, |
| 387 | request_images: false, | 394 | request_images: false, |
| 395 | enable_thinking: true, | ||
| 396 | thinking_budget: 1000, | ||
| 388 | seed: -1, | 397 | seed: -1, |
| 389 | n: 1, | 398 | n: 1, |
| 390 | }; | 399 | }; |
| @@ -466,6 +475,8 @@ const oai_settings = { | |||
| 466 | reasoning_effort: 'medium', | 475 | reasoning_effort: 'medium', |
| 467 | enable_web_search: false, | 476 | enable_web_search: false, |
| 468 | request_images: false, | 477 | request_images: false, |
| 478 | enable_thinking: true, | ||
| 479 | thinking_budget: 1000, | ||
| 469 | seed: -1, | 480 | seed: -1, |
| 470 | n: 1, | 481 | n: 1, |
| 471 | }; | 482 | }; |
| @@ -2029,6 +2040,11 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 2029 | 'custom_prompt_post_processing': oai_settings.custom_prompt_post_processing, | 2040 | 'custom_prompt_post_processing': oai_settings.custom_prompt_post_processing, |
| 2030 | }; | 2041 | }; |
| 2031 | 2042 | ||
| 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 | |||
| 2032 | if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) { | 2048 | if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) { |
| 2033 | await ToolManager.registerFunctionToolsOpenAI(generate_data); | 2049 | await ToolManager.registerFunctionToolsOpenAI(generate_data); |
| 2034 | } | 2050 | } |
| @@ -3284,6 +3300,8 @@ function loadOpenAISettings(data, settings) { | |||
| 3284 | oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts; | 3300 | oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts; |
| 3285 | oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort; | 3301 | oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort; |
| 3286 | oai_settings.enable_web_search = settings.enable_web_search ?? default_settings.enable_web_search; | 3302 | 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; | ||
| 3287 | oai_settings.request_images = settings.request_images ?? default_settings.request_images; | 3305 | oai_settings.request_images = settings.request_images ?? default_settings.request_images; |
| 3288 | oai_settings.seed = settings.seed ?? default_settings.seed; | 3306 | oai_settings.seed = settings.seed ?? default_settings.seed; |
| 3289 | oai_settings.n = settings.n ?? default_settings.n; | 3307 | oai_settings.n = settings.n ?? default_settings.n; |
| @@ -3419,6 +3437,10 @@ function loadOpenAISettings(data, settings) { | |||
| 3419 | $('#openai_reasoning_effort').val(oai_settings.reasoning_effort); | 3437 | $('#openai_reasoning_effort').val(oai_settings.reasoning_effort); |
| 3420 | $(`#openai_reasoning_effort option[value="${oai_settings.reasoning_effort}"]`).prop('selected', true); | 3438 | $(`#openai_reasoning_effort option[value="${oai_settings.reasoning_effort}"]`).prop('selected', true); |
| 3421 | 3439 | ||
| 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 | |||
| 3422 | if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy; | 3444 | if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy; |
| 3423 | $('#openai_reverse_proxy').val(oai_settings.reverse_proxy); | 3445 | $('#openai_reverse_proxy').val(oai_settings.reverse_proxy); |
| 3424 | 3446 | ||
| @@ -3449,6 +3471,7 @@ function loadOpenAISettings(data, settings) { | |||
| 3449 | 3471 | ||
| 3450 | setNamesBehaviorControls(); | 3472 | setNamesBehaviorControls(); |
| 3451 | setContinuePostfixControls(); | 3473 | setContinuePostfixControls(); |
| 3474 | updateThinkingBudgetUI(); | ||
| 3452 | 3475 | ||
| 3453 | if (oai_settings.custom_prompt_post_processing === custom_prompt_post_processing_types.CLAUDE) { | 3476 | if (oai_settings.custom_prompt_post_processing === custom_prompt_post_processing_types.CLAUDE) { |
| 3454 | oai_settings.custom_prompt_post_processing = custom_prompt_post_processing_types.MERGE; | 3477 | oai_settings.custom_prompt_post_processing = custom_prompt_post_processing_types.MERGE; |
| @@ -3506,6 +3529,14 @@ function setContinuePostfixControls() { | |||
| 3506 | $('#continue_postfix_display').text(checkedItemText); | 3529 | $('#continue_postfix_display').text(checkedItemText); |
| 3507 | } | 3530 | } |
| 3508 | 3531 | ||
| 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 | |||
| 3509 | async function getStatusOpen() { | 3540 | async function getStatusOpen() { |
| 3510 | if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) { | 3541 | if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) { |
| 3511 | let status; | 3542 | let status; |
| @@ -3686,6 +3717,8 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | |||
| 3686 | reasoning_effort: settings.reasoning_effort, | 3717 | reasoning_effort: settings.reasoning_effort, |
| 3687 | enable_web_search: settings.enable_web_search, | 3718 | enable_web_search: settings.enable_web_search, |
| 3688 | request_images: settings.request_images, | 3719 | request_images: settings.request_images, |
| 3720 | enable_thinking: settings.enable_thinking, | ||
| 3721 | thinking_budget: settings.thinking_budget, | ||
| 3689 | seed: settings.seed, | 3722 | seed: settings.seed, |
| 3690 | n: settings.n, | 3723 | n: settings.n, |
| 3691 | }; | 3724 | }; |
| @@ -4716,6 +4749,7 @@ async function onModelChange() { | |||
| 4716 | 4749 | ||
| 4717 | $('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max'))); | 4750 | $('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max'))); |
| 4718 | 4751 | ||
| 4752 | updateThinkingBudgetUI(); | ||
| 4719 | saveSettingsDebounced(); | 4753 | saveSettingsDebounced(); |
| 4720 | eventSource.emit(event_types.CHATCOMPLETION_MODEL_CHANGED, value); | 4754 | eventSource.emit(event_types.CHATCOMPLETION_MODEL_CHANGED, value); |
| 4721 | } | 4755 | } |
| @@ -5534,6 +5568,7 @@ export function initOpenAI() { | |||
| 5534 | $('#chat_completion_source').on('change', function () { | 5568 | $('#chat_completion_source').on('change', function () { |
| 5535 | oai_settings.chat_completion_source = String($(this).find(':selected').val()); | 5569 | oai_settings.chat_completion_source = String($(this).find(':selected').val()); |
| 5536 | toggleChatCompletionForms(); | 5570 | toggleChatCompletionForms(); |
| 5571 | updateThinkingBudgetUI(); | ||
| 5537 | saveSettingsDebounced(); | 5572 | saveSettingsDebounced(); |
| 5538 | reconnectOpenAi(); | 5573 | reconnectOpenAi(); |
| 5539 | forceCharacterEditorTokenize(); | 5574 | forceCharacterEditorTokenize(); |
| @@ -5719,6 +5754,29 @@ export function initOpenAI() { | |||
| 5719 | saveSettingsDebounced(); | 5754 | saveSettingsDebounced(); |
| 5720 | }); | 5755 | }); |
| 5721 | 5756 | ||
| 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 | |||
| 5722 | $('#openai_enable_web_search').on('input', function () { | 5780 | $('#openai_enable_web_search').on('input', function () { |
| 5723 | oai_settings.enable_web_search = !!$(this).prop('checked'); | 5781 | oai_settings.enable_web_search = !!$(this).prop('checked'); |
| 5724 | calculateOpenRouterCost(); | 5782 | calculateOpenRouterCost(); |
| @@ -412,6 +412,15 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 412 | tools.push({ function_declarations: functionDeclarations }); | 412 | tools.push({ function_declarations: functionDeclarations }); |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 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 | |||
| 415 | let body = { | 424 | let body = { |
| 416 | contents: prompt.contents, | 425 | contents: prompt.contents, |
| 417 | safetySettings: safetySettings, | 426 | safetySettings: safetySettings, |