@ggboy123/dsh-paper-reader 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/dist/host.js +72 -10
- package/dist/translate-config.js +101 -23
- package/dist/translate.js +57 -11
- package/package.json +1 -1
- package/reader/index.html +900 -108
- package/runtime/babeldoc-driver.py +13 -2
|
@@ -145,6 +145,15 @@ _TOO_LONG_RE = re.compile(
|
|
|
145
145
|
re.I,
|
|
146
146
|
)
|
|
147
147
|
_THINKING_RE = re.compile(r"始终思考|不支持关闭思考|thinking|推理", re.I)
|
|
148
|
+
_QUOTA_EXHAUSTED_RE = re.compile(
|
|
149
|
+
r"每周/每月使用上限|(?:weekly|monthly).*(?:quota|limit)|['\"]code['\"]:\s*['\"]1310['\"]",
|
|
150
|
+
re.I,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def is_quota_exhausted(error: BaseException) -> bool:
|
|
155
|
+
"""周期配额耗尽不是瞬时限流:重试一百次也不会成功,必须尽快把原因带回 UI。"""
|
|
156
|
+
return bool(_QUOTA_EXHAUSTED_RE.search(str(error)))
|
|
148
157
|
|
|
149
158
|
|
|
150
159
|
def rough_tokens(text: str) -> int:
|
|
@@ -209,7 +218,7 @@ def install_translation() -> None:
|
|
|
209
218
|
import openai
|
|
210
219
|
from tenacity import before_sleep_log
|
|
211
220
|
from tenacity import retry
|
|
212
|
-
from tenacity import
|
|
221
|
+
from tenacity import retry_if_exception
|
|
213
222
|
from tenacity import stop_after_attempt
|
|
214
223
|
from tenacity import wait_exponential
|
|
215
224
|
|
|
@@ -280,7 +289,9 @@ def install_translation() -> None:
|
|
|
280
289
|
raise
|
|
281
290
|
|
|
282
291
|
@retry(
|
|
283
|
-
retry=
|
|
292
|
+
retry=retry_if_exception(
|
|
293
|
+
lambda exc: isinstance(exc, openai.RateLimitError) and not is_quota_exhausted(exc)
|
|
294
|
+
),
|
|
284
295
|
stop=stop_after_attempt(100),
|
|
285
296
|
wait=wait_exponential(multiplier=1, min=1, max=15),
|
|
286
297
|
before_sleep=before_sleep_log(log, logging.WARNING),
|