fix(canvas): 画布引用 - 统一角色与图片编号并保持生成资源顺序
This commit is contained in:
1 parent
ef82ca1b62
commit
9ef10b7b2d
12 files changed
+368
-130
No files matched your search
@@ -11,7 +11,6 @@ var cloudAgentMediaMention = regexp.MustCompile(`@(图片|视频|音频)[0-9]+`)
|
||||
|
||||
func cloudAgentMediaComposerPrompt(prompt string, refs map[string]any) string {
|
||||
labels := map[string]string{}
|
||||
counts := map[string]int{}
|
||||
for _, kind := range []struct{ field, label string }{
|
||||
{"referenceImages", "图片"}, {"referenceVideos", "视频"}, {"referenceAudios", "音频"},
|
||||
} {
|
||||
@@ -20,11 +19,11 @@ func cloudAgentMediaComposerPrompt(prompt string, refs map[string]any) string {
|
||||
continue
|
||||
}
|
||||
label := kind.label
|
||||
if stringValue(ref["canvasReferenceKind"]) == "character" {
|
||||
if kind.field == "referenceImages" && stringValue(ref["canvasReferenceKind"]) == "character" {
|
||||
label = "角色"
|
||||
}
|
||||
counts[label]++
|
||||
labels[fmt.Sprintf("@%s%d", kind.label, index+1)] = fmt.Sprintf("@%s%d", label, counts[label])
|
||||
// 显示时保留角色类型,编号仍等于实际图片数组的位置。
|
||||
labels[fmt.Sprintf("@%s%d", kind.label, index+1)] = fmt.Sprintf("@%s%d", label, index+1)
|
||||
}
|
||||
}
|
||||
return cloudAgentMediaMention.ReplaceAllStringFunc(prompt, func(token string) string {
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestCloudAgentMediaReferencePrompt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentMediaComposerPromptSeparatesCharacterAndImageSlots(t *testing.T) {
|
||||
func TestCloudAgentMediaComposerPromptUsesUnifiedImageSlots(t *testing.T) {
|
||||
refs := map[string]any{
|
||||
"referenceImages": []any{
|
||||
map[string]any{"storageKey": "resource:character", "canvasReferenceKind": "character"},
|
||||
@@ -57,7 +57,7 @@ func TestCloudAgentMediaComposerPromptSeparatesCharacterAndImageSlots(t *testing
|
||||
"referenceAudios": []any{map[string]any{"storageKey": "resource:voice"}},
|
||||
}
|
||||
prompt := "@图片1、@图片2、@图片3 和 @音频1"
|
||||
want := "@角色1、@图片1、@角色2 和 @音频1"
|
||||
want := "@角色1、@图片2、@角色3 和 @音频1"
|
||||
if got := cloudAgentMediaComposerPrompt(prompt, refs); got != want {
|
||||
t.Fatalf("composer prompt = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user