Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support batches api #746

Merged
merged 20 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests coverage
  • Loading branch information
eiixy committed May 20, 2024
commit e7040a0f515cd31f0b375ce91757f8bce2a7cff9
4 changes: 4 additions & 0 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -148,6 +149,8 @@ type BatchResponse struct {
Batch
}

var ErrUploadBatchFile = errors.New("upload batch file")

// CreateBatch — API call to Create batch.
func (c *Client) CreateBatch(
ctx context.Context,
Expand All @@ -166,6 +169,7 @@ func (c *Client) CreateBatch(
Purpose: PurposeBatch,
})
if err != nil {
err = errors.Join(ErrUploadBatchFile, err)
return
}

Expand Down
9 changes: 9 additions & 0 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@
},
},
})
ctx := context.Background()
_, err := client.CreateBatch(context.Background(), req)
checks.NoError(t, err, "CreateBatch error")

server.RegisterHandler("/v1/files", func(w http.ResponseWriter, r *http.Request) {

Check warning on line 36 in batch_test.go

View workflow job for this annotation

GitHub Actions / Sanity check

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
w.WriteHeader(http.StatusGatewayTimeout)
})
_, err = client.CreateBatch(ctx, req)
msg := fmt.Sprintf("CreateBatch should return ErrUploadBatchFile, returned: %s", err)
fmt.Println(msg)

Check failure on line 41 in batch_test.go

View workflow job for this annotation

GitHub Actions / Sanity check

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
checks.ErrorIs(t, err, openai.ErrUploadBatchFile, msg)
}

func TestRetrieveBatch(t *testing.T) {
Expand Down
Loading