Skip to content

Commit 37f4dea

Browse files
committed
test(llm): add integration tests for HuggingFace and Gemini providers
- Add TestLLMClientIntegrationHuggingFace class with tests for: - Chat completion via huggingface/meta-llama/Llama-3.3-70B-Instruct - Embeddings via huggingface/microsoft/codebert-base - Add TestLLMClientIntegrationGemini class with test for: - Chat completion via gemini/gemini-1.5-flash - Tests require HF_TOKEN and GEMINI_API_KEY respectively - Tests skip gracefully when API keys are not set - Run with: uv run pytest tests/test_llm_client.py --run-api-tests
1 parent ae3d55d commit 37f4dea

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/test_llm_client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,80 @@ async def test_empty_messages_raises_error(self):
511511
model="gpt-4o-mini",
512512
messages=[],
513513
)
514+
515+
516+
@pytest.mark.requires_api_keys
517+
class TestLLMClientIntegrationHuggingFace:
518+
"""Integration tests for LLMClient with HuggingFace via LiteLLM.
519+
520+
These tests require HF_TOKEN to be set in the environment.
521+
Run with: uv run pytest tests/test_llm_client.py --run-api-tests
522+
"""
523+
524+
@pytest.mark.asyncio
525+
async def test_huggingface_chat_completion(self):
526+
"""Test HuggingFace chat completion via LiteLLM serverless inference."""
527+
import os
528+
529+
if not os.environ.get("HF_TOKEN"):
530+
pytest.skip("HF_TOKEN not set")
531+
532+
response = await LLMClient.create_chat_completion(
533+
model="huggingface/meta-llama/Llama-3.3-70B-Instruct",
534+
messages=[{"role": "user", "content": "Say 'hello' and nothing else."}],
535+
temperature=0.0,
536+
max_tokens=10,
537+
)
538+
539+
assert response.content is not None
540+
assert len(response.content) > 0
541+
assert response.finish_reason in ("stop", "length", "eos")
542+
assert response.total_tokens > 0
543+
544+
@pytest.mark.asyncio
545+
async def test_huggingface_embedding(self):
546+
"""Test HuggingFace embedding via LiteLLM."""
547+
import os
548+
549+
if not os.environ.get("HF_TOKEN"):
550+
pytest.skip("HF_TOKEN not set")
551+
552+
response = await LLMClient.create_embedding(
553+
model="huggingface/microsoft/codebert-base",
554+
input_texts=["Hello, world!", "This is a test."],
555+
)
556+
557+
assert len(response.embeddings) == 2
558+
assert len(response.embeddings[0]) > 0 # Has dimensions
559+
assert len(response.embeddings[1]) > 0
560+
assert response.total_tokens >= 0 # Some providers return 0
561+
562+
563+
@pytest.mark.requires_api_keys
564+
class TestLLMClientIntegrationGemini:
565+
"""Integration tests for LLMClient with Google Gemini via LiteLLM.
566+
567+
These tests require GEMINI_API_KEY to be set in the environment.
568+
Run with: uv run pytest tests/test_llm_client.py --run-api-tests
569+
"""
570+
571+
@pytest.mark.asyncio
572+
async def test_gemini_chat_completion(self):
573+
"""Test Gemini chat completion via LiteLLM."""
574+
import os
575+
576+
if not os.environ.get("GEMINI_API_KEY"):
577+
pytest.skip("GEMINI_API_KEY not set")
578+
579+
response = await LLMClient.create_chat_completion(
580+
model="gemini/gemini-1.5-flash",
581+
messages=[{"role": "user", "content": "Say 'hello' and nothing else."}],
582+
temperature=0.0,
583+
max_tokens=10,
584+
)
585+
586+
assert response.content is not None
587+
assert len(response.content) > 0
588+
assert response.finish_reason in ("stop", "length", "STOP")
589+
assert response.total_tokens > 0
590+
assert "gemini" in response.model.lower()

0 commit comments

Comments
 (0)