Added the exact token count where the provider reports it (#989)
Build and Release / Verify (push) Waiting to run
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
j-erlerandThorsten Sommer authored and GitHub committed 2026-09-23 20:17:02 +02:00
1 parent 82986afe62
commit be1e6532fb
34 files changed
+1360 -104

No files matched your search

@@ -29,9 +29,26 @@ public readonly record struct ConversationTokens
public bool IsKnown { get; init; }
/// <summary>
/// How many tokens the counted parts of the conversation take.
/// How many tokens the counted parts of the conversation take, the draft included.
/// </summary>
public int Tokens { get; init; }
public int Tokens => this.HistoryTokens + this.DraftTokens;
/// <summary>
/// How many tokens the conversation takes without the message being written right now.
/// </summary>
public int HistoryTokens { get; init; }
/// <summary>
/// How much of HistoryTokens the tools of the running request add: the calls to them and what
/// they returned so far.
/// </summary>
/// <remarks>
/// Named on its own because it is the one share which goes away again. The model reads it in
/// every round of the request, so it fills the window while the tools work -- and none of it is
/// sent with the next message. Without saying so, the number would climb by tens of thousands
/// and then drop back once the answer stands, and nobody could tell why.
/// </remarks>
public int ToolTokens { get; init; }
/// <summary>
/// Whether the number is an estimate rather than the model's own count.
@@ -45,13 +62,46 @@ public readonly record struct ConversationTokens
/// </remarks>
public bool IsEstimate { get; init; }
/// <summary>
/// How many tokens the message being written right now takes.
/// </summary>
/// <remarks>
/// Kept apart from the rest for the same reason the statements above are kept apart: what the
/// conversation has already cost is something a provider can be asked about, while a sentence
/// nobody has sent yet can only be estimated.
/// </remarks>
public int DraftTokens { get; init; }
/// <summary>
/// Whether the conversation so far was counted by the provider rather than by this app.
/// </summary>
/// <remarks>
/// True once a provider has stated what a request of this conversation cost, which makes
/// everything up to the last answer an exact number. That answer is counted by this app, since
/// the provider's number for it includes reasoning which no request carries; next to the rest
/// of the conversation, its share of the error is small enough to still call the history exact.
/// It says nothing about the draft, which stays an estimate either way -- nobody has charged
/// for that one yet.
/// </remarks>
public bool HistoryIsReported { get; init; }
/// <summary>
/// How much the model reads, where anybody has stated it.
/// </summary>
public ContextWindow Window { get; init; }
/// <summary>
/// How many images travel along which nobody can count.
/// How many images travel along, those of the conversation and those of the draft.
/// </summary>
public int Images { get; init; }
/// <summary>
/// How many of those images are attached to the message being written right now.
/// </summary>
public int DraftImages { get; init; }
/// <summary>
/// How many images travel along which nobody has counted.
/// </summary>
/// <remarks>
/// Every vendor charges images differently -- OpenAI by tiles of the scaled image, Anthropic by
@@ -59,8 +109,11 @@ public readonly record struct ConversationTokens
/// file without decoding it first. So they are reported as a number of images instead of being
/// guessed at, or worse, counted as the base64 text they are sent as: that text is two to three
/// orders of magnitude longer than what any vendor charges for the picture.
///
/// Where the provider reported the conversation so far, it counted the pictures in it as well,
/// however it charges them. Then only those of the draft are left uncounted.
/// </remarks>
public int UncountedImages { get; init; }
public int UncountedImages => this.HistoryIsReported ? this.DraftImages : this.Images;
/// <summary>
/// How many images the model takes, where its vendor stated a number.
@@ -77,7 +130,8 @@ public readonly record struct ConversationTokens
/// the person who crosses it has usually forgotten that the pictures are still there.
///
/// False whenever nobody stated a limit, which is most models. An invented ceiling would refuse
/// something that works.
/// something that works. Whether anybody counted the pictures plays no part: the limit is on
/// how many travel, not on what they cost.
/// </remarks>
public bool TooManyImages => this.ImageLimits.MaxInOneMessage is { } allowed && this.UncountedImages > allowed;
public bool TooManyImages => this.ImageLimits.MaxInOneMessage is { } allowed && this.Images > allowed;
}