l_bert/bert.go

51 lines
876 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}