Skip to content

Commit

Permalink
Add more descriptive error message in the presence of OpenAI API time…
Browse files Browse the repository at this point in the history
…outs (#1577)

* Add more descriptive error message in the presence of OpenAI API timeouts

* handle specific exception

* Update autogen/oai/client.py

Co-authored-by: Chi Wang <[email protected]>

---------

Co-authored-by: Chi Wang <[email protected]>
Co-authored-by: Eric Zhu <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 8ece258 commit d675489
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
AzureOpenAI = object
else:
# raises exception if openai>=1 is installed and something is wrong with imports
from openai import OpenAI, AzureOpenAI, APIError, __version__ as OPENAIVERSION
from openai import OpenAI, AzureOpenAI, APIError, APITimeoutError, __version__ as OPENAIVERSION
from openai.resources import Completions
from openai.types.chat import ChatCompletion
from openai.types.chat.chat_completion import ChatCompletionMessage, Choice # type: ignore [attr-defined]
Expand Down Expand Up @@ -581,6 +581,12 @@ def yes_or_no_filter(context, response):
continue # filter is not passed; try the next config
try:
response = client.create(params)
except APITimeoutError as err:
logger.debug(f"config {i} timed out", exc_info=True)
if i == last:
raise TimeoutError(
"OpenAI API call timed out. This could be due to congestion or too small a timeout value. The timeout can be specified by setting the 'timeout' value (in seconds) in the llm_config (if you are using agents) or the OpenAIWrapper constructor (if you are using the OpenAIWrapper directly)."
) from err
except APIError as err:
error_code = getattr(err, "code", None)
if error_code == "content_filter":
Expand Down

0 comments on commit d675489

Please sign in to comment.