**fix(translator): preserve raw JSON encoding in function call outputs**

- Updated handling of `output` in `gemini_openai-responses_request.go` to use `.Raw` instead of `.String` for preserving original JSON encoding.
- Ensured proper setting of raw JSON output when constructing `functionResponse`.
This commit is contained in:
Luis Pater
2025-11-27 08:26:53 +08:00
parent c8cee547fd
commit 0bcae68c6c

View File

@@ -186,7 +186,8 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
case "function_call_output": case "function_call_output":
// Handle function call outputs - convert to function message with functionResponse // Handle function call outputs - convert to function message with functionResponse
callID := item.Get("call_id").String() callID := item.Get("call_id").String()
output := item.Get("output").String() // Use .Raw to preserve the JSON encoding (includes quotes for strings)
outputRaw := item.Get("output").Raw
functionContent := `{"role":"function","parts":[]}` functionContent := `{"role":"function","parts":[]}`
functionResponse := `{"functionResponse":{"name":"","response":{}}}` functionResponse := `{"functionResponse":{"name":"","response":{}}}`
@@ -209,10 +210,9 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName) functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName)
// Parse output JSON string and set as response content // Set the raw JSON output directly (preserves string encoding)
if output != "" { if outputRaw != "" && outputRaw != "null" {
outputResult := gjson.Parse(output) functionResponse, _ = sjson.SetRaw(functionResponse, "functionResponse.response.result", outputRaw)
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.response.result", outputResult.Raw)
} }
functionContent, _ = sjson.SetRaw(functionContent, "parts.-1", functionResponse) functionContent, _ = sjson.SetRaw(functionContent, "parts.-1", functionResponse)