OpenRouter: Allow applying prompt post-processing Fixes #3689
| @@ -3415,13 +3415,6 @@ | ||
| 3415 | 3415 | <div class="flex-container"> |
| 3416 | 3416 | <select id="model_custom_select" class="text_pole model_custom_select"></select> |
| 3417 | 3417 | </div> |
| 3418 | - <h4 data-i18n="Prompt Post-Processing">Prompt Post-Processing</h4> | |
| 3419 | - <select id="custom_prompt_post_processing" class="text_pole" title="Applies additional processing to the prompt before sending it to the API." data-i18n="[title]Applies additional processing to the prompt before sending it to the API."> | |
| 3420 | - <option data-i18n="prompt_post_processing_none" value="">None</option> | |
| 3421 | - <option data-i18n="prompt_post_processing_merge" value="merge">Merge consecutive roles</option> | |
| 3422 | - <option data-i18n="prompt_post_processing_semi" value="semi">Semi-strict (alternating roles)</option> | |
| 3423 | - <option data-i18n="prompt_post_processing_strict" value="strict">Strict (user first, alternating roles)</option> | |
| 3424 | - </select> | |
| 3425 | 3418 | </form> |
| 3426 | 3419 | <div id="01ai_form" data-source="01ai"> |
| 3427 | 3420 | <h4> |
| @@ -3440,6 +3433,15 @@ | ||
| 3440 | 3433 | <select id="model_01ai_select"> |
| 3441 | 3434 | </select> |
| 3442 | 3435 | </div> |
| 3436 | + <div id="prompt_post_porcessing_form" data-source="custom,openrouter"> | |
| 3437 | + <h4 data-i18n="Prompt Post-Processing">Prompt Post-Processing</h4> | |
| 3438 | + <select id="custom_prompt_post_processing" class="text_pole" title="Applies additional processing to the prompt before sending it to the API." data-i18n="[title]Applies additional processing to the prompt before sending it to the API."> | |
| 3439 | + <option data-i18n="prompt_post_processing_none" value="">None</option> | |
| 3440 | + <option data-i18n="prompt_post_processing_merge" value="merge">Merge consecutive roles</option> | |
| 3441 | + <option data-i18n="prompt_post_processing_semi" value="semi">Semi-strict (alternating roles)</option> | |
| 3442 | + <option data-i18n="prompt_post_processing_strict" value="strict">Strict (user first, alternating roles)</option> | |
| 3443 | + </select> | |
| 3444 | + </div> | |
| 3443 | 3445 | <div class="flex-container flex"> |
| 3444 | 3446 | <div id="api_button_openai" class="api_button menu_button menu_button_icon" type="submit" data-i18n="Connect">Connect</div> |
| 3445 | 3447 | <div class="api_loading menu_button menu_button_icon" data-i18n="Cancel">Cancel</div> |
| @@ -2020,6 +2020,7 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2020 | 2020 | 'reasoning_effort': String(oai_settings.reasoning_effort), |
| 2021 | 2021 | 'enable_web_search': Boolean(oai_settings.enable_web_search), |
| 2022 | 2022 | 'request_images': Boolean(oai_settings.request_images), |
| 2023 | + 'custom_prompt_post_processing': oai_settings.custom_prompt_post_processing, | |
| 2023 | 2024 | }; |
| 2024 | 2025 | |
| 2025 | 2026 | if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) { |
| @@ -2100,7 +2101,6 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2100 | 2101 | generate_data['custom_include_body'] = oai_settings.custom_include_body; |
| 2101 | 2102 | generate_data['custom_exclude_body'] = oai_settings.custom_exclude_body; |
| 2102 | 2103 | generate_data['custom_include_headers'] = oai_settings.custom_include_headers; |
| 2103 | - generate_data['custom_prompt_post_processing'] = oai_settings.custom_prompt_post_processing; | |
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | 2106 | if (isCohere) { |
| @@ -1121,14 +1121,6 @@ router.post('/generate', function (request, response) { | ||
| 1121 | 1121 | |
| 1122 | 1122 | mergeObjectWithYaml(bodyParams, request.body.custom_include_body); |
| 1123 | 1123 | mergeObjectWithYaml(headers, request.body.custom_include_headers); |
| 1124 | - | |
| 1125 | - if (request.body.custom_prompt_post_processing) { | |
| 1126 | - console.info('Applying custom prompt post-processing of type', request.body.custom_prompt_post_processing); | |
| 1127 | - request.body.messages = postProcessPrompt( | |
| 1128 | - request.body.messages, | |
| 1129 | - request.body.custom_prompt_post_processing, | |
| 1130 | - getPromptNames(request)); | |
| 1131 | - } | |
| 1132 | 1124 | } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) { |
| 1133 | 1125 | apiUrl = API_PERPLEXITY; |
| 1134 | 1126 | apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY); |
| @@ -1160,6 +1152,15 @@ router.post('/generate', function (request, response) { | ||
| 1160 | 1152 | return response.status(400).send({ error: true }); |
| 1161 | 1153 | } |
| 1162 | 1154 | |
| 1155 | + const postProcessTypes = [CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENROUTER]; | |
| 1156 | + if (postProcessTypes.includes(request.body.chat_completion_source) && request.body.custom_prompt_post_processing) { | |
| 1157 | + console.info('Applying custom prompt post-processing of type', request.body.custom_prompt_post_processing); | |
| 1158 | + request.body.messages = postProcessPrompt( | |
| 1159 | + request.body.messages, | |
| 1160 | + request.body.custom_prompt_post_processing, | |
| 1161 | + getPromptNames(request)); | |
| 1162 | + } | |
| 1163 | + | |
| 1163 | 1164 | // A few of OpenAIs reasoning models support reasoning effort |
| 1164 | 1165 | if ([CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENAI].includes(request.body.chat_completion_source)) { |
| 1165 | 1166 | if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) { |