Refactor reasoning effort handling for OpenAI models in chat completions

dd2154c19be08f5c220ebe295940cb859bea09e3

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

1 files changed, +7 -10Ignore whitespace
src/endpoints/backends/chat-completions.js+7 -10
@@ -967,11 +967,6 @@ router.post('/generate', jsonParser, function (request, response) {
967 if (getConfigValue('openai.randomizeUserId', false)) {967 if (getConfigValue('openai.randomizeUserId', false)) {
968 bodyParams['user'] = uuidv4();968 bodyParams['user'] = uuidv4();
969 }969 }
970
971 // A few of OpenAIs reasoning models support reasoning effort
972 if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) {
973 bodyParams['reasoning_effort'] = request.body.reasoning_effort;
974 }
975 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) {970 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) {
976 apiUrl = 'https://openrouter.ai/api/v1';971 apiUrl = 'https://openrouter.ai/api/v1';
977 apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER);972 apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER);
@@ -1027,11 +1022,6 @@ router.post('/generate', jsonParser, function (request, response) {
1027 bodyParams.logprobs = true;1022 bodyParams.logprobs = true;
1028 }1023 }
10291024
1030 // A few of OpenAIs reasoning models support reasoning effort
1031 if (['o1', 'o3-mini', 'o3-mini-2025-01-31'].includes(request.body.model)) {
1032 bodyParams['reasoning_effort'] = request.body.reasoning_effort;
1033 }
1034
1035 mergeObjectWithYaml(bodyParams, request.body.custom_include_body);1025 mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
1036 mergeObjectWithYaml(headers, request.body.custom_include_headers);1026 mergeObjectWithYaml(headers, request.body.custom_include_headers);
10371027
@@ -1073,6 +1063,13 @@ router.post('/generate', jsonParser, function (request, response) {
1073 return response.status(400).send({ error: true });1063 return response.status(400).send({ error: true });
1074 }1064 }
10751065
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
1076 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) {
1077 console.warn('OpenAI API key is missing.');1074 console.warn('OpenAI API key is missing.');
1078 return response.status(400).send({ error: true });1075 return response.status(400).send({ error: true });