From eae2db49421227bb7639bfd4e35312270208a198 Mon Sep 17 00:00:00 2001 From: bx1834938347-prog Date: Fri, 5 Dec 2025 16:19:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Aai=E7=94=9F=E6=88=90=E5=9B=BE?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/import/imageContentImport.go | 2 ++ pkg/service/import/imageContentProcessor.go | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/service/import/imageContentImport.go b/pkg/service/import/imageContentImport.go index 6a045d9..de066d3 100644 --- a/pkg/service/import/imageContentImport.go +++ b/pkg/service/import/imageContentImport.go @@ -38,6 +38,8 @@ type excelData struct { PhotoUrl string //画作地址 PhotoNum int //图片数量 必须字段 LineNum int + Title string //标题 + Content string //内容 MediaAccountUuids []string MediaAccountNames []string } diff --git a/pkg/service/import/imageContentProcessor.go b/pkg/service/import/imageContentProcessor.go index 9b03c81..b9532ad 100644 --- a/pkg/service/import/imageContentProcessor.go +++ b/pkg/service/import/imageContentProcessor.go @@ -246,15 +246,20 @@ func (p *BatchProcessor) generateTitle(req *excelData) (string, error) { return "", errors.New("AI未生成标题内容") } - return strings.TrimSpace(result.Output.Choices[0].Message.Content), nil + req.Title = strings.TrimSpace(result.Output.Choices[0].Message.Content) + return req.Title, nil } func (p *BatchProcessor) generateContent(req *excelData) (string, error) { + // 使用已生成的标题作为上下文 prompt := fmt.Sprintf("请根据以下要求生成内容:%s", req.ContentRequire) + if req.Title != "" { + prompt += fmt.Sprintf("\n标题:%s", req.Title) // 关联标题 + } if req.Desc != "" { prompt += fmt.Sprintf("\n艺人简介:%s", req.Desc) } - prompt += "\n请直接输出内容,不要包含任何其他文字。" + prompt += "\n请基于标题生成相关内容,直接输出内容,不要包含任何其他文字。" result, err := NewAiGenerator().GenerateTextSync(prompt) if err != nil { @@ -265,10 +270,18 @@ func (p *BatchProcessor) generateContent(req *excelData) (string, error) { return "", errors.New("AI未生成内容") } - return strings.TrimSpace(result.Output.Choices[0].Message.Content), nil + req.Content = strings.TrimSpace(result.Output.Choices[0].Message.Content) + return req.Content, nil } + func (p *BatchProcessor) generateImage(req *excelData) (string, error) { prompt := fmt.Sprintf("请根据以下要求生成内容:%s", req.PhotoRequire) + if req.Title != "" { + prompt += fmt.Sprintf("\n标题:%s", req.Title) // 关联标题 + } + if req.Content != "" { + prompt += fmt.Sprintf("\n内容:%s", req.Content) // 关联内容 + } if req.Desc != "" { prompt += fmt.Sprintf("\n艺人简介:%s", req.Desc) } @@ -282,7 +295,6 @@ func (p *BatchProcessor) generateImage(req *excelData) (string, error) { return "", err } return result.Output.TaskID, nil - //} } func (p *BatchProcessor) GetTaskStatistics() (completed, pending, total int, completedTasks, failedTasks []*ImageTask) {