fix: LLM和搜索调用时记录统计到backend

This commit is contained in:
2026-04-27 18:50:33 +08:00
parent 1c3f7604c9
commit 0244715a8a

View File

@@ -3957,6 +3957,9 @@ async function streamGenerate(userMsgIndex) {
syncConversationToBackend(currentConversation);
renderMessages();
// 记录统计到 backend
logStatsToBackend('llm_call', currentConversation.agentId || 'chat', 1);
// 自动总结标题第一次对话和每隔5次对话
const totalMessages = currentConversation.messages.length;
// 第一次对话(用户+AI=2条或每5次对话10条
@@ -3966,6 +3969,15 @@ async function streamGenerate(userMsgIndex) {
}
}
// 记录统计到 backend
function logStatsToBackend(type, key, value = 1) {
fetch('/api/admin/stats/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ type, key, value })
}).catch(e => console.error('统计记录失败:', e));
}
// 执行 Tavily 搜索
async function performSearch(query) {
try {
@@ -3988,6 +4000,10 @@ async function performSearch(query) {
}
const data = await response.json();
// 记录搜索统计
logStatsToBackend('search_call', 'tavily', 1);
return data.results || [];
} catch (error) {
console.error('搜索错误:', error);