diff --git a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_delivery.go b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_delivery.go index 5e907ae..2ad0300 100644 --- a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_delivery.go +++ b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_delivery.go @@ -27,8 +27,8 @@ type weixinPublicAccountSection struct { } func executeWeixinPublicAccountImagePromptStep(workflow *weixinPublicAccountWorkflowState, article *weixinpublicaccountmodel.WeixinPublicAccountArticle, user *model.User, now time.Time) weixinPublicAccountStepExecution { - prompts := buildWeixinPublicAccountImagePrompts(workflow) - contentWithPrompts := buildWeixinPublicAccountContentWithPrompts(workflow.Shared.Content, prompts) + prompts := buildWeixinPublicAccountImagePromptsV2(workflow) + contentWithPrompts := buildWeixinPublicAccountContentWithPromptsFromJSON(workflow.Shared.Content, prompts) workflow.Shared.ContentWithPrompts = contentWithPrompts workflow.Shared.ImagePrompts = prompts @@ -55,9 +55,9 @@ func executeWeixinPublicAccountImagePromptStep(workflow *weixinPublicAccountWork func executeWeixinPublicAccountImageGenerationStep(workflow *weixinPublicAccountWorkflowState, article *weixinpublicaccountmodel.WeixinPublicAccountArticle, user *model.User, now time.Time) (weixinPublicAccountStepExecution, *web.AppError) { prompts := workflow.Shared.ImagePrompts if len(prompts) == 0 { - prompts = buildWeixinPublicAccountImagePrompts(workflow) + prompts = buildWeixinPublicAccountImagePromptsV2(workflow) workflow.Shared.ImagePrompts = prompts - workflow.Shared.ContentWithPrompts = buildWeixinPublicAccountContentWithPrompts(workflow.Shared.Content, prompts) + workflow.Shared.ContentWithPrompts = buildWeixinPublicAccountContentWithPromptsFromJSON(workflow.Shared.Content, prompts) } aiRoute, refs, appErr := generateWeixinPublicAccountImages(article.TaskID, workflow, prompts, user) if appErr != nil { @@ -181,6 +181,11 @@ func buildWeixinPublicAccountContentWithPrompts(content string, prompts []weixin return strings.Join(blocks, "\n") } +// buildWeixinPublicAccountContentWithPromptsFromJSON 基于 JSON 配置渲染带括号标记的正文。 +func buildWeixinPublicAccountContentWithPromptsFromJSON(content string, prompts []weixinPublicAccountImagePrompt) string { + return renderWeixinPublicAccountImagePromptFromJSON(content, prompts) +} + func buildWeixinPublicAccountVisualPrompt(workflow *weixinPublicAccountWorkflowState, sectionTitle, context string) string { keyword := firstNonEmpty(workflow.Form.Keyword, "业务主题") tone := firstNonEmpty(workflow.Form.Tone, "专业但好懂") diff --git a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_image_prompt_config.go b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_image_prompt_config.go index 50b17cf..6fc1710 100644 --- a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_image_prompt_config.go +++ b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_image_prompt_config.go @@ -217,18 +217,20 @@ func buildWeixinPublicAccountImagePromptsV2(workflow *weixinPublicAccountWorkflo func buildCoverImagePrompt(workflow *weixinPublicAccountWorkflowState, rule *imagePromptRule) string { title := firstNonEmpty(workflow.Shared.SelectedTitle, workflow.Form.Keyword, "公众号文章") - // 从 JSON 模板构建(当前回退到硬编码模板) + // 从 JSON 模板构建 template := rule.Template.Template - if template == "" { - // 回退到当前硬编码的英文模板 - return fmt.Sprintf("realistic editorial illustration, Chinese business article cover, %s, focus on %s, %s, clean composition, natural lighting, brand-safe, no text, no watermark", - weixinPublicAccountBusinessDomainLabel(workflow.Form.BusinessDomain), - title, - "公众号封面主视觉", - ) + if template != "" { + // 使用字符串替换,而非 fmt.Sprintf + prompt := strings.ReplaceAll(template, "{index}", "1") + prompt = strings.ReplaceAll(prompt, "{section_summary}", fmt.Sprintf("%s(截断至120字)", title)) + return prompt } - - return fmt.Sprintf(template, 1, title, fmt.Sprintf("%s(截断至120字)", title)) + // 回退到硬编码模板 + return fmt.Sprintf("realistic editorial illustration, Chinese business article cover, %s, focus on %s, %s, clean composition, natural lighting, brand-safe, no text, no watermark", + weixinPublicAccountBusinessDomainLabel(workflow.Form.BusinessDomain), + title, + "公众号封面主视觉", + ) } // buildContentImagePrompt 生成正文配图提示词。 @@ -237,16 +239,18 @@ func buildContentImagePrompt(workflow *weixinPublicAccountWorkflowState, section // 从 JSON 模板构建 template := rule.Template.Template - if template == "" { - // 回退到当前硬编码的英文模板 - return fmt.Sprintf("realistic editorial illustration, Chinese business article cover, %s, focus on %s, %s, clean composition, natural lighting, brand-safe, no text, no watermark", - weixinPublicAccountBusinessDomainLabel(workflow.Form.BusinessDomain), - firstNonEmpty(section.Title, workflow.Form.Keyword), - firstNonEmpty(summary, workflow.Form.Tone), - ) + if template != "" { + // 使用字符串替换,而非 fmt.Sprintf + prompt := strings.ReplaceAll(template, "{index}", fmt.Sprintf("%d", index)) + prompt = strings.ReplaceAll(prompt, "{section_summary}", summary) + return prompt } - - return fmt.Sprintf(template, index, firstNonEmpty(section.Title, workflow.Form.Keyword), summary) + // 回退到硬编码模板 + return fmt.Sprintf("realistic editorial illustration, Chinese business article cover, %s, focus on %s, %s, clean composition, natural lighting, brand-safe, no text, no watermark", + weixinPublicAccountBusinessDomainLabel(workflow.Form.BusinessDomain), + firstNonEmpty(section.Title, workflow.Form.Keyword), + firstNonEmpty(summary, workflow.Form.Tone), + ) } // countChineseWords 计算内容的中文字数。 diff --git a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_workflow.go b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_workflow.go index 49542ec..c809515 100644 --- a/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_workflow.go +++ b/eai_agentplatform/backend-go/internal/specialists/packages/weixin_public_account/api/weixin_public_account_workflow.go @@ -792,7 +792,7 @@ func respondWeixinPublicAccountWorkflow(c *gin.Context, task model.TaskRecord) { func findWeixinPublicAccountImagePrompt(workflow weixinPublicAccountWorkflowState, imageKey string) (weixinPublicAccountImagePrompt, int, bool) { prompts := workflow.Shared.ImagePrompts if len(prompts) == 0 { - prompts = buildWeixinPublicAccountImagePrompts(&workflow) + prompts = buildWeixinPublicAccountImagePromptsV2(&workflow) workflow.Shared.ImagePrompts = prompts } for idx, item := range prompts { diff --git a/eai_agentplatform/frontend/src/components/chat/WeixinPublicAccountSpecialistPanel.vue b/eai_agentplatform/frontend/src/components/chat/WeixinPublicAccountSpecialistPanel.vue index 0ea13a0..113cdcc 100644 --- a/eai_agentplatform/frontend/src/components/chat/WeixinPublicAccountSpecialistPanel.vue +++ b/eai_agentplatform/frontend/src/components/chat/WeixinPublicAccountSpecialistPanel.vue @@ -148,20 +148,51 @@