Skip to content

feat(nah_chat): support reasoning_effort (chat completions + Responses API) - #29

Merged
linmx0130 merged 5 commits into
mainfrom
feat/nah_chat-reasoning-effort
Sep 13, 2026
Merged

linmx0130 merged 5 commits into
mainfrom
feat/nah_chat-reasoning-effort

Conversation

@linmx0130

Copy link
Copy Markdown
Owner

What

Adds first-class support for the OpenAI/DeepSeek reasoning effort parameter to nah_chat, for both APIs:

API Request field Builder
Chat completion ({base}/chat/completions) reasoning_effort (top level) ChatCompletionParamsBuilder::reasoning_effort("high")
Responses ({base}/responses) reasoning: {"effort": ...} (nested) ResponsesParamsBuilder::reasoning_effort("high")

Before this PR the values could only be passed as raw JSON (insert(...) / reasoning(Value)), with no helper, no tests, no docs — and the two APIs use different wire spellings, which is easy to get wrong.

// chat completion API: flat field
let mut params = ChatCompletionParamsBuilder::new();
params.max_tokens(4096).reasoning_effort("high");

// Responses API: nested under `reasoning`; other keys are preserved
let mut params = ResponsesParamsBuilder::new();
params
  .reasoning(serde_json::json!({"summary": "auto"}))
  .reasoning_effort("high"); // -> {"reasoning": {"summary": "auto", "effort": "high"}}

Design notes

  • reasoning_effort takes a plain &str and sends it verbatim (server-side validation): OpenAI reasoning models take none/minimal/low/medium/high/xhigh/max, DeepSeek takes low/high/max. No new public types.
  • The Responses setter merges effort into an existing reasoning object, so it composes with the raw reasoning(Value) setter. reasoning(Value) itself keeps its whole-object semantics (documented + tested).
  • Vendor-specific thinking toggles stay unmodeled and go through insert (documented): DeepSeek thinking: {"type": "enabled"|"disabled"}, Qwen3/vLLM enable_thinking; in the Responses API DeepSeek uses reasoning.effort: "none" to disable thinking.
  • No version bump (additive change only): nah_chat stays 0.8.0, Cargo.toml/Cargo.lock untouched. CHANGELOG entry is under ## Unreleased. No new dependencies.

Tests

  • test_chat_completion_params_builder_reasoning_effort — value set, passed through verbatim, absent by default.
  • test_chat_completion_request_body_reasoning_effort — serialized body has top-level reasoning_effort and no nested reasoning object.
  • test_responses_request_body_reasoning_effort — serialized body has reasoning.effort and no top-level reasoning_effort.
  • test_responses_reasoning_effort_merges_into_existing_object — merge semantics; reasoning(Value) still replaces the object.

Verification

  • cargo fmt --check clean, cargo build --workspace ok, cargo test --workspace → 32 tests + 1 doctest pass, 0 failed.
  • cargo clippy -p nah_chat --all-targets: no warnings from the new code (remaining warnings are pre-existing).
  • End-to-end wire check against a local mock of DeepSeek (nah_chat/examples/reasoning_effort run with BASE_URL=http://127.0.0.1:8799): captured request bodies were /chat/completions -> reasoning_effort: "high" (no reasoning) and /responses -> reasoning: {"effort": "high"} (no top-level reasoning_effort); the example processed the replayed reasoning/text/usage SSE and printed reasoning_tokens=Some(7) / Some(3).
  • Not yet run against a live endpoint — no DEEPSEEK_API_KEY in the dev environment. To check: DEEPSEEK_API_KEY=... cargo run -p nah_chat --example reasoning_effort (swap in reasoning_effort("none") on the Responses call to confirm thinking is disabled, i.e. reasoning_tokens == 0).

Docs / examples

  • nah_chat/README.md: new “Reasoning effort” section (per-API field table, examples, DeepSeek thinking-mode notes: effort mapping, temperature/frequency_penalty ignored, top_p clamped to >= 0.95).
  • nah_chat/src/lib.rs crate docs feature bullet; CHANGELOG ## Unreleased.
  • Root README.md: how to set it from the nah CLI via model.extraParams (already works through the pass-through; no CLI code change).
  • New nah_chat/examples/reasoning_effort.rs; examples/responses.rs now uses the typed-free string setter.

@linmx0130
linmx0130 merged commit 23c4dc8 into main Sep 13, 2026
1 check passed
@linmx0130
linmx0130 deleted the feat/nah_chat-reasoning-effort branch September 13, 2026 03:40
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.

1 participant