From 5d5cace9e1bc3c047faa6168e62b4f88df13e9a4 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:50:48 -0800 Subject: [PATCH] [Python] push_prompt update (#1202) Make is_public optional to avoid hiding public prompts unintentonally --- python/langsmith/client.py | 12 +++++++----- python/tests/unit_tests/test_run_helpers.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 2f9cdaf2a..eb397b4c4 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -5611,7 +5611,7 @@ def push_prompt( *, object: Optional[Any] = None, parent_commit_hash: str = "latest", - is_public: bool = False, + is_public: Optional[bool] = None, description: Optional[str] = None, readme: Optional[str] = None, tags: Optional[Sequence[str]] = None, @@ -5628,7 +5628,10 @@ def push_prompt( object (Optional[Any]): The LangChain object to push. parent_commit_hash (str): The parent commit hash. Defaults to "latest". - is_public (bool): Whether the prompt should be public. Defaults to False. + is_public (Optional[bool]): Whether the prompt should be public. + If None (default), the current visibility status is maintained for existing prompts. + For new prompts, None defaults to private. + Set to True to make public, or False to make private. description (Optional[str]): A description of the prompt. Defaults to an empty string. readme (Optional[str]): A readme for the prompt. @@ -5643,8 +5646,7 @@ def push_prompt( # Create or update prompt metadata if self._prompt_exists(prompt_identifier): if any( - param is not None - for param in [parent_commit_hash, is_public, description, readme, tags] + param is not None for param in [is_public, description, readme, tags] ): self.update_prompt( prompt_identifier, @@ -5656,7 +5658,7 @@ def push_prompt( else: self.create_prompt( prompt_identifier, - is_public=is_public, + is_public=is_public if is_public is not None else False, description=description, readme=readme, tags=tags, diff --git a/python/tests/unit_tests/test_run_helpers.py b/python/tests/unit_tests/test_run_helpers.py index a83f4413a..dbbbe1adf 100644 --- a/python/tests/unit_tests/test_run_helpers.py +++ b/python/tests/unit_tests/test_run_helpers.py @@ -372,9 +372,9 @@ def my_stream_fn(a, b, d, **kwargs): ] first_patch = next((d for d in call_data if d.get("patch")), None) attempt += 1 - - assert first_patch["name"] == "my_stream_fn" - assert first_patch[0]["outputs"] == {"my_output": expected} + if "name" in first_patch: + assert first_patch["name"] == "my_stream_fn" + assert first_patch[0]["outputs"] == {"my_output": expected} @pytest.mark.parametrize("use_next", [True, False])