chat api endpoint (#1392)

This commit is contained in:
Bruce MacDonald 2023-12-05 14:57:33 -05:00 committed by GitHub
parent 00d06619a1
commit 195e3d9dbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 550 additions and 132 deletions

View file

@ -221,6 +221,19 @@ func (c *Client) Generate(ctx context.Context, req *GenerateRequest, fn Generate
})
}
type ChatResponseFunc func(ChatResponse) error
func (c *Client) Chat(ctx context.Context, req *ChatRequest, fn ChatResponseFunc) error {
return c.stream(ctx, http.MethodPost, "/api/chat", req, func(bts []byte) error {
var resp ChatResponse
if err := json.Unmarshal(bts, &resp); err != nil {
return err
}
return fn(resp)
})
}
type PullProgressFunc func(ProgressResponse) error
func (c *Client) Pull(ctx context.Context, req *PullRequest, fn PullProgressFunc) error {