package ai import ( "fmt" "github.com/gin-gonic/gin" "kefu/common" "kefu/lib" "kefu/models" "kefu/types" "log" "os" "strconv" ) // 训练素材文件列表 func GETFileList(c *gin.Context) { collectName, _ := c.Get("collect_name") list := models.FindFileList(1, 1000, "collect_name = ? ", collectName) c.JSON(200, gin.H{ "code": types.ApiCode.SUCCESS, "msg": types.ApiCode.GetMessage(types.ApiCode.SUCCESS), "result": list, }) } // 删除文件 func GetDelFile(c *gin.Context) { collectName, _ := c.Get("collect_name") id := c.Query("id") points := make([]string, 0) fileModel := models.FindAiFileRow("collect_name = ? and id = ?", collectName, id) filePoints := models.FindAiFilePoint(1, 100000, "collect_name = ? and file_id = ?", collectName, id) for _, item := range filePoints { points = append(points, item.PointsId) } list, err := lib.DeletePoints(collectName.(string), points) models.DelFile("collect_name = ? and id = ?", collectName, id) models.DelFilePoints("collect_name = ? and file_id = ?", collectName, id) //删除文件 fildDir := fmt.Sprintf("%sai/%s/", common.Upload, collectName) filepath := fmt.Sprintf("%s%s", fildDir, fileModel.FileName) removeErr := os.Remove(filepath) if removeErr != nil { log.Println("Remove error:", filepath, removeErr) } if err != nil { c.Writer.Write([]byte(err.Error())) return } c.Writer.Write([]byte(list)) } // 文件知识列表 func GetFilePoints(c *gin.Context) { collectName, _ := c.Get("collect_name") id := c.Query("id") points := make([]string, 0) filePoints := models.FindAiFilePoint(1, 100000, "collect_name = ? and file_id = ?", collectName, id) for _, item := range filePoints { points = append(points, item.PointsId) } list, err := lib.GetPointsByIds(collectName.(string), points) if err != nil { c.Writer.Write([]byte(err.Error())) return } c.Writer.Write(list) } // 删除知识 func GetDelPoints(c *gin.Context) { collectName, _ := c.Get("collect_name") id := c.Query("id") i, err := strconv.Atoi(id) var points interface{} if err != nil { points = []string{id} } else { points = []int{i} } list, err := lib.DeletePoints(collectName.(string), points) if err != nil { c.Writer.Write([]byte(err.Error())) return } c.Writer.Write([]byte(list)) }