修改缓存命中逻辑
This commit is contained in:
@@ -39,6 +39,17 @@ async function callDeepSeek(messages, userId, temperature = 0.1, jsonMode = true
|
|||||||
console.error('DeepSeek 返回异常:', JSON.stringify(data));
|
console.error('DeepSeek 返回异常:', JSON.stringify(data));
|
||||||
throw new Error('AI 返回数据异常');
|
throw new Error('AI 返回数据异常');
|
||||||
}
|
}
|
||||||
|
// 缓存命中日志
|
||||||
|
if (data.usage) {
|
||||||
|
var hit = data.usage.prompt_cache_hit_tokens || 0;
|
||||||
|
var miss = data.usage.prompt_cache_miss_tokens || 0;
|
||||||
|
var total = data.usage.prompt_tokens || 0;
|
||||||
|
var rate = total > 0 ? (hit / total * 100).toFixed(1) : 0;
|
||||||
|
console.log('缓存: hit=' + hit + ' miss=' + miss + ' total=' + total + ' 命中率=' + rate + '%');
|
||||||
|
}
|
||||||
|
// 输入消息大小日志
|
||||||
|
var inputChars = JSON.stringify(messages).length;
|
||||||
|
console.log('输入大小: ' + inputChars + ' 字符, ' + messages.length + ' 条消息');
|
||||||
return data.choices[0].message.content;
|
return data.choices[0].message.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
function buildSystemPrompt(username, isAdmin) {
|
function buildSystemPrompt(username, isAdmin) {
|
||||||
const now = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
|
const now = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
|
||||||
|
|
||||||
const role = '你是智能财务助手"小财"。当前服务器时间:' + now + '。结合对话历史理解用户意图,只返回JSON。';
|
// 稳定前缀放前面(提升缓存命中率)
|
||||||
|
const role = '你是智能财务助手"小财"。结合对话历史理解用户意图,只返回JSON。';
|
||||||
|
|
||||||
const intent = [
|
const intent = [
|
||||||
'意图分类:',
|
'意图分类:',
|
||||||
@@ -68,7 +69,10 @@ function buildSystemPrompt(username, isAdmin) {
|
|||||||
'- 无法确定物品名 → action="ask" 追问'
|
'- 无法确定物品名 → action="ask" 追问'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
return [role, intent, permission, deleteRules, attachmentRules, prohibitionRules, modifyGuide, purchaseRules].join('\n');
|
// 变动的放最后
|
||||||
|
const timeInfo = '当前服务器时间:' + now;
|
||||||
|
|
||||||
|
return [role, intent, permission, deleteRules, attachmentRules, prohibitionRules, modifyGuide, purchaseRules, timeInfo].join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { buildSystemPrompt };
|
module.exports = { buildSystemPrompt };
|
||||||
|
|||||||
Reference in New Issue
Block a user