fix: 兼容像素分辨率参数
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
@@ -699,6 +700,65 @@ func TestParamProcessorImageSizeConstraintsNormalizeExplicitDimensions(t *testin
|
||||
t.Fatalf("expected image size preprocessing log against output_size_range, got %+v", result.Log.Changes)
|
||||
}
|
||||
|
||||
func TestParamProcessorImageSizeConstraintsAcceptPixelResolutionStrings(t *testing.T) {
|
||||
candidate := store.RuntimeModelCandidate{
|
||||
ModelType: "image_generate",
|
||||
Capabilities: map[string]any{
|
||||
"image_generate": map[string]any{
|
||||
"output_resolutions": []any{"1K", "2K", "4K"},
|
||||
"aspect_ratio_allowed": []any{
|
||||
"1:1",
|
||||
"16:9",
|
||||
"9:16",
|
||||
},
|
||||
"output_size_range": []any{655360, 8294400},
|
||||
"width_height_range": []any{1, 3840},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, body := range map[string]map[string]any{
|
||||
"resolution": {
|
||||
"model": "gpt-image-2",
|
||||
"prompt": "draw",
|
||||
"resolution": "3840x2160",
|
||||
},
|
||||
"size": {
|
||||
"model": "gpt-image-2",
|
||||
"prompt": "draw",
|
||||
"size": "3840x2160",
|
||||
},
|
||||
"non-standard-resolution": {
|
||||
"model": "gpt-image-2",
|
||||
"prompt": "draw",
|
||||
"resolution": "3600x1900",
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
processed := preprocessRequest("images.generations", body, candidate)
|
||||
expectedWidth := 3840
|
||||
expectedHeight := 2160
|
||||
if name == "non-standard-resolution" {
|
||||
expectedWidth = 3600
|
||||
expectedHeight = 1900
|
||||
}
|
||||
if processed["width"] != expectedWidth || processed["height"] != expectedHeight {
|
||||
t.Fatalf("pixel resolution string should populate width/height, got %+v", processed)
|
||||
}
|
||||
if processed["aspect_ratio"] != "16:9" {
|
||||
t.Fatalf("pixel resolution string should infer aspect_ratio, got %+v", processed)
|
||||
}
|
||||
if processed["resolution"] != "4K" {
|
||||
t.Fatalf("pixel resolution string should normalize resolution to allowed bucket, got %+v", processed)
|
||||
}
|
||||
expectedSize := fmt.Sprintf("%dx%d", expectedWidth, expectedHeight)
|
||||
if processed["size"] != expectedSize {
|
||||
t.Fatalf("size should stay synchronized with normalized width/height, got %+v", processed)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParamProcessorImageSizeConstraintsNormalizeEditDimensions(t *testing.T) {
|
||||
body := map[string]any{
|
||||
"model": "gpt-image-2",
|
||||
|
||||
Reference in New Issue
Block a user