Skip to content

Conversation

@highkay
Copy link
Contributor

@highkay highkay commented Mar 3, 2025

  • 在 OpenAITranslator 类的 do_translate 方法中添加了对 RateLimitError 的捕获
  • 当遇到速率限制错误时,程序将暂停 6 秒后重试一次
  • 这种处理方式可以避免因频繁请求导致的接口限制问题,提高程序的稳定性

- 在 OpenAITranslator 类的 do_translate 方法中添加了对 RateLimitError 的捕获
- 当遇到速率限制错误时,程序将暂停 6 秒后重试一次
- 这种处理方式可以避免因频繁请求导致的接口限制问题,提高程序的稳定性
@awwaawwa
Copy link
Collaborator

awwaawwa commented Mar 3, 2025

跑下black .

@awwaawwa
Copy link
Collaborator

awwaawwa commented Mar 3, 2025

https://github.com/funstory-ai/BabelDOC/blob/312121f131495b8e679e24638696d44e15efbf05/babeldoc/assets/assets.py#L80

重试可以参考一下这个,使用 tenacity 库,然后用 wait_exponential 策略~

highkay added 3 commits March 5, 2025 13:27
- 引入 tenacity 库以实现重试机制
- 在 do_translate 方法中添加重试装饰器,处理 RateLimitError
- 配置重试参数:最多重试 100 次,指数退避等待时间
- 在每次重试前记录警告日志
- 移除原有的 sleep 和 递归重试逻辑
@awwaawwa awwaawwa requested a review from Copilot March 5, 2025 06:39
- 移除了 OpenAITranslator 类中的 try-except 块
- 删除了速率限制错误的重试逻辑
- 简化了错误响应的处理流程
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request adds rate limit error handling to the OpenAI translation endpoint to improve stability when too many requests are made. Key changes include the addition of a tenacity retry decorator for handling RateLimitError, an updated logging message reflecting retry attempts, and manual error handling with a sleep-and-retry approach in the translation function.

Reviewed Changes

File Description
pdf2zh/translator.py Introduces rate limit error handling via tenacity and manual handling of RateLimitError

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

@awwaawwa
Copy link
Collaborator

awwaawwa commented Mar 6, 2025

Thank you for your contribution. According to https://funstory-ai.github.io/BabelDOC/CONTRIBUTOR_REWARD/ , you can apply for a monthly membership redemption code for Immersive Translate.

@awwaawwa awwaawwa changed the title fix(pdf2zh): 增加 OpenAI 接口速率限制错误处理 fix(pdf2zh): Add error handling for OpenAI API rate limit Mar 6, 2025
@awwaawwa awwaawwa merged commit 0894af4 into PDFMathTranslate:main Mar 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants