From 74d8605f5c377241368a64855051cf25b35ccaf0 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 14 Jun 2024 21:20:40 -0700 Subject: [PATCH] fix(slack_alerting.py): check if webhook is in alerting list before triggering it Fixes https://github.com/BerriAI/litellm/issues/4193 --- litellm/integrations/slack_alerting.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index 1dc04cf1082..228353318ed 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -788,7 +788,13 @@ class SlackAlerting(CustomLogger): response_cost: Optional[float], max_budget: Optional[float], ): - if end_user_id is not None and token is not None and response_cost is not None: + if ( + self.alerting is not None + and "webhook" in self.alerting + and end_user_id is not None + and token is not None + and response_cost is not None + ): # log customer spend event = WebhookEvent( spend=response_cost, @@ -1195,6 +1201,9 @@ Model Info: Currently only implemented for budget alerts Returns -> True if sent, False if not. + + Raises Exception + - if WEBHOOK_URL is not set """ webhook_url = os.getenv("WEBHOOK_URL", None)