fix(slack_alerting.py): allow internal cache to be an optional param

This commit is contained in:
Krrish Dholakia 2024-05-06 18:34:09 -07:00
parent 3a8876b0d5
commit 72299a6894
2 changed files with 6 additions and 3 deletions

View file

@ -71,7 +71,7 @@ class SlackAlerting(CustomLogger):
# Class variables or attributes
def __init__(
self,
internal_usage_cache: DualCache,
internal_usage_cache: Optional[DualCache] = None,
alerting_threshold: float = 300,
alerting: Optional[List] = [],
alert_types: Optional[
@ -101,7 +101,7 @@ class SlackAlerting(CustomLogger):
self.alerting_threshold = alerting_threshold
self.alerting = alerting
self.alert_types = alert_types
self.internal_usage_cache = internal_usage_cache
self.internal_usage_cache = internal_usage_cache or DualCache()
self.async_http_handler = AsyncHTTPHandler()
self.alert_to_webhook_url = alert_to_webhook_url
self.is_running = False

View file

@ -98,7 +98,10 @@ def mock_env(monkeypatch):
# Test the __init__ method
def test_init():
slack_alerting = SlackAlerting(
alerting_threshold=32, alerting=["slack"], alert_types=["llm_exceptions"]
alerting_threshold=32,
alerting=["slack"],
alert_types=["llm_exceptions"],
internal_usage_cache=DualCache(),
)
assert slack_alerting.alerting_threshold == 32
assert slack_alerting.alerting == ["slack"]