Skip to content

Commit fe5b51e

Browse files
committed
cbox teach multi
1 parent f5ddcef commit fe5b51e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

classificationbox/classificationbox_teach.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,35 @@ func (c *Client) Teach(ctx context.Context, modelID string, example Example) err
4444
}
4545
return nil
4646
}
47+
48+
type examplesRequest struct {
49+
Examples []Example `json:"examples"`
50+
}
51+
52+
// TeachMulti gives an multiple Example to a model for it to learn from.
53+
func (c *Client) TeachMulti(ctx context.Context, modelID string, examples []Example) error {
54+
u, err := url.Parse(c.addr + "/" + path.Join("classificationbox", "models", modelID, "teach-multi"))
55+
if err != nil {
56+
return err
57+
}
58+
if !u.IsAbs() {
59+
return errors.New("box address must be absolute")
60+
}
61+
exreq := examplesRequest{Examples: examples}
62+
var buf bytes.Buffer
63+
if err := json.NewEncoder(&buf).Encode(exreq); err != nil {
64+
return errors.Wrap(err, "encoding request body")
65+
}
66+
req, err := http.NewRequest(http.MethodPost, u.String(), &buf)
67+
if err != nil {
68+
return err
69+
}
70+
req = req.WithContext(ctx)
71+
req.Header.Set("Accept", "application/json; charset=utf-8")
72+
req.Header.Set("Content-Type", "application/json; charset=utf-8")
73+
_, err = c.client.Do(req, nil)
74+
if err != nil {
75+
return err
76+
}
77+
return nil
78+
}

0 commit comments

Comments
 (0)