mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(ci): stabilize CI tests - conditional import, mock fixes, timing adjustments
Fix 1.1: Make ResponseApplyPatchToolCall import conditional with try/except for compatibility with openai==1.100.1 (CI environment) Fix 1.2: Move Router creation inside mock context in vector store tests so mocks are applied before Router captures function references Fix 1.3: Update test_model_group_info_e2e to check for 'anthropic/*' wildcard group instead of specific model names not in proxy config Fix 2.1: Increase redis cache test sleep from 1s to 5s Fix 2.2: Increase spend accuracy test sleep from 25s to 45s Fix 2.3: Add 0.5s sleep between budget test calls Fix 2.4: Increase vertex AI spend test sleep from 20s to 40s Co-authored-by: yuneng-jiang <yuneng-jiang@users.noreply.github.com>
This commit is contained in:
parent
cb77bdaeca
commit
cc3f9cd65b
7 changed files with 33 additions and 42 deletions
|
|
@ -398,9 +398,12 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
|
||||||
ResponseOutputMessage,
|
ResponseOutputMessage,
|
||||||
ResponseReasoningItem,
|
ResponseReasoningItem,
|
||||||
)
|
)
|
||||||
from openai.types.responses.response_output_item import (
|
try:
|
||||||
ResponseApplyPatchToolCall,
|
from openai.types.responses.response_output_item import (
|
||||||
)
|
ResponseApplyPatchToolCall,
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
ResponseApplyPatchToolCall = None # type: ignore[assignment,misc]
|
||||||
|
|
||||||
from litellm.types.utils import Choices, Message
|
from litellm.types.utils import Choices, Message
|
||||||
|
|
||||||
|
|
@ -457,7 +460,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
|
||||||
accumulated_tool_calls.append(tool_call_dict)
|
accumulated_tool_calls.append(tool_call_dict)
|
||||||
tool_call_index += 1
|
tool_call_index += 1
|
||||||
|
|
||||||
elif isinstance(item, ResponseApplyPatchToolCall):
|
elif ResponseApplyPatchToolCall is not None and isinstance(item, ResponseApplyPatchToolCall):
|
||||||
from litellm.responses.litellm_completion_transformation.transformation import (
|
from litellm.responses.litellm_completion_transformation.transformation import (
|
||||||
LiteLLMCompletionResponsesConfig,
|
LiteLLMCompletionResponsesConfig,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -531,7 +531,7 @@ def test_redis_cache_completion_stream():
|
||||||
response_1_content += chunk.choices[0].delta.content or ""
|
response_1_content += chunk.choices[0].delta.content or ""
|
||||||
print(response_1_content)
|
print(response_1_content)
|
||||||
|
|
||||||
time.sleep(1) # sleep for 0.1 seconds allow set cache to occur
|
time.sleep(5) # sleep for cache write to propagate
|
||||||
response2 = completion(
|
response2 = completion(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=messages,
|
messages=messages,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ async def make_calls_until_budget_exceeded(session, key: str, call_function, **k
|
||||||
while call_count < MAX_CALLS:
|
while call_count < MAX_CALLS:
|
||||||
await call_function(session=session, key=key, **kwargs)
|
await call_function(session=session, key=key, **kwargs)
|
||||||
call_count += 1
|
call_count += 1
|
||||||
|
await asyncio.sleep(0.5) # allow spend tracking to catch up
|
||||||
pytest.fail(f"Budget was not exceeded after {MAX_CALLS} calls")
|
pytest.fail(f"Budget was not exceeded after {MAX_CALLS} calls")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("vars: ", vars(e))
|
print("vars: ", vars(e))
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ async def test_basic_vertex_ai_pass_through_with_spendlog():
|
||||||
|
|
||||||
print("response", response)
|
print("response", response)
|
||||||
|
|
||||||
await asyncio.sleep(20)
|
await asyncio.sleep(40)
|
||||||
spend_after = await call_spend_logs_endpoint()
|
spend_after = await call_spend_logs_endpoint()
|
||||||
print("spend_after", spend_after)
|
print("spend_after", spend_after)
|
||||||
assert (
|
assert (
|
||||||
|
|
|
||||||
|
|
@ -156,8 +156,8 @@ async def test_basic_spend_accuracy():
|
||||||
response = await chat_completion(session, key)
|
response = await chat_completion(session, key)
|
||||||
print("response: ", response)
|
print("response: ", response)
|
||||||
|
|
||||||
# wait 25 seconds for spend to be updated
|
# wait for spend to be updated (batch writes can take a while)
|
||||||
await asyncio.sleep(25)
|
await asyncio.sleep(45)
|
||||||
|
|
||||||
# Get spend information for each entity
|
# Get spend information for each entity
|
||||||
key_info = await get_spend_info(session, "key", key)
|
key_info = await get_spend_info(session, "key", key)
|
||||||
|
|
@ -235,7 +235,7 @@ async def test_long_term_spend_accuracy_with_bursts():
|
||||||
print(f"Burst 1 - Request {i+1}/{BURST_1_REQUESTS} completed")
|
print(f"Burst 1 - Request {i+1}/{BURST_1_REQUESTS} completed")
|
||||||
|
|
||||||
# Wait for spend to be updated
|
# Wait for spend to be updated
|
||||||
await asyncio.sleep(15)
|
await asyncio.sleep(30)
|
||||||
|
|
||||||
# Check intermediate spend
|
# Check intermediate spend
|
||||||
intermediate_key_info = await get_spend_info(session, "key", key)
|
intermediate_key_info = await get_spend_info(session, "key", key)
|
||||||
|
|
@ -248,7 +248,7 @@ async def test_long_term_spend_accuracy_with_bursts():
|
||||||
print(f"Burst 2 - Request {i+1}/{BURST_2_REQUESTS} completed")
|
print(f"Burst 2 - Request {i+1}/{BURST_2_REQUESTS} completed")
|
||||||
|
|
||||||
# Wait for spend to be updated
|
# Wait for spend to be updated
|
||||||
await asyncio.sleep(15)
|
await asyncio.sleep(30)
|
||||||
|
|
||||||
# Get final spend information for each entity
|
# Get final spend information for each entity
|
||||||
key_info = await get_spend_info(session, "key", key)
|
key_info = await get_spend_info(session, "key", key)
|
||||||
|
|
|
||||||
|
|
@ -489,23 +489,20 @@ async def test_model_group_info_e2e():
|
||||||
models = await get_models(session=session, key="sk-1234")
|
models = await get_models(session=session, key="sk-1234")
|
||||||
print(models)
|
print(models)
|
||||||
|
|
||||||
expected_models = [
|
|
||||||
"anthropic/claude-3-5-haiku-20241022",
|
|
||||||
"anthropic/claude-3-opus-20240229",
|
|
||||||
]
|
|
||||||
|
|
||||||
model_group_info = await get_model_group_info(session=session, key="sk-1234")
|
model_group_info = await get_model_group_info(session=session, key="sk-1234")
|
||||||
print(model_group_info)
|
print(model_group_info)
|
||||||
|
|
||||||
has_anthropic_claude_3_5_haiku = False
|
# Check that the endpoint returns data and contains the wildcard
|
||||||
has_anthropic_claude_3_opus = False
|
# anthropic model group from the proxy config
|
||||||
|
has_anthropic_wildcard = False
|
||||||
for model in model_group_info["data"]:
|
for model in model_group_info["data"]:
|
||||||
if model["model_group"] == "anthropic/claude-3-5-haiku-20241022":
|
if model["model_group"] == "anthropic/*":
|
||||||
has_anthropic_claude_3_5_haiku = True
|
has_anthropic_wildcard = True
|
||||||
if model["model_group"] == "anthropic/claude-3-opus-20240229":
|
|
||||||
has_anthropic_claude_3_opus = True
|
|
||||||
|
|
||||||
assert has_anthropic_claude_3_5_haiku and has_anthropic_claude_3_opus
|
assert has_anthropic_wildcard, (
|
||||||
|
f"Expected 'anthropic/*' in model groups, got: "
|
||||||
|
f"{[m['model_group'] for m in model_group_info['data']]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ from litellm.proxy._types import UserAPIKeyAuth
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_retrieve_basic():
|
async def test_vector_store_retrieve_basic():
|
||||||
"""Test basic vector store retrieve functionality."""
|
"""Test basic vector store retrieve functionality."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_test123",
|
"id": "vs_test123",
|
||||||
"object": "vector_store",
|
"object": "vector_store",
|
||||||
|
|
@ -40,6 +38,7 @@ async def test_vector_store_retrieve_basic():
|
||||||
"litellm.vector_stores.main.aretrieve",
|
"litellm.vector_stores.main.aretrieve",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_retrieve:
|
) as mock_retrieve:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_retrieve(
|
result = await router.avector_store_retrieve(
|
||||||
vector_store_id="vs_test123",
|
vector_store_id="vs_test123",
|
||||||
custom_llm_provider="openai",
|
custom_llm_provider="openai",
|
||||||
|
|
@ -54,8 +53,6 @@ async def test_vector_store_retrieve_basic():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_list_basic():
|
async def test_vector_store_list_basic():
|
||||||
"""Test basic vector store list functionality."""
|
"""Test basic vector store list functionality."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
"data": [
|
"data": [
|
||||||
|
|
@ -81,6 +78,7 @@ async def test_vector_store_list_basic():
|
||||||
"litellm.vector_stores.main.alist",
|
"litellm.vector_stores.main.alist",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_list:
|
) as mock_list:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_list(
|
result = await router.avector_store_list(
|
||||||
limit=20,
|
limit=20,
|
||||||
order="desc",
|
order="desc",
|
||||||
|
|
@ -96,8 +94,6 @@ async def test_vector_store_list_basic():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_update_basic():
|
async def test_vector_store_update_basic():
|
||||||
"""Test basic vector store update functionality."""
|
"""Test basic vector store update functionality."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_test123",
|
"id": "vs_test123",
|
||||||
"object": "vector_store",
|
"object": "vector_store",
|
||||||
|
|
@ -111,6 +107,7 @@ async def test_vector_store_update_basic():
|
||||||
"litellm.vector_stores.main.aupdate",
|
"litellm.vector_stores.main.aupdate",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_update:
|
) as mock_update:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_update(
|
result = await router.avector_store_update(
|
||||||
vector_store_id="vs_test123",
|
vector_store_id="vs_test123",
|
||||||
name="Updated Name",
|
name="Updated Name",
|
||||||
|
|
@ -127,8 +124,6 @@ async def test_vector_store_update_basic():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_delete_basic():
|
async def test_vector_store_delete_basic():
|
||||||
"""Test basic vector store delete functionality."""
|
"""Test basic vector store delete functionality."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_test123",
|
"id": "vs_test123",
|
||||||
"object": "vector_store.deleted",
|
"object": "vector_store.deleted",
|
||||||
|
|
@ -139,6 +134,7 @@ async def test_vector_store_delete_basic():
|
||||||
"litellm.vector_stores.main.adelete",
|
"litellm.vector_stores.main.adelete",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_delete:
|
) as mock_delete:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_delete(
|
result = await router.avector_store_delete(
|
||||||
vector_store_id="vs_test123",
|
vector_store_id="vs_test123",
|
||||||
custom_llm_provider="openai",
|
custom_llm_provider="openai",
|
||||||
|
|
@ -153,8 +149,6 @@ async def test_vector_store_delete_basic():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_vector_store_retrieve():
|
async def test_async_vector_store_retrieve():
|
||||||
"""Test async vector store retrieve."""
|
"""Test async vector store retrieve."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_async123",
|
"id": "vs_async123",
|
||||||
"object": "vector_store",
|
"object": "vector_store",
|
||||||
|
|
@ -165,6 +159,7 @@ async def test_async_vector_store_retrieve():
|
||||||
"litellm.vector_stores.main.aretrieve",
|
"litellm.vector_stores.main.aretrieve",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_aretrieve:
|
) as mock_aretrieve:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_retrieve(
|
result = await router.avector_store_retrieve(
|
||||||
vector_store_id="vs_async123",
|
vector_store_id="vs_async123",
|
||||||
custom_llm_provider="openai",
|
custom_llm_provider="openai",
|
||||||
|
|
@ -177,8 +172,6 @@ async def test_async_vector_store_retrieve():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_vector_store_list():
|
async def test_async_vector_store_list():
|
||||||
"""Test async vector store list."""
|
"""Test async vector store list."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
"data": [{"id": "vs_1"}, {"id": "vs_2"}],
|
"data": [{"id": "vs_1"}, {"id": "vs_2"}],
|
||||||
|
|
@ -188,6 +181,7 @@ async def test_async_vector_store_list():
|
||||||
"litellm.vector_stores.main.alist",
|
"litellm.vector_stores.main.alist",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_alist:
|
) as mock_alist:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_list(
|
result = await router.avector_store_list(
|
||||||
limit=10,
|
limit=10,
|
||||||
custom_llm_provider="openai",
|
custom_llm_provider="openai",
|
||||||
|
|
@ -200,8 +194,6 @@ async def test_async_vector_store_list():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_vector_store_update():
|
async def test_async_vector_store_update():
|
||||||
"""Test async vector store update."""
|
"""Test async vector store update."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_async123",
|
"id": "vs_async123",
|
||||||
"name": "Updated Async Name",
|
"name": "Updated Async Name",
|
||||||
|
|
@ -211,6 +203,7 @@ async def test_async_vector_store_update():
|
||||||
"litellm.vector_stores.main.aupdate",
|
"litellm.vector_stores.main.aupdate",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_aupdate:
|
) as mock_aupdate:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_update(
|
result = await router.avector_store_update(
|
||||||
vector_store_id="vs_async123",
|
vector_store_id="vs_async123",
|
||||||
name="Updated Async Name",
|
name="Updated Async Name",
|
||||||
|
|
@ -224,8 +217,6 @@ async def test_async_vector_store_update():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_vector_store_delete():
|
async def test_async_vector_store_delete():
|
||||||
"""Test async vector store delete."""
|
"""Test async vector store delete."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"id": "vs_async123",
|
"id": "vs_async123",
|
||||||
"deleted": True,
|
"deleted": True,
|
||||||
|
|
@ -235,6 +226,7 @@ async def test_async_vector_store_delete():
|
||||||
"litellm.vector_stores.main.adelete",
|
"litellm.vector_stores.main.adelete",
|
||||||
new=AsyncMock(return_value=mock_response),
|
new=AsyncMock(return_value=mock_response),
|
||||||
) as mock_adelete:
|
) as mock_adelete:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = await router.avector_store_delete(
|
result = await router.avector_store_delete(
|
||||||
vector_store_id="vs_async123",
|
vector_store_id="vs_async123",
|
||||||
custom_llm_provider="openai",
|
custom_llm_provider="openai",
|
||||||
|
|
@ -247,8 +239,6 @@ async def test_async_vector_store_delete():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_list_with_pagination():
|
async def test_vector_store_list_with_pagination():
|
||||||
"""Test vector store list with pagination parameters."""
|
"""Test vector store list with pagination parameters."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
mock_response = {
|
mock_response = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
"data": [{"id": f"vs_{i}"} for i in range(5)],
|
"data": [{"id": f"vs_{i}"} for i in range(5)],
|
||||||
|
|
@ -261,6 +251,7 @@ async def test_vector_store_list_with_pagination():
|
||||||
"litellm.vector_stores.main.list",
|
"litellm.vector_stores.main.list",
|
||||||
return_value=mock_response,
|
return_value=mock_response,
|
||||||
) as mock_list:
|
) as mock_list:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = router.vector_store_list(
|
result = router.vector_store_list(
|
||||||
limit=5,
|
limit=5,
|
||||||
after="vs_previous",
|
after="vs_previous",
|
||||||
|
|
@ -281,8 +272,6 @@ async def test_vector_store_list_with_pagination():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_vector_store_update_with_expires_after():
|
async def test_vector_store_update_with_expires_after():
|
||||||
"""Test vector store update with expiration policy."""
|
"""Test vector store update with expiration policy."""
|
||||||
router = litellm.Router(model_list=[])
|
|
||||||
|
|
||||||
expires_after = {
|
expires_after = {
|
||||||
"anchor": "last_active_at",
|
"anchor": "last_active_at",
|
||||||
"days": 7,
|
"days": 7,
|
||||||
|
|
@ -298,6 +287,7 @@ async def test_vector_store_update_with_expires_after():
|
||||||
"litellm.vector_stores.main.update",
|
"litellm.vector_stores.main.update",
|
||||||
return_value=mock_response,
|
return_value=mock_response,
|
||||||
) as mock_update:
|
) as mock_update:
|
||||||
|
router = litellm.Router(model_list=[])
|
||||||
result = router.vector_store_update(
|
result = router.vector_store_update(
|
||||||
vector_store_id="vs_test123",
|
vector_store_id="vs_test123",
|
||||||
expires_after=expires_after,
|
expires_after=expires_after,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue