From d8d82ceda75fa17972d6996f83078367a19c1730 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 12 三月 2026 15:38:32 +0800
Subject: [PATCH] #
---
src/main/webapp/views/ai/diagnosis.html | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/main/webapp/views/ai/diagnosis.html b/src/main/webapp/views/ai/diagnosis.html
index 55bcd08..c613791 100644
--- a/src/main/webapp/views/ai/diagnosis.html
+++ b/src/main/webapp/views/ai/diagnosis.html
@@ -616,7 +616,7 @@
<footer class="composer-panel">
<div class="composer-head">
<div><strong>鍚� AI 鍔╂墜鎻愰棶</strong></div>
- <div>{{ currentChatId ? '浼氳瘽宸茬粦瀹�' : '涓存椂浼氳瘽' }}</div>
+ <div>{{ currentRunTokenSummary || currentChatTokenSummary || (currentChatId ? '浼氳瘽宸茬粦瀹�' : '涓存椂浼氳瘽') }}</div>
</div>
<el-input
v-model="userInput"
@@ -679,6 +679,7 @@
lastRenderTs: 0,
renderIntervalMs: 120,
stepChars: 6,
+ runTokenUsage: null,
userInput: '',
autoScrollThreshold: 80,
chats: [],
@@ -731,7 +732,15 @@
var current = this.findChat(this.currentChatId);
if (!current && this.resetting) return '鏂板缓浼氳瘽锛岀瓑寰呴鏉℃秷鎭�';
if (!current) return '浼氳瘽 ' + this.currentChatId;
- return this.chatLabel(current);
+ var tokenText = this.tokenSummaryText(current);
+ return tokenText ? (this.chatLabel(current) + ' 路 ' + tokenText) : this.chatLabel(current);
+ },
+ currentChatTokenSummary: function() {
+ var current = this.findChat(this.currentChatId);
+ return current ? this.tokenSummaryText(current) : '';
+ },
+ currentRunTokenSummary: function() {
+ return this.runTokenUsage ? this.tokenSummaryText(this.runTokenUsage, '鏈') : '';
},
inlinePrompts: function() {
return this.promptPresets.slice(1);
@@ -801,7 +810,22 @@
},
chatOptionLabel: function(chat) {
if (!chat) return '鏈懡鍚嶄細璇�';
- return this.chatLabel(chat) + ' 路 ' + (chat.size || 0) + ' 鏉� 路 ' + this.chatUpdatedAt(chat);
+ var suffix = this.tokenSummaryText(chat);
+ return this.chatLabel(chat) + ' 路 ' + (chat.size || 0) + ' 鏉� 路 ' + this.chatUpdatedAt(chat) + (suffix ? (' 路 ' + suffix) : '');
+ },
+ numericValue: function(value) {
+ if (value === null || value === undefined || value === '') return 0;
+ var num = Number(value);
+ return isNaN(num) ? 0 : num;
+ },
+ tokenSummaryText: function(source, prefix) {
+ if (!source) return '';
+ var total = this.numericValue(source.totalTokens != null ? source.totalTokens : source.lastTotalTokens);
+ if (!total) return '';
+ var prompt = this.numericValue(source.promptTokens != null ? source.promptTokens : source.lastPromptTokens);
+ var completion = this.numericValue(source.completionTokens != null ? source.completionTokens : source.lastCompletionTokens);
+ var label = prefix || '涓婃';
+ return label + ' tokens ' + total + '锛堣緭' + prompt + ' / 鍑�' + completion + '锛�';
},
chatUpdatedAt: function(chat) {
if (!chat || !chat.updatedAt) return '鍒氬垰鍒涘缓';
@@ -825,6 +849,7 @@
openChat: function(chatId) {
if (!chatId || this.streaming) return;
this.currentChatId = chatId;
+ this.runTokenUsage = null;
this.switchChat();
},
switchChat: function() {
@@ -869,6 +894,7 @@
if (this.streaming) return;
this.currentChatId = Date.now() + '_' + Math.random().toString(36).substr(2, 8);
this.resetting = true;
+ this.runTokenUsage = null;
this.clear();
},
deleteChat: function() {
@@ -932,6 +958,7 @@
if (!message) return;
this.loading = true;
this.streaming = true;
+ this.runTokenUsage = null;
this.messages.push({ role: 'user', text: message, ts: this.nowStr() });
this.appendAssistantPlaceholder();
this.scrollToBottom(true);
@@ -945,6 +972,12 @@
this.source.onopen = function() {
self.loading = false;
};
+ this.source.addEventListener('token_usage', function(e) {
+ if (!e || !e.data) return;
+ try {
+ self.runTokenUsage = JSON.parse(e.data);
+ } catch (ignore) {}
+ });
this.source.onmessage = function(e) {
if (!e || !e.data) return;
var chunk = (e.data || '').replace(/\\n/g, '\n');
@@ -966,6 +999,7 @@
this.clear();
this.loading = true;
this.streaming = true;
+ this.runTokenUsage = null;
this.appendAssistantPlaceholder();
this.scrollToBottom(true);
@@ -974,6 +1008,12 @@
this.source.onopen = function() {
self.loading = false;
};
+ this.source.addEventListener('token_usage', function(e) {
+ if (!e || !e.data) return;
+ try {
+ self.runTokenUsage = JSON.parse(e.data);
+ } catch (ignore) {}
+ });
this.source.onmessage = function(e) {
if (!e || !e.data) return;
var chunk = (e.data || '').replace(/\\n/g, '\n');
--
Gitblit v1.9.1