Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dataset url property #140

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def upload_csv(
file_name = csv_file if isinstance(csv_file, str) else csv_file[0]
file_name = file_name.split("/")[-1]
raise ValueError(f"Dataset {file_name} already exists")
return Dataset(**result)
return Dataset(**result, _host_url=self._host_url)

def create_run(
self,
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def create_dataset(
data=dataset.json(),
)
raise_for_status_with_text(response)
return Dataset(**response.json())
return Dataset(**response.json(), _host_url=self._host_url)

@xor_args(("dataset_name", "dataset_id"))
def read_dataset(
Expand Down Expand Up @@ -1039,8 +1039,8 @@ def read_dataset(
if isinstance(result, list):
if len(result) == 0:
raise LangSmithError(f"Dataset {dataset_name} not found")
return Dataset(**result[0])
return Dataset(**result)
return Dataset(**result[0], _host_url=self._host_url)
return Dataset(**result, _host_url=self._host_url)

def list_datasets(
self,
Expand Down Expand Up @@ -1068,7 +1068,7 @@ def list_datasets(
params["name_contains"] = dataset_name_contains

yield from (
Dataset(**dataset)
Dataset(**dataset, _host_url=self._host_url)
for dataset in self._get_paginated_list("/datasets", params=params)
)

Expand Down
13 changes: 13 additions & 0 deletions python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ class Dataset(DatasetBase):
id: UUID
created_at: datetime
modified_at: Optional[datetime] = Field(default=None)
_host_url: Optional[str] = PrivateAttr(default=None)

def __init__(self, _host_url: Optional[str] = None, **kwargs: Any) -> None:
"""Initialize a Run object."""
super().__init__(**kwargs)
self._host_url = _host_url

@property
def url(self) -> Optional[str]:
"""URL of this run within the app."""
if self._host_url:
return f"{self._host_url}/datasets/{self.id}"
return None


class RunTypeEnum(str, Enum):
Expand Down
3 changes: 2 additions & 1 deletion python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def test_list_datasets(langchain_client: Client) -> None:
dataset2 = langchain_client.create_dataset(
"___TEST dataset2", data_type=DataType.kv
)

assert dataset1.url is not None
assert dataset2.url is not None
datasets = list(
langchain_client.list_datasets(dataset_ids=[dataset1.id, dataset2.id])
)
Expand Down
Loading