fix(translator): simplify tool response handling and adjust JSON schema updates in Gemini modules

This commit is contained in:
Luis Pater
2025-11-05 22:48:50 +08:00
parent a318dff8b0
commit 2a73d8c4a3
6 changed files with 10 additions and 22 deletions

View File

@@ -92,7 +92,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
if len(toolCallIDs) > 1 {
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
}
responseData := contentResult.Get("content").String()
responseData := contentResult.Get("content").Raw
functionResponse := client.FunctionResponse{Name: funcName, Response: map[string]interface{}{"result": responseData}}
clientContent.Parts = append(clientContent.Parts, client.Part{FunctionResponse: &functionResponse})
}

View File

@@ -150,14 +150,11 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
toolCallID := m.Get("tool_call_id").String()
if toolCallID != "" {
c := m.Get("content")
if c.Type == gjson.String {
toolResponses[toolCallID] = c.String()
} else if c.IsObject() && c.Get("type").String() == "text" {
toolResponses[toolCallID] = c.Get("text").String()
}
toolResponses[toolCallID] = c.Raw
}
}
}
fmt.Printf("11111")
for i := 0; i < len(arr); i++ {
m := arr[i]
@@ -280,7 +277,7 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
if resp == "" {
resp = "{}"
}
toolNode, _ = sjson.SetRawBytes(toolNode, "parts."+itoa(pp)+".functionResponse.response", []byte(`{"result":`+quoteIfNeeded(resp)+`}`))
toolNode, _ = sjson.SetBytes(toolNode, "parts."+itoa(pp)+".functionResponse.response.result", []byte(resp))
pp++
}
}

View File

@@ -143,17 +143,11 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
}
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName)
// Also set response.name to align with docs/convert-2.md
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.response.name", functionName)
// Parse output JSON string and set as response content
if output != "" {
outputResult := gjson.Parse(output)
if outputResult.IsObject() {
functionResponse, _ = sjson.SetRaw(functionResponse, "functionResponse.response.content", outputResult.String())
} else {
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.response.content", output)
}
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.response.result", outputResult.Raw)
}
functionContent, _ = sjson.SetRaw(functionContent, "parts.-1", functionResponse)