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
This commit is contained in:
Xu Yang
2025-04-24 20:50:27 -06:00
committed by GitHub
parent d6990a12b8
commit c89321f5a2
+14 -14
View File
@@ -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)