fix: try to fix claude to openai format mcp #966

This commit is contained in:
CaIon
2025-04-15 01:16:06 +08:00
parent d283f6b35f
commit 99efc1fbb6

View File

@@ -24,6 +24,8 @@ func stopReasonClaude2OpenAI(reason string) string {
return "stop" return "stop"
case "max_tokens": case "max_tokens":
return "max_tokens" return "max_tokens"
case "tool_use":
return "tool_calls"
default: default:
return reason return reason
} }
@@ -317,8 +319,9 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *dto.ClaudeResponse
//choice.Delta.SetContentString(claudeResponse.ContentBlock.Text) //choice.Delta.SetContentString(claudeResponse.ContentBlock.Text)
if claudeResponse.ContentBlock.Type == "tool_use" { if claudeResponse.ContentBlock.Type == "tool_use" {
tools = append(tools, dto.ToolCallResponse{ tools = append(tools, dto.ToolCallResponse{
ID: claudeResponse.ContentBlock.Id, Index: common.GetPointer(0),
Type: "function", ID: claudeResponse.ContentBlock.Id,
Type: "function",
Function: dto.FunctionResponse{ Function: dto.FunctionResponse{
Name: claudeResponse.ContentBlock.Name, Name: claudeResponse.ContentBlock.Name,
Arguments: "", Arguments: "",
@@ -330,11 +333,12 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *dto.ClaudeResponse
} }
} else if claudeResponse.Type == "content_block_delta" { } else if claudeResponse.Type == "content_block_delta" {
if claudeResponse.Delta != nil { if claudeResponse.Delta != nil {
choice.Index = *claudeResponse.Index
choice.Delta.Content = claudeResponse.Delta.Text choice.Delta.Content = claudeResponse.Delta.Text
switch claudeResponse.Delta.Type { switch claudeResponse.Delta.Type {
case "input_json_delta": case "input_json_delta":
tools = append(tools, dto.ToolCallResponse{ tools = append(tools, dto.ToolCallResponse{
Type: "function",
Index: common.GetPointer(0),
Function: dto.FunctionResponse{ Function: dto.FunctionResponse{
Arguments: *claudeResponse.Delta.PartialJson, Arguments: *claudeResponse.Delta.PartialJson,
}, },