Repository navigation
feats: repair the thinking of claude to openrouter convert #3120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,22 +34,34 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re | |
|
|
||
| isOpenRouter := info.ChannelType == constant.ChannelTypeOpenRouter | ||
|
|
||
| if claudeRequest.Thinking != nil && claudeRequest.Thinking.Type == "enabled" { | ||
| if isOpenRouter { | ||
| reasoning := openrouter.RequestReasoning{ | ||
| MaxTokens: claudeRequest.Thinking.GetBudgetTokens(), | ||
| if isOpenRouter { | ||
| if effort := claudeRequest.GetEfforts(); effort != "" { | ||
| effortBytes, _ := json.Marshal(effort) | ||
| openAIRequest.Verbosity = effortBytes | ||
| } | ||
| if claudeRequest.Thinking != nil { | ||
| var reasoning openrouter.RequestReasoning | ||
| if claudeRequest.Thinking.Type == "enabled" { | ||
| reasoning = openrouter.RequestReasoning{ | ||
| Enabled: true, | ||
| MaxTokens: claudeRequest.Thinking.GetBudgetTokens(), | ||
| } | ||
| } else if claudeRequest.Thinking.Type == "adaptive" { | ||
| reasoning = openrouter.RequestReasoning{ | ||
| Enabled: true, | ||
| } | ||
| } | ||
| reasoningJSON, err := json.Marshal(reasoning) | ||
|
Comment on lines
+42
to
54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard unsupported thinking types before marshaling reasoning. If 🤖 Prompt for AI Agents |
||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to marshal reasoning: %w", err) | ||
| } | ||
| openAIRequest.Reasoning = reasoningJSON | ||
| } else { | ||
| thinkingSuffix := "-thinking" | ||
| if strings.HasSuffix(info.OriginModelName, thinkingSuffix) && | ||
| !strings.HasSuffix(openAIRequest.Model, thinkingSuffix) { | ||
| openAIRequest.Model = openAIRequest.Model + thinkingSuffix | ||
| } | ||
| } | ||
| } else { | ||
| thinkingSuffix := "-thinking" | ||
| if strings.HasSuffix(info.OriginModelName, thinkingSuffix) && | ||
| !strings.HasSuffix(openAIRequest.Model, thinkingSuffix) { | ||
| openAIRequest.Model = openAIRequest.Model + thinkingSuffix | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 121
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 1351
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 484
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 207
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 507
🏁 Script executed:
# Check imports at the top of dto/claude.go head -50 dto/claude.goRepository: QuantumNous/new-api
Length of output: 1534
🏁 Script executed:
# Check what JSON wrapper functions are available in common/json.go cat common/json.goRepository: QuantumNous/new-api
Length of output: 817
Use
common.UnmarshalinGetEffortsinstead ofjson.Unmarshal.Line 419 directly calls
json.Unmarshalin business code. This violates the project guideline requiring all JSON marshal/unmarshal operations to use wrapper functions fromcommon/json.go.Proposed fix
func (c *ClaudeRequest) GetEfforts() string { - var OutputConfig OutputConfigForEffort - if err := json.Unmarshal(c.OutputConfig, &OutputConfig); err == nil { - effort := OutputConfig.Effort - return effort - } - return "" + if len(c.OutputConfig) == 0 { + return "" + } + var outputConfig OutputConfigForEffort + if err := common.Unmarshal(c.OutputConfig, &outputConfig); err != nil { + return "" + } + return outputConfig.Effort }📝 Committable suggestion
🤖 Prompt for AI Agents