Skip to content

Commit

Permalink
feat(pagination): avoid fetching when has_more: false (#2098)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Feb 6, 2025
1 parent 4e5b368 commit 1882483
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 69
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml
18 changes: 18 additions & 0 deletions src/openai/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def next_page_info(self) -> None:

class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
data: List[_T]
has_more: Optional[bool] = None

@override
def _get_page_items(self) -> List[_T]:
Expand All @@ -69,6 +70,14 @@ def _get_page_items(self) -> List[_T]:
return []
return data

@override
def has_next_page(self) -> bool:
has_more = self.has_more
if has_more is not None and has_more is False:
return False

return super().has_next_page()

@override
def next_page_info(self) -> Optional[PageInfo]:
data = self.data
Expand All @@ -85,6 +94,7 @@ def next_page_info(self) -> Optional[PageInfo]:

class AsyncCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
data: List[_T]
has_more: Optional[bool] = None

@override
def _get_page_items(self) -> List[_T]:
Expand All @@ -93,6 +103,14 @@ def _get_page_items(self) -> List[_T]:
return []
return data

@override
def has_next_page(self) -> bool:
has_more = self.has_more
if has_more is not None and has_more is False:
return False

return super().has_next_page()

@override
def next_page_info(self) -> Optional[PageInfo]:
data = self.data
Expand Down

0 comments on commit 1882483

Please sign in to comment.