Fixed reasoning tokens inflating the exact token count

This commit is contained in:
Thorsten Sommer committed 2026-09-23 18:53:01 +02:00
1 parent c23ce9e12a
commit 3277f20f60
12 files changed
+172 -104

No files matched your search

+11 -8
View File
@@ -416,22 +416,25 @@ public sealed record ChatThread
/// is a lot of machinery for a number which corrects itself one answer later.
/// </remarks>
/// <param name="model">The model the next request would go to.</param>
/// <returns>What the provider reported, or unknown when no report describes this conversation.</returns>
public TokenUsage ReportedUsageFor(Model model)
/// <returns>
/// What the provider reported, together with the answer which followed it, or
/// ReportedHistory.UNKNOWN when no report describes this conversation.
/// </returns>
public ReportedHistory ReportedHistoryFor(Model model)
{
if (this.Blocks.Count is 0)
return TokenUsage.UNKNOWN;
return ReportedHistory.UNKNOWN;
if (this.Blocks[^1].Content is not ContentText { IsStreaming: false, ReportedUsage: { } reported })
return TokenUsage.UNKNOWN;
if (this.Blocks[^1].Content is not ContentText { IsStreaming: false, ReportedUsage: { } reported } answer)
return ReportedHistory.UNKNOWN;
if (reported.BlockCount != this.Blocks.Count)
return TokenUsage.UNKNOWN;
return ReportedHistory.UNKNOWN;
if (!string.Equals(reported.ModelId, model.Id, StringComparison.Ordinal))
return TokenUsage.UNKNOWN;
return ReportedHistory.UNKNOWN;
return reported.ToTokenUsage();
return ReportedHistory.Of(reported.ToTokenUsage(), answer.Text);
}
private static void DeleteManagedAttachments(ContentBlock block)