From cae0a2f0f975bf7091a7c33fba4ff109bf9a16a5 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:41:21 -0700 Subject: [PATCH] List limit (#1043) Closes #1042 --- python/langsmith/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 0bc09a4b8..6df0f9004 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -5328,7 +5328,7 @@ def list_prompt_commits( owner, prompt_name, _ = ls_utils.parse_prompt_identifier(prompt_identifier) params = { - "limit": limit if limit is not None else 100, + "limit": min(100, limit) if limit is not None else limit, "offset": offset, "include_model": include_model, } @@ -5347,12 +5347,12 @@ def list_prompt_commits( if not items: break for it in items: - i += 1 + if limit is not None and i >= limit: + return # Stop iteration if we've reached the limit yield ls_schemas.ListedPromptCommit( **{"owner": owner, "repo": prompt_name, **it} ) - if limit is not None and i >= limit: - break + i += 1 offset += len(items) if offset >= total: