mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 23:29:21 +00:00
code[patch]: Add in code documentation to core Runnable with_retry method (docs only) (#19192)
- **Description:** Add in code documentation to core Runnable with_retry method (docs only) - **Issue:** #18804 @baskaryan @eyurtsev PTAL --------- Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
parent
4b3dd34544
commit
2c835baae4
@ -1344,6 +1344,35 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
) -> Runnable[Input, Output]:
|
) -> Runnable[Input, Output]:
|
||||||
"""Create a new Runnable that retries the original runnable on exceptions.
|
"""Create a new Runnable that retries the original runnable on exceptions.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
from langchain_core.runnables import RunnableLambda
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
|
||||||
|
def _lambda(x: int) -> None:
|
||||||
|
global count
|
||||||
|
count = count + 1
|
||||||
|
if x == 1:
|
||||||
|
raise ValueError("x is 1")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
runnable = RunnableLambda(_lambda)
|
||||||
|
try:
|
||||||
|
runnable.with_retry(
|
||||||
|
stop_after_attempt=2,
|
||||||
|
retry_if_exception_type=(ValueError,),
|
||||||
|
).invoke(1)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert (count == 2)
|
||||||
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
retry_if_exception_type: A tuple of exception types to retry on
|
retry_if_exception_type: A tuple of exception types to retry on
|
||||||
wait_exponential_jitter: Whether to add jitter to the wait time
|
wait_exponential_jitter: Whether to add jitter to the wait time
|
||||||
|
Loading…
Reference in New Issue
Block a user