pull models

This commit is contained in:
Bruce MacDonald 2023-07-06 12:24:49 -04:00 committed by Jeffrey Morgan
parent 0833f5af3a
commit a6494f8211
5 changed files with 202 additions and 9 deletions

View file

@ -35,7 +35,7 @@ func checkError(resp *http.Response, body []byte) error {
return apiError
}
func (c *Client) stream(ctx context.Context, method string, path string, reqData any, callback func (data []byte)) error {
func (c *Client) stream(ctx context.Context, method string, path string, reqData any, callback func(data []byte)) error {
var reqBody io.Reader
var data []byte
var err error
@ -140,3 +140,14 @@ func (c *Client) Generate(ctx context.Context, req *GenerateRequest, callback fu
return &res, nil
}
func (c *Client) Pull(ctx context.Context, req *PullRequest, callback func(token string)) (*PullResponse, error) {
var res PullResponse
if err := c.stream(ctx, http.MethodPost, "/api/pull", req, func(token []byte) {
callback(string(token))
}); err != nil {
return nil, err
}
return &res, nil
}