Skip to content

Commit 1f5a352

Browse files
committed
Add exponential http backoff to work around constant HF Hub 429 errors
1 parent 1f5f9cd commit 1f5a352

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/python/testpipeline/testtext/testtranslation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"""
44

55
import unittest
6+
import time
7+
8+
import requests
69

710
from txtai.pipeline import Translation
811

@@ -20,6 +23,19 @@ def setUpClass(cls):
2023

2124
cls.translate = Translation()
2225

26+
# Preload list of models. Handle HF Hub errors.
27+
complete, wait = False, 1
28+
while not complete:
29+
try:
30+
cls.translate.lookup("en", "es")
31+
complete = True
32+
except requests.exceptions.HTTPError:
33+
# Exponential backoff
34+
time.sleep(wait)
35+
36+
# Wait up to 16 seconds
37+
wait = min(wait * 2, 16)
38+
2339
def testDetect(self):
2440
"""
2541
Test language detection

0 commit comments

Comments
 (0)