Skip to content

fix: deepseek claude response - #1833

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/deepseek-claude-code
Sep 18, 2025
Merged

fix: deepseek claude response#1833
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/deepseek-claude-code

Conversation

@seefs001

@seefs001 seefs001 commented Sep 18, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability for Claude-formatted requests, reducing errors.
    • Ensured consistent behavior for both streaming and non-streaming Claude responses.
  • Refactor
    • Introduced dedicated handling for Claude format to streamline response processing.
    • Unified non-Claude requests through a single adaptor path for consistent behavior.

@coderabbitai

coderabbitai Bot commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Refactors DoResponse in relay/channel/deepseek/adaptor.go to switch on info.RelayFormat. For RelayFormatClaude, it directly calls claude stream/non-stream handlers and returns. For all other formats, it constructs an openai.Adaptor and delegates to adaptor.DoResponse, changing control flow and return behavior for Claude requests.

Changes

Cohort / File(s) Summary of Changes
DeepSeek adaptor control flow
relay/channel/deepseek/adaptor.go
Replaced IsStream-based branching with a switch on info.RelayFormat. Added direct dispatch to claude.ClaudeStreamHandler/claude.ClaudeHandler for RelayFormatClaude; default path now instantiates openai.Adaptor and calls adaptor.DoResponse. Updated return paths to directly return Claude handler results.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant DeepSeekAdaptor as DeepSeek Adaptor
    participant ClaudeHandlers as Claude Handlers
    participant OpenAIAdaptor as OpenAI Adaptor

    Client->>DeepSeekAdaptor: DoResponse(c, resp, info)
    alt info.RelayFormat == RelayFormatClaude
        alt info.IsStream
            DeepSeekAdaptor->>ClaudeHandlers: ClaudeStreamHandler(c, resp, info)
            ClaudeHandlers-->>DeepSeekAdaptor: result
        else Non-stream
            DeepSeekAdaptor->>ClaudeHandlers: ClaudeHandler(c, resp, info)
            ClaudeHandlers-->>DeepSeekAdaptor: result
        end
        DeepSeekAdaptor-->>Client: return result
    else Default (non-Claude)
        DeepSeekAdaptor->>OpenAIAdaptor: new Adaptor()
        DeepSeekAdaptor->>OpenAIAdaptor: DoResponse(c, resp, info)
        OpenAIAdaptor-->>DeepSeekAdaptor: result
        DeepSeekAdaptor-->>Client: return result
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion

Poem

A switch I nibble, hop to Claude’s lane,
Stream or not, I follow the grain.
For all else, I burrow to OpenAI’s trail,
Delegation steady, without a fail.
Thump-thump—routes aligned, no fuss, no fog,
🐇 Shipping clean paths through the log.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: deepseek claude response" directly describes the primary change in the diff: DoResponse now routes RelayFormatClaude to Claude-specific handlers to correct Claude response handling for deepseek. It is concise, focused on the main fix, and uses a standard "fix:" prefix that signals the intent.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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

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

@seefs001
seefs001 merged commit 0dd475d into QuantumNous:main Sep 18, 2025
1 check was pending

@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: 1

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

97-101: Trim redundant else after early return.

Minor cleanup; reduces nesting.

-        if info.IsStream {
-            return claude.ClaudeStreamHandler(c, resp, info, claude.RequestModeMessage)
-        } else {
-            return claude.ClaudeHandler(c, resp, info, claude.RequestModeMessage)
-        }
+        if info.IsStream {
+            return claude.ClaudeStreamHandler(c, resp, info, claude.RequestModeMessage)
+        }
+        return claude.ClaudeHandler(c, resp, info, claude.RequestModeMessage)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daf3ef9 and dd374cd.

📒 Files selected for processing (1)
  • relay/channel/deepseek/adaptor.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
relay/channel/deepseek/adaptor.go (4)
types/relay_format.go (2)
  • RelayFormat (3-3)
  • RelayFormatClaude (7-7)
relay/channel/claude/relay-claude.go (2)
  • ClaudeStreamHandler (695-717)
  • ClaudeHandler (761-783)
relay/channel/claude/adaptor.go (2)
  • RequestModeMessage (20-20)
  • Adaptor (23-25)
relay/channel/openai/adaptor.go (1)
  • Adaptor (32-35)
🔇 Additional comments (2)
relay/channel/deepseek/adaptor.go (2)

95-105: Claude-vs-non-Claude split looks good.

Directly dispatching Claude stream/non-stream and delegating others to OpenAI adaptor is the right shaping for response compatibility.


97-101: Resolved — streaming path closes resp.Body via StreamScannerHandler.
relay/helper/stream_scanner.go defers resp.Body.Close(); ClaudeStreamHandler calls StreamScannerHandler, so the streaming path will not leak file descriptors.

Comment on lines +103 to +104
adaptor := openai.Adaptor{}
return adaptor.DoResponse(c, resp, info)

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.

⚠️ Potential issue

🧩 Analysis chain

Confirm OpenAI adaptor doesn’t need fields initialized.

openai.Adaptor has ChannelType/ResponseFormat fields. If DoResponse uses them, passing a zero-value struct may alter formatting/routing. Initialize if required.

Run:


🏁 Script executed:

#!/bin/bash
# Check how openai.Adaptor.DoResponse uses its fields
rg -nP -C3 'type\s+Adaptor\s+struct\b' relay/channel/openai
rg -nP -C5 'func\s+\(a\s*\*Adaptor\)\s*DoResponse\(' relay/channel/openai
rg -nP -C2 '\bResponseFormat\b|\bChannelType\b' relay/channel/openai

Length of output: 6900


Initialize openai.Adaptor before calling DoResponse.

openai.Adaptor has ChannelType and ResponseFormat that Init/ConvertAudioRequest set and that DoResponse/handlers (e.g., OpenaiSTTHandler, GetModelList) read — constructing a zero-value adaptor can break audio/STT or channel-specific logic.

Action (relay/channel/deepseek/adaptor.go:103-104): call adaptor.Init(info) before adaptor.DoResponse(...) and ensure adaptor.ResponseFormat is set for audio/transcription (e.g., via ConvertAudioRequest or assign from the audio request).

🤖 Prompt for AI Agents
In relay/channel/deepseek/adaptor.go around lines 103 to 104, the adaptor is
constructed as a zero-value and used immediately; call adaptor.Init(info) before
calling adaptor.DoResponse(c, resp, info) so ChannelType and other fields are
initialized, and ensure adaptor.ResponseFormat is set for audio/transcription
(either by invoking the existing ConvertAudioRequest flow or explicitly
assigning ResponseFormat from the audio request) so DoResponse and STT/audio
handlers have the correct configuration.

@coderabbitai coderabbitai Bot mentioned this pull request Dec 7, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Mar 7, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
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