Kept the reported token usage as one record on the answer

This commit is contained in:
Thorsten Sommer committed 2026-09-23 18:31:00 +02:00
1 parent ceb78ff9b7
commit 4918858650
4 files changed
+77 -58

No files matched your search

@@ -455,18 +455,7 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
aiText.IsStreaming = true;
aiText.Text += contentStreamChunk;
aiText.Sources.MergeSources(contentStreamChunk.Sources);
//
// Keep what the provider says the request cost. It arrives on one line of the stream,
// usually the last one, and only where a provider reports it at all -- so a chunk
// without it leaves what was reported before alone.
//
if (contentStreamChunk.Usage.IsKnown)
{
aiText.ReportedPromptTokens = contentStreamChunk.Usage.PromptTokens;
aiText.ReportedCompletionTokens = contentStreamChunk.Usage.CompletionTokens;
aiText.ReportedForModel = state.ChatGenerationRequest.ProviderSettings.Model.Id;
}
aiText.RecordReportedUsage(contentStreamChunk.Usage, state.ChatGenerationRequest.ProviderSettings.Model.Id);
if (state.Snapshot.Status is not AIJobStatus.RUNNING)
{