Map pi-ai's reasoning usage into reasoningTokens
#7110
Replies: 2 comments
|
Verified against Confirmed. Adjustment 1 — the snippet needs an undefined guard. ...usage.reasoning !== undefined && usage.reasoning > 0 ? { reasoningTokens: usage.reasoning } : {},Adjustment 2 — keep One boundary worth putting in the record. On the completions / responses / google paths, "the provider reports no breakdown" and "the provider reports zero" both surface as Mountability: none, and I checked before assuming. The value is discarded inside the adapter, before any chunk exists. The only two surfaces a plugin can see are the mapped |
|
Confirmed against The snippet now reads: ...usage.reasoning !== undefined && usage.reasoning > 0
? { reasoningTokens: usage.reasoning } : {},The strict-null half is a compile error we would have hit immediately. The half I had wrong is the predicate: copying Recorded with the ask: the boundary that a no-breakdown provider and a zero-reporting one are indistinguishable on completions/responses/google without a tri-state field, and the mountability finding — the value is gone before any chunk exists and Thank you for checking mountability rather than assuming it; that is the part that decides where the fix has to land. |
Uh oh!
There was an error while loading. Please reload this page.
What happens now. pi-ai parses the provider's split (
@earendil-works/pi-ai/dist/api/openai-completions.js:1201):@deepseek-ai/dsh-llm-pi-ai'smapUsage(lib/index.js:1403-1410) then mapsinput,output,totalTokens,cacheReadandcacheWrite— and dropsreasoning:Consequence. The harness's
TokenUsage.reasoningTokensis populated on the DeepSeek route (visible in a session transcript as{"inputTokens": 9707, "outputTokens": 153, "totalTokens": 11140, "cacheReadTokens": 1280, "reasoningTokens": 132}) and never on a pi-ai route, so the context meter and any per-turn accounting cannot separate thinking from answer there — exactly where local models spend most of their output tokens. The server does report the field; the adapter discards it. The doc comment ("reasoning folded into output by pi-ai") describes pi-ai's output bucket, not the separate count pi-ai also returns.Suggested patch (one line, mirroring the cache fields' "only when non-zero" rule):
Acceptance. On a pi-ai route, a thinking turn's
assistant/messagerecord carriesreasoningTokensmatching the provider'scompletion_tokens_details.reasoning_tokens; a non-thinking turn omits it, as the cache fields do.(Re-verified against
@deepseek-ai/dsh0.1.6-alpha.2 and@earendil-works/pi-ai0.85.1; the line numbers above are those versions'.)All reactions