Skip to content

Commit

Permalink
Added delete endpoint (sashabaranov#8)
Browse files Browse the repository at this point in the history
* Added a files endpoint, corrected a documents bug in answers requests, added error messages to API error handling

* Added file upload endpoint

* Added DeleteFile endpoint

Co-authored-by: eyelevelai <[email protected]>
  • Loading branch information
blfletcher and eyelevelai authored Aug 5, 2021
1 parent 3dfb5bd commit 7c56bd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ func (c *Client) sendRequest(req *http.Request, v interface{}) error {
return fmt.Errorf("error, status code: %d, message: %s", res.StatusCode, errRes.Error.Message)
}

if err = json.NewDecoder(res.Body).Decode(&v); err != nil {
return err
if v != nil {
if err = json.NewDecoder(res.Body).Decode(&v); err != nil {
return err
}
}

return nil
Expand Down
12 changes: 12 additions & 0 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File
return
}

// DeleteFile deletes an existing file
func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) {
req, err := http.NewRequest("DELETE", c.fullURL("/files/"+fileID), nil)
if err != nil {
return
}

req = req.WithContext(ctx)
err = c.sendRequest(req, nil)
return
}

// ListFiles Lists the currently available files,
// and provides basic information about each file such as the file name and purpose.
func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) {
Expand Down

0 comments on commit 7c56bd3

Please sign in to comment.