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

@@ -6,10 +6,11 @@ namespace AIStudio.Chat;
/// What a provider said the request behind one answer cost, as it is stored on that answer.
/// </summary>
/// <remarks>
/// The numbers and the model they were charged for travel as one value. Each of them is meaningless
/// without the others, and loose fields on the answer could be set, cleared, or copied apart.
/// The number, the model it was charged for, and the conversation it was counted on travel as one
/// value. Each of them is meaningless without the others, and loose fields on the answer could be
/// set, cleared, or copied apart.
///
/// Plain numbers rather than a TokenUsage: that type only ever comes out of its own factory, which
/// A plain number rather than a TokenUsage: that type only ever comes out of its own factory, which
/// is what keeps an impossible usage from existing, while a stored value has to be readable back by
/// the serializer. ToTokenUsage is the way back, and it treats a chat file somebody edited by hand
/// the same way the reading side treats a provider's JSON.
@@ -22,12 +23,7 @@ public sealed record ReportedTokenUsage
public int PromptTokens { get; init; }
/// <summary>
/// What the model wrote in answer.
/// </summary>
public int CompletionTokens { get; init; }
/// <summary>
/// Which model the numbers were charged for.
/// Which model the number was charged for.
/// </summary>
/// <remarks>
/// A token count belongs to the tokenizer which produced it. Switch the model of a chat, and
@@ -52,8 +48,8 @@ public sealed record ReportedTokenUsage
public int BlockCount { get; init; }
/// <summary>
/// States the stored numbers as a usage again.
/// States the stored number as a usage again.
/// </summary>
/// <returns>The usage, or TokenUsage.UNKNOWN when the stored numbers state nothing usable.</returns>
public TokenUsage ToTokenUsage() => TokenUsage.OfReported(this.PromptTokens, this.CompletionTokens);
/// <returns>The usage, or TokenUsage.UNKNOWN when the stored number states nothing usable.</returns>
public TokenUsage ToTokenUsage() => TokenUsage.OfReported(this.PromptTokens);
}