From 7869b1a4f61683b32e1b8bbc9e336813efd4d71d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E6=B5=B7=E6=B4=8B?= Date: Sun, 24 May 2026 20:00:56 +0800 Subject: [PATCH] ai --- routes/ai.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/routes/ai.js b/routes/ai.js index 3bb5d27..e7d8c38 100644 --- a/routes/ai.js +++ b/routes/ai.js @@ -5,8 +5,8 @@ const fs = require('fs'); const router = new Router(); -const DEEPSEEK_API_KEY = 'sk-21cc85a144874d9b902edffe6af8a971'; -const DEEPSEEK_API_URL = 'https://api.deepseek.com/chat/completions'; +const AI_API_KEY = 'sk-7f5d6f370f824f2ab76480c01bb00d40'; +const AI_API_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions'; router.post('/generate-product', async (ctx) => { try { @@ -31,14 +31,14 @@ router.post('/generate-product', async (ctx) => { "suggestedPrice": 建议售价(数字) }`; - const response = await fetch(DEEPSEEK_API_URL, { + const response = await fetch(AI_API_URL, { method: 'POST', headers: { - 'Authorization': `Bearer ${DEEPSEEK_API_KEY}`, + 'Authorization': `Bearer ${AI_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ - model: 'deepseek-v4-flash', + model: 'qwen3.5-flash', messages: [ { role: 'user', @@ -53,7 +53,7 @@ router.post('/generate-product', async (ctx) => { if (!response.ok) { const errorText = await response.text(); - console.error('DeepSeek API Error:', response.status, errorText); + console.error('Qwen API Error:', response.status, errorText); let errorMsg = 'AI 服务调用失败'; if (response.status === 401) { @@ -150,14 +150,15 @@ router.post('/recognize-product', async (ctx) => { const imageUrl = `data:image/jpeg;base64,${imageBase64}`; - const response = await fetch(DEEPSEEK_API_URL, { + console.log('Calling Qwen API with image...'); + const response = await fetch(AI_API_URL, { method: 'POST', headers: { - 'Authorization': `Bearer ${DEEPSEEK_API_KEY}`, + 'Authorization': `Bearer ${AI_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ - model: 'deepseek-v4-flash', + model: 'qwen3.5-flash', messages: [ { role: 'user', @@ -181,9 +182,11 @@ router.post('/recognize-product', async (ctx) => { timeout: 60000 }); + console.log('Qwen response status:', response.status); + if (!response.ok) { const errorText = await response.text(); - console.error('DeepSeek API Error:', response.status, errorText); + console.error('Qwen API Error:', response.status, errorText); let errorMsg = 'AI 服务调用失败'; if (response.status === 401) { @@ -194,6 +197,8 @@ router.post('/recognize-product', async (ctx) => { errorMsg = 'API 调用次数超限,请稍后重试'; } else if (response.status === 503) { errorMsg = 'AI 服务暂时不可用,请稍后重试'; + } else if (response.status === 404) { + errorMsg = '模型不支持图片输入,正在尝试兼容模式...'; } ctx.status = response.status; @@ -205,6 +210,7 @@ router.post('/recognize-product', async (ctx) => { } const data = await response.json(); + console.log('Qwen response data:', JSON.stringify(data, null, 2)); const aiResponse = data.choices?.[0]?.message?.content; if (!aiResponse) {