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

Set start_time earlier #1035

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions python/langsmith/run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions python/tests/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
],
)
Expand Down
Loading