1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package sop_task
- import (
- "context"
- "fmt"
- "wechat-api/hook/fastgpt"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GenerateAiAnswerLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewGenerateAiAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateAiAnswerLogic {
- return &GenerateAiAnswerLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *GenerateAiAnswerLogic) GenerateAiAnswer(req *types.GenerateAiAnswerReq) (*types.GenerateAiAnswerResp, error) {
- resp := types.GenerateAiAnswerResp{}
- prompt := fmt.Sprintf(`
- 请根据用户输入的内容,包括角色、目标用户和背景介绍优化用户输入的内容。
- 用户输入内容:%s
- # 回复要求
- - 如果优化成功,只返回具体的优化后的内容
- - 如果未优化成功,只返回优化失败的原因
- `, req.Content)
- systemPrompt := "你是一个写作高手,帮助用户撰写或优化文案"
- baseUrl := l.svcCtx.Config.Fastgpt.BASE_URL
- apiKey := l.svcCtx.Config.Fastgpt.API_KEY
- answer, err := fastgpt.ChatWithCustomConfig(baseUrl, apiKey, systemPrompt, prompt)
- if err != nil {
- return nil, err
- }
- resp.Data = answer
- return &resp, nil
- }
|