fix(canvas): 图片生成 - 合并局部重绘、规格校验与模型导入修复
This commit is contained in:
commit
05fd5cde03
19 files changed
+162
-59
No files matched your search
@@ -178,7 +178,7 @@ func (s *Service) FetchAdminChannelModels(ctx context.Context, actor *model.User
|
||||
if idErr != nil {
|
||||
return nil, idErr
|
||||
}
|
||||
missing = append(missing, model.ChannelModel{ID: modelID, ChannelID: channelID, ModelKey: name, DisplayName: name, BillingMode: "fixed_request", Enabled: false, PriceVersion: 1})
|
||||
missing = append(missing, model.ChannelModel{ID: modelID, ChannelID: channelID, ModelKey: name, ProviderModelKey: name, DisplayName: name, BillingMode: "fixed_request", Enabled: false, PriceVersion: 1})
|
||||
}
|
||||
added, err := s.repo.CreateMissingChannelModels(missing)
|
||||
if err != nil {
|
||||
@@ -249,7 +249,8 @@ func (s *Service) ImportAdminChannelModels(ctx context.Context, actor *model.Use
|
||||
}
|
||||
known := make(map[string]struct{}, len(existing))
|
||||
for _, item := range existing {
|
||||
known[channelModelCatalogKey(item.ModelKey)] = struct{}{}
|
||||
providerKey := firstNonEmpty(item.ProviderModelKey, item.ModelKey)
|
||||
known[channelModelCatalogKey(providerKey)] = struct{}{}
|
||||
}
|
||||
retired := retiredChannelModelKeys(channel.RetiredModelsJSON)
|
||||
missing := make([]model.ChannelModel, 0, len(chosen))
|
||||
|
||||
@@ -846,10 +846,11 @@ func validateImageTask(profile *ImageCapabilityConfig, input canvasGenerationInp
|
||||
return BadAuthRequest(err.Error())
|
||||
}
|
||||
}
|
||||
if profile.Quality.Supported && strings.TrimSpace(input.Config.Quality) != "" && !containsCapabilityString(profile.Quality.Values, input.Config.Quality) {
|
||||
quality := strings.TrimSpace(input.Config.Quality)
|
||||
if profile.Quality.Supported && quality != "" && !strings.EqualFold(quality, "auto") && !strings.EqualFold(quality, "any") && !containsCapabilityString(profile.Quality.Values, quality) {
|
||||
return BadAuthRequest("图片质量不在当前模型支持范围内")
|
||||
}
|
||||
if err := validateImagePresetSelection(profile, firstNonEmpty(input.Config.Quality, profile.Quality.Default), firstNonEmpty(input.Config.Size, profile.Size.Default)); err != nil {
|
||||
if err := validateImagePresetSelection(profile, qualityForImageValidation(quality, profile.Quality.Default), firstNonEmpty(input.Config.Size, profile.Size.Default)); err != nil {
|
||||
return err
|
||||
}
|
||||
count, err := strconv.Atoi(strings.TrimSpace(input.Config.Count))
|
||||
@@ -859,6 +860,13 @@ func validateImageTask(profile *ImageCapabilityConfig, input canvasGenerationInp
|
||||
return nil
|
||||
}
|
||||
|
||||
func qualityForImageValidation(quality string, fallback string) string {
|
||||
if strings.EqualFold(quality, "auto") || strings.EqualFold(quality, "any") {
|
||||
return fallback
|
||||
}
|
||||
return firstNonEmpty(quality, fallback)
|
||||
}
|
||||
|
||||
func validateImagePresetSelection(profile *ImageCapabilityConfig, quality, ratio string) error {
|
||||
if profile.Size.Parameter != "aspect_ratio" || profile.Size.AllowCustom || len(profile.Size.Presets) == 0 || ratio == "auto" {
|
||||
return nil
|
||||
|
||||
@@ -65,6 +65,13 @@ func ModelRequestIntentFromTaskInput(input map[string]any, taskType string, oper
|
||||
explicitOptions = true
|
||||
for key, value := range options {
|
||||
name := canonicalCapabilityOptionName(key)
|
||||
// auto/any 表示调用方不指定质量;不能把它当作模型必须声明的
|
||||
// 枚举值,否则未列出 auto 的模型会被错误判定为参数不支持。
|
||||
if name == "quality" {
|
||||
if normalized, ok := value.(string); ok && (strings.EqualFold(strings.TrimSpace(normalized), "auto") || strings.EqualFold(strings.TrimSpace(normalized), "any")) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
intent.Options[name] = normalizeModelRequestOption(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,19 @@ func TestImagePriceTiersMatchResolutionAndActualReferences(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoQualityIsOmittedFromCapabilityIntent(t *testing.T) {
|
||||
intent := ModelRequestIntentFromTaskInput(map[string]any{
|
||||
"mode": "image",
|
||||
"capabilityOptions": map[string]any{"quality": "auto", "size": "2048x878"},
|
||||
}, "canvas_image", "image")
|
||||
if _, exists := intent.Options["quality"]; exists {
|
||||
t.Fatalf("quality option = %#v, want omitted for auto", intent.Options["quality"])
|
||||
}
|
||||
if intent.Options["size"] != "2048x878" {
|
||||
t.Fatalf("size option = %#v, want preserved", intent.Options["size"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelRequestIntentNormalizesVideoResolution(t *testing.T) {
|
||||
input := map[string]any{
|
||||
"mode": "video",
|
||||
|
||||
Reference in new issue
Block a user