feat: added performance statistics info when using embedded LLM
This commit is contained in:
@@ -110,6 +110,7 @@ export class AgentCore {
|
||||
let assistantTextContent = '';
|
||||
const accumulatedToolCalls: ToolCall[] = [];
|
||||
let finishReason = 'stop';
|
||||
let performanceInfo: StreamChunk['performanceInfo'];
|
||||
|
||||
for await (const chunk of this.llmProvider.generateStream(conversationHistory, systemPrompt, tools)) {
|
||||
if (chunk.type === 'text') {
|
||||
@@ -120,6 +121,7 @@ export class AgentCore {
|
||||
accumulatedToolCalls.push(chunk.toolCall);
|
||||
} else if (chunk.type === 'done') {
|
||||
finishReason = chunk.finishReason ?? 'stop';
|
||||
performanceInfo = chunk.performanceInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,10 +165,9 @@ export class AgentCore {
|
||||
// LLM finished with text response (stop reason)
|
||||
this.agentState.updateMessage(this.currentAssistantMessageId, assistantTextContent);
|
||||
continueLoop = false;
|
||||
yield { type: 'done', content: '', finishReason, performanceInfo };
|
||||
}
|
||||
}
|
||||
|
||||
yield { type: 'done', content: '', finishReason: 'stop' };
|
||||
} finally {
|
||||
this.currentUserMessageId = null;
|
||||
this.currentAssistantMessageId = null;
|
||||
|
||||
@@ -296,6 +296,14 @@ export class LocalBrowserLLMProvider implements LLMProvider {
|
||||
yield { type: 'tool_call', content: '', toolCall };
|
||||
}
|
||||
|
||||
yield { type: 'done', content: '', finishReason };
|
||||
yield {
|
||||
type: 'done',
|
||||
content: '',
|
||||
finishReason,
|
||||
performanceInfo: {
|
||||
prefillTps,
|
||||
generationTps,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@
|
||||
|
||||
import type { ToolCall } from '../core/AgentState';
|
||||
|
||||
export interface PerformanceInfo {
|
||||
prefillTps?: number;
|
||||
generationTps?: number;
|
||||
}
|
||||
|
||||
export interface StreamChunk {
|
||||
type: 'text' | 'tool_call' | 'tool_result' | 'done';
|
||||
content: string;
|
||||
toolCall?: ToolCall;
|
||||
toolResult?: { name: string; success: boolean; result: string };
|
||||
finishReason?: string; // 'stop' | 'tool_calls' — present on 'done' chunks
|
||||
performanceInfo?: PerformanceInfo;
|
||||
finishReason?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user