forked from phoenix/litellm-mirror
fix slack alerting
This commit is contained in:
parent
c08352a0ce
commit
e8053c3d0b
1 changed files with 12 additions and 4 deletions
|
@ -68,11 +68,15 @@ class SlackAlertingCacheKeys(Enum):
|
||||||
|
|
||||||
|
|
||||||
class SlackAlerting(CustomLogger):
|
class SlackAlerting(CustomLogger):
|
||||||
|
"""
|
||||||
|
Class for sending Slack Alerts
|
||||||
|
"""
|
||||||
|
|
||||||
# Class variables or attributes
|
# Class variables or attributes
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
internal_usage_cache: Optional[DualCache] = None,
|
internal_usage_cache: Optional[DualCache] = None,
|
||||||
alerting_threshold: float = 300,
|
alerting_threshold: float = 300, # threshold for slow / hanging llm responses (in seconds)
|
||||||
alerting: Optional[List] = [],
|
alerting: Optional[List] = [],
|
||||||
alert_types: Optional[
|
alert_types: Optional[
|
||||||
List[
|
List[
|
||||||
|
@ -97,6 +101,7 @@ class SlackAlerting(CustomLogger):
|
||||||
Dict
|
Dict
|
||||||
] = None, # if user wants to separate alerts to diff channels
|
] = None, # if user wants to separate alerts to diff channels
|
||||||
alerting_args={},
|
alerting_args={},
|
||||||
|
default_webhook_url: Optional[str] = None,
|
||||||
):
|
):
|
||||||
self.alerting_threshold = alerting_threshold
|
self.alerting_threshold = alerting_threshold
|
||||||
self.alerting = alerting
|
self.alerting = alerting
|
||||||
|
@ -106,6 +111,7 @@ class SlackAlerting(CustomLogger):
|
||||||
self.alert_to_webhook_url = alert_to_webhook_url
|
self.alert_to_webhook_url = alert_to_webhook_url
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
self.alerting_args = SlackAlertingArgs(**alerting_args)
|
self.alerting_args = SlackAlertingArgs(**alerting_args)
|
||||||
|
self.default_webhook_url = default_webhook_url
|
||||||
|
|
||||||
def update_values(
|
def update_values(
|
||||||
self,
|
self,
|
||||||
|
@ -302,7 +308,7 @@ class SlackAlerting(CustomLogger):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
async def send_daily_reports(self, router: litellm.Router) -> bool:
|
async def send_daily_reports(self, router) -> bool:
|
||||||
"""
|
"""
|
||||||
Send a daily report on:
|
Send a daily report on:
|
||||||
- Top 5 deployments with most failed requests
|
- Top 5 deployments with most failed requests
|
||||||
|
@ -740,6 +746,8 @@ Model Info:
|
||||||
and alert_type in self.alert_to_webhook_url
|
and alert_type in self.alert_to_webhook_url
|
||||||
):
|
):
|
||||||
slack_webhook_url = self.alert_to_webhook_url[alert_type]
|
slack_webhook_url = self.alert_to_webhook_url[alert_type]
|
||||||
|
elif self.default_webhook_url is not None:
|
||||||
|
slack_webhook_url = self.default_webhook_url
|
||||||
else:
|
else:
|
||||||
slack_webhook_url = os.getenv("SLACK_WEBHOOK_URL", None)
|
slack_webhook_url = os.getenv("SLACK_WEBHOOK_URL", None)
|
||||||
|
|
||||||
|
@ -805,7 +813,7 @@ Model Info:
|
||||||
alert_type="llm_exceptions",
|
alert_type="llm_exceptions",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _run_scheduler_helper(self, llm_router: litellm.Router) -> bool:
|
async def _run_scheduler_helper(self, llm_router) -> bool:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
- True -> report sent
|
- True -> report sent
|
||||||
|
@ -847,7 +855,7 @@ Model Info:
|
||||||
|
|
||||||
return report_sent_bool
|
return report_sent_bool
|
||||||
|
|
||||||
async def _run_scheduled_daily_report(self, llm_router: Optional[litellm.Router]):
|
async def _run_scheduled_daily_report(self, llm_router: Optional[Any] = None):
|
||||||
"""
|
"""
|
||||||
If 'daily_reports' enabled
|
If 'daily_reports' enabled
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue