mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
parent
2423f7f3b4
commit
1b0eebe1e3
@ -254,7 +254,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
def with_retry(
|
def with_retry(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
retry_if_exception_type: Tuple[Type[BaseException]] = (Exception,),
|
retry_if_exception_type: Tuple[Type[BaseException], ...] = (Exception,),
|
||||||
wait_exponential_jitter: bool = True,
|
wait_exponential_jitter: bool = True,
|
||||||
stop_after_attempt: int = 3,
|
stop_after_attempt: int = 3,
|
||||||
) -> Runnable[Input, Output]:
|
) -> Runnable[Input, Output]:
|
||||||
@ -280,7 +280,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
self,
|
self,
|
||||||
fallbacks: Sequence[Runnable[Input, Output]],
|
fallbacks: Sequence[Runnable[Input, Output]],
|
||||||
*,
|
*,
|
||||||
exceptions_to_handle: Tuple[Type[BaseException]] = (Exception,),
|
exceptions_to_handle: Tuple[Type[BaseException], ...] = (Exception,),
|
||||||
) -> RunnableWithFallbacks[Input, Output]:
|
) -> RunnableWithFallbacks[Input, Output]:
|
||||||
return RunnableWithFallbacks(
|
return RunnableWithFallbacks(
|
||||||
runnable=self,
|
runnable=self,
|
||||||
@ -653,7 +653,7 @@ class RunnableWithFallbacks(Serializable, Runnable[Input, Output]):
|
|||||||
|
|
||||||
runnable: Runnable[Input, Output]
|
runnable: Runnable[Input, Output]
|
||||||
fallbacks: Sequence[Runnable[Input, Output]]
|
fallbacks: Sequence[Runnable[Input, Output]]
|
||||||
exceptions_to_handle: Tuple[Type[BaseException]] = (Exception,)
|
exceptions_to_handle: Tuple[Type[BaseException], ...] = (Exception,)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
arbitrary_types_allowed = True
|
arbitrary_types_allowed = True
|
||||||
|
@ -24,7 +24,7 @@ U = TypeVar("U")
|
|||||||
class RunnableRetry(RunnableBinding[Input, Output]):
|
class RunnableRetry(RunnableBinding[Input, Output]):
|
||||||
"""Retry a Runnable if it fails."""
|
"""Retry a Runnable if it fails."""
|
||||||
|
|
||||||
retry_exception_types: Tuple[Type[BaseException]] = (Exception,)
|
retry_exception_types: Tuple[Type[BaseException], ...] = (Exception,)
|
||||||
|
|
||||||
wait_exponential_jitter: bool = True
|
wait_exponential_jitter: bool = True
|
||||||
|
|
||||||
|
@ -1507,7 +1507,7 @@ async def test_async_retrying(mocker: MockerFixture) -> None:
|
|||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
await runnable.with_retry(
|
await runnable.with_retry(
|
||||||
stop_after_attempt=2,
|
stop_after_attempt=2,
|
||||||
retry_if_exception_type=(ValueError,),
|
retry_if_exception_type=(ValueError, KeyError),
|
||||||
).ainvoke(1)
|
).ainvoke(1)
|
||||||
|
|
||||||
assert _lambda_mock.call_count == 2 # retried
|
assert _lambda_mock.call_count == 2 # retried
|
||||||
|
Loading…
Reference in New Issue
Block a user