From c89321f5a2ac38bd1aabbb7f8828319d9bafb132 Mon Sep 17 00:00:00 2001 From: Xu Yang Date: Thu, 24 Apr 2025 20:50:27 -0600 Subject: [PATCH] fix: add time to timer when api timeout bug (#826) * If not use the session stored timer, need to replace it with the default timer * when api timeout, add the waiting time to timer --- rdagent/oai/backend/base.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rdagent/oai/backend/base.py b/rdagent/oai/backend/base.py index f7c4159c..9322d351 100644 --- a/rdagent/oai/backend/base.py +++ b/rdagent/oai/backend/base.py @@ -348,21 +348,21 @@ class APIBackend(ABC): kwargs["input_content_list"] = [ content[: len(content) // 2] for content in kwargs.get("input_content_list", []) ] - elif ( - openai_imported - and isinstance(e, openai.APITimeoutError) - or ( - isinstance(e, openai.APIError) - and hasattr(e, "message") - and "Your resource has been temporarily blocked because we detected behavior that may violate our content policy." - in e.message - ) - ): - timeout_count += 1 - if timeout_count >= 3: - logger.warning("Timeout error, please check your network connection.") - raise e else: + if ( + openai_imported + and isinstance(e, openai.APITimeoutError) + or ( + isinstance(e, openai.APIError) + and hasattr(e, "message") + and "Your resource has been temporarily blocked because we detected behavior that may violate our content policy." + in e.message + ) + ): + timeout_count += 1 + if timeout_count >= 3: + logger.warning("Timeout error, please check your network connection.") + raise e time.sleep(self.retry_wait_seconds) if RD_Agent_TIMER_wrapper.timer.started and not isinstance(e, json.decoder.JSONDecodeError): RD_Agent_TIMER_wrapper.timer.add_duration(datetime.now() - API_start_time)