Skip to content

Commit

Permalink
feat: support name parameter to update_run (#927) (#931)
Browse files Browse the repository at this point in the history
This change makes it possible to update the name of a run after it has
been created. Previously, run names could not be modified once set.

Co-authored-by: Fred Jonsson <fridrik@pyth.net>
  • Loading branch information
hinthornw and enginoid authored Aug 20, 2024
1 parent bee2a0c commit 8a53cf2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ def update_run(
self,
run_id: ID_TYPE,
*,
name: Optional[str] = None,
end_time: Optional[datetime.datetime] = None,
error: Optional[str] = None,
inputs: Optional[Dict] = None,
Expand All @@ -1450,6 +1451,8 @@ def update_run(
----------
run_id : str or UUID
The ID of the run to update.
name : str or None, default=None
The name of the run.
end_time : datetime or None
The end time of the run.
error : str or None, default=None
Expand All @@ -1469,6 +1472,7 @@ def update_run(
"""
data: Dict[str, Any] = {
"id": _as_uuid(run_id, "run_id"),
"name": name,
"trace_id": kwargs.pop("trace_id", None),
"parent_run_id": kwargs.pop("parent_run_id", None),
"dotted_order": kwargs.pop("dotted_order", None),
Expand Down
1 change: 1 addition & 0 deletions python/langsmith/run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def patch(self) -> None:
if not self.end_time:
self.end()
self.client.update_run(
name=self.name,
run_id=self.id,
outputs=self.outputs.copy() if self.outputs else None,
error=self.error,
Expand Down
2 changes: 2 additions & 0 deletions python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,11 @@ def test_persist_update_run(langchain_client: Client) -> None:
langchain_client.create_run(**run)
run["outputs"] = {"output": ["Hi"]}
run["extra"]["foo"] = "bar"
run["name"] = "test_run_updated"
langchain_client.update_run(run["id"], **run)
wait_for(lambda: langchain_client.read_run(run["id"]).end_time is not None)
stored_run = langchain_client.read_run(run["id"])
assert stored_run.name == run["name"]
assert stored_run.id == run["id"]
assert stored_run.outputs == run["outputs"]
assert stored_run.start_time == run["start_time"]
Expand Down

0 comments on commit 8a53cf2

Please sign in to comment.