mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 20:28:10 +00:00
Dereference run tree (#30377)
This commit is contained in:
parent
8265be4d3e
commit
ce84f8ba7e
@ -173,7 +173,13 @@ class LangChainTracer(BaseTracer):
|
||||
return chat_model_run
|
||||
|
||||
def _persist_run(self, run: Run) -> None:
|
||||
self.latest_run = run
|
||||
# We want to free up more memory by avoiding keeping a reference to the
|
||||
# whole nested run tree.
|
||||
self.latest_run = Run.construct(
|
||||
**run.dict(exclude={"child_runs", "inputs", "outputs"}),
|
||||
inputs=run.inputs,
|
||||
outputs=run.outputs,
|
||||
)
|
||||
|
||||
def get_run_url(self) -> str:
|
||||
"""Get the LangSmith root run URL.
|
||||
|
@ -445,12 +445,13 @@ def test_tree_is_constructed(parent_type: Literal["ls", "lc"]) -> None:
|
||||
metadata={"some_foo": "some_bar"},
|
||||
tags=["afoo"],
|
||||
):
|
||||
if parent_type == "ls":
|
||||
collected: dict[str, RunTree] = {} # noqa
|
||||
|
||||
def collect_run(run: RunTree) -> None:
|
||||
collected[str(run.id)] = run
|
||||
|
||||
if parent_type == "ls":
|
||||
|
||||
@traceable
|
||||
def parent() -> str:
|
||||
return child.invoke("foo")
|
||||
@ -459,7 +460,6 @@ def test_tree_is_constructed(parent_type: Literal["ls", "lc"]) -> None:
|
||||
parent(langsmith_extra={"on_end": collect_run, "run_id": rid}) == "foo"
|
||||
)
|
||||
assert collected
|
||||
run = collected.get(str(rid))
|
||||
|
||||
else:
|
||||
|
||||
@ -468,8 +468,10 @@ def test_tree_is_constructed(parent_type: Literal["ls", "lc"]) -> None:
|
||||
return child.invoke("foo")
|
||||
|
||||
tracer = LangChainTracer()
|
||||
tracer._persist_run = collect_run # type: ignore
|
||||
|
||||
assert parent.invoke(..., {"run_id": rid, "callbacks": [tracer]}) == "foo" # type: ignore
|
||||
run = tracer.latest_run
|
||||
run = collected.get(str(rid))
|
||||
|
||||
assert run is not None
|
||||
assert run.name == "parent"
|
||||
|
Loading…
Reference in New Issue
Block a user