Skip to content

fix(transformer): support DeepSeek thinking parameter passthrough (#88) - #99

Merged
Hureru merged 2 commits into
devfrom
fix/issue-88-deepseek-thinking-parameter
Jun 25, 2026
Merged

fix(transformer): support DeepSeek thinking parameter passthrough (#88)#99
Hureru merged 2 commits into
devfrom
fix/issue-88-deepseek-thinking-parameter

Conversation

@Hureru

@Hureru Hureru commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Add support for DeepSeek's thinking parameter to fix issue where thinking mode could not be disabled from client applications.

Root cause: The thinking parameter ({"thinking": {"type": "disabled"}}) sent by clients like Cherry Studio was silently dropped during JSON deserialization because InternalLLMRequest lacked this field. This caused DeepSeek API to use its default value (thinking.type = "enabled"), making the model think even when users explicitly disabled it.

Changes:

  • Add ThinkingConfig type to model package
  • Add Thinking field to InternalLLMRequest
  • Pass through thinking parameter in OpenAI chat outbound transformer
  • Add unit tests and end-to-end regression test

Design:

  • Protocol-neutral: only passes through the parameter without transformation
  • Backward compatible: thinking is optional (omitempty)
  • Isolated: does not affect other providers (Anthropic, Gemini, etc.)

Fixes: #88

Summary by CodeRabbit

  • New Features

    • Added support for an optional “thinking” setting in chat requests, including enabled/disabled values.
    • Preserves this setting end-to-end so it is included in outgoing requests when configured.
    • Allows the “thinking” setting to be used alongside other request options.
  • Tests

    • Added regression coverage to ensure the “thinking” setting is not lost during request processing.
    • Added validation for both present and omitted “thinking” payloads.

Add support for DeepSeek's thinking parameter to fix issue where
thinking mode could not be disabled from client applications.

Root cause: The thinking parameter ({"thinking": {"type": "disabled"}})
sent by clients like Cherry Studio was silently dropped during JSON
deserialization because InternalLLMRequest lacked this field. This
caused DeepSeek API to use its default value (thinking.type = "enabled"),
making the model think even when users explicitly disabled it.

Changes:
- Add ThinkingConfig type to model package
- Add Thinking field to InternalLLMRequest
- Pass through thinking parameter in OpenAI chat outbound transformer
- Add unit tests and end-to-end regression test

Design:
- Protocol-neutral: only passes through the parameter without transformation
- Backward compatible: thinking is optional (omitempty)
- Isolated: does not affect other providers (Anthropic, Gemini, etc.)

Fixes: #88
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a thinking configuration to the internal LLM request model, forwards it into OpenAI chat completions, and adds regression coverage for passthrough and reasoning_effort coexistence.

Changes

Thinking parameter passthrough

Layer / File(s) Summary
Internal thinking config contract
internal/transformer/model/model.go
InternalLLMRequest gains a thinking field, and ThinkingConfig defines the serialized type value.
OpenAI chat payload mapping
internal/transformer/outbound/openai/chat.go
ChatCompletionsRequest gains thinking, and the request builder copies it from the internal request.
End-to-end thinking passthrough regression
internal/transformer/outbound/openai/chat_issue88_test.go
The regression test sends thinking.type = "disabled" through inbound and outbound transformation and checks the outgoing JSON body.
Thinking payload cases
internal/transformer/outbound/openai/chat_thinking_test.go
The outbound tests cover thinking present, omitted, and combined with reasoning_effort.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

A bunny hopped through JSON green,
And found a thinking field serene.
Off stays off, with ears held high,
No stray thought-cloud drifts by the sky.
🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: passing through DeepSeek's thinking parameter.
Linked Issues check ✅ Passed The changes add and forward the thinking field so the off setting is preserved for OpenAI-compatible requests.
Out of Scope Changes check ✅ Passed The diff stays focused on thinking-parameter passthrough and related regression tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/transformer/outbound/openai/chat_issue88_test.go (1)

45-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use io.ReadAll and handle read errors explicitly.

The manual read loop breaks on any error and can hide unexpected read failures. Use io.ReadAll(httpReq.Body) for clearer and safer test logic.

♻️ Proposed refactor
 import (
 	"context"
 	"encoding/json"
+	"io"
 	"testing"
@@
-	// Read the request body that would be sent to DeepSeek
-	body := make([]byte, 0)
-	buf := make([]byte, 1024)
-	for {
-		n, err := httpReq.Body.Read(buf)
-		if n > 0 {
-			body = append(body, buf[:n]...)
-		}
-		if err != nil {
-			break
-		}
-	}
+	// Read the request body that would be sent to DeepSeek
+	body, err := io.ReadAll(httpReq.Body)
+	if err != nil {
+		t.Fatalf("failed to read outgoing request body: %v", err)
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/transformer/outbound/openai/chat_issue88_test.go` around lines 45 -
56, The request-body capture in the chat_issue88 test uses a manual read loop
that can mask unexpected failures; update the test to use io.ReadAll on
httpReq.Body instead, and handle any returned read error explicitly before
asserting on the collected body. Keep the change scoped to the test helper logic
around httpReq.Body so the intent remains clear and safer.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/transformer/outbound/openai/chat_issue88_test.go`:
- Around line 45-56: The request-body capture in the chat_issue88 test uses a
manual read loop that can mask unexpected failures; update the test to use
io.ReadAll on httpReq.Body instead, and handle any returned read error
explicitly before asserting on the collected body. Keep the change scoped to the
test helper logic around httpReq.Body so the intent remains clear and safer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e4051ef-53ae-44cf-a1fd-e9dc79df7bd1

📥 Commits

Reviewing files that changed from the base of the PR and between c50e9d0 and 52b7ea6.

📒 Files selected for processing (4)
  • internal/transformer/model/model.go
  • internal/transformer/outbound/openai/chat.go
  • internal/transformer/outbound/openai/chat_issue88_test.go
  • internal/transformer/outbound/openai/chat_thinking_test.go

@Hureru
Hureru merged commit 5bcb02d into dev Jun 25, 2026
4 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.

[Bug] 没开启深度思考,但是使用时会自动思考

1 participant