Skip to content

Commit d09f4f4

Browse files
committed
Fix AttributeError: Update OpenAI error imports (Closes openai#1564)
1 parent cdb8ce9 commit d09f4f4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

evals/utils/api_utils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
import logging
22
import os
3-
43
import backoff
4+
import requests
5+
6+
from openai import APIError, APIConnectionError, APITimeoutError, RateLimitError
57

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

11+
RETRY_ERRORS = (
12+
APIConnectionError,
13+
APIError,
14+
APITimeoutError,
15+
RateLimitError,
16+
requests.exceptions.ConnectionError,
17+
requests.exceptions.Timeout,
18+
)
919

1020
@backoff.on_predicate(
1121
wait_gen=backoff.expo,
1222
max_value=60,
1323
factor=1.5,
1424
)
15-
def create_retrying(func: callable, retry_exceptions: tuple[Exception], *args, **kwargs):
25+
def create_retrying(func: callable, retry_exceptions: tuple[Exception] = RETRY_ERRORS, *args, **kwargs):
1626
"""
1727
Retries given function if one of given exceptions is raised
1828
"""
1929
try:
2030
return func(*args, **kwargs)
21-
except retry_exceptions:
22-
return False
31+
except retry_exceptions as e:
32+
logging.warning(f"Retrying due to error: {str(e)}")
33+
return False

0 commit comments

Comments
 (0)