fix(convert): 修复 OpenAI 转 Claude 流时 thinking 块的格式问题 - #2035
Merged
Conversation
将 `ClaudeMediaMessage.Thinking` 的类型从 `string` 修改为 `*string`,以解决 `omitempty` 导致 `"thinking": ""` 字段在 JSON 序列化时被忽略的问题。 同时更新了 `service/convert.go` 和 `relay/channel/claude/relay-claude.go` 中的相关逻辑,以兼容新的指针类型,确保生成的 Claude 事件流符合官方规范。
Contributor
WalkthroughConverts Claude thinking content from string to nullable pointer in DTOs and updates relay and conversion logic to use nil-safe handling for streaming and response formatting. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Relay as Relay (Claude)
participant DTO as DTO (ClaudeMediaMessage)
participant Service as Service (Convert)
Note over DTO: Thinking: string → *string
Client->>Relay: Stream request
Relay->>Service: Convert OpenAI → Claude stream
Service-->>Relay: content_block_start (Thinking: pointer to "")
Relay->>DTO: Set Thinking = pointer (nil or "")
loop Streaming deltas
Service-->>Relay: thinking_delta (ReasoningContent: *string)
alt Thinking present
Relay->>DTO: Assign ReasoningContent = *string (nil-safe)
else No thinking
Relay->>DTO: Skip assignment
end
Relay-->>Client: Forward delta
end
Client->>Relay: Request final response
Relay->>DTO: responseThinking only if Thinking != nil
Relay-->>Client: Final response (thinking included iff non-nil)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
5 tasks
seefs001
approved these changes
Oct 13, 2025
ennnnny
pushed a commit
to ennnnny/new-api
that referenced
this pull request
Mar 17, 2026
fix(convert): 修复 OpenAI 转 Claude 流时 thinking 块的格式问题
This was referenced Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联问题 #2020
将
ClaudeMediaMessage.Thinking的类型从string修改为*string,以解决omitempty导致"thinking": ""字段在 JSON 序列化时被忽略的问题。同时更新了
service/convert.go和relay/channel/claude/relay-claude.go中的相关逻辑,以兼容新的指针类型,确保生成的 SSE data 符合官方规范。Summary by CodeRabbit
Bug Fixes
Refactor