소스 검색

fix:edit agent/data/upload

jimmyyem 4 달 전
부모
커밋
fab87e3756
1개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 12 5
      internal/logic/agent/upload_agent_data_logic.go

+ 12 - 5
internal/logic/agent/upload_agent_data_logic.go

@@ -38,8 +38,6 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
 		return nil, err
 	}
 
-	fmt.Printf("req=%+v", *req)
-
 	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)
@@ -54,14 +52,24 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
 
 	qas := make([]fastgpt.DataQuestion, 0, 100)
 	for idx, record := range records {
-		//l.Logger.Infof("idx=>%d 0=>%s 1=>%s\n", idx, record[0], record[1])
+		// 第一行标题内容过滤
+		//fmt.Printf("idx=%v, q=%v, a=%v \n", idx, record[0], record[1])
+		//fmt.Println(idx == 0, record[0] == "问题", record[1] == "答案")
+		//fmt.Printf("record=%+v\n", record)
+		if idx == 0 && record[1] == "答案" {
+			continue
+		}
+		// 空内容过滤
+		if record[0] == "" || record[1] == "" {
+			continue
+		}
+
 		qas = append(qas, fastgpt.DataQuestion{
 			Q: record[0],
 			A: record[1],
 		})
 		if idx%100 == 0 && len(qas) > 0 {
 			params.Data = qas
-			//response, err := fastgpt.DiyCreateBulkData(token, &params)
 			response, err := fastgpt.CreateBulkData(&params)
 			if err != nil {
 				l.Logger.Errorf("batch insert data to fastgpt failed. collection=%s error=%s", agent.CollectionID, err.Error())
@@ -75,7 +83,6 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
 	if len(qas) > 0 {
 		params.Data = qas
 		response, err := fastgpt.DiyCreateBulkData(token, &params)
-		//response, err := fastgpt.CreateBulkData(&params)
 		if err != nil {
 			l.Logger.Errorf("batch insert data to fastgpt failed. collection=%s error=%s", agent.CollectionID, err.Error())
 			return nil, err