修复推理字段删除逻辑:当reasoning设置为off时正确删除原始请求中的推理字段

- 修正request-openai.js中reasoning字段的处理逻辑
- 修正request-anthropic.js中thinking字段的处理逻辑
- 确保当模型配置reasoning为off时,原始请求中的推理相关字段被显式删除
- 与routes.js中的直接转发逻辑保持一致
This commit is contained in:
1e0n
2025-10-08 22:07:41 +08:00
parent 21b852b59e
commit 74521c54c3
2 changed files with 9 additions and 28 deletions

View File

@@ -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

View File

@@ -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