v3.0.1, 改成tools调用方式
This commit is contained in:
+5
-12
@@ -96,10 +96,6 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
|
||||
}
|
||||
|
||||
if (aiResult.action === 'purchase') {
|
||||
if (aiResult.use_recent_image && (!aiResult.purchase_item || aiResult.purchase_item === 'null')) {
|
||||
const lastPurchase = db.prepare("SELECT item FROM purchases WHERE room_id = ? AND item IS NOT NULL AND item != '' ORDER BY created_at DESC LIMIT 1").get(roomId);
|
||||
if (lastPurchase) { aiResult.purchase_item = lastPurchase.item; }
|
||||
}
|
||||
const item = aiResult.purchase_item;
|
||||
if (!item || item === 'null' || item === 'undefined' || item.trim().length < 2) {
|
||||
storeAndBroadcastText(roomId, '小财', '请提供具体的物品名称。');
|
||||
@@ -108,13 +104,9 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
|
||||
}
|
||||
|
||||
let usedRecentImage = false;
|
||||
if (aiResult.use_recent_image) {
|
||||
const recentMsg = db.prepare("SELECT attachments FROM messages WHERE room_id = ? AND attachments IS NOT NULL AND attachments != '' AND attachments != '[]' ORDER BY id DESC LIMIT 1").get(roomId);
|
||||
if (recentMsg) {
|
||||
try { const files = JSON.parse(recentMsg.attachments); if (files.length) { attachments = files; usedRecentImage = true; } } catch(e) {}
|
||||
}
|
||||
}
|
||||
if (!usedRecentImage && !attachments?.length && /(图片|附件|加到|存入|关联|作为附件)/.test(originalText)) {
|
||||
// 图片关联:由后端根据消息文本判断,不再依赖模型返回 use_recent_image。
|
||||
// 用户消息提及图片/附件等词且本次未带附件时,自动关联最近的图片消息。
|
||||
if (!attachments?.length && /(图片|附件|加到|存入|关联|作为附件)/.test(originalText)) {
|
||||
const recentMsg = db.prepare("SELECT attachments FROM messages WHERE room_id = ? AND attachments IS NOT NULL AND attachments != '' AND attachments != '[]' ORDER BY id DESC LIMIT 1").get(roomId);
|
||||
if (recentMsg) {
|
||||
try { const files = JSON.parse(recentMsg.attachments); if (files.length) { attachments = files; usedRecentImage = true; } } catch(e) {}
|
||||
@@ -190,7 +182,8 @@ async function callDeepSeekForSummary(prompt, userId) {
|
||||
{ role: 'system', content: '你是一个财务助手,请根据采购记录生成简洁回复。' },
|
||||
{ role: 'user', content: prompt }
|
||||
];
|
||||
return callDeepSeek(messages, userId, 0.3, false);
|
||||
const msg = await callDeepSeek(messages, userId, 0.3, false);
|
||||
return msg && typeof msg === 'object' ? (msg.content || '') : (msg || '');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user