mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 17:36:47 +08:00
feat(translator): preserve input_image details in OpenAI response conversion
- Updated handling in `ConvertOpenAIResponsesRequestToOpenAIChatCompletions` to retain `input_image` detail fields such as `image_url` and `detail`. - Added `TestConvertOpenAIResponsesRequestToOpenAIChatCompletions_PreservesInputImageDetail` to verify preservation of image details during transformation. Closes: #3385
This commit is contained in:
@@ -154,6 +154,9 @@ func ConvertOpenAIResponsesRequestToOpenAIChatCompletions(modelName string, inpu
|
||||
imageURL := contentItem.Get("image_url").String()
|
||||
contentPart := []byte(`{"type":"image_url","image_url":{"url":""}}`)
|
||||
contentPart, _ = sjson.SetBytes(contentPart, "image_url.url", imageURL)
|
||||
if detail := contentItem.Get("detail"); detail.Exists() {
|
||||
contentPart, _ = sjson.SetBytes(contentPart, "image_url.detail", detail.String())
|
||||
}
|
||||
message, _ = sjson.SetRawBytes(message, "content.-1", contentPart)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -198,3 +198,31 @@ func TestConvertOpenAIResponsesRequestToOpenAIChatCompletions_PreservesStructure
|
||||
t.Fatalf("tool_choice.function.name = %q, want run_command; output=%s", got, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertOpenAIResponsesRequestToOpenAIChatCompletions_PreservesInputImageDetail(t *testing.T) {
|
||||
raw := []byte(`{
|
||||
"input": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "input_image",
|
||||
"image_url": "https://example.com/image.png",
|
||||
"detail": "high"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}`)
|
||||
t.Logf("input json:\n%s", prettyJSONForTest(raw))
|
||||
|
||||
out := ConvertOpenAIResponsesRequestToOpenAIChatCompletions("gpt-5.4", raw, false)
|
||||
t.Logf("output json:\n%s", prettyJSONForTest(out))
|
||||
|
||||
if got := gjson.GetBytes(out, "messages.0.content.0.image_url.url").String(); got != "https://example.com/image.png" {
|
||||
t.Fatalf("messages.0.content.0.image_url.url = %q, want https://example.com/image.png; output=%s", got, out)
|
||||
}
|
||||
if got := gjson.GetBytes(out, "messages.0.content.0.image_url.detail").String(); got != "high" {
|
||||
t.Fatalf("messages.0.content.0.image_url.detail = %q, want high; output=%s", got, out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user