diff --git a/ai.go b/ai.go index 1b6646b..9e80e6c 100644 --- a/ai.go +++ b/ai.go @@ -42,8 +42,17 @@ func getCategoryWithAi(ctx context.Context, goodsName string, address string) (c return } cateInfo := strings.Split(resMap.Predictions[0].Category, "_") - cateId, _ = strconv.Atoi(cateInfo[1]) - return cateId, cateInfo[0], resMap.Predictions[0].Confidence, nil + if len(cateInfo) != 2 { + cateName = "" + cateId = 0.000000 + } else { + cateName = cateInfo[0] + cateId, err = strconv.Atoi(cateInfo[1]) + if err != nil { + } + } + + return cateId, cateName, resMap.Predictions[0].Confidence, nil } type Category struct { diff --git a/ai_test.go b/ai_test.go index 9605056..c5e38da 100644 --- a/ai_test.go +++ b/ai_test.go @@ -86,7 +86,7 @@ func goodsAll() (data []Goods) { row Goods err error ) - rows, _ := db.Raw("SELECT id,title FROM `goods` order by id desc limit 1000 offset 3156").Rows() //where brand_category_check=4 + rows, _ := db.Raw("SELECT id,title FROM `goods` order by id ").Rows() //where brand_category_check=4 defer rows.Close() for rows.Next() { err = db.ScanRows(rows, &row) diff --git a/go.mod b/go.mod index d77ec3e..748d323 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,14 @@ go 1.22.10 toolchain go1.23.7 require ( + gitea.cdlsxd.cn/self-tools/l_ai_category v1.9.0 + gitea.cdlsxd.cn/self-tools/l_request v1.0.8 github.com/volcengine/volcengine-go-sdk v1.0.187 gorm.io/driver/mysql v1.5.7 gorm.io/gorm v1.25.12 ) require ( - gitea.cdlsxd.cn/self-tools/l_request v1.0.8 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect