mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
chore: lint
This commit is contained in:
parent
271ee0959b
commit
fb00b38fcd
4 changed files with 53 additions and 50 deletions
|
|
@ -26,7 +26,9 @@ class FocusDestinationFactory:
|
|||
)
|
||||
if provider_lower == "s3":
|
||||
return FocusS3Destination(prefix=prefix, config=normalized_config)
|
||||
raise NotImplementedError(f"Provider '{provider}' not supported for Focus export")
|
||||
raise NotImplementedError(
|
||||
f"Provider '{provider}' not supported for Focus export"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _resolve_config(
|
||||
|
|
@ -50,9 +52,7 @@ class FocusDestinationFactory:
|
|||
or os.getenv("FOCUS_S3_SESSION_TOKEN"),
|
||||
}
|
||||
if not resolved.get("bucket_name"):
|
||||
raise ValueError(
|
||||
"FOCUS_S3_BUCKET_NAME must be provided for S3 exports"
|
||||
)
|
||||
raise ValueError("FOCUS_S3_BUCKET_NAME must be provided for S3 exports")
|
||||
return {k: v for k, v in resolved.items() if v is not None}
|
||||
raise NotImplementedError(
|
||||
f"Provider '{provider}' not supported for Focus export configuration"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from litellm.integrations.custom_logger import CustomLogger
|
|||
|
||||
from .database import FocusLiteLLMDatabase
|
||||
from .destinations import (
|
||||
FocusDestination,
|
||||
FocusDestinationFactory,
|
||||
FocusTimeWindow,
|
||||
)
|
||||
|
|
@ -50,9 +49,7 @@ class FocusLogger(CustomLogger):
|
|||
self.export_format = (
|
||||
export_format or os.getenv("FOCUS_FORMAT") or "parquet"
|
||||
).lower()
|
||||
self.frequency = (
|
||||
frequency or os.getenv("FOCUS_FREQUENCY") or "hourly"
|
||||
).lower()
|
||||
self.frequency = (frequency or os.getenv("FOCUS_FREQUENCY") or "hourly").lower()
|
||||
self.cron_offset_minute = (
|
||||
cron_offset_minute
|
||||
if cron_offset_minute is not None
|
||||
|
|
@ -90,7 +87,9 @@ class FocusLogger(CustomLogger):
|
|||
) -> None:
|
||||
"""Public hook to trigger export immediately."""
|
||||
if bool(start_time_utc) ^ bool(end_time_utc):
|
||||
raise ValueError("start_time_utc and end_time_utc must be provided together")
|
||||
raise ValueError(
|
||||
"start_time_utc and end_time_utc must be provided together"
|
||||
)
|
||||
|
||||
if start_time_utc and end_time_utc:
|
||||
window = FocusTimeWindow(
|
||||
|
|
@ -160,7 +159,6 @@ class FocusLogger(CustomLogger):
|
|||
scheduler: AsyncIOScheduler,
|
||||
) -> None:
|
||||
"""Register the export cron/interval job with the provided scheduler."""
|
||||
from litellm.integrations.custom_logger import CustomLogger
|
||||
|
||||
focus_loggers: List[
|
||||
CustomLogger
|
||||
|
|
@ -168,7 +166,9 @@ class FocusLogger(CustomLogger):
|
|||
callback_type=FocusLogger
|
||||
)
|
||||
if not focus_loggers:
|
||||
verbose_logger.debug("No Focus export logger registered; skipping scheduler")
|
||||
verbose_logger.debug(
|
||||
"No Focus export logger registered; skipping scheduler"
|
||||
)
|
||||
return
|
||||
|
||||
focus_logger = cast(FocusLogger, focus_loggers[0])
|
||||
|
|
@ -218,7 +218,9 @@ class FocusLogger(CustomLogger):
|
|||
|
||||
normalized = self._transformer.transform(data)
|
||||
if normalized.is_empty():
|
||||
verbose_logger.debug("Focus export: normalized data empty for window %s", window)
|
||||
verbose_logger.debug(
|
||||
"Focus export: normalized data empty for window %s", window
|
||||
)
|
||||
return
|
||||
|
||||
await self._serialize_and_upload(normalized, window)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class FocusTransformer:
|
|||
return col.dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
DEC = pl.Decimal(18, 6)
|
||||
|
||||
def dec(col):
|
||||
return col.cast(DEC)
|
||||
|
||||
|
|
|
|||
|
|
@ -533,9 +533,9 @@ except ImportError:
|
|||
server_root_path = os.getenv("SERVER_ROOT_PATH", "")
|
||||
_license_check = LicenseCheck()
|
||||
premium_user: bool = _license_check.is_premium()
|
||||
premium_user_data: Optional["EnterpriseLicenseData"] = (
|
||||
_license_check.airgapped_license_data
|
||||
)
|
||||
premium_user_data: Optional[
|
||||
"EnterpriseLicenseData"
|
||||
] = _license_check.airgapped_license_data
|
||||
global_max_parallel_request_retries_env: Optional[str] = os.getenv(
|
||||
"LITELLM_GLOBAL_MAX_PARALLEL_REQUEST_RETRIES"
|
||||
)
|
||||
|
|
@ -1083,9 +1083,7 @@ try:
|
|||
# In non-root Docker, we restructure in /var/lib/litellm/ui.
|
||||
try:
|
||||
_restructure_ui_html_files(ui_path)
|
||||
verbose_proxy_logger.info(
|
||||
f"Restructured UI directory: {ui_path}"
|
||||
)
|
||||
verbose_proxy_logger.info(f"Restructured UI directory: {ui_path}")
|
||||
except PermissionError as e:
|
||||
verbose_proxy_logger.exception(
|
||||
f"Permission error while restructuring UI directory {ui_path}: {e}"
|
||||
|
|
@ -1171,9 +1169,9 @@ master_key: Optional[str] = None
|
|||
config_agents: Optional[List[AgentConfig]] = None
|
||||
otel_logging = False
|
||||
prisma_client: Optional[PrismaClient] = None
|
||||
shared_aiohttp_session: Optional["ClientSession"] = (
|
||||
None # Global shared session for connection reuse
|
||||
)
|
||||
shared_aiohttp_session: Optional[
|
||||
"ClientSession"
|
||||
] = None # Global shared session for connection reuse
|
||||
user_api_key_cache = DualCache(
|
||||
default_in_memory_ttl=UserAPIKeyCacheTTLEnum.in_memory_cache_ttl.value
|
||||
)
|
||||
|
|
@ -1181,9 +1179,9 @@ model_max_budget_limiter = _PROXY_VirtualKeyModelMaxBudgetLimiter(
|
|||
dual_cache=user_api_key_cache
|
||||
)
|
||||
litellm.logging_callback_manager.add_litellm_callback(model_max_budget_limiter)
|
||||
redis_usage_cache: Optional[RedisCache] = (
|
||||
None # redis cache used for tracking spend, tpm/rpm limits
|
||||
)
|
||||
redis_usage_cache: Optional[
|
||||
RedisCache
|
||||
] = None # redis cache used for tracking spend, tpm/rpm limits
|
||||
polling_via_cache_enabled: Union[Literal["all"], List[str], bool] = False
|
||||
polling_cache_ttl: int = 3600 # Default 1 hour TTL for polling cache
|
||||
user_custom_auth = None
|
||||
|
|
@ -1522,9 +1520,9 @@ async def update_cache( # noqa: PLR0915
|
|||
_id = "team_id:{}".format(team_id)
|
||||
try:
|
||||
# Fetch the existing cost for the given user
|
||||
existing_spend_obj: Optional[LiteLLM_TeamTable] = (
|
||||
await user_api_key_cache.async_get_cache(key=_id)
|
||||
)
|
||||
existing_spend_obj: Optional[
|
||||
LiteLLM_TeamTable
|
||||
] = await user_api_key_cache.async_get_cache(key=_id)
|
||||
if existing_spend_obj is None:
|
||||
# do nothing if team not in api key cache
|
||||
return
|
||||
|
|
@ -1876,7 +1874,6 @@ class ProxyConfig:
|
|||
"environment_variables" in config_to_save
|
||||
and config_to_save["environment_variables"]
|
||||
):
|
||||
|
||||
# decrypt the environment_variables - in case a caller function has already encrypted the environment_variables
|
||||
decrypted_env_vars = self._decrypt_and_set_db_env_variables(
|
||||
environment_variables=config_to_save["environment_variables"],
|
||||
|
|
@ -2794,21 +2791,21 @@ class ProxyConfig:
|
|||
verbose_proxy_logger.debug(f"_alerting_callbacks: {general_settings}")
|
||||
if _alerting_callbacks is None:
|
||||
return
|
||||
|
||||
|
||||
# Ensure proxy_logging_obj.alerting is set for all alerting types
|
||||
_alerting_value = general_settings.get("alerting", None)
|
||||
verbose_proxy_logger.debug(f"_load_alerting_settings: Calling update_values with alerting={_alerting_value}")
|
||||
verbose_proxy_logger.debug(
|
||||
f"_load_alerting_settings: Calling update_values with alerting={_alerting_value}"
|
||||
)
|
||||
proxy_logging_obj.update_values(
|
||||
alerting=_alerting_value,
|
||||
alerting_threshold=general_settings.get("alerting_threshold", 600),
|
||||
alert_types=general_settings.get("alert_types", None),
|
||||
alert_to_webhook_url=general_settings.get(
|
||||
"alert_to_webhook_url", None
|
||||
),
|
||||
alert_to_webhook_url=general_settings.get("alert_to_webhook_url", None),
|
||||
alerting_args=general_settings.get("alerting_args", None),
|
||||
redis_cache=redis_usage_cache,
|
||||
)
|
||||
|
||||
|
||||
for _alert in _alerting_callbacks:
|
||||
if _alert == "slack":
|
||||
# [OLD] v0 implementation - already handled by update_values above
|
||||
|
|
@ -3279,7 +3276,7 @@ class ProxyConfig:
|
|||
proxy_logging_obj: ProxyLogging
|
||||
"""
|
||||
_general_settings = config_data.get("general_settings", {})
|
||||
|
||||
|
||||
if _general_settings is not None and "alerting" in _general_settings:
|
||||
if (
|
||||
general_settings is not None
|
||||
|
|
@ -3294,7 +3291,8 @@ class ProxyConfig:
|
|||
_merged_alerting = list(_yaml_alerting.union(_db_alerting))
|
||||
# Preserve order: YAML values first, then DB values
|
||||
_merged_alerting = list(general_settings["alerting"]) + [
|
||||
item for item in _general_settings["alerting"]
|
||||
item
|
||||
for item in _general_settings["alerting"]
|
||||
if item not in general_settings["alerting"]
|
||||
]
|
||||
verbose_proxy_logger.debug(
|
||||
|
|
@ -3605,7 +3603,6 @@ class ProxyConfig:
|
|||
await self._init_vector_stores_in_db(prisma_client=prisma_client)
|
||||
|
||||
if self._should_load_db_object(object_type="vector_store_indexes"):
|
||||
|
||||
await self._init_vector_store_indexes_in_db(prisma_client=prisma_client)
|
||||
|
||||
if self._should_load_db_object(object_type="mcp"):
|
||||
|
|
@ -3804,10 +3801,10 @@ class ProxyConfig:
|
|||
)
|
||||
|
||||
try:
|
||||
guardrails_in_db: List[Guardrail] = (
|
||||
await GuardrailRegistry.get_all_guardrails_from_db(
|
||||
prisma_client=prisma_client
|
||||
)
|
||||
guardrails_in_db: List[
|
||||
Guardrail
|
||||
] = await GuardrailRegistry.get_all_guardrails_from_db(
|
||||
prisma_client=prisma_client
|
||||
)
|
||||
verbose_proxy_logger.debug(
|
||||
"guardrails from the DB %s", str(guardrails_in_db)
|
||||
|
|
@ -4134,9 +4131,9 @@ async def initialize( # noqa: PLR0915
|
|||
user_api_base = api_base
|
||||
dynamic_config[user_model]["api_base"] = api_base
|
||||
if api_version:
|
||||
os.environ["AZURE_API_VERSION"] = (
|
||||
api_version # set this for azure - litellm can read this from the env
|
||||
)
|
||||
os.environ[
|
||||
"AZURE_API_VERSION"
|
||||
] = api_version # set this for azure - litellm can read this from the env
|
||||
if max_tokens: # model-specific param
|
||||
dynamic_config[user_model]["max_tokens"] = max_tokens
|
||||
if temperature: # model-specific param
|
||||
|
|
@ -4654,10 +4651,14 @@ class ProxyStartupEvent:
|
|||
replace_existing=True,
|
||||
misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME,
|
||||
)
|
||||
verbose_proxy_logger.info("Responses cost check job scheduled successfully")
|
||||
verbose_proxy_logger.info(
|
||||
"Responses cost check job scheduled successfully"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
verbose_proxy_logger.debug(f"Failed to setup responses cost checking: {e}")
|
||||
verbose_proxy_logger.debug(
|
||||
f"Failed to setup responses cost checking: {e}"
|
||||
)
|
||||
verbose_proxy_logger.debug(
|
||||
"Checking responses cost for LiteLLM Managed Files is an Enterprise Feature. Skipping..."
|
||||
)
|
||||
|
|
@ -5944,7 +5945,6 @@ async def realtime_websocket_endpoint(
|
|||
),
|
||||
user_api_key_dict=Depends(user_api_key_auth_websocket),
|
||||
):
|
||||
|
||||
await websocket.accept()
|
||||
|
||||
# Only use explicit parameters, not all query params
|
||||
|
|
@ -9532,9 +9532,9 @@ async def get_config_list(
|
|||
hasattr(sub_field_info, "description")
|
||||
and sub_field_info.description is not None
|
||||
):
|
||||
nested_fields[idx].field_description = (
|
||||
sub_field_info.description
|
||||
)
|
||||
nested_fields[
|
||||
idx
|
||||
].field_description = sub_field_info.description
|
||||
idx += 1
|
||||
|
||||
_stored_in_db = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue