30 lines
767 B
Go
30 lines
767 B
Go
package l_ai_category
|
||
|
||
import (
|
||
"context"
|
||
"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 {
|
||
categoryId = 0
|
||
}
|
||
return
|
||
}
|