From 75602595f2912ed51c1258168f0a661333892080 Mon Sep 17 00:00:00 2001 From: ddCat <2695092045@qq.com> Date: Mon, 10 Aug 2026 01:45:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E6=A8=A1=E5=9E=8B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20-=20=E6=8C=89=E5=9B=BE=E7=89=87=E8=83=BD=E5=8A=9B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E5=B0=BA=E5=AF=B8=E4=B8=8E?= =?UTF-8?q?=E8=B4=A8=E9=87=8F=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/service/channel_models.go | 36 ++++++++++++---- .../internal/service/channel_models_test.go | 42 +++++++++++++++++++ 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/backend/internal/service/channel_models.go b/backend/internal/service/channel_models.go index 555108a6c..4dbde0715 100644 --- a/backend/internal/service/channel_models.go +++ b/backend/internal/service/channel_models.go @@ -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 == "" { diff --git a/backend/internal/service/channel_models_test.go b/backend/internal/service/channel_models_test.go index 6693d3231..f50eedaf4 100644 --- a/backend/internal/service/channel_models_test.go +++ b/backend/internal/service/channel_models_test.go @@ -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) + } + }) + } +}