Skip to content

Commit

Permalink
chore: add pagination type
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Nov 9, 2023
1 parent 413fea3 commit e5a29cd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) {
return client.ModifyRun(ctx, "", "", RunModifyRequest{})
}},
{"ListRuns", func() (any, error) {
return client.ListRuns(ctx, "", nil, nil, nil, nil)
return client.ListRuns(ctx, "", Pagination{})
}},
{"SubmitToolOutputs", func() (any, error) {
return client.SubmitToolOutputs(ctx, "", "", SubmitToolOutputsRequest{})
Expand All @@ -338,7 +338,7 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) {
return client.RetrieveRunStep(ctx, "", "", "")
}},
{"ListRunSteps", func() (any, error) {
return client.ListRunSteps(ctx, "", "", nil, nil, nil, nil)
return client.ListRunSteps(ctx, "", "", Pagination{})
}},
}

Expand Down
49 changes: 25 additions & 24 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ type RunStepList struct {
httpHeader
}

type Pagination struct {
Limit *int
Order *string
After *string
Before *string
}

// CreateRun creates a new run.
func (c *Client) CreateRun(
ctx context.Context,
Expand Down Expand Up @@ -230,23 +237,20 @@ func (c *Client) ModifyRun(
func (c *Client) ListRuns(
ctx context.Context,
threadID string,
limit *int,
order *string,
after *string,
before *string,
pagination Pagination,
) (response RunList, err error) {
urlValues := url.Values{}
if limit != nil {
urlValues.Add("limit", fmt.Sprintf("%d", *limit))
if pagination.Limit != nil {
urlValues.Add("limit", fmt.Sprintf("%d", *pagination.Limit))
}
if order != nil {
urlValues.Add("order", *order)
if pagination.Order != nil {
urlValues.Add("order", *pagination.Order)
}
if after != nil {
urlValues.Add("after", *after)
if pagination.After != nil {
urlValues.Add("after", *pagination.After)
}
if before != nil {
urlValues.Add("before", *before)
if pagination.Before != nil {
urlValues.Add("before", *pagination.Before)
}

encodedValues := ""
Expand Down Expand Up @@ -358,23 +362,20 @@ func (c *Client) ListRunSteps(
ctx context.Context,
threadID string,
runID string,
limit *int,
order *string,
after *string,
before *string,
pagination Pagination,
) (response RunStepList, err error) {
urlValues := url.Values{}
if limit != nil {
urlValues.Add("limit", fmt.Sprintf("%d", *limit))
if pagination.Limit != nil {
urlValues.Add("limit", fmt.Sprintf("%d", *pagination.Limit))
}
if order != nil {
urlValues.Add("order", *order)
if pagination.Order != nil {
urlValues.Add("order", *pagination.Order)
}
if after != nil {
urlValues.Add("after", *after)
if pagination.After != nil {
urlValues.Add("after", *pagination.After)
}
if before != nil {
urlValues.Add("before", *before)
if pagination.Before != nil {
urlValues.Add("before", *pagination.Before)
}

encodedValues := ""
Expand Down
23 changes: 21 additions & 2 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,16 @@ func TestRun(t *testing.T) {
})
checks.NoError(t, err, "ModifyRun error")

_, err = client.ListRuns(ctx, threadID, &limit, &order, &after, &before)
_, err = client.ListRuns(
ctx,
threadID,
openai.Pagination{
Limit: &limit,
Order: &order,
After: &after,
Before: &before,
},
)
checks.NoError(t, err, "ListRuns error")

_, err = client.SubmitToolOutputs(ctx, threadID, runID,
Expand Down Expand Up @@ -213,6 +222,16 @@ func TestRun(t *testing.T) {
_, err = client.RetrieveRunStep(ctx, threadID, runID, stepID)
checks.NoError(t, err, "RetrieveRunStep error")

_, err = client.ListRunSteps(ctx, threadID, runID, &limit, &order, &after, &before)
_, err = client.ListRunSteps(
ctx,
threadID,
runID,
openai.Pagination{
Limit: &limit,
Order: &order,
After: &after,
Before: &before,
},
)
checks.NoError(t, err, "ListRunSteps error")
}

0 comments on commit e5a29cd

Please sign in to comment.