32 lines
849 B
Go
32 lines
849 B
Go
package l_ai_category
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"gitea.cdlsxd.cn/self-tools/l_ai_category/doubao"
|
||
"strconv"
|
||
)
|
||
|
||
func GetCategory(ctx context.Context, goodsName, key, model string, cateJson string) (categoryId int, err error) {
|
||
|
||
modelObj := doubao.NewDouBao(model, key)
|
||
text := []string{
|
||
"根据商品名称,从json中找到该商品对应的第三级分类[QUESTION]" + goodsName + "[/QUESTION]",
|
||
"-只需要返回类型的名称对应的id,不用返回其他任何文字",
|
||
"-如果无法匹配,则返回数字0",
|
||
"-以下是 JSON 数据:" + cateJson,
|
||
}
|
||
category, err := modelObj.GetData(ctx, key, func(input string) (string, error) {
|
||
return input, nil
|
||
}, text...)
|
||
if err != nil {
|
||
return
|
||
}
|
||
categoryId, err = strconv.Atoi(category)
|
||
if err != nil {
|
||
err = fmt.Errorf("未找到商品分类")
|
||
categoryId = 0
|
||
}
|
||
return
|
||
}
|