From 0bcae68c6c693a9a659380d233a5ffd7aa573af9 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Thu, 27 Nov 2025 08:26:53 +0800 Subject: [PATCH] **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`. --- .../responses/gemini_openai-responses_request.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go b/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go index b8e471e3..b7d9b193 100644 --- a/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go +++ b/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go @@ -186,7 +186,8 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte case "function_call_output": // Handle function call outputs - convert to function message with functionResponse 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":[]}` functionResponse := `{"functionResponse":{"name":"","response":{}}}` @@ -209,10 +210,9 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName) - // Parse output JSON string and set as response content - if output != "" { - outputResult := gjson.Parse(output) - functionResponse, _ = sjson.Set(functionResponse, "functionResponse.response.result", outputResult.Raw) + // Set the raw JSON output directly (preserves string encoding) + if outputRaw != "" && outputRaw != "null" { + functionResponse, _ = sjson.SetRaw(functionResponse, "functionResponse.response.result", outputRaw) } functionContent, _ = sjson.SetRaw(functionContent, "parts.-1", functionResponse)