From 9647c6158ee90a7db621eed1abec302dc4e400d7 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 31 Oct 2024 18:15:35 +0530 Subject: [PATCH] fix use failing_model as cache key for failed_tracking_alert --- litellm/integrations/SlackAlerting/slack_alerting.py | 12 +++++++++--- litellm/proxy/proxy_config.yaml | 10 +++++----- litellm/proxy/proxy_server.py | 1 + litellm/proxy/utils.py | 9 +++++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/litellm/integrations/SlackAlerting/slack_alerting.py b/litellm/integrations/SlackAlerting/slack_alerting.py index dbe9e4161da..85d54a337d1 100644 --- a/litellm/integrations/SlackAlerting/slack_alerting.py +++ b/litellm/integrations/SlackAlerting/slack_alerting.py @@ -550,8 +550,14 @@ class SlackAlerting(CustomBatchLogger): alerting_metadata=alerting_metadata, ) - async def failed_tracking_alert(self, error_message: str): - """Raise alert when tracking failed for specific model""" + async def failed_tracking_alert(self, error_message: str, failing_model: str): + """ + Raise alert when tracking failed for specific model + + Args: + error_message (str): Error message + failing_model (str): Model that failed tracking + """ if self.alerting is None or self.alert_types is None: # do nothing if alerting is not switched on return @@ -560,7 +566,7 @@ class SlackAlerting(CustomBatchLogger): _cache: DualCache = self.internal_usage_cache message = "Failed Tracking Cost for " + error_message - _cache_key = "budget_alerts:failed_tracking:{}".format(message) + _cache_key = "budget_alerts:failed_tracking:{}".format(failing_model) result = await _cache.async_get_cache(key=_cache_key) if result is None: await self.send_alert( diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 95eff095c22..23834f75970 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -1,11 +1,11 @@ model_list: - model_name: gpt-4o litellm_params: - model: gpt-4o + model: openai/gpt-5 api_key: os.environ/OPENAI_API_KEY api_base: https://exampleopenaiendpoint-production.up.railway.app/ -litellm_settings: - callbacks: ["prometheus"] - service_callback: ["prometheus_system"] - cache: true + +general_settings: + alerting: ["slack"] + alerting_threshold: 0.001 diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 1f0271f3451..402063177a6 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -845,6 +845,7 @@ async def _PROXY_track_cost_callback( asyncio.create_task( proxy_logging_obj.failed_tracking_alert( error_message=error_msg, + failing_model=model, ) ) verbose_proxy_logger.debug("error in tracking cost callback - %s", e) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 656e97a6c5c..8919da97861 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -667,13 +667,18 @@ class ProxyLogging: raise e return data - async def failed_tracking_alert(self, error_message: str): + async def failed_tracking_alert( + self, + error_message: str, + failing_model: str, + ): if self.alerting is None: return if self.slack_alerting_instance: await self.slack_alerting_instance.failed_tracking_alert( - error_message=error_message + error_message=error_message, + failing_model=failing_model, ) async def budget_alerts(