feat(protocol): 可美 KM Seedream - 接入图片生成与编辑
This commit is contained in:
@@ -27,6 +27,19 @@ func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapab
|
||||
MaxOutputs: 15,
|
||||
}
|
||||
switch model.ChannelInterfaceType(protocol) {
|
||||
case "km-kemei-seedream":
|
||||
image.References.MaxImages = 10
|
||||
image.References.MaskSupported = false
|
||||
presets := kemeiSeedreamImagePresets()
|
||||
values := make([]string, 0, len(presets))
|
||||
for _, preset := range presets {
|
||||
values = append(values, preset.Size)
|
||||
}
|
||||
image.Size = ImageSizeConfig{Parameter: "size", Values: values, Default: "2048x2048", AllowCustom: true, Presets: presets}
|
||||
image.Quality = ImageQualityConfig{Supported: false, Values: []string{}, Default: "auto"}
|
||||
// 透明背景需要带 alpha 的单张参考图,通过插件命名空间显式配置。
|
||||
image.TransparentBackground = VideoBooleanConfig{Supported: false, Default: false}
|
||||
image.MaxOutputs = 1
|
||||
case model.ChannelInterfaceGrokImage:
|
||||
image.References.MaxImages = 1
|
||||
image.References.MaskSupported = false
|
||||
|
||||
29
backend/internal/app/model_capability_kemei.go
Normal file
29
backend/internal/app/model_capability_kemei.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 供应商与 Seedream 5.0 官方文档的精确尺寸;档位不能由通用像素阈值推断。
|
||||
func kemeiSeedreamImagePresets() []ImageSizePreset {
|
||||
ratios := []string{"1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "21:9"}
|
||||
tiers := []struct {
|
||||
name string
|
||||
sizes []string
|
||||
}{
|
||||
{"1k", []string{"1024x1024", "1152x864", "864x1152", "1424x800", "800x1424", "1248x832", "832x1248", "1568x672"}},
|
||||
{"1.5k", []string{"1536x1536", "1792x1344", "1344x1792", "2048x1152", "1152x2048", "1872x1248", "1248x1872", "2352x1008"}},
|
||||
{"2k", []string{"2048x2048", "2368x1776", "1776x2368", "2816x1584", "1584x2816", "2496x1664", "1664x2496", "3136x1344"}},
|
||||
}
|
||||
result := make([]ImageSizePreset, 0, 24)
|
||||
for _, tier := range tiers {
|
||||
for index, size := range tier.sizes {
|
||||
parts := strings.Split(size, "x")
|
||||
width, _ := strconv.Atoi(parts[0])
|
||||
height, _ := strconv.Atoi(parts[1])
|
||||
result = append(result, ImageSizePreset{Tier: tier.name, Ratio: ratios[index], Width: width, Height: height, Size: size})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
23
backend/internal/app/model_capability_kemei_test.go
Normal file
23
backend/internal/app/model_capability_kemei_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestKemeiSeedreamDefaultsAreValidAndUseOfficialTiers(t *testing.T) {
|
||||
for _, name := range []string{"doubao-seedream-5-0-pro-260628", "doubao-seedream-5-0-flash-260915"} {
|
||||
profile := DefaultModelCapabilityConfigForModel("km-kemei-seedream", name).Image
|
||||
if err := validateImageCapabilityConfig(profile); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if profile.References.MaxImages != 10 || profile.References.MaskSupported || profile.MaxOutputs != 1 || profile.Size.Default != "2048x2048" || len(profile.Size.Presets) != 24 || profile.Quality.Supported || profile.TransparentBackground.Supported {
|
||||
t.Fatalf("defaults: %#v", profile)
|
||||
}
|
||||
for _, preset := range profile.Size.Presets {
|
||||
if preset.Tier == "4k" {
|
||||
t.Fatal("unsupported 4K default")
|
||||
}
|
||||
if preset.Size == "2816x1584" && preset.Tier != "2k" {
|
||||
t.Fatal("official 2K must not become 4K")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,8 @@ func validateImageCapabilityConfig(value *ImageCapabilityConfig) error {
|
||||
}
|
||||
seenPresets := make(map[string]bool)
|
||||
for _, preset := range value.Size.Presets {
|
||||
if preset.Tier != "1k" && preset.Tier != "2k" && preset.Tier != "4k" {
|
||||
return BadAuthRequest("图片分辨率档位仅支持 1K、2K、4K")
|
||||
if preset.Tier != "1k" && preset.Tier != "1.5k" && preset.Tier != "2k" && preset.Tier != "4k" {
|
||||
return BadAuthRequest("图片分辨率档位仅支持 1K、1.5K、2K、4K")
|
||||
}
|
||||
parts := strings.Split(preset.Ratio, ":")
|
||||
if len(parts) != 2 {
|
||||
@@ -416,6 +416,8 @@ func imageResolutionTier(quality string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(quality)) {
|
||||
case "1k", "low":
|
||||
return "1k"
|
||||
case "1.5k":
|
||||
return "1.5k"
|
||||
case "2k", "medium":
|
||||
return "2k"
|
||||
case "4k", "high":
|
||||
|
||||
Reference in New Issue
Block a user