promote_controller.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package llm
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/controllers/llm/llm_http"
  6. "eta/eta_api/models"
  7. "eta/eta_api/services/llm/facade"
  8. "eta/eta_api/utils"
  9. )
  10. type PromoteController struct {
  11. controllers.BaseAuthController
  12. }
  13. // PromoteTrainRecordList @Title 获取聊天记录
  14. // @Description 获取聊天记录
  15. // @Success 101 {object} response.ListResp
  16. // @router /promote/train_list [get]
  17. func (pCtrl *PromoteController) PromoteTrainRecordList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. pCtrl.Data["json"] = br
  21. pCtrl.ServeJSON()
  22. }()
  23. sysUser := pCtrl.SysUser
  24. if sysUser == nil {
  25. br.Msg = "请登录"
  26. br.ErrMsg = "请登录,SysUser Is Empty"
  27. br.Ret = 408
  28. return
  29. }
  30. pageSize, _ := pCtrl.GetInt("PageSize")
  31. currentIndex, _ := pCtrl.GetInt("CurrentIndex")
  32. //var total, startSize int
  33. if pageSize <= 0 {
  34. pageSize = utils.PageSize5
  35. }
  36. if currentIndex <= 0 {
  37. currentIndex = 1
  38. }
  39. //startSize = paging.StartIndex(currentIndex, pageSize)
  40. //page := paging.GetPaging(currentIndex, pageSize, total)
  41. //total, err := rag.CountQuestionList()
  42. //if err != nil {
  43. // br.Msg = "获取失败"
  44. // br.ErrMsg = "获取失败,Err:" + err.Error()
  45. // return
  46. //}
  47. //list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
  48. //if err != nil {
  49. // br.Msg = "获取失败"
  50. // br.ErrMsg = "获取失败,Err:" + err.Error()
  51. // return
  52. //}
  53. br.Data = nil
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "获取聊天记录成功"
  57. }
  58. // GenerateContent @Title 生成问答内容
  59. // @Description 生成问答内容
  60. // @Success 101 {object} response.ListResp
  61. // @router /promote/generate_content [post]
  62. func (pCtrl *PromoteController) GenerateContent() {
  63. br := new(models.BaseResponse).Init()
  64. defer func() {
  65. pCtrl.Data["json"] = br
  66. pCtrl.ServeJSON()
  67. }()
  68. var gcReq llm_http.GenerateContentReq
  69. err := json.Unmarshal(pCtrl.Ctx.Input.RequestBody, &gcReq)
  70. if err != nil {
  71. br.Msg = "参数解析异常!"
  72. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  73. return
  74. }
  75. sysUser := pCtrl.SysUser
  76. if sysUser == nil {
  77. br.Msg = "请登录"
  78. br.ErrMsg = "请登录,SysUser Is Empty"
  79. br.Ret = 408
  80. return
  81. }
  82. if gcReq.Promote == "" {
  83. br.Msg = "提示词不能为空"
  84. br.ErrMsg = "提示词不能为空"
  85. return
  86. }
  87. if gcReq.WechatArticleId <= 0 {
  88. br.Msg = "公众号文章编号非法"
  89. br.ErrMsg = "公众号文章编号非法"
  90. return
  91. }
  92. res, err := facade.AIGCBaseOnPromote(facade.AIGC{
  93. Promote: gcReq.Promote,
  94. ArticleId: gcReq.WechatArticleId,
  95. })
  96. if err != nil {
  97. br.Msg = "内容生成失败"
  98. br.ErrMsg = "内容生成失败,Err:" + err.Error()
  99. return
  100. }
  101. br.Data = res
  102. br.Ret = 200
  103. br.Success = true
  104. br.Msg = "内容生成成功"
  105. }