|
@@ -5,8 +5,10 @@ import (
|
|
|
"eta/eta_api/controllers"
|
|
|
"eta/eta_api/controllers/llm/llm_http"
|
|
|
"eta/eta_api/models"
|
|
|
+ "eta/eta_api/models/rag"
|
|
|
"eta/eta_api/services/llm/facade"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type PromoteController struct {
|
|
@@ -95,6 +97,11 @@ func (pCtrl *PromoteController) GenerateContent() {
|
|
|
br.ErrMsg = "公众号文章编号非法"
|
|
|
return
|
|
|
}
|
|
|
+ userContent := llm_http.Content{
|
|
|
+ Content: gcReq.Promote,
|
|
|
+ Role: "user",
|
|
|
+ SendTime: time.Now().Format(utils.FormatDateTime),
|
|
|
+ }
|
|
|
res, err := facade.AIGCBaseOnPromote(facade.AIGC{
|
|
|
Promote: gcReq.Promote,
|
|
|
ArticleId: gcReq.WechatArticleId,
|
|
@@ -104,8 +111,119 @@ func (pCtrl *PromoteController) GenerateContent() {
|
|
|
br.ErrMsg = "内容生成失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- br.Data = res
|
|
|
+ aiContent := llm_http.Content{
|
|
|
+ Content: res.Answer,
|
|
|
+ Role: "assistant",
|
|
|
+ SendTime: time.Now().Format(utils.FormatDateTime),
|
|
|
+ }
|
|
|
+ br.Data = llm_http.AIGCResp{
|
|
|
+ Promote: userContent,
|
|
|
+ Answer: aiContent,
|
|
|
+ }
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "内容生成成功"
|
|
|
}
|
|
|
+
|
|
|
+// SavePromoteContent @Title 保存问答内容
|
|
|
+// @Description 生成问答内容
|
|
|
+// @Success 101 {object} response.ListResp
|
|
|
+// @router /promote/save_content [post]
|
|
|
+func (pCtrl *PromoteController) SavePromoteContent() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ pCtrl.Data["json"] = br
|
|
|
+ pCtrl.ServeJSON()
|
|
|
+ }()
|
|
|
+ var gcReq llm_http.SaveContentReq
|
|
|
+ err := json.Unmarshal(pCtrl.Ctx.Input.RequestBody, &gcReq)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sysUser := pCtrl.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if gcReq.Promote == nil {
|
|
|
+ br.Msg = "提示词内容不能为空"
|
|
|
+ br.ErrMsg = "提示词不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if gcReq.AigcContent == nil {
|
|
|
+ br.Msg = "回答内容不能为空"
|
|
|
+ br.ErrMsg = "提示词不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if gcReq.WechatArticleId <= 0 {
|
|
|
+ br.Msg = "公众号文章编号非法"
|
|
|
+ br.ErrMsg = "公众号文章编号非法"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var userContent, assistantContent llm_http.Content
|
|
|
+ parseErr := json.Unmarshal([]byte(gcReq.AigcContent), &assistantContent)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "内容参数解析异常!"
|
|
|
+ br.ErrMsg = "内容参数解析异,err" + parseErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ parseErr = json.Unmarshal([]byte(gcReq.Promote), &userContent)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "内容参数解析异常!"
|
|
|
+ br.ErrMsg = "内容参数解析异,err" + parseErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var titile string
|
|
|
+ if gcReq.Title != "" {
|
|
|
+ titile = gcReq.Title
|
|
|
+ } else {
|
|
|
+ titile = userContent.Content
|
|
|
+ }
|
|
|
+ var userSendTime, assistantSendTime time.Time
|
|
|
+ if userContent.SendTime != "" {
|
|
|
+ userSendTime, parseErr = time.ParseInLocation(utils.FormatDateTime, userContent.SendTime, time.Local)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "用户发送时间解析异常!"
|
|
|
+ br.ErrMsg = "用户发送时间解析异常,err" + parseErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ br.Msg = "用户发送时间不能为空!"
|
|
|
+ br.ErrMsg = "用户发送时间不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if assistantContent.SendTime != "" {
|
|
|
+ assistantSendTime, parseErr = time.ParseInLocation(utils.FormatDateTime, assistantContent.SendTime, time.Local)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "AI生成时间解析异常!"
|
|
|
+ br.ErrMsg = "AI生成时间解析异常,err" + parseErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ br.Msg = "AI生成时间不能为空!"
|
|
|
+ br.ErrMsg = "AI生成时间不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ saveContentReq := rag.PromoteTrainRecord{
|
|
|
+ WechatArticleId: gcReq.WechatArticleId,
|
|
|
+ Title: titile,
|
|
|
+ AigcContent: assistantContent.Content,
|
|
|
+ AigcSendTime: assistantSendTime,
|
|
|
+ TemplatePromote: userContent.Content,
|
|
|
+ PromoteSendTime: userSendTime,
|
|
|
+ CreatedTime: time.Now(),
|
|
|
+ }
|
|
|
+ err = saveContentReq.SaveContent()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存内容失败"
|
|
|
+ br.ErrMsg = "保存内容失败,err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存内容成功"
|
|
|
+}
|