backup codes
This commit is contained in:
@@ -336,6 +336,13 @@ async function analyzeWithDeepSeek(text, historyMessages, username, isAdmin) {
|
|||||||
- 不要再返回 action="ask" 来处理删除请求,只要确定是删除意图,就必须返回 action="delete" 并填好 delete_item。
|
- 不要再返回 action="ask" 来处理删除请求,只要确定是删除意图,就必须返回 action="delete" 并填好 delete_item。
|
||||||
- 若用户描述的是特定记录(如“名字叫XXX的”),则 delete_item 填那个物品名。
|
- 若用户描述的是特定记录(如“名字叫XXX的”),则 delete_item 填那个物品名。
|
||||||
|
|
||||||
|
⚠️ 附件补充规则:
|
||||||
|
- 如果用户发送图片并明确说"这是XX的图片"或"作为附件存到XX采购里",
|
||||||
|
你只需返回 purchase_item 为 XX,**绝对不要**返回 quantity、unit_price、amount、freight、payment_method 等任何字段。
|
||||||
|
- 当消息中只有图片且文本明确指出"这是XX的图片"时,提取 purchase_item 为 XX,其余字段全部省略。
|
||||||
|
- 如果用户要求"把刚才/之前的图片作为附件存到XX采购",你可以返回 {"action":"purchase","purchase_item":"XX","use_recent_image":true},
|
||||||
|
不提供任何数量、价格字段,系统会自动查找最近一张图片并关联。
|
||||||
|
|
||||||
⚠️ 采购规则:
|
⚠️ 采购规则:
|
||||||
- 用户补充信息时更新已有记录。更新时请返回完整字段值,包括未变化的字段。如果用户要求修改时间,请生成正确的created_time字段。
|
- 用户补充信息时更新已有记录。更新时请返回完整字段值,包括未变化的字段。如果用户要求修改时间,请生成正确的created_time字段。
|
||||||
- 总金额(amount)由系统自动按“数量×单价+邮费”计算,你无需提供该字段。
|
- 总金额(amount)由系统自动按“数量×单价+邮费”计算,你无需提供该字段。
|
||||||
@@ -354,6 +361,10 @@ async function analyzeWithDeepSeek(text, historyMessages, username, isAdmin) {
|
|||||||
body: JSON.stringify({ model: 'deepseek-v4-flash', messages, temperature: 0.1, stream: false })
|
body: JSON.stringify({ model: 'deepseek-v4-flash', messages, temperature: 0.1, stream: false })
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
if (!data.choices || !data.choices[0]) {
|
||||||
|
console.error('🤖 DeepSeek 返回异常:', JSON.stringify(data));
|
||||||
|
throw new Error('DeepSeek API 返回异常: ' + (data.error?.message || JSON.stringify(data)));
|
||||||
|
}
|
||||||
const content = data.choices[0].message.content;
|
const content = data.choices[0].message.content;
|
||||||
console.log('🤖 AI 返回:', content);
|
console.log('🤖 AI 返回:', content);
|
||||||
return JSON.parse(content.replace(/```json|```/g, '').trim());
|
return JSON.parse(content.replace(/```json|```/g, '').trim());
|
||||||
@@ -361,7 +372,7 @@ async function analyzeWithDeepSeek(text, historyMessages, username, isAdmin) {
|
|||||||
|
|
||||||
function handleAIResult(aiResult, roomId, username, originalText, attachments) {
|
function handleAIResult(aiResult, roomId, username, originalText, attachments) {
|
||||||
const now = timestamp();
|
const now = timestamp();
|
||||||
if (aiResult.action === 'ask') { storeAndBroadcastText(roomId, '小财', aiResult.question); addToHistory(roomId, 'assistant', aiResult.question); return; }
|
if (aiResult.action === 'ask') { const q = aiResult.question || aiResult.reply || '请提供更多信息。'; storeAndBroadcastText(roomId, '小财', q); addToHistory(roomId, 'assistant', q); return; }
|
||||||
if (aiResult.action === 'delete') {
|
if (aiResult.action === 'delete') {
|
||||||
const itemName = aiResult.delete_item;
|
const itemName = aiResult.delete_item;
|
||||||
let purchases;
|
let purchases;
|
||||||
@@ -394,6 +405,16 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (aiResult.action === 'purchase') {
|
if (aiResult.action === 'purchase') {
|
||||||
|
// 引用最近图片:用户要求把之前的图片关联到某采购
|
||||||
|
if (aiResult.use_recent_image) {
|
||||||
|
const recentMsg = db.prepare("SELECT attachments FROM messages WHERE room_id = ? AND attachments IS NOT NULL AND attachments != '' ORDER BY timestamp DESC LIMIT 1").get(roomId);
|
||||||
|
if (recentMsg) {
|
||||||
|
try {
|
||||||
|
const files = JSON.parse(recentMsg.attachments);
|
||||||
|
if (files.length) attachments = files;
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
const createdTime = aiResult.created_time || now;
|
const createdTime = aiResult.created_time || now;
|
||||||
let purchase = db.prepare('SELECT * FROM purchases WHERE room_id = ? AND item LIKE ? AND status != ?').get(roomId, `%${aiResult.purchase_item}%`, '已完成');
|
let purchase = db.prepare('SELECT * FROM purchases WHERE room_id = ? AND item LIKE ? AND status != ?').get(roomId, `%${aiResult.purchase_item}%`, '已完成');
|
||||||
let replyText = '';
|
let replyText = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user