From bd499ead3c871c8246b954a95a8ea559f73a87fb Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:17:15 -0700 Subject: [PATCH] mv timing --- python/langsmith/client.py | 7 +++++-- python/langsmith/run_trees.py | 2 ++ python/tests/unit_tests/test_client.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/python/langsmith/client.py b/python/langsmith/client.py index d15cfa46f..dea06bde5 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -1153,10 +1153,15 @@ def _run_transform( run_create: dict = run.dict() # type: ignore else: run_create = cast(dict, run) + if not update and not run_create.get("start_time"): + # Should not hit here if you're using run_trees or other higher-order + # abstractions + run_create["start_time"] = datetime.datetime.now(datetime.timezone.utc) if "id" not in run_create: run_create["id"] = uuid.uuid4() elif isinstance(run_create["id"], str): run_create["id"] = uuid.UUID(run_create["id"]) + if "inputs" in run_create and run_create["inputs"] is not None: if copy: run_create["inputs"] = ls_utils.deepish_copy(run_create["inputs"]) @@ -1165,8 +1170,6 @@ def _run_transform( if copy: run_create["outputs"] = ls_utils.deepish_copy(run_create["outputs"]) run_create["outputs"] = self._hide_run_outputs(run_create["outputs"]) - if not update and not run_create.get("start_time"): - run_create["start_time"] = datetime.datetime.now(datetime.timezone.utc) # Only retain LLM & Prompt manifests if "serialized" in run_create: diff --git a/python/langsmith/run_trees.py b/python/langsmith/run_trees.py index f52dda1c1..0db1dcc78 100644 --- a/python/langsmith/run_trees.py +++ b/python/langsmith/run_trees.py @@ -81,6 +81,8 @@ class Config: @root_validator(pre=True) def infer_defaults(cls, values: dict) -> dict: """Assign name to the run.""" + if not values.get("start_time"): + values["start_time"] = datetime.now(timezone.utc) if values.get("name") is None and values.get("serialized") is not None: if "name" in values["serialized"]: values["name"] = values["serialized"]["name"] diff --git a/python/tests/unit_tests/test_client.py b/python/tests/unit_tests/test_client.py index 0e648ffc4..d95c9ced1 100644 --- a/python/tests/unit_tests/test_client.py +++ b/python/tests/unit_tests/test_client.py @@ -972,6 +972,7 @@ def test_batch_ingest_run_retry_on_429(mock_raise_for_status): "id": str(uuid.uuid4()), "trace_id": str(uuid.uuid4()), "dotted_order": str(uuid.uuid4()), + "start_time": datetime.now(tz=timezone.utc), } ], )