From ed347313121a39a2f6ed91a9542c412cbe23ad9b 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 21:17:05 +0800 Subject: [PATCH] ai --- routes/ai.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/routes/ai.js b/routes/ai.js index 7059944..156b7ff 100644 --- a/routes/ai.js +++ b/routes/ai.js @@ -148,9 +148,23 @@ router.post('/recognize-product', async (ctx) => { "confidence": 0到1之间的数字(识别置信度) }`; - const imageUrl = `data:image/jpeg;base64,${imageBase64}`; + // omni 模型不支持 data URI,先保存为文件再用 URL + const imageBuffer = Buffer.from(imageBase64, 'base64'); + const fileName = `ai_${Date.now()}_${Math.random().toString(36).slice(2, 8)}.jpg`; + const filePath = path.join(__dirname, '..', 'public', 'uploads', fileName); + + // 确保 uploads 目录存在 + const uploadsDir = path.join(__dirname, '..', 'public', 'uploads'); + if (!fs.existsSync(uploadsDir)) { + fs.mkdirSync(uploadsDir, { recursive: true }); + } + fs.writeFileSync(filePath, imageBuffer); - console.log('Calling Qwen Omni API with image...'); + // 构造公网可访问的 URL + const serverHost = process.env.SERVER_HOST || 'http://110.42.255.239:3006'; + const imageUrl = `${serverHost}/uploads/${fileName}`; + + console.log('Calling Qwen Omni API with image:', imageUrl); const response = await fetch(AI_API_URL, { method: 'POST', headers: {