Skip to content

docs(examples): add chat reasoningEffort examples - #214

Merged
andreaonofrei01 merged 1 commit into
mainfrom
docs/examples-reasoning
May 5, 2026
Merged

andreaonofrei01 merged 1 commit into
mainfrom
docs/examples-reasoning

Conversation

@andreaonofrei01

Copy link
Copy Markdown
Contributor

Summary

Adds four runnable examples in examples/src/ demonstrating reasoningEffort on mistral-medium-3-5. The SDK already supports the parameter and the ThinkChunk / TextChunk types, but there were no examples showing how to use them. TypeScript port of mistralai/client-python#511.

Files

  • reasoning_response_shape.ts — first stop. Calls the API once with reasoningEffort: "high" and once with "none", then dumps the raw message.content so the reader can see the ThinkChunk / TextChunk JSON before consuming it.
  • reasoning.ts — single-turn call. Iterates message.content and discriminates on chunk.type === "thinking" | "text". Notes that reasoningEffort: "none" returns a plain string.
  • reasoning_with_streaming.ts — the streaming version. Handles the three shapes that arrive on delta.content: ThinkChunk arrays during the thinking phase, a transition array containing both a closing ThinkChunk and the first TextChunk, and plain string fragments after thinking ends.
  • reasoning_multi_turn.ts — 3-turn math chain (17 × 23 → × 3 → −100). Replays the assistant turn back into messages with ThinkChunks intact and prints per-turn token usage so the cost difference is visible.

Notes

  • All examples use per-call { timeoutMs: 300_000 } because reasoning runs routinely exceed the default 30s timeout.
  • Model is pinned to mistral-medium-3-5 (the model docs explicitly list as supporting reasoningEffort).

Test plan

  • `npx tsc --noEmit` passes for all four files against the project's strict tsconfig.
  • `npx tsx examples/src/reasoning_response_shape.ts` — verified output matches the documented `ThinkChunk` / `TextChunk` schema; `"none"` returns `string`.
  • `npx tsx examples/src/reasoning.ts` — verified the John puzzle returns `John is 22 years old`.
  • `npx tsx examples/src/reasoning_with_streaming.ts` — verified the trains problem returns `11:16:40 am` and the thinking → final-answer transition renders cleanly.
  • `npx tsx examples/src/reasoning_multi_turn.ts` — verified the chain arrives at `1073`; observed totals prompt=1020, completion=608 (sum 1628).

@andreaonofrei01
andreaonofrei01 merged commit b8551b8 into main May 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants