From d4e6704f33e82c81447f4c028601f991abe11333 Mon Sep 17 00:00:00 2001 From: rinfx Date: Mon, 10 Nov 2025 10:03:01 +0800 Subject: [PATCH] [bugfix] add claude usage & bedrock tool_call index (#3095) --- .../wasm-go/extensions/ai-proxy/provider/bedrock.go | 8 +++++--- .../ai-proxy/provider/claude_to_openai.go | 13 +++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/bedrock.go b/plugins/wasm-go/extensions/ai-proxy/provider/bedrock.go index 4f0761f8a..4e84a758a 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/bedrock.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/bedrock.go @@ -107,8 +107,9 @@ func (b *bedrockProvider) convertEventFromBedrockToOpenAI(ctx wrapper.HttpContex chatChoice.Delta.Content = nil chatChoice.Delta.ToolCalls = []toolCall{ { - Id: bedrockEvent.Start.ToolUse.ToolUseID, - Type: "function", + Id: bedrockEvent.Start.ToolUse.ToolUseID, + Index: 0, + Type: "function", Function: functionCall{ Name: bedrockEvent.Start.ToolUse.Name, Arguments: "", @@ -137,7 +138,8 @@ func (b *bedrockProvider) convertEventFromBedrockToOpenAI(ctx wrapper.HttpContex if bedrockEvent.Delta.ToolUse != nil { chatChoice.Delta.ToolCalls = []toolCall{ { - Type: "function", + Index: 0, + Type: "function", Function: functionCall{ Arguments: bedrockEvent.Delta.ToolUse.Input, }, diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/claude_to_openai.go b/plugins/wasm-go/extensions/ai-proxy/provider/claude_to_openai.go index 81e26e3c7..f5f7bc9a1 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/claude_to_openai.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/claude_to_openai.go @@ -440,12 +440,17 @@ func (c *ClaudeToOpenAIConverter) ConvertOpenAIStreamResponseToClaude(ctx wrappe // buildClaudeStreamResponse builds Claude streaming responses from OpenAI streaming response func (c *ClaudeToOpenAIConverter) buildClaudeStreamResponse(ctx wrapper.HttpContext, openaiResponse *chatCompletionResponse) []*claudeTextGenStreamResponse { + var choice chatCompletionChoice if len(openaiResponse.Choices) == 0 { - log.Debugf("[OpenAI->Claude] No choices in OpenAI response, skipping") - return nil + choice = chatCompletionChoice{ + Index: 0, + Delta: &chatMessage{ + Content: "", + }, + } + } else { + choice = openaiResponse.Choices[0] } - - choice := openaiResponse.Choices[0] var responses []*claudeTextGenStreamResponse // Log what we're processing