Skip to content

Commit 6652dd7

Browse files
Revert "test: skip HF API live integration tests (#8889)" (#8914)
* Revert "test: skip HF API live integration tests (#8889)" This reverts commit 56a3a9b. * Replace zephyr-7b-beta model with SmolLM2-1.7B-Instruct * Use zephyr-7b-beta model but extend instructions --------- Co-authored-by: David S. Batista <dsbatista@gmail.com>
1 parent 76753fd commit 6652dd7

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

test/components/embedders/test_hugging_face_api_document_embedder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ def test_run_custom_batch_size(self, mock_check_valid_model):
358358

359359
@pytest.mark.flaky(reruns=5, reruns_delay=5)
360360
@pytest.mark.integration
361-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
361+
@pytest.mark.skipif(
362+
not os.environ.get("HF_API_TOKEN", None),
363+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
364+
)
362365
def test_live_run_serverless(self):
363366
docs = [
364367
Document(content="I love cheese", meta={"topic": "Cuisine"}),

test/components/embedders/test_hugging_face_api_text_embedder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ def test_run_wrong_embedding_shape(self, mock_check_valid_model):
187187

188188
@pytest.mark.flaky(reruns=5, reruns_delay=5)
189189
@pytest.mark.integration
190-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
190+
@pytest.mark.skipif(
191+
not os.environ.get("HF_API_TOKEN", None),
192+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
193+
)
191194
def test_live_run_serverless(self):
192195
embedder = HuggingFaceAPITextEmbedder(
193196
api_type=HFEmbeddingAPIType.SERVERLESS_INFERENCE_API,

test/components/generators/chat/test_hugging_face_api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,10 @@ def test_run_with_tools(self, mock_check_valid_model, tools):
526526
}
527527

528528
@pytest.mark.integration
529-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
529+
@pytest.mark.skipif(
530+
not os.environ.get("HF_API_TOKEN", None),
531+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
532+
)
530533
@pytest.mark.flaky(reruns=3, reruns_delay=10)
531534
def test_live_run_serverless(self):
532535
generator = HuggingFaceAPIChatGenerator(
@@ -547,7 +550,10 @@ def test_live_run_serverless(self):
547550
assert "completion_tokens" in response["replies"][0].meta["usage"]
548551

549552
@pytest.mark.integration
550-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
553+
@pytest.mark.skipif(
554+
not os.environ.get("HF_API_TOKEN", None),
555+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
556+
)
551557
@pytest.mark.flaky(reruns=3, reruns_delay=10)
552558
def test_live_run_serverless_streaming(self):
553559
generator = HuggingFaceAPIChatGenerator(
@@ -573,7 +579,13 @@ def test_live_run_serverless_streaming(self):
573579
assert "completion_tokens" in response_meta["usage"]
574580

575581
@pytest.mark.integration
576-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
582+
@pytest.mark.skipif(
583+
not os.environ.get("HF_API_TOKEN", None),
584+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
585+
)
586+
@pytest.mark.xfail(
587+
reason="The Hugging Face API can be unstable and this test may fail intermittently", strict=False
588+
)
577589
def test_live_run_with_tools(self, tools):
578590
"""
579591
We test the round trip: generate tool call, pass tool message, generate response.

test/components/generators/test_hugging_face_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ def mock_iter(self):
291291

292292
@pytest.mark.flaky(reruns=5, reruns_delay=5)
293293
@pytest.mark.integration
294-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
294+
@pytest.mark.skipif(
295+
not os.environ.get("HF_API_TOKEN", None),
296+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
297+
)
295298
def test_run_serverless(self):
296299
generator = HuggingFaceAPIGenerator(
297300
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
@@ -312,16 +315,21 @@ def test_run_serverless(self):
312315
assert len(response["meta"]) > 0
313316
assert [isinstance(meta, dict) for meta in response["meta"]]
314317

318+
@pytest.mark.flaky(reruns=5, reruns_delay=5)
315319
@pytest.mark.integration
316-
@pytest.mark.skip(reason="Temporarily skipped due to limits on HF API requests.")
320+
@pytest.mark.skipif(
321+
not os.environ.get("HF_API_TOKEN", None),
322+
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
323+
)
317324
def test_live_run_streaming_check_completion_start_time(self):
318325
generator = HuggingFaceAPIGenerator(
319326
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
320327
api_params={"model": "HuggingFaceH4/zephyr-7b-beta"},
328+
generation_kwargs={"max_new_tokens": 30},
321329
streaming_callback=streaming_callback_handler,
322330
)
323331

324-
results = generator.run("What is the capital of France?")
332+
results = generator.run("You are a helpful agent that answers questions. What is the capital of France?")
325333

326334
assert len(results["replies"]) == 1
327335
assert "Paris" in results["replies"][0]

0 commit comments

Comments
 (0)