|
@@ -30,22 +30,21 @@ func NewUploadAgentDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
|
|
}
|
|
|
|
|
|
func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file multipart.File, agentId uint64) (*types.BaseDataInfo, error) {
|
|
|
- var count uint64
|
|
|
+ var count uint64 = 0
|
|
|
+ //fmt.Printf("count=%d \n", count)
|
|
|
|
|
|
reader := csv.NewReader(file)
|
|
|
records, err := reader.ReadAll()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ //fmt.Printf("records=%v \n", records)
|
|
|
|
|
|
agent, err := l.svcCtx.DB.Agent.Query().Where(agentModel.ID(agentId)).Only(l.ctx)
|
|
|
if err != nil {
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
|
|
|
- //TODO
|
|
|
- token := agent.CollectionID
|
|
|
-
|
|
|
var params fastgpt.CreateBulkDataReq
|
|
|
params.CollectionID = agent.CollectionID
|
|
|
params.TrainingMode = "chunk"
|
|
@@ -53,7 +52,7 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
|
|
|
qas := make([]fastgpt.DataQuestion, 0, 100)
|
|
|
for idx, record := range records {
|
|
|
// 第一行标题内容过滤
|
|
|
- //fmt.Printf("idx=%v, q=%v, a=%v \n", idx, record[0], record[1])
|
|
|
+ //fmt.Printf("idx=%v, record=%v \n", idx, record)
|
|
|
//fmt.Println(idx == 0, record[0] == "问题", record[1] == "答案")
|
|
|
//fmt.Printf("record=%+v\n", record)
|
|
|
if idx == 0 && record[1] == "答案" {
|
|
@@ -68,26 +67,36 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
|
|
|
Q: record[0],
|
|
|
A: record[1],
|
|
|
})
|
|
|
- if idx%100 == 0 && len(qas) > 0 {
|
|
|
+
|
|
|
+ length := len(qas)
|
|
|
+ if length > 0 && length%100 == 0 {
|
|
|
params.Data = qas
|
|
|
+ //fmt.Printf("11 qas=%+v \n", qas)
|
|
|
response, err := fastgpt.CreateBulkData(¶ms)
|
|
|
if err != nil {
|
|
|
l.Logger.Errorf("batch insert data to fastgpt failed. collection=%s error=%s", agent.CollectionID, err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
+ //fmt.Printf("response=%+v \n", response)
|
|
|
count += response.Data.InsertLen
|
|
|
+ //fmt.Printf("count=%d insert=%d \n", count, response.Data.InsertLen)
|
|
|
+
|
|
|
qas = make([]fastgpt.DataQuestion, 0, 100)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(qas) > 0 {
|
|
|
params.Data = qas
|
|
|
- response, err := fastgpt.DiyCreateBulkData(token, ¶ms)
|
|
|
+ //fmt.Printf("22 qas=%+v \n", qas)
|
|
|
+ response, err := fastgpt.CreateBulkData(¶ms)
|
|
|
if err != nil {
|
|
|
l.Logger.Errorf("batch insert data to fastgpt failed. collection=%s error=%s", agent.CollectionID, err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
+ //fmt.Printf("response=%+v \n", response)
|
|
|
+ //fmt.Printf("count=%d insert=%d \n", count, response.Data.InsertLen)
|
|
|
count += response.Data.InsertLen
|
|
|
+ //fmt.Printf("count=%d insert=%d \n", count, response.Data.InsertLen)
|
|
|
}
|
|
|
|
|
|
resp := &types.BaseDataInfo{}
|