|
|
|
@ -1357,6 +1357,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from langchain_core.runnables import RunnableLambda
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
@ -3388,6 +3389,7 @@ class RunnableGenerator(Runnable[Input, Output]):
|
|
|
|
|
|
|
|
|
|
RunnableGenerator makes it easy to implement custom behavior within a streaming
|
|
|
|
|
context. Below we show an example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
@ -4384,12 +4386,15 @@ class RunnableEach(RunnableEachBase[Input, Output]):
|
|
|
|
|
Union[Callable[[Run], None], Callable[[Run, RunnableConfig], None]]
|
|
|
|
|
] = None,
|
|
|
|
|
) -> RunnableEach[Input, Output]:
|
|
|
|
|
"""
|
|
|
|
|
Bind lifecycle listeners to a Runnable, returning a new Runnable.
|
|
|
|
|
"""Bind lifecycle listeners to a Runnable, returning a new Runnable.
|
|
|
|
|
|
|
|
|
|
on_start: Called before the runnable starts running, with the Run object.
|
|
|
|
|
on_end: Called after the runnable finishes running, with the Run object.
|
|
|
|
|
on_error: Called if the runnable throws an error, with the Run object.
|
|
|
|
|
Args:
|
|
|
|
|
on_start: Called before the runnable starts running, with the Run object.
|
|
|
|
|
on_end: Called after the runnable finishes running, with the Run object.
|
|
|
|
|
on_error: Called if the runnable throws an error, with the Run object.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A new Runnable with the listeners bound.
|
|
|
|
|
|
|
|
|
|
The Run object contains information about the run, including its id,
|
|
|
|
|
type, input, output, error, start_time, end_time, and any tags or metadata
|
|
|
|
@ -4408,15 +4413,18 @@ class RunnableEach(RunnableEachBase[Input, Output]):
|
|
|
|
|
on_end: Optional[AsyncListener] = None,
|
|
|
|
|
on_error: Optional[AsyncListener] = None,
|
|
|
|
|
) -> RunnableEach[Input, Output]:
|
|
|
|
|
"""
|
|
|
|
|
Bind async lifecycle listeners to a Runnable, returning a new Runnable.
|
|
|
|
|
|
|
|
|
|
on_start: Called asynchronously before the runnable starts running,
|
|
|
|
|
with the Run object.
|
|
|
|
|
on_end: Called asynchronously after the runnable finishes running,
|
|
|
|
|
with the Run object.
|
|
|
|
|
on_error: Called asynchronously if the runnable throws an error,
|
|
|
|
|
with the Run object.
|
|
|
|
|
"""Bind async lifecycle listeners to a Runnable, returning a new Runnable.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
on_start: Called asynchronously before the runnable starts running,
|
|
|
|
|
with the Run object.
|
|
|
|
|
on_end: Called asynchronously after the runnable finishes running,
|
|
|
|
|
with the Run object.
|
|
|
|
|
on_error: Called asynchronously if the runnable throws an error,
|
|
|
|
|
with the Run object.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A new Runnable with the listeners bound.
|
|
|
|
|
|
|
|
|
|
The Run object contains information about the run, including its id,
|
|
|
|
|
type, input, output, error, start_time, end_time, and any tags or metadata
|
|
|
|
|