升级到v1.3.0:新增auto推理模式和完善推理级别文档

主要功能更新:
- 新增auto推理级别,完全遵循客户端原始请求参数
- 支持五档推理级别:auto/off/low/medium/high
- auto模式零干预:不修改推理字段和anthropic-beta头
- 除gpt-5-codex外,所有模型默认设为auto模式

文档完善:
- 更新核心功能说明,突出智能推理级别控制
- 新增auto推理模式详细说明和使用场景
- 添加推理级别对比表格和配置示例
- 增强FAQ部分,分场景解答推理相关问题
- 提供OpenAI和Anthropic模型字段对应关系

技术实现:
- 更新getModelReasoning函数支持auto选项
- 完善所有transformer的auto模式处理逻辑
- 优化routes.js中直接转发端点的auto支持
- 确保auto模式下头信息和请求体完全透传
This commit is contained in:
1e0n
2025-10-09 13:32:50 +08:00
parent 036198cebb
commit 4a8d7986dd
7 changed files with 110 additions and 34 deletions

View File

@@ -113,7 +113,14 @@ export function transformToAnthropic(openaiRequest) {
// Handle thinking field based on model configuration
const reasoningLevel = getModelReasoning(openaiRequest.model);
if (reasoningLevel) {
if (reasoningLevel === 'auto') {
// Auto mode: preserve original request's thinking field exactly as-is
if (openaiRequest.thinking !== undefined) {
anthropicRequest.thinking = openaiRequest.thinking;
}
// If original request has no thinking field, don't add one
} else if (reasoningLevel && ['low', 'medium', 'high'].includes(reasoningLevel)) {
// Specific level: override with model configuration
const budgetTokens = {
'low': 4096,
'medium': 12288,
@@ -125,7 +132,7 @@ export function transformToAnthropic(openaiRequest) {
budget_tokens: budgetTokens[reasoningLevel]
};
} else {
// If reasoning is off or invalid, explicitly remove thinking field
// Off or invalid: explicitly remove thinking field
// This ensures any thinking field from the original request is deleted
delete anthropicRequest.thinking;
}
@@ -179,7 +186,10 @@ export function getAnthropicHeaders(authHeader, clientHeaders = {}, isStreaming
// Handle thinking beta based on reasoning configuration
const thinkingBeta = 'interleaved-thinking-2025-05-14';
if (reasoningLevel) {
if (reasoningLevel === 'auto') {
// Auto mode: don't modify anthropic-beta header, preserve original
// betaValues remain unchanged from client headers
} else if (reasoningLevel && ['low', 'medium', 'high'].includes(reasoningLevel)) {
// Add thinking beta if not already present
if (!betaValues.includes(thinkingBeta)) {
betaValues.push(thinkingBeta);

View File

@@ -94,14 +94,20 @@ 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
if (reasoningLevel === 'auto') {
// Auto mode: preserve original request's reasoning field exactly as-is
if (openaiRequest.reasoning !== undefined) {
targetRequest.reasoning = openaiRequest.reasoning;
}
// If original request has no reasoning field, don't add one
} else if (reasoningLevel && ['low', 'medium', 'high'].includes(reasoningLevel)) {
// Specific level: override with model configuration
targetRequest.reasoning = {
effort: reasoningLevel,
summary: 'auto'
};
} else {
// If reasoning is off or invalid, explicitly remove reasoning field
// Off or invalid: explicitly remove reasoning field
// This ensures any reasoning field from the original request is deleted
delete targetRequest.reasoning;
}