mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 09:57:59 +00:00
Added the exact token count for Anthropic and OpenAI (#1004)
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Verify (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Sync Flatpak repo (push) Has been cancelled
Build and Release / Collect Flatpak artifacts (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Verify (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Sync Flatpak repo (push) Has been cancelled
Build and Release / Collect Flatpak artifacts (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
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) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
This commit is contained in:
1 parent
0c585144e2
commit
4baf21656a
25 files changed
+837
-51
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
namespace AIStudio.Provider.Anthropic;
|
||||
|
||||
/// <summary>
|
||||
/// What Anthropic reports a messages call carried, as it opens the stream.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The input arrives in up to three parts, and only their sum is what the request carried: the
|
||||
/// input tokens are just those after the last cache breakpoint, the other two are what was written
|
||||
/// to and read from the cache before it. Read on 2026-09-24 at
|
||||
/// https://platform.claude.com/docs/en/build-with-claude/prompt-caching.
|
||||
///
|
||||
/// A missing cache part means that nothing was cached, not that its size is unknown: the API
|
||||
/// caches only for a request which asks for it with cache_control, which AI Studio never does on
|
||||
/// its own -- somebody could, though, through the additional API parameters. A missing input part
|
||||
/// is different, and without it the block states nothing.
|
||||
///
|
||||
/// The output tokens are left unread on purpose, for the reason given at TokenUsage: they include
|
||||
/// the model's thinking, which no later request carries.
|
||||
/// </remarks>
|
||||
public sealed record AnthropicUsage
|
||||
{
|
||||
/// <summary>
|
||||
/// What the request carried after its last cache breakpoint, which is all of it without caching.
|
||||
/// </summary>
|
||||
public int? InputTokens { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// What the request wrote to the cache.
|
||||
/// </summary>
|
||||
public int? CacheCreationInputTokens { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// What the request read from the cache.
|
||||
/// </summary>
|
||||
public int? CacheReadInputTokens { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// States what this block reports, as far as it can be believed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The one way from the wire to a usage, shared by the plain text path and the tool calling
|
||||
/// path, so that what counts as believable is decided in a single place.
|
||||
/// </remarks>
|
||||
/// <returns>The usage, or TokenUsage.UNKNOWN when the block states nothing usable.</returns>
|
||||
public TokenUsage ToTokenUsage() => this.InputTokens is { } inputTokens
|
||||
? TokenUsage.OfReported(inputTokens + (this.CacheCreationInputTokens ?? 0) + (this.CacheReadInputTokens ?? 0))
|
||||
: TokenUsage.UNKNOWN;
|
||||
}
|
||||
Reference in new issue
Block a user