51 lines
876 B
Go
51 lines
876 B
Go
package l_bert
|
||
|
||
import (
|
||
"encoding/json"
|
||
|
||
"fmt"
|
||
"gitea.cdlsxd.cn/self-tools/l_request"
|
||
)
|
||
|
||
type Bert struct {
|
||
host string
|
||
auth string
|
||
}
|
||
|
||
func NewClient(args ...Option) *Bert {
|
||
s := &Bert{
|
||
host: "https://117.175.169.61:5003",
|
||
}
|
||
for _, opt := range args {
|
||
opt(s)
|
||
}
|
||
return s
|
||
}
|
||
|
||
func (s *Bert) BatchCreate(in *Predict) (*PredictRes, error) {
|
||
path := "/predict"
|
||
|
||
requestJson, err := StructToMap(in)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
req := l_request.Request{
|
||
Method: "POST",
|
||
Url: s.host + path,
|
||
Json: requestJson,
|
||
}
|
||
resp, err := req.Send()
|
||
|
||
if err != nil {
|
||
return nil, fmt.Errorf("请求失败,err: %v", err)
|
||
}
|
||
var resData PredictRes
|
||
if err = json.Unmarshal(resp.Content, &resData); err != nil {
|
||
return nil, fmt.Errorf("解析响应失败,err: %v", err)
|
||
}
|
||
if resData.Status != "success" {
|
||
return nil, err
|
||
}
|
||
return &resData, nil
|
||
}
|