Apply post-process before setting cache at depth
| @@ -1048,6 +1048,15 @@ router.post('/generate', function (request, response) { | |||
| 1048 | let bodyParams; | 1048 | let bodyParams; |
| 1049 | const isTextCompletion = Boolean(request.body.model && TEXT_COMPLETION_MODELS.includes(request.body.model)) || typeof request.body.messages === 'string'; | 1049 | const isTextCompletion = Boolean(request.body.model && TEXT_COMPLETION_MODELS.includes(request.body.model)) || typeof request.body.messages === 'string'; |
| 1050 | 1050 | ||
| 1051 | const postProcessTypes = [CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENROUTER]; | ||
| 1052 | if (Array.isArray(request.body.messages) && postProcessTypes.includes(request.body.chat_completion_source) && request.body.custom_prompt_post_processing) { | ||
| 1053 | console.info('Applying custom prompt post-processing of type', request.body.custom_prompt_post_processing); | ||
| 1054 | request.body.messages = postProcessPrompt( | ||
| 1055 | request.body.messages, | ||
| 1056 | request.body.custom_prompt_post_processing, | ||
| 1057 | getPromptNames(request)); | ||
| 1058 | } | ||
| 1059 | |||
| 1051 | if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) { | 1060 | if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) { |
| 1052 | apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString(); | 1061 | apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString(); |
| 1053 | apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI); | 1062 | apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| @@ -1152,15 +1161,6 @@ router.post('/generate', function (request, response) { | |||
| 1152 | return response.status(400).send({ error: true }); | 1161 | return response.status(400).send({ error: true }); |
| 1153 | } | 1162 | } |
| 1154 | 1163 | ||
| 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 | |||
| 1164 | // A few of OpenAIs reasoning models support reasoning effort | 1164 | // A few of OpenAIs reasoning models support reasoning effort |
| 1165 | if ([CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENAI].includes(request.body.chat_completion_source)) { | 1165 | if ([CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENAI].includes(request.body.chat_completion_source)) { |
| 1166 | if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) { | 1166 | if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) { |