Skip to content

Commit 1882483

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(pagination): avoid fetching when has_more: false (#2098)
1 parent 4e5b368 commit 1882483

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 69
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml

src/openai/pagination.py

+18
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def next_page_info(self) -> None:
6161

6262
class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
6363
data: List[_T]
64+
has_more: Optional[bool] = None
6465

6566
@override
6667
def _get_page_items(self) -> List[_T]:
@@ -69,6 +70,14 @@ def _get_page_items(self) -> List[_T]:
6970
return []
7071
return data
7172

73+
@override
74+
def has_next_page(self) -> bool:
75+
has_more = self.has_more
76+
if has_more is not None and has_more is False:
77+
return False
78+
79+
return super().has_next_page()
80+
7281
@override
7382
def next_page_info(self) -> Optional[PageInfo]:
7483
data = self.data
@@ -85,6 +94,7 @@ def next_page_info(self) -> Optional[PageInfo]:
8594

8695
class AsyncCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
8796
data: List[_T]
97+
has_more: Optional[bool] = None
8898

8999
@override
90100
def _get_page_items(self) -> List[_T]:
@@ -93,6 +103,14 @@ def _get_page_items(self) -> List[_T]:
93103
return []
94104
return data
95105

106+
@override
107+
def has_next_page(self) -> bool:
108+
has_more = self.has_more
109+
if has_more is not None and has_more is False:
110+
return False
111+
112+
return super().has_next_page()
113+
96114
@override
97115
def next_page_info(self) -> Optional[PageInfo]:
98116
data = self.data

0 commit comments

Comments
 (0)