mirror of
https://github.com/alibaba/higress.git
synced 2026-05-26 21:57:30 +08:00
fix: remove non-standard thinking/reasoning_max_tokens from Claude-to… (#3667)
This commit is contained in:
@@ -168,6 +168,8 @@ const (
|
||||
finishReasonLength = "length"
|
||||
finishReasonToolCall = "tool_calls"
|
||||
|
||||
ctxKeyClaudeBudgetTokens = "claudeBudgetTokens"
|
||||
ctxKeyClaudeThinkingType = "claudeThinkingType"
|
||||
ctxKeyIncrementalStreaming = "incrementalStreaming"
|
||||
ctxKeyApiKey = "apiKey"
|
||||
CtxKeyApiName = "apiName"
|
||||
@@ -1155,6 +1157,21 @@ func (c *ProviderConfig) handleRequestBody(
|
||||
// If main.go detected a Claude request that needs conversion, convert the body
|
||||
needClaudeConversion, _ := ctx.GetContext("needClaudeResponseConversion").(bool)
|
||||
if needClaudeConversion {
|
||||
// Extract thinking config from original Claude body before conversion,
|
||||
// so downstream providers (OpenRouter, ZhipuAI) can access it.
|
||||
thinkingType := gjson.GetBytes(body, "thinking.type").String()
|
||||
if thinkingType == "" {
|
||||
// Claude request had no thinking field at all - treat as disabled
|
||||
thinkingType = "disabled"
|
||||
}
|
||||
ctx.SetContext(ctxKeyClaudeThinkingType, thinkingType)
|
||||
// Only extract budget_tokens when thinking is explicitly enabled
|
||||
if thinkingType == "enabled" {
|
||||
if budgetTokens := gjson.GetBytes(body, "thinking.budget_tokens").Int(); budgetTokens > 0 {
|
||||
ctx.SetContext(ctxKeyClaudeBudgetTokens, int(budgetTokens))
|
||||
}
|
||||
}
|
||||
|
||||
// Convert Claude protocol to OpenAI protocol
|
||||
converter := &ClaudeToOpenAIConverter{}
|
||||
body, err = converter.ConvertClaudeRequestToOpenAI(body)
|
||||
|
||||
Reference in New Issue
Block a user