Skip to content

Commit

Permalink
fixup int tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Jan 28, 2024
1 parent 70ce886 commit 8732a81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,9 @@ def _run_transform(
run_create = run.dict() # type: ignore
else:
run_create = cast(dict, run)
if isinstance(run["id"], str):
if "id" not in run_create:
run_create["id"] = uuid.uuid4()
elif isinstance(run["id"], str):
run["id"] = uuid.UUID(run["id"])
if "inputs" in run_create:
run_create["inputs"] = _hide_inputs(run_create["inputs"])
Expand Down
38 changes: 19 additions & 19 deletions python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def test_persist_update_run(
if project_name in [sess.name for sess in langchain_client.list_projects()]:
langchain_client.delete_project(project_name=project_name)
start_time = datetime.now()
revision_id = uuid4()
run: dict = dict(
id=uuid4(),
name="test_run",
Expand All @@ -149,22 +150,27 @@ def test_persist_update_run(
execution_order=1,
start_time=start_time,
extra={"extra": "extra"},
revision_id=revision_id,
)
langchain_client.create_run(**run)
run["outputs"] = {"output": ["Hi"]}
run["extra"]["foo"] = "bar"
langchain_client.update_run(run["id"], **run)
for _ in range(5):
try:
stored_run = langchain_client.read_run(run["id"])
break
except LangSmithError:
time.sleep(2)

assert stored_run.id == run["id"]
assert stored_run.outputs == run["outputs"]
assert stored_run.start_time == run["start_time"]
langchain_client.delete_project(project_name=project_name)
try:
for _ in range(10):
try:
stored_run = langchain_client.read_run(run["id"])
if stored_run.end_time is not None:
break
except LangSmithError:
time.sleep(2)

assert stored_run.id == run["id"]
assert stored_run.outputs == run["outputs"]
assert stored_run.start_time == run["start_time"]
assert stored_run.extra["metadata"]["revision_id"] == str(revision_id)
finally:
langchain_client.delete_project(project_name=project_name)


@freeze_time("2023-01-01")
Expand Down Expand Up @@ -313,8 +319,8 @@ def test_list_datasets(langchain_client: Client) -> None:
assert dataset2.data_type == DataType.kv
# Sub-filter on data type
datasets = list(langchain_client.list_datasets(data_type=DataType.llm.value))
assert len(datasets) == 1
assert datasets[0].id == dataset1.id
assert len(datasets) > 0
assert dataset1.id in {dataset.id for dataset in datasets}
# Sub-filter on name
datasets = list(
langchain_client.list_datasets(
Expand All @@ -325,12 +331,6 @@ def test_list_datasets(langchain_client: Client) -> None:
# Delete datasets
langchain_client.delete_dataset(dataset_id=dataset1.id)
langchain_client.delete_dataset(dataset_id=dataset2.id)
assert (
len(
list(langchain_client.list_datasets(dataset_ids=[dataset1.id, dataset2.id]))
)
== 0
)


@freeze_time("2023-01-01")
Expand Down

0 comments on commit 8732a81

Please sign in to comment.