A programming framework for agentic AI
Add more descriptive error message in the presence of OpenAI API timeouts (#1577)
Jack Gerritsd675489352be
diff --git a/autogen/oai/client.py b/autogen/oai/client.pyindex 70251353f..fd6742027 100644--- a/autogen/oai/client.py+++ b/autogen/oai/client.py@@ -26,7 +26,7 @@ except ImportError:AzureOpenAI = objectelse:# 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 OPENAIVERSIONfrom openai.resources import Completionsfrom openai.types.chat import ChatCompletionfrom openai.types.chat.chat_completion import ChatCompletionMessage, Choice # type: ignore [attr-defined]@@ -581,6 +581,12 @@ class OpenAIWrapper:continue # filter is not passed; try the next configtry: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 errexcept APIError as err:error_code = getattr(err, "code", None)if error_code == "content_filter":