fix(admin): 模型测试 - 按图片能力使用默认尺寸与质量参数
This commit is contained in:
@@ -259,6 +259,16 @@ func (s *Service) TestAdminChannelModel(ctx context.Context, actor *model.User,
|
||||
videoSeconds = "5"
|
||||
videoSecondsValue = 5
|
||||
}
|
||||
imageSize, imageQuality := "", ""
|
||||
var imageProfile *ImageCapabilityConfig
|
||||
if capability == "image" {
|
||||
profile, normalizeErr := NormalizeModelCapabilityConfig(capability, string(protocol), req.CapabilityConfig)
|
||||
if normalizeErr != nil {
|
||||
return nil, normalizeErr
|
||||
}
|
||||
imageProfile = profile.Image
|
||||
imageSize, imageQuality = imageTestDefaults(imageProfile)
|
||||
}
|
||||
input := canvasGenerationInput{
|
||||
Mode: capability,
|
||||
Prompt: prompt,
|
||||
@@ -271,8 +281,8 @@ func (s *Service) TestAdminChannelModel(ctx context.Context, actor *model.User,
|
||||
SecretKey: channel.SecretKey,
|
||||
Headers: headers,
|
||||
Model: modelKey,
|
||||
Size: map[string]string{"image": "1024x1024", "video": "16:9"}[capability],
|
||||
Quality: "auto",
|
||||
Size: map[string]string{"image": imageSize, "video": "16:9"}[capability],
|
||||
Quality: imageQuality,
|
||||
Count: "1",
|
||||
VideoSeconds: videoSeconds,
|
||||
VQuality: "720",
|
||||
@@ -285,11 +295,7 @@ func (s *Service) TestAdminChannelModel(ctx context.Context, actor *model.User,
|
||||
Metadata: map[string]interface{}{},
|
||||
}
|
||||
if capability == "image" {
|
||||
profile, normalizeErr := NormalizeModelCapabilityConfig(capability, string(protocol), req.CapabilityConfig)
|
||||
if normalizeErr != nil {
|
||||
return nil, normalizeErr
|
||||
}
|
||||
input.ImageCapability = profile.Image
|
||||
input.ImageCapability = imageProfile
|
||||
}
|
||||
|
||||
// 测试复用真实生成协议、运行时并发和熔断策略,但不创建用户任务或计费订单。
|
||||
@@ -320,6 +326,22 @@ func (s *Service) TestAdminChannelModel(ctx context.Context, actor *model.User,
|
||||
return &AdminChannelModelTestResult{DurationMs: time.Since(startedAt).Milliseconds()}, nil
|
||||
}
|
||||
|
||||
// 模型测试必须使用当前模型声明的默认参数,避免固定分辨率 SKU 被通用 1K 测试值误伤。
|
||||
func imageTestDefaults(profile *ImageCapabilityConfig) (string, string) {
|
||||
if profile == nil {
|
||||
return "1024x1024", "auto"
|
||||
}
|
||||
size := ""
|
||||
if profile.Size.Parameter != "none" {
|
||||
size = strings.TrimSpace(profile.Size.Default)
|
||||
}
|
||||
quality := ""
|
||||
if profile.Quality.Supported {
|
||||
quality = strings.TrimSpace(profile.Quality.Default)
|
||||
}
|
||||
return size, quality
|
||||
}
|
||||
|
||||
func normalizeChannelModelContract(channel *model.ModelChannel, req ChannelModelRequest) (string, string, model.ChannelInterfaceType, error) {
|
||||
modelKey := strings.TrimPrefix(strings.TrimSpace(req.ModelKey), "models/")
|
||||
if modelKey == "" {
|
||||
|
||||
@@ -38,3 +38,45 @@ func TestNormalizeChannelModelContractRequiresJiMengSecret(t *testing.T) {
|
||||
t.Fatal("normalizeChannelModelContract() should require JiMeng credentials")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageTestDefaultsUseModelCapability(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
profile *ImageCapabilityConfig
|
||||
wantSize string
|
||||
wantQuality string
|
||||
}{
|
||||
{name: "legacy fallback", wantSize: "1024x1024", wantQuality: "auto"},
|
||||
{
|
||||
name: "fixed 2k model",
|
||||
profile: &ImageCapabilityConfig{
|
||||
Size: ImageSizeConfig{Parameter: "size", Default: "2048x2048"},
|
||||
Quality: ImageQualityConfig{Supported: false, Default: "auto"},
|
||||
},
|
||||
wantSize: "2048x2048",
|
||||
},
|
||||
{
|
||||
name: "provider selected size",
|
||||
profile: &ImageCapabilityConfig{
|
||||
Size: ImageSizeConfig{Parameter: "none", Default: "auto"},
|
||||
Quality: ImageQualityConfig{Supported: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "gpt image capability",
|
||||
profile: &ImageCapabilityConfig{
|
||||
Size: ImageSizeConfig{Parameter: "size", Default: "1024x1536"},
|
||||
Quality: ImageQualityConfig{Supported: true, Default: "high"},
|
||||
},
|
||||
wantSize: "1024x1536", wantQuality: "high",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
size, quality := imageTestDefaults(test.profile)
|
||||
if size != test.wantSize || quality != test.wantQuality {
|
||||
t.Fatalf("imageTestDefaults() = %q, %q; want %q, %q", size, quality, test.wantSize, test.wantQuality)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user