Handle Gemini inline data in asset and size processing

This commit is contained in:
2026-06-15 00:14:40 +08:00
parent b860ef37e8
commit 10ec25d87b
10 changed files with 380 additions and 18 deletions
@@ -759,6 +759,75 @@ func TestParamProcessorImageSizeConstraintsAcceptPixelResolutionStrings(t *testi
}
}
func TestParamProcessorImageSizeConstraintsPreferPixelSizeOverExplicitDimensions(t *testing.T) {
for name, testcase := range map[string]struct {
kind string
modelType string
body map[string]any
}{
"generate": {
kind: "images.generations",
modelType: "image_generate",
body: map[string]any{
"model": "gpt-image-2",
"prompt": "draw",
"size": "2160x1566",
"width": 1024,
"height": 1024,
"aspect_ratio": "1:1",
},
},
"edit": {
kind: "images.edits",
modelType: "image_edit",
body: map[string]any{
"model": "gpt-image-2",
"prompt": "edit",
"image": "https://example.com/input.png",
"size": "2160x1566",
"width": 1024,
"height": 1024,
"aspect_ratio": "1:1",
},
},
} {
t.Run(name, func(t *testing.T) {
candidate := store.RuntimeModelCandidate{
ModelType: testcase.modelType,
Capabilities: map[string]any{
testcase.modelType: map[string]any{
"output_resolutions": []any{"1K", "2K", "4K"},
"aspect_ratio_allowed": []any{
"1:1",
"4:3",
"16:9",
"9:16",
},
"output_size_range": []any{655360, 8294400},
"width_height_range": []any{1, 3840},
"width_height_multiple": 16,
"input_multiple_images": true,
},
},
}
processed := preprocessRequest(testcase.kind, testcase.body, candidate)
if processed["width"] != 2160 || processed["height"] != 1568 {
t.Fatalf("size dimensions should win before constraints, got %+v", processed)
}
if processed["size"] != "2160x1568" {
t.Fatalf("size should sync with constrained dimensions, got %+v", processed)
}
if processed["aspect_ratio"] != "4:3" {
t.Fatalf("aspect_ratio should be inferred from size dimensions, got %+v", processed)
}
if processed["resolution"] != "2K" {
t.Fatalf("resolution should be inferred from size dimensions, got %+v", processed)
}
})
}
}
func TestParamProcessorImageSizeConstraintsNormalizeEditDimensions(t *testing.T) {
body := map[string]any{
"model": "gpt-image-2",