mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
Ollama ssl verify = False + Spend Logs reliability fixes (#7931)
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 13s
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 13s
* fix(http_handler.py): support passing ssl verify dynamically and using the correct httpx client based on passed ssl verify param
Fixes https://github.com/BerriAI/litellm/issues/6499
* feat(llm_http_handler.py): support passing `ssl_verify=False` dynamically in call args
Closes https://github.com/BerriAI/litellm/issues/6499
* fix(proxy/utils.py): prevent bad logs from breaking all cost tracking + reset list regardless of success/failure
prevents malformed logs from causing all spend tracking to break since they're constantly retried
* test(test_proxy_utils.py): add test to ensure bad log is dropped
* test(test_proxy_utils.py): ensure in-memory spend logs reset after bad log error
* test(test_user_api_key_auth.py): add unit test to ensure end user id as str works
* fix(auth_utils.py): ensure extracted end user id is always a str
prevents db cost tracking errors
* test(test_auth_utils.py): ensure get end user id from request body always returns a string
* test: update tests
* test: skip bedrock test- behaviour now supported
* test: fix testing
* refactor(spend_tracking_utils.py): reduce size of get_logging_payload
* test: fix test
* bump: version 1.59.4 → 1.59.5
* Revert "bump: version 1.59.4 → 1.59.5"
This reverts commit 1182b46b2e
.
* fix(utils.py): fix spend logs retry logic
* fix(spend_tracking_utils.py): fix get tags
* fix(spend_tracking_utils.py): fix end user id spend tracking on pass-through endpoints
This commit is contained in:
parent
851b0c4c4d
commit
1e011b66d3
17 changed files with 406 additions and 187 deletions
|
@ -1497,6 +1497,62 @@ def test_custom_openapi(mock_get_openapi_schema):
|
|||
assert openapi_schema is not None
|
||||
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, AsyncMock
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
from litellm.proxy.utils import ProxyUpdateSpend
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_end_user_transactions_reset():
|
||||
# Setup
|
||||
mock_client = MagicMock()
|
||||
mock_client.end_user_list_transactons = {"1": 10.0} # Bad log
|
||||
mock_client.db.tx = AsyncMock(side_effect=Exception("DB Error"))
|
||||
|
||||
# Call function - should raise error
|
||||
with pytest.raises(Exception):
|
||||
await ProxyUpdateSpend.update_end_user_spend(
|
||||
n_retry_times=0, prisma_client=mock_client, proxy_logging_obj=MagicMock()
|
||||
)
|
||||
|
||||
# Verify cleanup happened
|
||||
assert (
|
||||
mock_client.end_user_list_transactons == {}
|
||||
), "Transactions list should be empty after error"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spend_logs_cleanup_after_error():
|
||||
# Setup test data
|
||||
mock_client = MagicMock()
|
||||
mock_client.spend_log_transactions = [
|
||||
{"id": 1, "amount": 10.0},
|
||||
{"id": 2, "amount": 20.0},
|
||||
{"id": 3, "amount": 30.0},
|
||||
]
|
||||
# Make the DB operation fail
|
||||
mock_client.db.litellm_spendlogs.create_many = AsyncMock(
|
||||
side_effect=Exception("DB Error")
|
||||
)
|
||||
|
||||
original_logs = mock_client.spend_log_transactions.copy()
|
||||
|
||||
# Call function - should raise error
|
||||
with pytest.raises(Exception):
|
||||
await ProxyUpdateSpend.update_spend_logs(
|
||||
n_retry_times=0,
|
||||
prisma_client=mock_client,
|
||||
db_writer_client=None, # Test DB write path
|
||||
proxy_logging_obj=MagicMock(),
|
||||
)
|
||||
|
||||
# Verify the first batch was removed from spend_log_transactions
|
||||
assert (
|
||||
mock_client.spend_log_transactions == original_logs[100:]
|
||||
), "Should remove processed logs even after error"
|
||||
|
||||
def test_provider_specific_header():
|
||||
from litellm.proxy.litellm_pre_call_utils import (
|
||||
add_provider_specific_headers_to_request,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue