Merge pull request #3424 from SillyTavern/oai-reasoning-effort OpenAI "Reasoning Effort" for o1/o3-mini + oai models restructured
Signed| @@ -1957,14 +1957,16 @@ | |||
| 1957 | <span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span> | 1957 | <span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span> |
| 1958 | </div> | 1958 | </div> |
| 1959 | <div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom"> | 1959 | <div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom"> |
| 1960 | <label for="openai_inline_image_quality" data-i18n="Inline Image Quality"> | 1960 | <div class="flex-container oneline-dropdown"> |
| 1961 | Inline Image Quality | 1961 | <label for="openai_inline_image_quality" data-i18n="Inline Image Quality"> |
| 1962 | </label> | 1962 | Inline Image Quality |
| 1963 | <select id="openai_inline_image_quality"> | 1963 | </label> |
| 1964 | <option data-i18n="openai_inline_image_quality_auto" value="auto">Auto</option> | 1964 | <select id="openai_inline_image_quality"> |
| 1965 | <option data-i18n="openai_inline_image_quality_low" value="low">Low</option> | 1965 | <option data-i18n="openai_inline_image_quality_auto" value="auto">Auto</option> |
| 1966 | <option data-i18n="openai_inline_image_quality_high" value="high">High</option> | 1966 | <option data-i18n="openai_inline_image_quality_low" value="low">Low</option> |
| 1967 | </select> | 1967 | <option data-i18n="openai_inline_image_quality_high" value="high">High</option> |
| 1968 | </select> | ||
| 1969 | </div> | ||
| 1968 | </div> | 1970 | </div> |
| 1969 | </div> | 1971 | </div> |
| 1970 | <div class="range-block" data-source="makersuite"> | 1972 | <div class="range-block" data-source="makersuite"> |
| @@ -1995,6 +1997,18 @@ | |||
| 1995 | </span> | 1997 | </span> |
| 1996 | </div> | 1998 | </div> |
| 1997 | </div> | 1999 | </div> |
| 2000 | <div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom"> | ||
| 2001 | <div class="flex-container oneline-dropdown" title="Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response."> | ||
| 2002 | <label for="openai_reasoning_effort" data-i18n="Reasoning Effort"> | ||
| 2003 | Reasoning Effort | ||
| 2004 | </label> | ||
| 2005 | <select id="openai_reasoning_effort"> | ||
| 2006 | <option data-i18n="openai_reasoning_effort_low" value="low">Low</option> | ||
| 2007 | <option data-i18n="openai_reasoning_effort_medium" value="medium">Medium</option> | ||
| 2008 | <option data-i18n="openai_reasoning_effort_high" value="high">High</option> | ||
| 2009 | </select> | ||
| 2010 | </div> | ||
| 2011 | </div> | ||
| 1998 | <div class="range-block" data-source="claude"> | 2012 | <div class="range-block" data-source="claude"> |
| 1999 | <div class="wide100p"> | 2013 | <div class="wide100p"> |
| 2000 | <div class="flex-container alignItemsCenter"> | 2014 | <div class="flex-container alignItemsCenter"> |
| @@ -2809,27 +2823,6 @@ | |||
| 2809 | <div> | 2823 | <div> |
| 2810 | <h4 data-i18n="OpenAI Model">OpenAI Model</h4> | 2824 | <h4 data-i18n="OpenAI Model">OpenAI Model</h4> |
| 2811 | <select id="model_openai_select"> | 2825 | <select id="model_openai_select"> |
| 2812 | <optgroup label="GPT-3.5 Turbo"> | ||
| 2813 | <option value="gpt-3.5-turbo">gpt-3.5-turbo</option> | ||
| 2814 | <option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024)</option> | ||
| 2815 | <option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023)</option> | ||
| 2816 | <option value="gpt-3.5-turbo-0613">gpt-3.5-turbo-0613 (2023)</option> | ||
| 2817 | <option value="gpt-3.5-turbo-0301">gpt-3.5-turbo-0301 (2023)</option> | ||
| 2818 | <option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option> | ||
| 2819 | <option value="gpt-3.5-turbo-16k-0613">gpt-3.5-turbo-16k-0613 (2023)</option> | ||
| 2820 | </optgroup> | ||
| 2821 | <optgroup label="GPT-3.5 Turbo Instruct"> | ||
| 2822 | <option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct</option> | ||
| 2823 | <option value="gpt-3.5-turbo-instruct-0914">gpt-3.5-turbo-instruct-0914</option> | ||
| 2824 | </optgroup> | ||
| 2825 | <optgroup label="GPT-4"> | ||
| 2826 | <option value="gpt-4">gpt-4</option> | ||
| 2827 | <option value="gpt-4-0613">gpt-4-0613 (2023)</option> | ||
| 2828 | <option value="gpt-4-0314">gpt-4-0314 (2023)</option> | ||
| 2829 | <option value="gpt-4-32k">gpt-4-32k</option> | ||
| 2830 | <option value="gpt-4-32k-0613">gpt-4-32k-0613 (2023)</option> | ||
| 2831 | <option value="gpt-4-32k-0314">gpt-4-32k-0314 (2023)</option> | ||
| 2832 | </optgroup> | ||
| 2833 | <optgroup label="GPT-4o"> | 2826 | <optgroup label="GPT-4o"> |
| 2834 | <option value="gpt-4o">gpt-4o</option> | 2827 | <option value="gpt-4o">gpt-4o</option> |
| 2835 | <option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option> | 2828 | <option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option> |
| @@ -2837,33 +2830,44 @@ | |||
| 2837 | <option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option> | 2830 | <option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option> |
| 2838 | <option value="chatgpt-4o-latest">chatgpt-4o-latest</option> | 2831 | <option value="chatgpt-4o-latest">chatgpt-4o-latest</option> |
| 2839 | </optgroup> | 2832 | </optgroup> |
| 2840 | <optgroup label="gpt-4o-mini"> | 2833 | <optgroup label="GPT-4o mini"> |
| 2841 | <option value="gpt-4o-mini">gpt-4o-mini</option> | 2834 | <option value="gpt-4o-mini">gpt-4o-mini</option> |
| 2842 | <option value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option> | 2835 | <option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option> |
| 2836 | <option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option> | ||
| 2837 | <option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option> | ||
| 2838 | <option value="chatgpt-4o-latest">chatgpt-4o-latest</option> | ||
| 2839 | </optgroup> | ||
| 2840 | <optgroup label="o1 and o1-mini"> | ||
| 2841 | <option value="o1">o1</option> | ||
| 2842 | <option value="o1-2024-12-17">o1-2024-12-17</option> | ||
| 2843 | <option value="o1-mini">o1-mini</option> | ||
| 2844 | <option value="o1-mini-2024-09-12">o1-mini-2024-09-12</option> | ||
| 2845 | <option value="o1-preview">o1-preview</option> | ||
| 2846 | <option value="o1-preview-2024-09-12">o1-preview-2024-09-12</option> | ||
| 2843 | </optgroup> | 2847 | </optgroup> |
| 2844 | <optgroup label="GPT-4 Turbo"> | 2848 | <optgroup label="o3"> |
| 2849 | <option value="o3-mini">o3-mini</option> | ||
| 2850 | <option value="o3-mini-2025-01-31">o3-mini-2025-01-31</option> | ||
| 2851 | </optgroup> | ||
| 2852 | <optgroup label="GPT-4 Turbo and GPT-4"> | ||
| 2845 | <option value="gpt-4-turbo">gpt-4-turbo</option> | 2853 | <option value="gpt-4-turbo">gpt-4-turbo</option> |
| 2846 | <option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09</option> | 2854 | <option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09</option> |
| 2847 | <option value="gpt-4-turbo-preview">gpt-4-turbo-preview</option> | 2855 | <option value="gpt-4-turbo-preview">gpt-4-turbo-preview</option> |
| 2848 | <option value="gpt-4-vision-preview">gpt-4-vision-preview</option> | ||
| 2849 | <option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option> | 2856 | <option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option> |
| 2850 | <option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option> | 2857 | <option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option> |
| 2858 | <option value="gpt-4">gpt-4</option> | ||
| 2859 | <option value="gpt-4-0613">gpt-4-0613 (2023)</option> | ||
| 2860 | <option value="gpt-4-0314">gpt-4-0314 (2023)</option> | ||
| 2851 | </optgroup> | 2861 | </optgroup> |
| 2852 | <optgroup label="o1"> | 2862 | <optgroup label="GPT-3.5 Turbo"> |
| 2853 | <option value="o1-preview">o1-preview</option> | 2863 | <option value="gpt-3.5-turbo">gpt-3.5-turbo</option> |
| 2854 | <option value="o1-mini">o1-mini</option> | 2864 | <option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024)</option> |
| 2855 | </optgroup> | 2865 | <option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023)</option> |
| 2856 | <optgroup label="o3"> | 2866 | <option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct</option> |
| 2857 | <option value="o3-mini">o3-mini</option> | ||
| 2858 | <option value="o3-mini-2025-01-31">o3-mini-2025-01-31</option> | ||
| 2859 | </optgroup> | 2867 | </optgroup> |
| 2860 | <optgroup label="Other"> | 2868 | <optgroup label="Other"> |
| 2861 | <option value="text-davinci-003">text-davinci-003</option> | 2869 | <option value="babbage-002">babbage-002</option> |
| 2862 | <option value="text-davinci-002">text-davinci-002</option> | 2870 | <option value="davinci-002">davinci-002</option> |
| 2863 | <option value="text-curie-001">text-curie-001</option> | ||
| 2864 | <option value="text-babbage-001">text-babbage-001</option> | ||
| 2865 | <option value="text-ada-001">text-ada-001</option> | ||
| 2866 | <option value="code-davinci-002">code-davinci-002</option> | ||
| 2867 | </optgroup> | 2871 | </optgroup> |
| 2868 | <optgroup id="openai_external_category" label="External"> | 2872 | <optgroup id="openai_external_category" label="External"> |
| 2869 | </optgroup> | 2873 | </optgroup> |
| @@ -299,6 +299,7 @@ const default_settings = { | |||
| 299 | continue_postfix: continue_postfix_types.SPACE, | 299 | continue_postfix: continue_postfix_types.SPACE, |
| 300 | custom_prompt_post_processing: custom_prompt_post_processing_types.NONE, | 300 | custom_prompt_post_processing: custom_prompt_post_processing_types.NONE, |
| 301 | show_thoughts: true, | 301 | show_thoughts: true, |
| 302 | reasoning_effort: 'medium', | ||
| 302 | seed: -1, | 303 | seed: -1, |
| 303 | n: 1, | 304 | n: 1, |
| 304 | }; | 305 | }; |
| @@ -378,6 +379,7 @@ const oai_settings = { | |||
| 378 | continue_postfix: continue_postfix_types.SPACE, | 379 | continue_postfix: continue_postfix_types.SPACE, |
| 379 | custom_prompt_post_processing: custom_prompt_post_processing_types.NONE, | 380 | custom_prompt_post_processing: custom_prompt_post_processing_types.NONE, |
| 380 | show_thoughts: true, | 381 | show_thoughts: true, |
| 382 | reasoning_effort: 'medium', | ||
| 381 | seed: -1, | 383 | seed: -1, |
| 382 | n: 1, | 384 | n: 1, |
| 383 | }; | 385 | }; |
| @@ -1912,6 +1914,7 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 1912 | 'char_name': name2, | 1914 | 'char_name': name2, |
| 1913 | 'group_names': getGroupNames(), | 1915 | 'group_names': getGroupNames(), |
| 1914 | 'include_reasoning': Boolean(oai_settings.show_thoughts), | 1916 | 'include_reasoning': Boolean(oai_settings.show_thoughts), |
| 1917 | 'reasoning_effort': String(oai_settings.reasoning_effort), | ||
| 1915 | }; | 1918 | }; |
| 1916 | 1919 | ||
| 1917 | // Empty array will produce a validation error | 1920 | // Empty array will produce a validation error |
| @@ -3122,6 +3125,7 @@ function loadOpenAISettings(data, settings) { | |||
| 3122 | oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality; | 3125 | oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality; |
| 3123 | oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check; | 3126 | oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check; |
| 3124 | oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts; | 3127 | oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts; |
| 3128 | oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort; | ||
| 3125 | oai_settings.seed = settings.seed ?? default_settings.seed; | 3129 | oai_settings.seed = settings.seed ?? default_settings.seed; |
| 3126 | oai_settings.n = settings.n ?? default_settings.n; | 3130 | oai_settings.n = settings.n ?? default_settings.n; |
| 3127 | 3131 | ||
| @@ -3251,6 +3255,9 @@ function loadOpenAISettings(data, settings) { | |||
| 3251 | $('#n_openai').val(oai_settings.n); | 3255 | $('#n_openai').val(oai_settings.n); |
| 3252 | $('#openai_show_thoughts').prop('checked', oai_settings.show_thoughts); | 3256 | $('#openai_show_thoughts').prop('checked', oai_settings.show_thoughts); |
| 3253 | 3257 | ||
| 3258 | $('#openai_reasoning_effort').val(oai_settings.reasoning_effort); | ||
| 3259 | $(`#openai_reasoning_effort option[value="${oai_settings.reasoning_effort}"]`).prop('selected', true); | ||
| 3260 | |||
| 3254 | if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy; | 3261 | if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy; |
| 3255 | $('#openai_reverse_proxy').val(oai_settings.reverse_proxy); | 3262 | $('#openai_reverse_proxy').val(oai_settings.reverse_proxy); |
| 3256 | 3263 | ||
| @@ -3511,6 +3518,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | |||
| 3511 | continue_postfix: settings.continue_postfix, | 3518 | continue_postfix: settings.continue_postfix, |
| 3512 | function_calling: settings.function_calling, | 3519 | function_calling: settings.function_calling, |
| 3513 | show_thoughts: settings.show_thoughts, | 3520 | show_thoughts: settings.show_thoughts, |
| 3521 | reasoning_effort: settings.reasoning_effort, | ||
| 3514 | seed: settings.seed, | 3522 | seed: settings.seed, |
| 3515 | n: settings.n, | 3523 | n: settings.n, |
| 3516 | }; | 3524 | }; |
| @@ -3969,6 +3977,7 @@ function onSettingsPresetChange() { | |||
| 3969 | continue_postfix: ['#continue_postfix', 'continue_postfix', false], | 3977 | continue_postfix: ['#continue_postfix', 'continue_postfix', false], |
| 3970 | function_calling: ['#openai_function_calling', 'function_calling', true], | 3978 | function_calling: ['#openai_function_calling', 'function_calling', true], |
| 3971 | show_thoughts: ['#openai_show_thoughts', 'show_thoughts', true], | 3979 | show_thoughts: ['#openai_show_thoughts', 'show_thoughts', true], |
| 3980 | reasoning_effort: ['#openai_reasoning_effort', 'reasoning_effort', false], | ||
| 3972 | seed: ['#seed_openai', 'seed', false], | 3981 | seed: ['#seed_openai', 'seed', false], |
| 3973 | n: ['#n_openai', 'n', false], | 3982 | n: ['#n_openai', 'n', false], |
| 3974 | }; | 3983 | }; |
| @@ -5510,6 +5519,11 @@ export function initOpenAI() { | |||
| 5510 | saveSettingsDebounced(); | 5519 | saveSettingsDebounced(); |
| 5511 | }); | 5520 | }); |
| 5512 | 5521 | ||
| 5522 | $('#openai_reasoning_effort').on('input', function () { | ||
| 5523 | oai_settings.reasoning_effort = String($(this).val()); | ||
| 5524 | saveSettingsDebounced(); | ||
| 5525 | }); | ||
| 5526 | |||
| 5513 | if (!CSS.supports('field-sizing', 'content')) { | 5527 | if (!CSS.supports('field-sizing', 'content')) { |
| 5514 | $(document).on('input', '#openai_settings .autoSetHeight', function () { | 5528 | $(document).on('input', '#openai_settings .autoSetHeight', function () { |
| 5515 | resetScrollHeight($(this)); | 5529 | resetScrollHeight($(this)); |
| @@ -5914,3 +5914,15 @@ body:not(.movingUI) .drawer-content.maximized { | |||
| 5914 | .mes_text div[data-type="assistant_note"]:has(.assistant_note_export)>div:not(.assistant_note_export) { | 5914 | .mes_text div[data-type="assistant_note"]:has(.assistant_note_export)>div:not(.assistant_note_export) { |
| 5915 | flex: 1; | 5915 | flex: 1; |
| 5916 | } | 5916 | } |
| 5917 | |||
| 5918 | .oneline-dropdown label { | ||
| 5919 | margin-top: 3px; | ||
| 5920 | margin-bottom: 5px; | ||
| 5921 | flex-grow: 1; | ||
| 5922 | text-align: left; | ||
| 5923 | } | ||
| 5924 | |||
| 5925 | .oneline-dropdown select { | ||
| 5926 | min-width: fit-content; | ||
| 5927 | width: 40%; | ||
| 5928 | } | ||
| @@ -1063,6 +1063,13 @@ router.post('/generate', jsonParser, function (request, response) { | |||
| 1063 | return response.status(400).send({ error: true }); | 1063 | return response.status(400).send({ error: true }); |
| 1064 | } | 1064 | } |
| 1065 | 1065 | ||
| 1066 | // A few of OpenAIs reasoning models support reasoning effort | ||
| 1067 | if ([CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENAI].includes(request.body.chat_completion_source)) { | ||
| 1068 | if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) { | ||
| 1069 | bodyParams['reasoning_effort'] = request.body.reasoning_effort; | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | |||
| 1066 | if (!apiKey && !request.body.reverse_proxy && request.body.chat_completion_source !== CHAT_COMPLETION_SOURCES.CUSTOM) { | 1073 | if (!apiKey && !request.body.reverse_proxy && request.body.chat_completion_source !== CHAT_COMPLETION_SOURCES.CUSTOM) { |
| 1067 | console.warn('OpenAI API key is missing.'); | 1074 | console.warn('OpenAI API key is missing.'); |
| 1068 | return response.status(400).send({ error: true }); | 1075 | return response.status(400).send({ error: true }); |