get_agent_base_by_id_logic.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package agent_base
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/zeromicro/go-zero/core/errorx"
  6. "wechat-api/hook/fastgpt"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetAgentBaseByIdLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewGetAgentBaseByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentBaseByIdLogic {
  17. return &GetAgentBaseByIdLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx}
  21. }
  22. func (l *GetAgentBaseByIdLogic) GetAgentBaseById(req *types.DataDetailReq) (*types.DataDetailResp, error) {
  23. resp, err := fastgpt.GetDataDetail(*req.ID)
  24. if err != nil {
  25. return nil, errorx.NewInvalidArgumentError("fastgpt get data failed " + err.Error())
  26. }
  27. if resp.Code == 200 {
  28. indexes := make([]types.Index, 0, len(resp.Data.Indexes))
  29. for _, val := range resp.Data.Indexes {
  30. indexes = append(indexes, types.Index{
  31. DefaultIndex: &val.DefaultIndex,
  32. Text: &val.Text,
  33. DataId: &val.DataID,
  34. ID: &val.ID,
  35. })
  36. }
  37. return &types.DataDetailResp{
  38. BaseDataInfo: types.BaseDataInfo{
  39. Code: 0,
  40. Msg: errormsg.Success,
  41. },
  42. Data: types.DataInfo{
  43. ID: &resp.Data.ID,
  44. Q: &resp.Data.Q,
  45. A: &resp.Data.A,
  46. ChunkIndex: &resp.Data.ChunkIndex,
  47. DatasetId: &resp.Data.DatasetID,
  48. CollectionId: &resp.Data.CollectionID,
  49. SourceName: &resp.Data.SourceName,
  50. CanWrite: &resp.Data.CanWrite,
  51. IsOwner: &resp.Data.IsOwner,
  52. Indexes: indexes,
  53. },
  54. }, nil
  55. }
  56. return nil, errorx.NewInvalidArgumentError(resp.StatusText)
  57. }