ac4af582301a4e8a29245dbba767eba31334ddf9
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
defbb1a159 |
gateway: a Chat reply's cache read reaches the agent in OpenAI's names (B3TT3R on Discord)
B3TT3R (Discord #feedback, 10-25): DeepSeek Harness on DS-v4.1-Flash showed
"缓存命中 0%" over 1.2M input, and dsh's message usage carried only
inputTokens, outputTokens and totalTokens.
dsh reaches magpie through @deepseek-ai/dsh-llm-pi-ai with api
openai-completions, so its usage comes from pi-ai 1.4.0's parseChunkUsage:
cacheRead = prompt_tokens_details.cached_tokens ?? prompt_cache_hit_tokens
?? cached_tokens ?? 0, and nothing of Anthropic's. dsh's mapUsage drops a
0. magpie's Chat passthrough sent the upstream's usage as it came, so when
a provider told the cache only in another vendor's names (a relay giving
Anthropic's cache_read_input_tokens, or DeepSeek's prompt_cache_hit_tokens
or Moonshot's top-level cached_tokens beside a 0 in prompt_tokens_details)
the gateway counted the hit in its own usage log while the agent saw none.
Now chatTidy (stream) and chatWhole (whole reply) tell such a usage in
OpenAI's names too: prompt_tokens_details.cached_tokens, cache_write_tokens
when a write was told, and prompt_tokens counting both, with total_tokens
moved by the same amount. Every field the upstream sent stays. A usage in
OpenAI's names alone is never decoded (mayMendUsage looks for the other
names first), and one that already agrees comes back byte for byte.
Translated routes (Responses, Messages, Gemini) and plugin replies already
build the usage from cUsage and needed nothing.
Not proven: which provider B3TT3R uses. "DS-v4.1-Flash" is not how magpie
names a dsh model, and DeepSeek's own API sends both names, which pi-ai
already read right through magpie (checked live below). So this fixes the
case where magpie is at fault; if B3TT3R is on DeepSeek's own key the
cause is elsewhere and the reply asks.
Run, at this head (rebased on
|
||
|
|
8653bead72 |
usage, gui: a usage record and a request's details carry its cache read and cache creation beside in and out (#1839)
kensenzhao asked for usage.jsonl and the Usage page's request details to
carry cache read and cache creation tokens beside input and output.
What changed
- usage.Record's cache_read and cache_write are written on every record,
0 too (they were omitempty), so a prompt that missed the cache reads as
that rather than as a record that kept no cache. A record from before
has neither and reads as 0, as it did. Input still holds neither.
- Every route already filled them; this pins it per wire format:
Anthropic messages, OpenAI Chat (prompt_tokens_details.cached_tokens and
DeepSeek's prompt_cache_hit_tokens), Responses
(input_tokens_details.cached_tokens) and Gemini
(cachedContentTokenCount), relayed and translated, whole and streamed,
a plugin's fetch, and the Claude subscription bridge. System One's
decision calls report no cache and are left as they are.
- A request's details in the ledger have a Tokens row at every width:
"{i} in · {o} out · {r} cache read · {w} cache creation", plus the
5-minute/1-hour split when known. Before, the cache showed only as
"{w} written · {r} read" when non-zero, so a missed cache said nothing.
That string is gone; the new one is in zh, zh-TW, ja and de.
Prices and quotas: the JSON tag is the only change to the record, so the
cost math (CostAt -> CostSplit reads CacheRead/CacheWrite/CacheWrite1h),
Totals' cache sums, budget's CacheReads and access/limit's token windows
read the same values as before. Checked by reading each and by the usage,
access and catalog tests passing unchanged.
Tests
- TestRecordAlwaysCarriesCacheTokens (usage): 0s written, old records read.
- TestUsageRecordsCacheTokensOnEveryRoute, TestPluginUsageRecordsCacheTokens,
TestClaudeSubscriptionUsageKeepsCacheTokens (gateway): each wire format,
whole and streamed.
- ledger-cache-tokens.test.cjs: Chromium and WebKit, 1100 and 390 wide,
en/zh/zh-TW/ja/de; usage-ledger-detail.test.cjs updated for the row.
- Broken by hand: putting omitempty back and dropping the Tokens row each
turned its test red. The gateway route tests pin what the routes
already did; they don't fail on the code before this commit.
Run: gofmt -l; go vet on darwin, linux -tags nogui and windows; go test
for usage, access, catalog, gui (-tags nogui) and gateway in full; the
GUI tests above plus the translation tests. Not run: a real vendor
request to see its cache figures land in usage.jsonl.
|