Browse Source

提示词内容生成

kobe6258 2 weeks ago
parent
commit
17cafe8bfb

+ 6 - 0
controllers/llm/llm_http/request.go

@@ -31,3 +31,9 @@ type SaveContentReq struct {
 	Promote         json.RawMessage `json:"Promote" description:"提示词"`
 	AigcContent     json.RawMessage `json:"AigcContent" description:"生成内容"`
 }
+type DeleteContentReq struct {
+	RecordId int
+}
+type ContentListReq struct {
+	WechatArticleId int
+}

+ 79 - 0
controllers/llm/promote_controller.go

@@ -227,3 +227,82 @@ func (pCtrl *PromoteController) SavePromoteContent() {
 	br.Success = true
 	br.Msg = "保存内容成功"
 }
+
+// DeletePromoteContent @Title 删除问答内容
+// @Description 生成问答内容
+// @Success 101 {object} response.ListResp
+// @router /promote/delete_content [post]
+func (pCtrl *PromoteController) DeletePromoteContent() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		pCtrl.Data["json"] = br
+		pCtrl.ServeJSON()
+	}()
+	var gcReq llm_http.DeleteContentReq
+	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.RecordId <= 0 {
+		br.Msg = "记录编号非法"
+		br.ErrMsg = "记录编号非法"
+		return
+	}
+
+	err = rag.DeleteContent(gcReq.RecordId)
+	if err != nil {
+		br.Msg = "删除内容失败"
+		br.ErrMsg = "删除内容失败,err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "删除内容成功"
+}
+
+// PromoteContentList @Title 删除问答内容
+// @Description 生成问答内容
+// @Success 101 {object} response.ListResp
+// @router /promote/content_list [get]
+func (pCtrl *PromoteController) PromoteContentList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		pCtrl.Data["json"] = br
+		pCtrl.ServeJSON()
+	}()
+	wechatArticleId, _ := pCtrl.GetInt("WechatArticleId")
+	sysUser := pCtrl.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	if wechatArticleId <= 0 {
+		br.Msg = "记录编号非法"
+		br.ErrMsg = "记录编号非法"
+		return
+	}
+
+	list, err := rag.GetRecordList(wechatArticleId)
+	if err != nil {
+		br.Msg = "查询列表失败"
+		br.ErrMsg = "查询列表失败,err:" + err.Error()
+		return
+	}
+	br.Data = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "查询列表成功"
+}

+ 37 - 0
models/rag/promote_train_record.go

@@ -19,6 +19,28 @@ type PromoteTrainRecord struct {
 	UpdateTime      time.Time `gorm:"update_time"`
 }
 
+func (p *PromoteTrainRecord) ToView() PromoteTrainRecordView {
+	return PromoteTrainRecordView{
+		Id:              p.Id,
+		Title:           p.Title,
+		WechatArticleId: p.WechatArticleId,
+		TemplatePromote: p.TemplatePromote,
+		PromoteSendTime: p.PromoteSendTime.Format(utils.FormatDateTime),
+		AigcContent:     p.AigcContent,
+		AigcSendTime:    p.AigcSendTime.Format(utils.FormatDateTime),
+	}
+}
+
+type PromoteTrainRecordView struct {
+	Id              int
+	Title           string
+	WechatArticleId int
+	TemplatePromote string
+	PromoteSendTime string
+	AigcContent     string
+	AigcSendTime    string
+}
+
 func (p *PromoteTrainRecord) TableName() string {
 	return "promote_train_record"
 }
@@ -26,3 +48,18 @@ func (p *PromoteTrainRecord) TableName() string {
 func (p *PromoteTrainRecord) SaveContent() error {
 	return global.DbMap[utils.DbNameAI].Create(p).Error
 }
+func DeleteContent(id int) error {
+	return global.DbMap[utils.DbNameAI].Model(&PromoteTrainRecord{}).Where("id = ?", id).Update("is_deleted", true).Error
+}
+
+func GetRecordList(wechatArticleId int) (list []PromoteTrainRecordView, err error) {
+	var ormList []PromoteTrainRecord
+	err = global.DbMap[utils.DbNameAI].Model(&PromoteTrainRecord{}).Where("wechat_article_id = ? and is_deleted=?", wechatArticleId, false).Find(&ormList).Error
+	if err!=nil{
+		return
+	}
+	for _, item := range ormList {
+		list = append(list, item.ToView())
+	}
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -8404,6 +8404,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"],
+        beego.ControllerComments{
+            Method: "PromoteContentList",
+            Router: `/promote/content_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"],
+        beego.ControllerComments{
+            Method: "DeletePromoteContent",
+            Router: `/promote/delete_content`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/llm:PromoteController"],
         beego.ControllerComments{
             Method: "GenerateContent",