Skip to content

Commit

Permalink
python[patch]: Return cloned dataset (#930)
Browse files Browse the repository at this point in the history
Co-authored-by: William FH <13333726+hinthornw@users.noreply.github.com>
  • Loading branch information
baskaryan and hinthornw authored Aug 22, 2024
1 parent 8322a80 commit 5f1b4ef
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
15 changes: 12 additions & 3 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,7 @@ def clone_public_dataset(
*,
source_api_url: Optional[str] = None,
dataset_name: Optional[str] = None,
) -> None:
) -> ls_schemas.Dataset:
"""Clone a public dataset to your own langsmith tenant.
This operation is idempotent. If you already have a dataset with the given name,
Expand All @@ -2957,6 +2957,10 @@ def clone_public_dataset(
dataset_name (str): The name of the dataset to create in your tenant.
Defaults to the name of the public dataset.
Returns:
-------
Dataset
The created dataset.
"""
source_api_url = source_api_url or self.api_url
source_api_url, token_uuid = _parse_token_or_url(token_or_url, source_api_url)
Expand All @@ -2969,11 +2973,15 @@ def clone_public_dataset(
)
ds = source_client.read_shared_dataset(token_uuid)
dataset_name = dataset_name or ds.name
if self.has_dataset(dataset_name=dataset_name):
try:
ds = self.read_dataset(dataset_name=dataset_name)
logger.info(
f"Dataset {dataset_name} already exists in your tenant. Skipping."
)
return
return ds
except ls_utils.LangSmithNotFoundError:
pass

try:
# Fetch examples first
examples = list(source_client.list_shared_examples(token_uuid))
Expand Down Expand Up @@ -3001,6 +3009,7 @@ def clone_public_dataset(
raise e
finally:
del source_client
return dataset

def _get_data_type(self, dataset_id: ID_TYPE) -> ls_schemas.DataType:
dataset = self.read_dataset(dataset_id=dataset_id)
Expand Down
2 changes: 1 addition & 1 deletion python/langsmith/evaluation/_arunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def aevaluate(
>>> from langsmith.evaluation import evaluate
>>> from langsmith.schemas import Example, Run
>>> client = Client()
>>> client.clone_public_dataset(
>>> dataset = client.clone_public_dataset(
... "https://smith.langchain.com/public/419dcab2-1d66-4b94-8901-0357ead390df/d"
... )
>>> dataset_name = "Evaluate Examples"
Expand Down
4 changes: 2 additions & 2 deletions python/langsmith/evaluation/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def evaluate(
>>> from langsmith.evaluation import evaluate
>>> from langsmith.schemas import Example, Run
>>> client = Client()
>>> client.clone_public_dataset(
>>> dataset = client.clone_public_dataset(
... "https://smith.langchain.com/public/419dcab2-1d66-4b94-8901-0357ead390df/d"
... )
>>> dataset_name = "Evaluate Examples"
Expand Down Expand Up @@ -480,7 +480,7 @@ def evaluate_comparative(
>>> from langsmith.evaluation import evaluate
>>> from langsmith.schemas import Example, Run
>>> client = Client()
>>> client.clone_public_dataset(
>>> dataset = client.clone_public_dataset(
... "https://smith.langchain.com/public/419dcab2-1d66-4b94-8901-0357ead390df/d"
... )
>>> dataset_name = "Evaluate Examples"
Expand Down
4 changes: 2 additions & 2 deletions python/tests/evaluation/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def test_evaluate():
client = Client()
client.clone_public_dataset(
_ = client.clone_public_dataset(
"https://smith.langchain.com/public/419dcab2-1d66-4b94-8901-0357ead390df/d"
)
dataset_name = "Evaluate Examples"
Expand Down Expand Up @@ -49,7 +49,7 @@ def predict(inputs: dict) -> dict:

async def test_aevaluate():
client = Client()
client.clone_public_dataset(
_ = client.clone_public_dataset(
"https://smith.langchain.com/public/419dcab2-1d66-4b94-8901-0357ead390df/d"
)
dataset_name = "Evaluate Examples"
Expand Down

0 comments on commit 5f1b4ef

Please sign in to comment.