fix(slack_alerting.py): check if webhook is in alerting list before triggering it

Fixes https://github.com/BerriAI/litellm/issues/4193
This commit is contained in:
Krrish Dholakia 2024-06-14 21:20:40 -07:00
parent cb7521b11f
commit 74d8605f5c

View file

@ -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)