fix: convert thinking.type=enabled to adaptive for Opus 4.7 in ClaudeHelper
Claude Code sends Anthropic format requests directly to /v1/messages with thinking.type=enabled. ClaudeHelper was forwarding this unchanged to upstream, but Opus 4.7 rejects thinking.type=enabled and requires thinking.type=adaptive with output_config.effort instead.
This commit is contained in:
@@ -103,6 +103,25 @@ func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
|
||||
info.UpstreamModelName = request.Model
|
||||
}
|
||||
|
||||
// Opus 4.7 rejects thinking.type="enabled"; convert to adaptive.
|
||||
if strings.HasPrefix(request.Model, "claude-opus-4-7") && request.Thinking != nil && request.Thinking.Type == "enabled" {
|
||||
budgetTokens := 0
|
||||
if request.Thinking.BudgetTokens != nil {
|
||||
budgetTokens = *request.Thinking.BudgetTokens
|
||||
}
|
||||
effortLevel := "high"
|
||||
if budgetTokens > 0 && budgetTokens <= 1024 {
|
||||
effortLevel = "low"
|
||||
} else if budgetTokens > 0 && budgetTokens <= 8192 {
|
||||
effortLevel = "medium"
|
||||
}
|
||||
request.Thinking = &dto.Thinking{Type: "adaptive", Display: "summarized"}
|
||||
request.OutputConfig = json.RawMessage(fmt.Sprintf(`{"effort":"%s"}`, effortLevel))
|
||||
request.Temperature = nil
|
||||
request.TopP = nil
|
||||
request.TopK = nil
|
||||
}
|
||||
|
||||
if info.ChannelSetting.SystemPrompt != "" {
|
||||
if request.System == nil {
|
||||
request.SetStringSystem(info.ChannelSetting.SystemPrompt)
|
||||
|
||||
Reference in New Issue
Block a user