mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
feat - send send_email_alert_using_smtp
This commit is contained in:
parent
215fb132f9
commit
25abdbdcc2
1 changed files with 58 additions and 0 deletions
|
@ -781,6 +781,57 @@ Model Info:
|
|||
|
||||
return False
|
||||
|
||||
async def send_email_alert_using_smtp(self, webhook_event: WebhookEvent) -> bool:
|
||||
"""
|
||||
Sends structured Email alert to an SMTP server
|
||||
|
||||
Currently only implemented for budget alerts
|
||||
|
||||
Returns -> True if sent, False if not.
|
||||
"""
|
||||
from litellm.proxy.utils import send_email
|
||||
|
||||
event_name = webhook_event.event_message
|
||||
recipient_email = webhook_event.user_email
|
||||
user_name = webhook_event.user_id
|
||||
max_budget = webhook_event.max_budget
|
||||
email_html_content = "Alert from LiteLLM Server"
|
||||
|
||||
if webhook_event.event == "budget_crossed":
|
||||
email_html_content = f"""
|
||||
<h1>LiteLLM</h1>
|
||||
|
||||
<p> Hi {user_name}, <br/>
|
||||
|
||||
Your LLM API usage this month has reached your account's monthly budget of ${max_budget} <br /> <br />
|
||||
|
||||
API requests will be rejected until either (a) you increase your monthly budget or (b) your monthly usage resets at the beginning of the next calendar month. <br /> <br />
|
||||
|
||||
If you have any questions, please send an email to support@berri.ai <br /> <br />
|
||||
|
||||
Best, <br />
|
||||
The LiteLLM team <br />
|
||||
"""
|
||||
|
||||
payload = webhook_event.model_dump_json()
|
||||
email_event = {
|
||||
"from": "support@alerts.litellm.ai",
|
||||
"to": recipient_email,
|
||||
"subject": event_name,
|
||||
"html": email_html_content,
|
||||
}
|
||||
headers = {"Content-type": "application/json"}
|
||||
|
||||
response = await send_email(
|
||||
sender_name=email_event["from"],
|
||||
sender_email=email_event["from"],
|
||||
receiver_email=email_event["to"],
|
||||
subject=email_event["subject"],
|
||||
html=email_event["html"],
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
async def send_alert(
|
||||
self,
|
||||
message: str,
|
||||
|
@ -823,6 +874,13 @@ Model Info:
|
|||
):
|
||||
await self.send_webhook_alert(webhook_event=user_info)
|
||||
|
||||
if (
|
||||
"email" in self.alerting
|
||||
and alert_type == "budget_alerts"
|
||||
and user_info is not None
|
||||
):
|
||||
await self.send_email_alert_using_smtp(webhook_event=user_info)
|
||||
|
||||
if "slack" not in self.alerting:
|
||||
return
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue