From 4863cf88b2ae7376b026a8bfdf57dfb00ff81082 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Fri, 31 May 2024 09:06:18 -0700 Subject: [PATCH] [Python] Handoff Bugs (#753) 1. from_runnable_config doesn't lbyl to see if the parent is in the order_map. Should fix 2. events are null by default here but are populated in langchain, meaning run trees cant be treated as interchangeable in the base tracer. --- python/langsmith/run_trees.py | 4 +++- python/pyproject.toml | 2 +- python/tests/unit_tests/test_run_trees.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/python/langsmith/run_trees.py b/python/langsmith/run_trees.py index cb767108e..7672c1f10 100644 --- a/python/langsmith/run_trees.py +++ b/python/langsmith/run_trees.py @@ -90,6 +90,8 @@ def infer_defaults(cls, values: dict) -> dict: else: values["trace_id"] = values["id"] cast(dict, values.setdefault("extra", {})) + if values.get("events") is None: + values["events"] = [] return values @root_validator(pre=False) @@ -335,7 +337,7 @@ def from_runnable_config( ) ) ): - if hasattr(tracer, "order_map"): + if hasattr(tracer, "order_map") and cb.parent_run_id in tracer.order_map: dotted_order = tracer.order_map[cb.parent_run_id][1] elif ( run := tracer.run_map.get(str(cb.parent_run_id)) diff --git a/python/pyproject.toml b/python/pyproject.toml index b92ba21df..ee9798d84 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langsmith" -version = "0.1.65" +version = "0.1.66" description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform." authors = ["LangChain "] license = "MIT" diff --git a/python/tests/unit_tests/test_run_trees.py b/python/tests/unit_tests/test_run_trees.py index 92c398b2d..73a963eeb 100644 --- a/python/tests/unit_tests/test_run_trees.py +++ b/python/tests/unit_tests/test_run_trees.py @@ -59,3 +59,15 @@ def test_run_tree_accepts_tpe() -> None: ) def test_parse_dotted_order(inputs, expected): assert run_trees._parse_dotted_order(inputs) == expected + + +def test_run_tree_events_not_null(): + mock_client = MagicMock(spec=Client) + run_tree = run_trees.RunTree( + name="My Chat Bot", + inputs={"text": "Summarize this morning's meetings."}, + client=mock_client, + executor=ThreadPoolExecutor(), + events=None, + ) + assert run_tree.events == []