feat(AI): 两后端归一的 GenerateStats(prefill/decode 实测统计)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
link2026
2026-06-10 06:42:59 +08:00
parent 8c8599e77d
commit 070e016f81
3 changed files with 51 additions and 4 deletions

View File

@@ -8,6 +8,11 @@ import MLXLMCommon
actor LLMSession {
let container: ModelContainer
/// ( .info ,)
private(set) var lastStats: GenerateStats?
private func record(_ s: GenerateStats) { lastStats = s }
init(container: ModelContainer) {
self.container = container
}
@@ -78,9 +83,14 @@ actor LLMSession {
let rate = elapsed > 0 ? Double(produced) / elapsed : 0
continuation.yield(TokenChunk(text: text, decodeRate: rate))
case .info:
case .info(let info):
// ,
break
await self.record(GenerateStats(
promptTokens: info.promptTokenCount,
genTokens: info.generationTokenCount,
prefillSeconds: info.promptTime,
decodeSeconds: info.generateTime
))
case .toolCall:
// ,switch