Refactor reasoning effort handling for OpenAI models in chat completions
| @@ -967,11 +967,6 @@ router.post('/generate', jsonParser, function (request, response) { | ||
| 967 | 967 | if (getConfigValue('openai.randomizeUserId', false)) { |
| 968 | 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 | 970 | } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) { |
| 976 | 971 | apiUrl = 'https://openrouter.ai/api/v1'; |
| 977 | 972 | apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER); |
| @@ -1027,11 +1022,6 @@ router.post('/generate', jsonParser, function (request, response) { | ||
| 1027 | 1022 | bodyParams.logprobs = true; |
| 1028 | 1023 | } |
| 1029 | 1024 | |
| 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 | 1025 | mergeObjectWithYaml(bodyParams, request.body.custom_include_body); |
| 1036 | 1026 | mergeObjectWithYaml(headers, request.body.custom_include_headers); |
| 1037 | 1027 | |
| @@ -1073,6 +1063,13 @@ router.post('/generate', jsonParser, function (request, response) { | ||
| 1073 | 1063 | return response.status(400).send({ error: true }); |
| 1074 | 1064 | } |
| 1075 | 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 | + | |
| 1076 | 1073 | if (!apiKey && !request.body.reverse_proxy && request.body.chat_completion_source !== CHAT_COMPLETION_SOURCES.CUSTOM) { |
| 1077 | 1074 | console.warn('OpenAI API key is missing.'); |
| 1078 | 1075 | return response.status(400).send({ error: true }); |