补全图像尺寸预处理约束

This commit is contained in:
2026-06-07 23:55:25 +08:00
parent 4d1a01ec71
commit b7500d81d1
4 changed files with 442 additions and 0 deletions
@@ -661,6 +661,80 @@ func TestParamProcessorImageResolutionAndOutputCount(t *testing.T) {
}
}
func TestParamProcessorImageSizeConstraintsNormalizeExplicitDimensions(t *testing.T) {
body := map[string]any{
"model": "doubao-5.0图像编辑",
"prompt": "draw",
"resolution": "2K",
"width": 1024,
"height": 1024,
"size": "1024x1024",
}
candidate := store.RuntimeModelCandidate{
ModelType: "image_generate",
Capabilities: map[string]any{
"image_generate": map[string]any{
"output_resolutions": []any{"2K", "3K"},
"output_size_range": []any{3686400, 10404496},
"aspect_ratio_range": []any{0.0625, 16},
},
},
}
result := preprocessRequestWithLog("images.generations", body, candidate)
if result.Body["width"] != 1920 || result.Body["height"] != 1920 {
t.Fatalf("explicit dimensions below model minimum should be scaled to 1920x1920, got %+v", result.Body)
}
if result.Body["size"] != "1920x1920" {
t.Fatalf("size should be synchronized with normalized width/height, got %+v", result.Body)
}
if result.Body["resolution"] != "2K" {
t.Fatalf("resolution should stay on allowed 2K, got %+v", result.Body)
}
for _, change := range result.Log.Changes {
if change.Processor == "ImageSizeProcessor" && change.CapabilityPath == "capabilities.image_generate.output_size_range" {
return
}
}
t.Fatalf("expected image size preprocessing log against output_size_range, got %+v", result.Log.Changes)
}
func TestParamProcessorImageSizeConstraintsNormalizeEditDimensions(t *testing.T) {
body := map[string]any{
"model": "gpt-image-2",
"prompt": "edit",
"image": "https://example.com/input.png",
"width": "513",
"height": "513",
}
candidate := store.RuntimeModelCandidate{
ModelType: "image_edit",
Capabilities: map[string]any{
"image_edit": map[string]any{
"aspect_ratio_allowed": []any{"1:1", "16:9"},
"aspect_ratio_range": []any{1.0 / 3.0, 3.0},
"output_size_range": []any{655360, 8294400},
"width_height_range": []any{1, 3840},
"width_height_multiple": 16,
"input_multiple_images": true,
},
},
}
processed := preprocessRequest("images.edits", body, candidate)
width := int(floatFromAny(processed["width"]))
height := int(floatFromAny(processed["height"]))
if width != 816 || height != 816 {
t.Fatalf("edit dimensions should scale up and align to 16px multiples, got %+v", processed)
}
if processed["size"] != "816x816" {
t.Fatalf("edit size should be synchronized with normalized dimensions, got %+v", processed)
}
if width*height < 655360 || width%16 != 0 || height%16 != 0 {
t.Fatalf("edit dimensions should satisfy model constraints, got %+v", processed)
}
}
func TestParamProcessorImageQualityControl(t *testing.T) {
body := map[string]any{
"model": "mock-image",