Skip to content

Commit

Permalink
retry on ReadTimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
phelps-sg committed Jun 29, 2023
1 parent b7689fa commit 429fb6f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/openai_pygenerator/openai_pygenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import openai
from openai.error import APIError, RateLimitError, ServiceUnavailableError
from urllib3.exceptions import ReadTimeoutError

Completion = Dict[str, str]
Seconds = NewType("Seconds", int)
Expand Down Expand Up @@ -88,7 +89,7 @@ def generate_completions(
logger.debug("response = %s", result)
for choice in result.choices:
yield choice.message
except (RateLimitError, APIError, ServiceUnavailableError) as err:
except (ReadTimeoutError, RateLimitError, APIError, ServiceUnavailableError) as err:
if isinstance(err, APIError) and not (err.http_status in [524, 502]):
raise
logger.warning("Error returned from openai API: %s", err)
Expand Down

0 comments on commit 429fb6f

Please sign in to comment.