forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge changes from langchain-ai#19084
- Loading branch information
1 parent
c727bae
commit bbe6ae4
Showing
6 changed files
with
88 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any, Callable | ||
|
||
import cohere | ||
import logger | ||
from tenacity import ( | ||
before_sleep_log, | ||
retry, | ||
retry_if_exception_type, | ||
stop_after_attempt, | ||
wait_exponential, | ||
) | ||
|
||
|
||
def _create_retry_decorator(max_retries: int) -> Callable[[Any], Any]: | ||
# support v4 and v5 | ||
retry_conditions = ( | ||
retry_if_exception_type(cohere.error.CohereError) | ||
if hasattr(cohere, "error") | ||
else retry_if_exception_type(Exception) | ||
) | ||
|
||
min_seconds = 4 | ||
max_seconds = 10 | ||
# Wait 2^x * 1 second between each retry starting with | ||
# 4 seconds, then up to 10 seconds, then 10 seconds afterwards | ||
return retry( | ||
reraise=True, | ||
stop=stop_after_attempt(max_retries), | ||
wait=wait_exponential(multiplier=1, min=min_seconds, max=max_seconds), | ||
retry=retry_conditions, | ||
before_sleep=before_sleep_log(logger, logging.WARNING), | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters