Browse Source

fix:edit sop_task/generate_ai_answer

jimmyyem 3 months ago
parent
commit
1f9296a7b0
2 changed files with 12 additions and 4 deletions
  1. 5 1
      hook/fastgpt/aioptimize.go
  2. 7 3
      internal/logic/sop_task/generate_ai_answer_logic.go

+ 5 - 1
hook/fastgpt/aioptimize.go

@@ -5,7 +5,7 @@ import (
 	"github.com/sashabaranov/go-openai"
 )
 
-func ChatWithCustomConfig(baseURL, apiKey, prompt string) (string, error) {
+func ChatWithCustomConfig(baseURL, apiKey, prompt, systemPrompt string) (string, error) {
 	// 创建OpenAI客户端配置
 	config := openai.DefaultConfig(apiKey)
 	config.BaseURL = baseURL
@@ -21,6 +21,10 @@ func ChatWithCustomConfig(baseURL, apiKey, prompt string) (string, error) {
 				Role:    "user",
 				Content: prompt,
 			},
+			{
+				Role:    "system",
+				Content: systemPrompt,
+			},
 		},
 		Stream: false,
 	}

+ 7 - 3
internal/logic/sop_task/generate_ai_answer_logic.go

@@ -27,13 +27,17 @@ func NewGenerateAiAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 func (l *GenerateAiAnswerLogic) GenerateAiAnswer(req *types.GenerateAiAnswerReq) (*types.GenerateAiAnswerResp, error) {
 	resp := types.GenerateAiAnswerResp{}
 	prompt := fmt.Sprintf(`
-请根据用户输入的消息,优化用户输入的内容。
+请根据用户输入的内容,包括角色、目标用户和背景介绍优化用户输入的内容。
 用户输入内容:%s
-`, req.Content)
 
+# 回复要求
+- 如果优化成功,只返回具体的优化后的内容
+- 如果未优化成功,只返回优化失败的原因
+`, req.Content)
+	systemPrompt := "你是一个写作高手,帮助用户撰写或优化文案"
 	baseUrl := l.svcCtx.Config.Fastgpt.BASE_URL
 	apiKey := l.svcCtx.Config.Fastgpt.API_KEY
-	answer, err := fastgpt.ChatWithCustomConfig(baseUrl, apiKey, prompt)
+	answer, err := fastgpt.ChatWithCustomConfig(baseUrl, apiKey, systemPrompt, prompt)
 	if err != nil {
 		return nil, err
 	}