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

code[patch]: Add in code documentation to core Runnable with_fallbacks method (docs only) #19104

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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