fix: deepseek claude response - #1833
Conversation
WalkthroughRefactors 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
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
📒 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.
| adaptor := openai.Adaptor{} | ||
| return adaptor.DoResponse(c, resp, info) |
There was a problem hiding this comment.
🧩 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/openaiLength 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.
…aude-code fix: deepseek claude response
Summary by CodeRabbit