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

Retry configuration options? #336

Open
mcantrell opened this issue Feb 13, 2025 · 2 comments
Open

Retry configuration options? #336

mcantrell opened this issue Feb 13, 2025 · 2 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@mcantrell
Copy link

I've poked around the documentation and the source code a little and I was not able to find anything regarding retry configuration in the lib. Is this something that I've overlooked or is it left as a responsibility for the developer?

@mcantrell mcantrell added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Feb 13, 2025
@sararob sararob added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Feb 13, 2025
@sararob
Copy link
Contributor

sararob commented Feb 13, 2025

We're working on adding support for retries and will comment on this issue when there's an update. Thanks!

@mcantrell
Copy link
Author

For those looking for an interim solution, I ended up going with tenacity for the following errors:

from google.genai.errors import APIError
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception

def _is_retryable_error(exception: BaseException) -> bool:
    """
    Checks if the exception is a retryable error based on the criteria.
    """
    if isinstance(exception, APIError):
        return exception.code in [429, 502, 503, 504]
    if isinstance(exception, requests.exceptions.ConnectionError):
        return True
    return False


retry_gemini_call = retry(
    retry=retry_if_exception(_is_retryable_error),
    wait=wait_exponential(min=1, max=10),
    stop=stop_after_attempt(3),
    reraise=True
)
@retry_gemini_call
def test_gemini_completion(self, prompt: str) -> str:
  # example usage

@yinghsienwu yinghsienwu self-assigned this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants