From aa68fd7e91fc220c36dbe295d6f6ab688053738c Mon Sep 17 00:00:00 2001 From: aditya thomas Date: Tue, 26 Mar 2024 01:54:58 +0530 Subject: [PATCH] core[runnables]: docstring for class runnable, method with_listeners() (#19515) **Description:** Docstring for method with_listerners() of class Runnable **Issue:** [Add in code documentation to core Runnable methods #18804](https://github.com/langchain-ai/langchain/issues/18804) **Dependencies:** None --- libs/core/langchain_core/runnables/base.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py index 817bb29720a4c..382d0d7efa9db 100644 --- a/libs/core/langchain_core/runnables/base.py +++ b/libs/core/langchain_core/runnables/base.py @@ -1374,6 +1374,26 @@ def with_listeners( The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run. + + Example: + + .. code-block:: python + from langchain_core.runnables import RunnableLambda + import time + + def test_runnable(time_to_sleep : int): + time.sleep(time_to_sleep) + + def fn_start(run_obj : Runnable): + print("start_time:", run_obj.start_time) + + def fn_end(run_obj : Runnable): + print("end_time:", run_obj.end_time) + + RunnableLambda(test_runnable).with_listeners( + on_start=fn_start, + on_end=fn_end + ).invoke(2) """ from langchain_core.tracers.root_listeners import RootListenersTracer