Skip to content

Commit

Permalink
[Evals] Update the errors we except for retries (#1406)
Browse files Browse the repository at this point in the history
Resolve #1399
  • Loading branch information
andrew-openai authored Nov 13, 2023
1 parent a53f52b commit a06a07b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
5 changes: 0 additions & 5 deletions evals/cli/oaieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import sys
from typing import Any, Mapping, Optional, Union, cast

import openai

import evals
import evals.api
import evals.base
Expand Down Expand Up @@ -268,9 +266,6 @@ def main() -> None:
filename=args.log_to_file if args.log_to_file else None,
)
logging.getLogger("openai").setLevel(logging.WARN)

if hasattr(openai.error, "set_display_cause"): # type: ignore
openai.error.set_display_cause() # type: ignore
run(args)


Expand Down
4 changes: 2 additions & 2 deletions evals/elsuite/make_me_say/autoeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Callable, Optional, Union

import backoff
from openai.error import InvalidRequestError
from openai import BadRequestError

from evals.api import CompletionFn, CompletionResult
from evals.elsuite.make_me_say.core import Game, Message, Player
Expand All @@ -17,7 +17,7 @@
)


@backoff.on_exception(backoff.constant, InvalidRequestError, max_tries=3)
@backoff.on_exception(backoff.constant, BadRequestError, max_tries=3)
def run(
codeword: str,
manipulator_completion_fn: CompletionFn,
Expand Down
10 changes: 6 additions & 4 deletions evals/elsuite/make_me_say/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import backoff
import openai
import openai.error
import urllib3.exceptions

from evals.api import CompletionResult
Expand All @@ -12,9 +11,12 @@
@backoff.on_exception(
backoff.expo,
(
openai.error.RateLimitError,
openai.error.ServiceUnavailableError,
openai.error.TryAgain,
openai.APIError,
openai.APIStatusError,
openai.RateLimitError,
openai.APITimeoutError,
openai.APIConnectionError,
openai.InternalServerError,
urllib3.exceptions.TimeoutError,
),
)
Expand Down
2 changes: 1 addition & 1 deletion evals/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def add_registry_paths(self, paths: Sequence[Union[str, Path]]) -> None:
def api_model_ids(self) -> list[str]:
try:
return [m["id"] for m in openai.Model.list()["data"]]
except openai.error.OpenAIError as err: # type: ignore
except openai.OpenAIError as err: # type: ignore
# Errors can happen when running eval with completion function that uses custom
# API endpoints and authentication mechanisms.
logger.warning(f"Could not fetch API model IDs from OpenAI API: {err}")
Expand Down
26 changes: 14 additions & 12 deletions evals/utils/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
@backoff.on_exception(
wait_gen=backoff.expo,
exception=(
openai.error.ServiceUnavailableError,
openai.error.APIError,
openai.error.RateLimitError,
openai.error.APIConnectionError,
openai.error.Timeout,
openai.APIError,
openai.APIStatusError,
openai.RateLimitError,
openai.APITimeoutError,
openai.APIConnectionError,
openai.InternalServerError,
),
max_value=60,
factor=1.5,
Expand All @@ -31,7 +32,7 @@ def openai_completion_create_retrying(*args, **kwargs):
result = openai.Completion.create(*args, **kwargs)
if "error" in result:
logging.warning(result)
raise openai.error.APIError(result["error"])
raise openai.APIError(result["error"])
return result


Expand All @@ -52,11 +53,12 @@ def request_with_timeout(func, *args, timeout=EVALS_THREAD_TIMEOUT, **kwargs):
@backoff.on_exception(
wait_gen=backoff.expo,
exception=(
openai.error.ServiceUnavailableError,
openai.error.APIError,
openai.error.RateLimitError,
openai.error.APIConnectionError,
openai.error.Timeout,
openai.APIError,
openai.APIStatusError,
openai.RateLimitError,
openai.APITimeoutError,
openai.APIConnectionError,
openai.InternalServerError,
),
max_value=60,
factor=1.5,
Expand All @@ -69,5 +71,5 @@ def openai_chat_completion_create_retrying(*args, **kwargs):
result = request_with_timeout(openai.ChatCompletion.create, *args, **kwargs)
if "error" in result:
logging.warning(result)
raise openai.error.APIError(result["error"])
raise openai.APIError(result["error"])
return result

0 comments on commit a06a07b

Please sign in to comment.