From 1d522df07eb314470acfb4aa85a14fe9b0cefaa3 Mon Sep 17 00:00:00 2001 From: Yuzhiran Dev Date: Sat, 11 Jul 2026 13:37:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20AI=20Chat=20LLM=20=E4=BB=8E=E5=B7=B2?= =?UTF-8?q?=E5=A4=B1=E6=95=88=20api.qnaigc.com=20=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=88=B0=20OpenCode=20Zen=20=E5=85=8D=E8=B4=B9=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 数据库 AIModel 记录从 meituan/longcat-flash-lite → deepseek-v4-flash-free - API 端点 https://api.qnaigc.com → https://opencode.ai/zen/v1/chat/completions - aiChat.js 支持免 Authorization 的免费 API(apiKey 为 sk-dummy 时跳过) - .env 同步更新 --- server/src/routes/aiChat.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/src/routes/aiChat.js b/server/src/routes/aiChat.js index bab18b7..66f5c01 100755 --- a/server/src/routes/aiChat.js +++ b/server/src/routes/aiChat.js @@ -91,22 +91,24 @@ router.post('/ask', userAuthMiddleware, async (req, res) => { modelConfig = { temperature: 0.7, maxTokens: 800, topP: 1 } } - // 检查API配置 - if (!apiKey) { - logger.error('AI API Key未配置') - return ApiResponse.error(res, 'AI服务暂时不可用', 500) - } + // 检查API配置(opencode.ai免费API无需key) + const needsAuth = apiKey && apiKey !== 'sk-dummy' && apiKey !== '***' // 构建系统提示词 const systemPrompt = getSystemPromptByDimension(dimension) + // 构建请求头 + const headers = { + 'Content-Type': 'application/json' + } + if (needsAuth) { + headers['Authorization'] = `Bearer ${apiKey}` + } + // 调用AI API const response = await fetch(apiUrl, { method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${apiKey}` - }, + headers, body: JSON.stringify({ model: modelId, messages: [