feat: added performance statistics info when using embedded LLM

This commit is contained in:
Xiaohan-Tian
2026-05-14 19:05:13 -07:00
parent 98c2b97413
commit eb1c7bd2fc
8 changed files with 58 additions and 8 deletions
+7 -2
View File
@@ -38,6 +38,7 @@ export const useStreamProcessor = (options: StreamProcessorOptions): StreamProce
let assistantResponse = '';
let tokenCount = 0;
let hasTextContent = false;
let performanceInfo: ChatMessage['performanceInfo'];
console.log(`------------ ${logPrefix} ------------`);
console.log(input);
@@ -65,7 +66,8 @@ export const useStreamProcessor = (options: StreamProcessorOptions): StreamProce
...msg,
content: assistantResponse,
isStreaming: false,
tokenCount: undefined
tokenCount: undefined,
performanceInfo
}));
console.log('------------ ASSISTANT ------------');
@@ -98,19 +100,22 @@ export const useStreamProcessor = (options: StreamProcessorOptions): StreamProce
assistantResponse = '';
tokenCount = 0;
hasTextContent = false;
performanceInfo = undefined;
// Create a fresh streaming placeholder for the next LLM response
const nextMsg = createStreamingMessage();
currentStreamingId = nextMsg.id;
onMessageAdd(nextMsg);
} else if (chunk.type === 'done') {
performanceInfo = chunk.performanceInfo;
// Finalize the streaming message
if (hasTextContent) {
onMessageUpdate(currentStreamingId, (msg) => ({
...msg,
content: assistantResponse,
isStreaming: false,
tokenCount: undefined
tokenCount: undefined,
performanceInfo
}));
} else {
// No text in final response — remove empty placeholder