Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6ef77f

Browse files
committed
[fine_tuning] fix pagination for auto-generated list_events (#188)
1 parent 9d559b0 commit b6ef77f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

openai/api_resources/abstract/nested_resource_class_methods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ def list_nested_resources(cls, id, **params):
127127
elif operation == "paginated_list":
128128

129129
def paginated_list_nested_resources(
130-
cls, id, limit=None, cursor=None, **params
130+
cls, id, limit=None, after=None, **params
131131
):
132132
url = getattr(cls, resource_url_method)(id)
133133
return getattr(cls, resource_request_method)(
134-
"get", url, limit=limit, cursor=cursor, **params
134+
"get", url, limit=limit, after=after, **params
135135
)
136136

137137
list_method = "list_%s" % resource_plural

openai/cli.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,17 @@ def results(cls, args):
779779

780780
@classmethod
781781
def events(cls, args):
782-
seen, has_more = 0, True
782+
seen, has_more, after = 0, True, None
783783
while has_more:
784-
resp = openai.FineTuningJob.list_events(id=args.id) # type: ignore
784+
resp = openai.FineTuningJob.list_events(id=args.id, after=after) # type: ignore
785785
for event in resp["data"]:
786786
print(event)
787787
seen += 1
788788
if args.limit is not None and seen >= args.limit:
789789
return
790-
has_more = resp["has_more"]
790+
has_more = resp.get("has_more", False)
791+
if resp["data"]:
792+
after = resp["data"][-1]["id"]
791793

792794
@classmethod
793795
def follow(cls, args):

0 commit comments

Comments
 (0)