mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
fix - user based alerting
This commit is contained in:
parent
c3dcbf2067
commit
9a5fd07f16
2 changed files with 15 additions and 22 deletions
|
@ -10,17 +10,7 @@ model_list:
|
||||||
api_key: os.environ/OPENAI_API_KEY
|
api_key: os.environ/OPENAI_API_KEY
|
||||||
|
|
||||||
|
|
||||||
litellm_settings:
|
|
||||||
default_team_settings:
|
|
||||||
- team_id: team-1
|
|
||||||
success_callback: ["langfuse"]
|
|
||||||
langfuse_public_key: os.environ/LANGFUSE_PROJECT1_PUBLIC # Project 1
|
|
||||||
langfuse_secret: os.environ/LANGFUSE_PROJECT1_SECRET # Project 1
|
|
||||||
- team_id: team-2
|
|
||||||
success_callback: ["langfuse"]
|
|
||||||
langfuse_public_key: os.environ/LANGFUSE_PROJECT2_PUBLIC # Project 2
|
|
||||||
langfuse_secret: os.environ/LANGFUSE_PROJECT2_SECRET # Project 2
|
|
||||||
|
|
||||||
general_settings:
|
general_settings:
|
||||||
store_model_in_db: true
|
store_model_in_db: true
|
||||||
master_key: sk-1234
|
master_key: sk-1234
|
||||||
|
alerting: ["slack"]
|
|
@ -360,22 +360,25 @@ class ProxyLogging:
|
||||||
f"Budget Alerts: Percent left: {percent_left} for {user_info}"
|
f"Budget Alerts: Percent left: {percent_left} for {user_info}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# check if crossed budget
|
|
||||||
if user_current_spend >= user_max_budget:
|
|
||||||
verbose_proxy_logger.debug("Budget Crossed for %s", user_info)
|
|
||||||
message = "Budget Crossed for" + user_info
|
|
||||||
await self.alerting_handler(
|
|
||||||
message=message,
|
|
||||||
level="High",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
## PREVENTITIVE ALERTING ## - https://github.com/BerriAI/litellm/issues/2727
|
## PREVENTITIVE ALERTING ## - https://github.com/BerriAI/litellm/issues/2727
|
||||||
# - Alert once within 28d period
|
# - Alert once within 28d period
|
||||||
# - Cache this information
|
# - Cache this information
|
||||||
# - Don't re-alert, if alert already sent
|
# - Don't re-alert, if alert already sent
|
||||||
_cache: DualCache = self.internal_usage_cache
|
_cache: DualCache = self.internal_usage_cache
|
||||||
|
|
||||||
|
# check if crossed budget
|
||||||
|
if user_current_spend >= user_max_budget:
|
||||||
|
verbose_proxy_logger.debug("Budget Crossed for %s", user_info)
|
||||||
|
message = "Budget Crossed for" + user_info
|
||||||
|
result = await _cache.async_get_cache(key=message)
|
||||||
|
if result is None:
|
||||||
|
await self.alerting_handler(
|
||||||
|
message=message,
|
||||||
|
level="High",
|
||||||
|
)
|
||||||
|
await _cache.async_set_cache(key=message, value="SENT", ttl=2419200)
|
||||||
|
return
|
||||||
|
|
||||||
# check if 5% of max budget is left
|
# check if 5% of max budget is left
|
||||||
if percent_left <= 0.05:
|
if percent_left <= 0.05:
|
||||||
message = "5% budget left for" + user_info
|
message = "5% budget left for" + user_info
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue