mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
test: migrate wave 1 phase 2 legacy unit tests to tests/unit
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
6ef7b86748
commit
522c3e3ed6
20 changed files with 0 additions and 237 deletions
|
|
@ -1,195 +0,0 @@
|
|||
import os
|
||||
import pytest
|
||||
|
||||
# Ensure the project root is on the import path
|
||||
|
||||
from litellm import completion
|
||||
from litellm.types.utils import ModelResponse, Usage, Choices, Message
|
||||
|
||||
|
||||
def _has_api_key() -> bool:
|
||||
"""Check if Amazon Nova API key is available"""
|
||||
return (
|
||||
"AMAZON_NOVA_API_KEY" in os.environ
|
||||
and os.environ["AMAZON_NOVA_API_KEY"] is not None
|
||||
)
|
||||
|
||||
|
||||
def _create_mock_nova_response():
|
||||
"""Helper function to create mock Amazon Nova response for testing"""
|
||||
return ModelResponse(
|
||||
id="chatcmpl-test-nova-micro",
|
||||
choices=[
|
||||
Choices(
|
||||
finish_reason="stop",
|
||||
index=0,
|
||||
message=Message(
|
||||
content="I am Amazon Nova Micro. 777 times 9 equals 6993.",
|
||||
role="assistant",
|
||||
),
|
||||
)
|
||||
],
|
||||
created=1234567890,
|
||||
model="amazon-nova/nova-micro-v1",
|
||||
object="chat.completion",
|
||||
usage=Usage(prompt_tokens=25, completion_tokens=15, total_tokens=40),
|
||||
)
|
||||
|
||||
|
||||
def test_amazon_nova_chat_completion_nova_micro():
|
||||
if _has_api_key():
|
||||
response: ModelResponse = completion(
|
||||
model="amazon-nova/nova-micro-v1",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What model are you? Can you calculate 777 times 9?",
|
||||
},
|
||||
],
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
else:
|
||||
# Use mock response when API key is not available
|
||||
response = _create_mock_nova_response()
|
||||
# Additional mock-specific assertions for code review reference
|
||||
assert (
|
||||
response.choices[0].message.content
|
||||
== "I am Amazon Nova Micro. 777 times 9 equals 6993."
|
||||
)
|
||||
assert response.model == "amazon-nova/nova-micro-v1"
|
||||
assert response.usage.prompt_tokens == 25
|
||||
assert response.usage.completion_tokens == 15
|
||||
assert response.object == "chat.completion"
|
||||
assert response.choices[0].finish_reason == "stop"
|
||||
assert response.choices[0].message.role == "assistant"
|
||||
|
||||
# Common assertions for both real and mock responses
|
||||
assert response is not None
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert response.choices[0].message.content is not None
|
||||
assert response.usage.total_tokens > 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _has_api_key(), reason="Amazon Nova API key not available")
|
||||
def test_amazon_nova_chat_completion_nova_lite():
|
||||
response: ModelResponse = completion(
|
||||
model="amazon-nova/nova-lite-v1",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What model are you? Please tell me a poem on rain",
|
||||
},
|
||||
],
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert response.choices[0].message.content is not None
|
||||
assert response.usage.total_tokens > 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _has_api_key(), reason="Amazon Nova API key not available")
|
||||
def test_amazon_nova_chat_completion_nova_pro():
|
||||
response: ModelResponse = completion(
|
||||
model="amazon-nova/nova-pro-v1",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What model are you? What is MCP server and how does that help in building GenAI applications?",
|
||||
},
|
||||
],
|
||||
timeout=30,
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert response.choices[0].message.content is not None
|
||||
assert response.usage.total_tokens > 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _has_api_key(), reason="Amazon Nova API key not available")
|
||||
def test_amazon_nova_chat_completion_nova_premier():
|
||||
response: ModelResponse = completion(
|
||||
model="amazon-nova/nova-premier-v1",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What model are you? Can you help me understand what Trigonometry is?",
|
||||
},
|
||||
],
|
||||
timeout=60,
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
print(response.choices[0].message.content)
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert response.choices[0].message.content is not None
|
||||
assert response.usage.total_tokens > 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _has_api_key(), reason="Amazon Nova API key not available")
|
||||
def test_amazon_nova_chat_completion_with_tool_usage():
|
||||
response: ModelResponse = completion(
|
||||
model="amazon-nova/nova-micro-v1",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{"role": "user", "content": "What is the temperature in SFO?"},
|
||||
],
|
||||
tools=[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getCurrentWeather",
|
||||
"description": "Get the current weather in a given city",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "City and country e.g. Bogotá, Colombia",
|
||||
}
|
||||
},
|
||||
"required": ["location"],
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert response.choices[0].message is not None
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _has_api_key(), reason="Amazon Nova API key not available")
|
||||
def test_amazon_nova_chat_completion_with_stream_response():
|
||||
response = completion(
|
||||
model="amazon-nova/nova-micro-v1",
|
||||
stream=True,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant"},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What are MMO games? Can you give me some sample references?",
|
||||
},
|
||||
],
|
||||
api_key=os.environ["AMAZON_NOVA_API_KEY"],
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
chunks = list(response)
|
||||
assert chunks is not None
|
||||
assert len(chunks) > 0
|
||||
|
|
@ -151,48 +151,6 @@ class TestLevoConfig(unittest.TestCase):
|
|||
class TestLevoIntegration(unittest.TestCase):
|
||||
"""Integration tests for LevoLogger."""
|
||||
|
||||
@patch.dict(
|
||||
"os.environ",
|
||||
{
|
||||
"LEVOAI_API_KEY": "test-api-key",
|
||||
"LEVOAI_ORG_ID": "test-org-id",
|
||||
"LEVOAI_WORKSPACE_ID": "test-workspace-id",
|
||||
"LEVOAI_COLLECTOR_URL": "https://collector.levo.ai",
|
||||
},
|
||||
)
|
||||
@pytest.mark.skipif(
|
||||
not OPENTELEMETRY_AVAILABLE, reason="OpenTelemetry packages not installed"
|
||||
)
|
||||
@patch(
|
||||
"litellm.integrations.opentelemetry.OpenTelemetry._init_otel_logger_on_litellm_proxy"
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_levo_logger_health_check_healthy(self, mock_init_proxy):
|
||||
"""Test health check returns healthy status when config is valid."""
|
||||
# Mock the proxy initialization to avoid importing proxy code
|
||||
mock_init_proxy.return_value = None
|
||||
|
||||
config = LevoLogger.get_levo_config()
|
||||
otel_config = OpenTelemetryConfig(
|
||||
exporter=config.protocol,
|
||||
endpoint=config.endpoint,
|
||||
headers=config.otlp_auth_headers,
|
||||
)
|
||||
|
||||
# Create tracer provider with in-memory exporter
|
||||
tracer_provider = TracerProvider()
|
||||
tracer_provider.add_span_processor(SimpleSpanProcessor(InMemorySpanExporter()))
|
||||
|
||||
levo_logger = LevoLogger(
|
||||
config=otel_config, callback_name="levo", tracer_provider=tracer_provider
|
||||
)
|
||||
|
||||
# Run health check
|
||||
result = await levo_logger.async_health_check()
|
||||
|
||||
self.assertEqual(result["status"], "healthy")
|
||||
self.assertIn("message", result)
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_levo_logger_health_check_unhealthy(self):
|
||||
"""Test health check returns unhealthy status when required vars are missing."""
|
||||
Loading…
Add table
Reference in a new issue