style: apply Black formatting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Smeet Agrawal 2026-04-09 11:22:59 +05:30
parent cb481f5615
commit 87b3e92a2f
3 changed files with 49 additions and 33 deletions

View file

@ -54,7 +54,7 @@ from litellm.constants import (
LITELLM_SETTINGS_SAFE_DB_OVERRIDES,
LITELLM_UI_ALLOW_HEADERS,
LITELLM_UI_SESSION_DURATION,
DAILY_TAG_SPEND_BATCH_MULTIPLIER
DAILY_TAG_SPEND_BATCH_MULTIPLIER,
)
from litellm.litellm_core_utils.litellm_logging import (
_init_custom_logger_compatible_class,
@ -2330,9 +2330,13 @@ def _write_health_state_to_router_cache(
exception_status = getattr(original_exception, "status_code", 500)
if llm_router.health_check_ignore_transient_errors and exception_status in (
429,
408,
if (
llm_router.health_check_ignore_transient_errors
and exception_status
in (
429,
408,
)
):
continue
@ -6301,7 +6305,9 @@ class ProxyStartupEvent:
### UPDATE DAILY TAG SPEND (separate scheduler job with longer interval) ###
## Reduces QPS as there are more tags for a single request
tag_spend_update_interval = int(batch_writing_interval * DAILY_TAG_SPEND_BATCH_MULTIPLIER)
tag_spend_update_interval = int(
batch_writing_interval * DAILY_TAG_SPEND_BATCH_MULTIPLIER
)
from litellm.proxy.utils import update_daily_tag_spend
scheduler.add_job(

View file

@ -1899,9 +1899,9 @@ class ProxyLogging:
normalized_call_type = CallTypes.aembedding.value
if normalized_call_type is not None:
litellm_logging_obj.call_type = normalized_call_type
litellm_logging_obj.model_call_details[
"call_type"
] = normalized_call_type
litellm_logging_obj.model_call_details["call_type"] = (
normalized_call_type
)
# Pass-through endpoints are logged via the callback loop's
# async_post_call_failure_hook — skip pre_call and failure handlers.
if litellm_logging_obj.call_type == CallTypes.pass_through.value:
@ -2525,8 +2525,7 @@ class PrismaClient:
required_view = "LiteLLM_VerificationTokenView"
expected_views_str = ", ".join(f"'{view}'" for view in expected_views)
pg_schema = os.getenv("DATABASE_SCHEMA", "public")
ret = await self.db.query_raw(
f"""
ret = await self.db.query_raw(f"""
WITH existing_views AS (
SELECT viewname
FROM pg_views
@ -2538,8 +2537,7 @@ class PrismaClient:
(SELECT COUNT(*) FROM existing_views) AS view_count,
ARRAY_AGG(viewname) AS view_names
FROM existing_views
"""
)
""")
expected_total_views = len(expected_views)
if ret[0]["view_count"] == expected_total_views:
verbose_proxy_logger.info("All necessary views exist!")
@ -2548,8 +2546,7 @@ class PrismaClient:
## check if required view exists ##
if ret[0]["view_names"] and required_view not in ret[0]["view_names"]:
await self.health_check() # make sure we can connect to db
await self.db.execute_raw(
"""
await self.db.execute_raw("""
CREATE VIEW "LiteLLM_VerificationTokenView" AS
SELECT
v.*,
@ -2559,8 +2556,7 @@ class PrismaClient:
t.rpm_limit AS team_rpm_limit
FROM "LiteLLM_VerificationToken" v
LEFT JOIN "LiteLLM_TeamTable" t ON v.team_id = t.team_id;
"""
)
""")
verbose_proxy_logger.info(
"LiteLLM_VerificationTokenView Created in DB!"
@ -4869,25 +4865,27 @@ async def update_daily_tag_spend(
):
"""
Separate scheduler job to commit daily tag spend updates.
Runs at a longer interval (2.3x default) than the main update_spend job
to reduce query contention for DailyTagSpend table.
This is called by a dedicated scheduler job and does NOT process:
- Regular spend updates (user, key, team, org)
- End-user spend
- Agent spend
- Spend logs
Only processes tag spend transactions from the daily_tag_spend_update_queue.
Args:
prisma_client: PrismaClient instance
proxy_logging_obj: ProxyLogging instance for error handling
"""
n_retry_times = 3
try:
if proxy_logging_obj.db_spend_update_writer.redis_update_buffer._should_commit_spend_updates_to_redis():
if (
proxy_logging_obj.db_spend_update_writer.redis_update_buffer._should_commit_spend_updates_to_redis()
):
await proxy_logging_obj.db_spend_update_writer._commit_daily_tag_spend_to_db_with_redis(
prisma_client=prisma_client,
n_retry_times=n_retry_times,

View file

@ -18,7 +18,17 @@ def _apply_server_root_path_replacements(
litellm_asset_prefix: str = "/litellm-asset-prefix",
) -> None:
"""Replicate the replacement logic from proxy_server.py for testing."""
skip_extensions = (".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2", ".ttf", ".eot")
skip_extensions = (
".png",
".jpg",
".jpeg",
".gif",
".ico",
".woff",
".woff2",
".ttf",
".eot",
)
for root, _, files in os.walk(ui_path):
for filename in files:
if filename.endswith(skip_extensions):
@ -28,8 +38,12 @@ def _apply_server_root_path_replacements(
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
modified = content.replace(litellm_asset_prefix, server_root_path)
modified = modified.replace('"/ui/assets/', f'"{server_root_path}/ui/assets/')
modified = modified.replace("'/ui/assets/", f"'{server_root_path}/ui/assets/")
modified = modified.replace(
'"/ui/assets/', f'"{server_root_path}/ui/assets/'
)
modified = modified.replace(
"'/ui/assets/", f"'{server_root_path}/ui/assets/"
)
modified = modified.replace(
"/litellm/.well-known/litellm-ui-config",
f"{server_root_path}/.well-known/litellm-ui-config",
@ -62,12 +76,12 @@ def test_absolute_ui_asset_paths_rewritten_with_server_root_path(tmp_path):
_apply_server_root_path_replacements(str(ui_path), server_root_path)
result = js_file.read_text()
assert f'"{server_root_path}/ui/assets/logos/"' in result, (
f"Absolute /ui/assets/ path not rewritten to include SERVER_ROOT_PATH. Got: {result}"
)
assert '"/ui/assets/logos/"' not in result, (
"Old absolute /ui/assets/ path should have been replaced"
)
assert (
f'"{server_root_path}/ui/assets/logos/"' in result
), f"Absolute /ui/assets/ path not rewritten to include SERVER_ROOT_PATH. Got: {result}"
assert (
'"/ui/assets/logos/"' not in result
), "Old absolute /ui/assets/ path should have been replaced"
def test_litellm_asset_prefix_still_rewritten(tmp_path):
@ -76,9 +90,7 @@ def test_litellm_asset_prefix_still_rewritten(tmp_path):
ui_path.mkdir()
js_file = ui_path / "bundle.js"
js_file.write_text(
'let t="/litellm-asset-prefix/_next/",eq="/ui/assets/logos/"'
)
js_file.write_text('let t="/litellm-asset-prefix/_next/",eq="/ui/assets/logos/"')
server_root_path = "/myapp"
_apply_server_root_path_replacements(str(ui_path), server_root_path)