Skip to content

Commit

Permalink
[fine_tuning] fix pagination for auto-generated list_events (#188) (#597
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jhallard authored Aug 31, 2023
1 parent 9d559b0 commit 1be14ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def list_nested_resources(cls, id, **params):
elif operation == "paginated_list":

def paginated_list_nested_resources(
cls, id, limit=None, cursor=None, **params
cls, id, limit=None, after=None, **params
):
url = getattr(cls, resource_url_method)(id)
return getattr(cls, resource_request_method)(
"get", url, limit=limit, cursor=cursor, **params
"get", url, limit=limit, after=after, **params
)

list_method = "list_%s" % resource_plural
Expand Down
8 changes: 5 additions & 3 deletions openai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,17 @@ def results(cls, args):

@classmethod
def events(cls, args):
seen, has_more = 0, True
seen, has_more, after = 0, True, None
while has_more:
resp = openai.FineTuningJob.list_events(id=args.id) # type: ignore
resp = openai.FineTuningJob.list_events(id=args.id, after=after) # type: ignore
for event in resp["data"]:
print(event)
seen += 1
if args.limit is not None and seen >= args.limit:
return
has_more = resp["has_more"]
has_more = resp.get("has_more", False)
if resp["data"]:
after = resp["data"][-1]["id"]

@classmethod
def follow(cls, args):
Expand Down

0 comments on commit 1be14ee

Please sign in to comment.