ai
This commit is contained in:
+16
-2
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user