fix(canvas): 创作工作台 - 恢复连续对话并完善附件、媒体占位与生成分辨率

Fixes #231

Fixes #233
This commit is contained in:
ddCat committed 2026-08-15 22:01:42 +08:00
1 parent 11d9d469f5
commit 7804574f9f
15 files changed
+753 -115

No files matched your search

+5 -1
View File
@@ -158,7 +158,7 @@ func DefaultModelCapabilityConfigForModel(protocol string, modelName string) *Mo
Duration: VideoDurationConfig{Selection: "range", Min: 1, Max: 15, Step: 1, Default: 6},
Ratios: []string{"16:9", "9:16", "1:1", "4:3", "3:4", "21:9"},
DefaultRatio: "16:9",
Resolutions: []string{"480p", "720p", "1080p", "2160p"},
Resolutions: []string{"480p", "720p", "1080p", "1440p", "2160p"},
DefaultResolution: "720p",
GenerateAudio: VideoBooleanConfig{Supported: false, Default: false},
Watermark: VideoBooleanConfig{Supported: false, Default: false},
@@ -178,11 +178,15 @@ func DefaultModelCapabilityConfigForModel(protocol string, modelName string) *Mo
video.References.MaxVideoDuration, video.References.MaxAudioDuration = 15, 15
video.GenerateAudio = VideoBooleanConfig{Supported: true, Default: true}
video.Watermark = VideoBooleanConfig{Supported: true, Default: false}
video.Resolutions = []string{"480p", "720p", "1080p"}
case model.ChannelInterfaceNewAPIChannel1, model.ChannelInterfaceNewAPIChannel2:
video.References.MaxVideos, video.References.MaxAudios = 3, 3
video.References.MaxVideoBytes, video.References.MaxAudioBytes = 200*1024*1024, 15*1024*1024
video.References.MaxVideoDuration, video.References.MaxAudioDuration = 15, 15
video.GenerateAudio = VideoBooleanConfig{Supported: true, Default: true}
if model.ChannelInterfaceType(protocol) == model.ChannelInterfaceNewAPIChannel1 {
video.Resolutions = []string{"480p", "720p", "1080p"}
}
case model.ChannelInterfaceNewAPIVideo, model.ChannelInterfaceXAIVideo:
video.GenerateAudio = VideoBooleanConfig{Supported: false, Default: false}
case model.ChannelInterfaceNovitaVideo:
@@ -62,3 +62,23 @@ func TestValidateImageTaskEnforcesGPTImage2CustomSizeLimits(t *testing.T) {
})
}
}
func TestDefaultVideoCapabilityUsesProtocolSpecificResolutionTiers(t *testing.T) {
tests := map[string][]string{
"newapi-channel-2": {"480p", "720p", "1080p", "1440p", "2160p"},
"volcengine-ark-video": {"480p", "720p", "1080p"},
"volcengine-jimeng-video": {"720p"},
"gemini-veo": {"720p", "1080p"},
}
for protocol, want := range tests {
t.Run(protocol, func(t *testing.T) {
profile := DefaultModelCapabilityConfigForModel(protocol, "")
if profile == nil || profile.Video == nil {
t.Fatalf("DefaultModelCapabilityConfigForModel(%q) video profile = nil", protocol)
}
if fmt.Sprint(profile.Video.Resolutions) != fmt.Sprint(want) {
t.Fatalf("resolutions = %v, want %v", profile.Video.Resolutions, want)
}
})
}
}
+9 -3
View File
@@ -2025,16 +2025,22 @@ func normalizeNewAPIChannel2Resolution(value string, modelName string) string {
if modelName == "grok-video-1.5-1080p" {
return "1080p"
}
switch strings.ToLower(strings.TrimSpace(value)) {
normalized := strings.ToLower(strings.TrimSpace(value))
switch normalized {
case "480", "480p", "low":
return "480p"
case "1080", "1080p":
return "1080p"
case "1440", "1440p", "2k":
return "1440p"
case "2160", "2160p", "4k":
return "2160p"
default:
return "720p"
}
numeric := strings.TrimSuffix(normalized, "p")
if resolution, err := strconv.Atoi(numeric); err == nil && resolution > 0 {
return strconv.Itoa(resolution) + "p"
}
return "720p"
}
func runNewAPIChannel1VideoTask(ctx context.Context, input canvasGenerationInput) (map[string]interface{}, error) {
+16
View File
@@ -116,6 +116,22 @@ func TestProviderHTTPErrorWarnsAboutUncertain524Billing(t *testing.T) {
}
}
func TestNormalizeNewAPIChannel2ResolutionPreservesDeclaredTiers(t *testing.T) {
tests := map[string]string{
"1440": "1440p",
"2k": "1440p",
"4K": "2160p",
"768p": "768p",
}
for input, want := range tests {
t.Run(input, func(t *testing.T) {
if got := normalizeNewAPIChannel2Resolution(input, "custom-video-model"); got != want {
t.Fatalf("normalizeNewAPIChannel2Resolution(%q) = %q, want %q", input, got, want)
}
})
}
}
func TestVolcengineArkImageBodyUsesJSONReferencesAndDownscalesSize(t *testing.T) {
body, err := volcengineArkImageBody(canvasGenerationInput{
Prompt: "combine the references",
@@ -160,6 +160,9 @@ func normalizeVideoResolution(value string) string {
if strings.EqualFold(value, "4k") {
return "2160p"
}
if strings.EqualFold(value, "2k") {
return "1440p"
}
if strings.HasSuffix(value, "p") {
return value
}
@@ -180,6 +183,8 @@ func normalizeXAIVideoResolution(value string) string {
return "480p"
case "1080", "1080p":
return "1080p"
case "1440", "1440p", "2k":
return "1440p"
case "2160", "2160p", "4k":
return "2160p"
default: