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

Missing has_more in pagination struct and wasted API calls during pagination #184

Open
qhenkart opened this issue Jan 25, 2025 · 0 comments

Comments

@qhenkart
Copy link

qhenkart commented Jan 25, 2025

Regarding https://github.com/openai/openai-go/blob/main/packages/pagination/pagination.go#L111

The API reference lists the pagination for every request with specific fields.

{
  "object": "list",
  "data": [],
  "first_id": "msg_abc123",
  "last_id": "msg_abc456",
  "has_more": false
}

While I love the abstraction in the pagination package and the ease of "GetNextPage()". Being able to check "has_ more" was a very simple way to manage whether I need to call the GetNextPage() or not.

Additionally, looking at the inner workings of GetNextPage, it itself utilizes a wasted API call to determine when the pagination itself has ended instead of checking the has_ more field to determine if the API call should be run. Ideally if I trust GetNextPage, I want to avoid unnecessary API calls so it would be great if that pagination abstraction could utilize the has_more field provided by the API.

Additionally it would be great if has_more was exposed in the struct as either a public field or a method accessible private field. Calling the raw json method and re-marshalling it into a complete struct isn't really a great option

EDIT:
I realize the documentation covers missing SDK fields which was good foresight
hasMore, err :=strconv.ParseBool(res.JSON.ExtraFields["my_unexpected_field"].Raw())

It would be nice if ExtraFields had a ToBool helper

The issue still stands with the way GetNextPage does_not leverage this field and that it is important enough to be included in the actual struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant