This commit is contained in:
董海洋
2026-05-24 20:00:56 +08:00
parent d9037460cf
commit 7869b1a4f6
+16 -10
View File
@@ -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) {