fix(openai translator): enhance error handling for empty API responses#604
fix(openai translator): enhance error handling for empty API responses#604awwaawwa merged 1 commit intoPDFMathTranslate:mainfrom zqqian:add-openai-err-raise
Conversation
|
The print statements in the logs can be changed to logger. You can refer to the following code: https://github.com/funstory-ai/BabelDOC/blob/520a84a223ac0488522bb42cf7a5d0b2d8937e7e/babeldoc/high_level.py#L433C1-L434C1 |
|
In current versions, there was error handling for upstream issues at this position, you can take a look. For logger, you can use |
|
@awwaawwa I have removed the error-handling code, keeping only a check for When using third-party OpenAI-compatible APIs, such as Tencent Cloud's Deepseek, errors are not generated according to OpenAI's specifications. This leads to issues like: This makes it difficult to diagnose the root cause of the issue, as it appears to be a problem with Pdf2zh itself. With the code modification, the error message now explicitly indicates an issue with the OpenAI API call: This change helps to better identify API-related issues. |
|
Thank you for your contribution! |
fix(api): add error handling for OpenAI API failures
Previously, API errors were not handled, This commit adds exception
handling for API errors, connection issues, and rate limits, ensuring
better stability.
Handled exceptions:
openai.APIError: Captures general API errors.openai.APIConnectionError: Handles network issues.openai.RateLimitError: Prevents crashes due to rate limiting.This improves robustness when interacting with OpenAI's API.