Skip to content

feat: adapt Volcengine adaptor for deepseek3.1 with thinking mode - #1652

Merged
Calcium-Ion merged 1 commit into
QuantumNous:alphafrom
HynoR:feat/ds3.1
Aug 26, 2025
Merged

feat: adapt Volcengine adaptor for deepseek3.1 with thinking mode#1652
Calcium-Ion merged 1 commit into
QuantumNous:alphafrom
HynoR:feat/ds3.1

Conversation

@HynoR

@HynoR HynoR commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

ref: #1638

适配火山方舟 Deepseek 3.1 思考后缀
模型名称为 deepseek-v3-1-250821-thinking 将会启用思考功能
image

Summary by CodeRabbit

  • New Features

    • Automatic "thinking" mode for DeepSeek hybrid models: selecting a model with the “-thinking” suffix now transparently routes to the correct underlying model and enables the thinking behavior without extra configuration.
  • Chores

    • Internal handling updated to recognize “-thinking” model variants while preserving existing behavior for all other models; no API or settings changes.

@HynoR
HynoR changed the base branch from main to alpha August 25, 2025 02:37
@coderabbitai

coderabbitai Bot commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@HynoR has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 19f6a2d and ee6dd91.

📒 Files selected for processing (1)
  • relay/channel/volcengine/adaptor.go (2 hunks)

Walkthrough

Adds an import and a conditional in ConvertOpenAIRequest to detect upstream model names starting with "deepseek" and ending with "-thinking"; it trims the "-thinking" suffix and injects a JSON RawMessage into request.THINKING. No signature or exported declarations changed.

Changes

Cohort / File(s) Summary
Volcengine adaptor logic
relay/channel/volcengine/adaptor.go
Add encoding/json import. In ConvertOpenAIRequest, if info.UpstreamModelName starts with "deepseek" and ends with "-thinking", strip the suffix for request.Model and set request.THINKING to json.RawMessage(\{"thinking":{"type":"enabled"}}`)`. Other behavior unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Convert as ConvertOpenAIRequest
  participant Request as Outgoing OpenAI Request

  Caller->>Convert: call ConvertOpenAIRequest(info)
  activate Convert
  Convert->>Convert: eval info.UpstreamModelName\nstartsWith("deepseek") && endsWith("-thinking")
  alt deepseek thinking variant
    Convert->>Request: Model = trimmed name (remove "-thinking")
    Convert->>Request: THINKING = json.RawMessage({"thinking":{"type":"enabled"}})
  else other models
    Convert->>Request: build request normally
  end
  Convert-->>Caller: return request
  deactivate Convert
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I nibble code with careful paws,
Spot a suffix, snip because —
DeepSeek dreams now whisper, bright,
I tuck a thinking flag at night.
Hop, dispatch, the model hums — hooray! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@HynoR HynoR changed the title feat: 适配火山方舟 Deepseek 3.1 思考后缀 feat: adapt Volcengine adaptor for deepseek3.1 with thinking mode Aug 25, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
relay/channel/volcengine/adaptor.go (1)

218-223: Don’t mutate info.UpstreamModelName; merge into ExtraBody when enabling “thinking”

We’ve verified that:

  • ExtraBody is defined as json.RawMessage in dto/openai_request.go (line 62), so it’s safe to unmarshal and re-marshal when merging .
  • info.UpstreamModelName is used pervasively after this block (logs, metrics, routing, downstream adaptors), so in-place mutation here would have unintended side effects across the relay pipeline .

Location in question
• File relay/channel/volcengine/adaptor.go, lines 218–223

Suggested optional refactor

-	// 适配 方舟deepseek混合模型 的 thinking 后缀
-	if strings.HasSuffix(info.UpstreamModelName, "-thinking") && strings.HasPrefix(info.UpstreamModelName, "deepseek") {
-		info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking")
-		request.Model = info.UpstreamModelName
-		request.ExtraBody = json.RawMessage(`{"thinking": {"type": "enabled"}}`)
-	}
+	// 适配 方舟 deepseek 混合模型 的 thinking 后缀;不修改 info.UpstreamModelName,避免副作用
+	name := strings.ToLower(info.UpstreamModelName)
+	if strings.HasSuffix(name, "-thinking") && strings.HasPrefix(name, "deepseek") {
+		trimmed := strings.TrimSuffix(info.UpstreamModelName, "-thinking")
+		request.Model = trimmed
+		if len(request.ExtraBody) == 0 {
+			request.ExtraBody = json.RawMessage(`{"thinking":{"type":"enabled"}}`)
+		} else {
+			var extra map[string]any
+			if err := json.Unmarshal(request.ExtraBody, &extra); err == nil {
+				if _, exists := extra["thinking"]; !exists {
+					extra["thinking"] = map[string]any{"type":"enabled"}
+				}
+				if b, err := json.Marshal(extra); err == nil {
+					request.ExtraBody = b
+				}
+			}
+		}
+	}

Optional: add a unit test covering

  • Input model "deepseek-v3-1-250821-thinking" → request.Model "deepseek-v3-1-250821"
  • Pre-populated ExtraBody retains existing keys and injects "thinking" only once.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f96a733 and 4727a08.

📒 Files selected for processing (1)
  • relay/channel/volcengine/adaptor.go (2 hunks)
🔇 Additional comments (1)
relay/channel/volcengine/adaptor.go (1)

5-5: Import looks correct and necessary

encoding/json is required for json.RawMessage below. No issues.

@HynoR
HynoR force-pushed the feat/ds3.1 branch 2 times, most recently from 19f6a2d to a368e3a Compare August 25, 2025 03:16
@Calcium-Ion
Calcium-Ion merged commit 3e01dc8 into QuantumNous:alpha Aug 26, 2025
3 checks passed
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
feat: adapt Volcengine adaptor for deepseek3.1 with thinking mode
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