1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package agent_base
- import (
- "context"
- "fmt"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/errorx"
- "wechat-api/hook/fastgpt"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CreateAgentBaseLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewCreateAgentBaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAgentBaseLogic {
- return &CreateAgentBaseLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *CreateAgentBaseLogic) CreateAgentBase(req *types.CreateDataInfoReq) (*types.BaseDataInfo, error) {
- params := fastgpt.CreateBulkDataReq{}
- params.CollectionID = *req.CollectionId
- params.TrainingMode = "chunk"
- pair := make([]fastgpt.DataQuestion, 0, 1)
- pair = append(pair, fastgpt.DataQuestion{
- Q: *req.Q,
- A: *req.A,
- })
- params.Data = append(params.Data, pair...)
- resp, err := fastgpt.CreateBulkData(¶ms)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt create data failed " + err.Error())
- }
- if resp.Code == 200 {
- if resp.Data.InsertLen > 0 {
- return &types.BaseDataInfo{
- Code: 0,
- Msg: errormsg.Success,
- Data: fmt.Sprintf("Insert %d rows", resp.Data.InsertLen),
- }, nil
- } else {
- return &types.BaseDataInfo{
- Code: 0,
- Msg: "字数超限,添加失败,请修改后重试",
- Data: fmt.Sprintf("Insert %d rows", resp.Data.InsertLen),
- }, nil
- }
- }
- return nil, errorx.NewInvalidArgumentError(resp.StatusText)
- }
|