Skip to content

Commit db1b418

Browse files
committed
fix: update alert type formatting to handle enum names in Slack messages
1 parent 92f631d commit db1b418

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

litellm/integrations/SlackAlerting/slack_alerting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,9 @@ async def send_alert(
13671367
# Get the current timestamp
13681368
current_time = datetime.now().strftime("%H:%M:%S")
13691369
_proxy_base_url = os.getenv("PROXY_BASE_URL", None)
1370-
alert_type_formatted = f"Alert type: `{alert_type}`\n"
1370+
# Use .name if it's an enum, otherwise use as is
1371+
alert_type_name = getattr(alert_type, 'name', alert_type)
1372+
alert_type_formatted = f"Alert type: `{alert_type_name}`"
13711373
if alert_type == "daily_reports" or alert_type == "new_model_added":
13721374
formatted_message = alert_type_formatted + message
13731375
else:

tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ def test_alert_type_in_formatted_message(self, mock_datetime):
188188
current_time = "12:34:56"
189189

190190
# Test the specific formatting logic we're interested in
191-
alert_type_formatted = f"Alert type: `{alert_type}`\n"
191+
alert_type_formatted = f"Alert type: `{alert_type.name}`\n"
192192
formatted_message = f"{alert_type_formatted}\n Level: `{level}`\nTimestamp: `{current_time}`\n\nMessage: {message}"
193193

194194
# Verify alert_type is in the formatted message as expected
195-
self.assertIn("Alert type: `AlertType.llm_exceptions`", formatted_message)
195+
self.assertIn("Alert type: `llm_exceptions`", formatted_message)
196196
self.assertIn("Level: `Medium`", formatted_message)
197197
self.assertIn("Timestamp: `12:34:56`", formatted_message)
198198
self.assertIn("Message: Test alert message", formatted_message)

0 commit comments

Comments
 (0)