mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Add Run Collector Callback (#6133)
Add a callback handler that can collect nested run objects. Useful for evaluation.
This commit is contained in:
parent
6ac120f299
commit
4555ad5d1f
20
langchain/callbacks/tracers/run_collector.py
Normal file
20
langchain/callbacks/tracers/run_collector.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""A tracer that collects all nested runs in a list."""
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
from langchain.callbacks.tracers.base import BaseTracer
|
||||||
|
from langchain.callbacks.tracers.schemas import Run
|
||||||
|
|
||||||
|
|
||||||
|
class RunStackCallbackHandler(BaseTracer):
|
||||||
|
"""A tracer that collects all nested runs in a list.
|
||||||
|
|
||||||
|
Useful for inspection and for evaluation."""
|
||||||
|
|
||||||
|
name = "run-collector_callback_handler"
|
||||||
|
|
||||||
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.traced_runs: List[Run] = []
|
||||||
|
|
||||||
|
def _persist_run(self, run: Run) -> None:
|
||||||
|
self.traced_runs.append(run)
|
Loading…
Reference in New Issue
Block a user