Skip to content

Commit

Permalink
docs: Add in code documentation to core Runnable with_fallbacks metho…
Browse files Browse the repository at this point in the history
…d (docs only) (#19104)

- Description: [a description of the change] Add in code documentation
to core Runnable with_fallbacks method (docs only)
- Issue: the issue #18804 
@eyurtsev PTAL
  • Loading branch information
liugddx authored and hinthornw committed Apr 26, 2024
1 parent 1994040 commit 5b47b26
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libs/core/langchain_core/runnables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,29 @@ def with_fallbacks(
) -> RunnableWithFallbacksT[Input, Output]:
"""Add fallbacks to a runnable, returning a new Runnable.
Example:
.. code-block:: python
from typing import Iterator
from langchain_core.runnables import RunnableGenerator
def _generate_immediate_error(input: Iterator) -> Iterator[str]:
raise ValueError()
yield ""
def _generate(input: Iterator) -> Iterator[str]:
yield from "foo bar"
runnable = RunnableGenerator(_generate_immediate_error).with_fallbacks(
[RunnableGenerator(_generate)]
)
print(''.join(runnable.stream({}))) #foo bar
Args:
fallbacks: A sequence of runnables to try if the original runnable fails.
exceptions_to_handle: A tuple of exception types to handle.
Expand All @@ -1391,6 +1414,7 @@ def with_fallbacks(
Returns:
A new Runnable that will try the original runnable, and then each
fallback in order, upon failures.
"""
from langchain_core.runnables.fallbacks import RunnableWithFallbacks

Expand Down

0 comments on commit 5b47b26

Please sign in to comment.