Pārlūkot izejas kodu

fix:修改上传知识库API

jimmyyem 5 dienas atpakaļ
vecāks
revīzija
d39fcc8cc4
1 mainītis faili ar 18 papildinājumiem un 5 dzēšanām
  1. 18 5
      internal/logic/agent/upload_agent_data_logic.go

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

@@ -8,6 +8,7 @@ import (
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"io"
 	"mime/multipart"
+	"strings"
 	agentModel "wechat-api/ent/agent"
 	"wechat-api/hook/fastgpt"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -64,12 +65,9 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
 
 		fmt.Printf("转换前:question=%s, answer=%s \n", record[0], record[1])
 
-		var question, answer []byte
-		reader0 := transform.NewReader(bytes.NewReader([]byte(record[0])), simplifiedchinese.GBK.NewDecoder())
-		question, _ = io.ReadAll(reader0)
+		question := transCharset(record[0])
 
-		reader1 := transform.NewReader(bytes.NewReader([]byte(record[1])), simplifiedchinese.GBK.NewDecoder())
-		answer, _ = io.ReadAll(reader1)
+		answer := transCharset(record[1])
 
 		fmt.Printf("转换后:question=%s, answer=%s \n", question, answer)
 
@@ -110,3 +108,18 @@ func (l *UploadAgentDataLogic) UploadAgentData(req *types.UploadDataReq, file mu
 	resp.Data = fmt.Sprintf("upload %d rows", count)
 	return resp, nil
 }
+
+func trim(s string) string {
+	s = strings.TrimLeft(s, " \r\n\t")
+	s = strings.TrimRight(s, " \r\n\t")
+	return s
+}
+
+func transCharset(s string) string {
+	s = trim(s)
+	return s
+	rd := transform.NewReader(bytes.NewReader([]byte(s)), simplifiedchinese.GBK.NewDecoder())
+	bytes, err := io.ReadAll(rd)
+	fmt.Printf("bytes=%s err=%v\n", bytes, err)
+	return string(bytes)
+}