diff --git a/app/api/ai/claude/route.js b/app/api/ai/claude/route.js index d337f19..47d57aa 100644 --- a/app/api/ai/claude/route.js +++ b/app/api/ai/claude/route.js @@ -5,7 +5,7 @@ export const runtime = 'edge'; export async function POST(request) { try { - const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP } = await request.json(); + const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP, reasoningEffort } = await request.json(); const apiKey = apiConfig?.apiKey; const baseUrl = (apiConfig?.baseUrl || 'https://api.anthropic.com').replace(/\/$/, ''); @@ -23,7 +23,7 @@ export async function POST(request) { // 构造 Messages API 请求体 const requestBody = { model, - max_tokens: maxTokens || 4096, + max_tokens: maxTokens || 8192, system: systemPrompt, messages: [ { role: 'user', content: userPrompt } @@ -33,8 +33,16 @@ export async function POST(request) { ...(topP != null ? { top_p: topP } : {}), }; - // 如果模型支持 extended thinking (claude-3-7-sonnet),可以启用 - // 但默认不启用,因为需要额外的 budget 参数 + // 扩展思考 (extended thinking) — 当 reasoningEffort 不为 auto 时启用 + if (reasoningEffort && reasoningEffort !== 'auto') { + const budgetMap = { low: 2048, medium: 8192, high: 32768 }; + requestBody.thinking = { + type: 'enabled', + budget_tokens: budgetMap[reasoningEffort] || 8192, + }; + // 扩展思考不支持同时设 temperature + delete requestBody.temperature; + } const response = await fetch(url, { method: 'POST', diff --git a/app/api/ai/gemini/route.js b/app/api/ai/gemini/route.js index 7d9e07b..49ad649 100644 --- a/app/api/ai/gemini/route.js +++ b/app/api/ai/gemini/route.js @@ -5,7 +5,7 @@ export const runtime = 'edge'; export async function POST(request) { try { - const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP } = await request.json(); + const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP, reasoningEffort } = await request.json(); const apiKey = apiConfig?.apiKey || process.env.GEMINI_API_KEY; let rawBaseUrl = apiConfig?.baseUrl; @@ -36,9 +36,14 @@ export async function POST(request) { } ], generationConfig: { - temperature: temperature ?? 0.8, - topP: topP ?? 0.9, + ...(temperature != null ? { temperature } : {}), + ...(topP != null ? { topP } : {}), ...(maxTokens ? { maxOutputTokens: maxTokens } : {}), + ...(reasoningEffort && reasoningEffort !== 'auto' ? { + thinkingConfig: { + thinkingBudget: { low: 1024, medium: 8192, high: 32768 }[reasoningEffort] || 8192, + }, + } : {}), }, }; diff --git a/app/api/ai/responses/route.js b/app/api/ai/responses/route.js index 416b865..8b9c3da 100644 --- a/app/api/ai/responses/route.js +++ b/app/api/ai/responses/route.js @@ -32,8 +32,9 @@ export async function POST(request) { ...(topP != null ? { top_p: topP } : {}), }; - // 添加思考等级(默认 medium) - const effort = apiConfig?.reasoningEffort || 'medium'; + // 添加思考等级(默认 medium,不受高级参数面板影响) + const rawEffort = apiConfig?.reasoningEffort; + const effort = (!rawEffort || rawEffort === 'auto') ? 'medium' : rawEffort; if (['low', 'medium', 'high', 'xhigh'].includes(effort)) { requestBody.reasoning = { effort, summary: 'auto' }; } diff --git a/app/api/ai/route.js b/app/api/ai/route.js index 411c80d..4d60c69 100644 --- a/app/api/ai/route.js +++ b/app/api/ai/route.js @@ -5,7 +5,7 @@ export const runtime = 'edge'; export async function POST(request) { try { - const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP } = await request.json(); + const { systemPrompt, userPrompt, apiConfig, maxTokens, temperature, topP, reasoningEffort } = await request.json(); const apiKey = apiConfig?.apiKey || process.env.ZHIPU_API_KEY; const baseUrl = apiConfig?.baseUrl || 'https://open.bigmodel.cn/api/paas/v4'; @@ -33,9 +33,10 @@ export async function POST(request) { { role: 'system', content: systemPrompt }, { role: 'user', content: userPrompt } ], - temperature: temperature ?? 0.8, + ...(temperature != null ? { temperature } : {}), ...(topP != null ? { top_p: topP } : {}), ...(maxTokens ? { max_tokens: maxTokens } : {}), + ...(reasoningEffort && reasoningEffort !== 'auto' ? { reasoning_effort: reasoningEffort } : {}), stream: true, }), }); diff --git a/app/components/AiSidebar.js b/app/components/AiSidebar.js index a9492bc..7b58994 100644 --- a/app/components/AiSidebar.js +++ b/app/components/AiSidebar.js @@ -214,7 +214,8 @@ export default function AiSidebar({ onInsertText }) { maxTokens: apiConfig.maxOutputTokens || 65536, temperature: apiConfig.temperature ?? 1, topP: apiConfig.topP ?? 0.95, - } : { maxTokens: 4096 }), + reasoningEffort: apiConfig.reasoningEffort || 'auto', + } : {}), }), }); diff --git a/app/components/SettingsConflictModal.js b/app/components/SettingsConflictModal.js index fb6ed47..adc7bcb 100644 --- a/app/components/SettingsConflictModal.js +++ b/app/components/SettingsConflictModal.js @@ -139,7 +139,8 @@ ${importedFields} maxTokens: apiConfig.maxOutputTokens || 65536, temperature: apiConfig.temperature ?? 1, topP: apiConfig.topP ?? 0.95, - } : { maxTokens: 4096 }), + reasoningEffort: apiConfig.reasoningEffort || 'auto', + } : {}), }), }); diff --git a/app/components/SettingsPanel.js b/app/components/SettingsPanel.js index 8439df1..f812549 100644 --- a/app/components/SettingsPanel.js +++ b/app/components/SettingsPanel.js @@ -1135,20 +1135,43 @@ function ApiConfigForm({ data, onChange }) {