Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add exponential http backoff to work around constant HF Hub 429 errors

davidmezzetti1f5a352261ad
diff --git a/test/python/testpipeline/testtext/testtranslation.py b/test/python/testpipeline/testtext/testtranslation.py
index 79f878a3..a383d968 100644
--- a/test/python/testpipeline/testtext/testtranslation.py
+++ b/test/python/testpipeline/testtext/testtranslation.py
@@ -3,6 +3,9 @@ Translation module tests
"""
import unittest
+import time
+
+import requests
from txtai.pipeline import Translation
@@ -20,6 +23,19 @@ class TestTranslation(unittest.TestCase):
cls.translate = Translation()
+ # Preload list of models. Handle HF Hub errors.
+ complete, wait = False, 1
+ while not complete:
+ try:
+ cls.translate.lookup("en", "es")
+ complete = True
+ except requests.exceptions.HTTPError:
+ # Exponential backoff
+ time.sleep(wait)
+
+ # Wait up to 16 seconds
+ wait = min(wait * 2, 16)
+
def testDetect(self):
"""
Test language detection