From 74521c54c359155e8c96fe2947867741c806e24f Mon Sep 17 00:00:00 2001 From: 1e0n Date: Wed, 8 Oct 2025 22:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A8=E7=90=86=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=88=A0=E9=99=A4=E9=80=BB=E8=BE=91=EF=BC=9A=E5=BD=93?= =?UTF-8?q?reasoning=E8=AE=BE=E7=BD=AE=E4=B8=BAoff=E6=97=B6=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E5=88=A0=E9=99=A4=E5=8E=9F=E5=A7=8B=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=8E=A8=E7=90=86=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正request-openai.js中reasoning字段的处理逻辑 - 修正request-anthropic.js中thinking字段的处理逻辑 - 确保当模型配置reasoning为off时,原始请求中的推理相关字段被显式删除 - 与routes.js中的直接转发逻辑保持一致 --- transformers/request-anthropic.js | 21 ++++----------------- transformers/request-openai.js | 16 +++++----------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/transformers/request-anthropic.js b/transformers/request-anthropic.js index 1e8573a..7f533ca 100644 --- a/transformers/request-anthropic.js +++ b/transformers/request-anthropic.js @@ -120,23 +120,10 @@ export function transformToAnthropic(openaiRequest) { type: 'enabled', budget_tokens: budgetTokens[reasoningLevel] }; - } - // If request already has thinking field, respect the configuration rule - // Remove it if model config is off/invalid, otherwise override with config - if (openaiRequest.thinking) { - if (reasoningLevel) { - const budgetTokens = { - 'low': 4096, - 'medium': 12288, - 'high': 24576 - }; - - anthropicRequest.thinking = { - type: 'enabled', - budget_tokens: budgetTokens[reasoningLevel] - }; - } - // If reasoningLevel is null (off/invalid), don't add thinking field + } else { + // If reasoning is off or invalid, explicitly remove thinking field + // This ensures any thinking field from the original request is deleted + delete anthropicRequest.thinking; } // Pass through other compatible parameters diff --git a/transformers/request-openai.js b/transformers/request-openai.js index e17c97f..fb95ea1 100644 --- a/transformers/request-openai.js +++ b/transformers/request-openai.js @@ -91,21 +91,15 @@ export function transformToOpenAI(openaiRequest) { // Handle reasoning field based on model configuration const reasoningLevel = getModelReasoning(openaiRequest.model); if (reasoningLevel) { + // Add reasoning field based on model configuration targetRequest.reasoning = { effort: reasoningLevel, summary: 'auto' }; - } - // If request already has reasoning field, respect the configuration rule - // Remove it if model config is off/invalid, otherwise override with config - if (openaiRequest.reasoning) { - if (reasoningLevel) { - targetRequest.reasoning = { - effort: reasoningLevel, - summary: 'auto' - }; - } - // If reasoningLevel is null (off/invalid), don't add reasoning field + } else { + // If reasoning is off or invalid, explicitly remove reasoning field + // This ensures any reasoning field from the original request is deleted + delete targetRequest.reasoning; } // Pass through other parameters