修改缓存命中逻辑

This commit is contained in:
2026-07-29 08:16:57 +08:00
parent 0e17abd653
commit 074e907cae
2 changed files with 17 additions and 2 deletions

View File

@@ -39,6 +39,17 @@ async function callDeepSeek(messages, userId, temperature = 0.1, jsonMode = true
console.error('DeepSeek 返回异常:', JSON.stringify(data));
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;
}