Repository navigation
[Community solution] Reasoning-token breakdown for DSH evaluations: a one-line source change #11778
zhangdw156
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Chinese version
DSH already includes reasoning tokens in output tokens, consistent with its documented accounting model. For evaluations, reasoning-effort comparisons, and failure analysis, some of us also need to know how much of that output was reasoning.
We encountered this while integrating DSH into an evaluation workflow: reasoning text was recorded, but the usage emitted by
llm-pi-aidid not retain pi-ai's breakdown. This optional change preservesusage.reasoningas DSH's existingreasoningTokensfield while keeping the official output and total accounting unchanged.Implementation and tests · Download patch
Related community discussions: #3825, #7110, #10840, and #11352. This post adds an implementation people can use and a reproducible validation path.
The change
Add one line to the object returned by
mapUsage()inpackages/llm/llm-pi-ai/src/stream.ts:It preserves positive counts and explicit zero, and omits the field when pi-ai supplies
undefined. Both successful completion and error termination use this mapping.A local HTTP fixture exercises the actual Loader, adapter, pi-ai parser, DSH LLM stream, and BlockAssembler. With 3 input tokens, 10 output tokens, and 6 reported thinking tokens:
inputTokensoutputTokensreasoningTokenstotalTokensReasoning is a subset of output. Do not add it to output or total tokens again. The change exposes a breakdown; it does not reduce consumption or change totals.
Apply to your own DSH source checkout
From the root of an existing DSH checkout with dependencies installed and a working build environment:
The
--includefilter applies only thestream.tschange: one added line of runtime logic and an updated adjacent comment. It does not bring the commit's tests or package documentation into your checkout. Continue updating and building your own upstream checkout.Restart from this checkout with your usual
pnpm dsharguments, for examplepnpm dsh web. An evaluation program that loads DSH directly must also use this source or its built artifacts. This does not update a global npm or Desktop installation.Updates and compatibility
Git locates the patch by code context rather than fixed line numbers. This keeps the change small, but does not guarantee compatibility with every future release. Changes to source paths, usage fields, or adapter interfaces still require validation. Do not force a patch that fails to apply.
As of November 1, 2026, the patch applies cleanly and modifies only the intended source file on:
master:ce7073d51254c26cd63b22a60835b8f948deb447.dsh-v0.2.2-alpha.2,dsh-v0.2.1-rc.5,dsh-v0.2.1-rc.2,dsh-v0.2.1-alpha.3, anddsh-v0.2.0-rc.2.The pi-ai versions locked by those tags,
1.3.0,1.1.0, and0.87.1, all declare optionalUsage.reasoning. These release-tag checks establish patch applicability and field availability, not successful builds or runtime behavior on each release. The full adapter validation below uses the currentmasterbaseline.The public
llm/streamhook inspected here runs after adapter conversion, so it cannot recover an omitted value.llm-pi-ai/request-headersdoes not expose responses. A future hook exposing raw usage before conversion could support an independent plugin and further reduce dependence on internal source. Suggestions for such an optional extension point are welcome.Reproduce without an API key
The complete example branch, pinned to
f23717593d228e7143c7fb7e9ec68fbe6133cfdc, includes regression tests. The minimal application above intentionally does not copy those test files.Run the reproducer in a separate directory
Requires Node.js 24.9 or newer and pnpm 11.28.5; see the official development prerequisites.
Expected: 8 passed. Six of these cases fail on the default implementation. Coverage includes positive counts, zero, absence, and both terminal event types. The Loader test replaces only the HTTP provider with a local fixture; DSH and pi-ai run their actual code.
The full adapter suite passed 452 tests locally. Artifact builds, final Host/Client type checks, and documentation checks passed; lint exited with code 0. Environment: macOS arm64, Node 26.13.0, pnpm 11.28.5, pi-ai 1.3.0. No live-model inference or Linux/Windows validation was performed.
Scope and feedback
reasoning: 0when the raw response has no breakdown, so zero is not universally proof that the model did no reasoning.If you need this breakdown too, please share your DSH commit, API protocol, and the layer where the count appears or disappears. A redacted usage snippet is enough; no credentials or full conversations are needed.
All reactions