Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[runnables]: docstring for class runnable, method with_listeners() #19515

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libs/core/langchain_core/runnables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading