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

Fix AttributeError: Update OpenAI error imports (Closes #1564) #1577

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions evals/utils/api_utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import logging
import os

import backoff
import requests

from openai import APIError, APIConnectionError, APITimeoutError, RateLimitError

EVALS_THREAD_TIMEOUT = float(os.environ.get("EVALS_THREAD_TIMEOUT", "40"))
logging.getLogger("httpx").setLevel(logging.WARNING) # suppress "OK" logs from openai API calls
logging.getLogger("httpx").setLevel(logging.WARNING) # Suppress "OK" logs from OpenAI API

RETRY_ERRORS = (
APIConnectionError,
APIError,
APITimeoutError,
RateLimitError,
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
)

@backoff.on_predicate(
wait_gen=backoff.expo,
max_value=60,
factor=1.5,
)
def create_retrying(func: callable, retry_exceptions: tuple[Exception], *args, **kwargs):
def create_retrying(func: callable, retry_exceptions: tuple[Exception] = RETRY_ERRORS, *args, **kwargs):
"""
Retries given function if one of given exceptions is raised
"""
try:
return func(*args, **kwargs)
except retry_exceptions:
return False
except retry_exceptions as e:
logging.warning(f"Retrying due to error: {str(e)}")
return False