fix issues

This commit is contained in:
2026-07-22 17:17:00 +08:00
parent db31e7209d
commit 981f9ed4bf
4 changed files with 22 additions and 6 deletions

View File

@@ -60,11 +60,17 @@ async function analyzeWithDeepSeek(text, historyMessages, username, isAdmin) {
];
const content = await callDeepSeek(messages, 0.1);
console.log('🤖 AI 返回:', content);
const parsed = JSON.parse(content.replace(/```json|```/g, '').trim());
normalize(parsed);
const v = validate(parsed);
if (!v.valid) console.warn('⚠️ AI 返回校验失败:', v.error);
return parsed;
try {
const parsed = JSON.parse(content.replace(/```json|```/g, '').trim());
normalize(parsed);
const v = validate(parsed);
if (!v.valid) console.warn('⚠️ AI 返回校验失败:', v.error);
return parsed;
} catch (e) {
// AI 返回非 JSON如纯文本回复图片消息→ 降级为 chat
console.warn('⚠️ AI 返回非 JSON降级为 chat:', content.substring(0, 50));
return { action: 'chat', reply: content };
}
}
module.exports = router;