fix: LLM和搜索调用时记录统计到backend
This commit is contained in:
16
www/app.js
16
www/app.js
@@ -3957,6 +3957,9 @@ async function streamGenerate(userMsgIndex) {
|
|||||||
syncConversationToBackend(currentConversation);
|
syncConversationToBackend(currentConversation);
|
||||||
renderMessages();
|
renderMessages();
|
||||||
|
|
||||||
|
// 记录统计到 backend
|
||||||
|
logStatsToBackend('llm_call', currentConversation.agentId || 'chat', 1);
|
||||||
|
|
||||||
// 自动总结标题:第一次对话和每隔5次对话
|
// 自动总结标题:第一次对话和每隔5次对话
|
||||||
const totalMessages = currentConversation.messages.length;
|
const totalMessages = currentConversation.messages.length;
|
||||||
// 第一次对话(用户+AI=2条)或每5次对话(10条)
|
// 第一次对话(用户+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 搜索
|
// 执行 Tavily 搜索
|
||||||
async function performSearch(query) {
|
async function performSearch(query) {
|
||||||
try {
|
try {
|
||||||
@@ -3988,6 +4000,10 @@ async function performSearch(query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// 记录搜索统计
|
||||||
|
logStatsToBackend('search_call', 'tavily', 1);
|
||||||
|
|
||||||
return data.results || [];
|
return data.results || [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('搜索错误:', error);
|
console.error('搜索错误:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user