Spaces:
Sleeping
Sleeping
Download email_agent.py from VIRAJcHOPADE/Research_Assistant: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/VIRAJcHOPADE/Research_Assistant/resolve/main/email_agent.py
- Command line
-
hf download hf://spaces/VIRAJcHOPADE/Research_Assistant/email_agent.py
-
curl -L -o email_agent.py https://huggingface.co/spaces/VIRAJcHOPADE/Research_Assistant/resolve/main/email_agent.py
1.62 kB
| import os | |
| from typing import Dict | |
| import sendgrid | |
| from sendgrid.helpers.mail import Email, Mail, Content, To | |
| from agents import Agent, function_tool | |
| # send_email is a tool that sends HTML emails via SendGrid. | |
| # email_agent is an AI that takes a report, formats it nicely, writes a subject line, and then uses the tool to send it out. | |
| # This completes your end-to-end pipeline: | |
| # PlannerAgent → plan searches | |
| # SearchAgent → gather summaries | |
| # WriterAgent → synthesize full report | |
| # EmailAgent → send polished report as email | |
| def send_email(subject: str, html_body: str) -> Dict[str, str]: | |
| """ Send an email with the given subject and HTML body """ | |
| sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) | |
| from_email = Email("clucth55567122636@gmail.com") # put your verified sender here | |
| to_email = To("virajchopade527@gmail.com") # put your recipient here | |
| content = Content("text/html", html_body) | |
| mail = Mail(from_email, to_email, subject, content).get() | |
| response = sg.client.mail.send.post(request_body=mail) | |
| print("Email response", response.status_code) | |
| return {"status": "success"} | |
| INSTRUCTIONS = """You are able to send a nicely formatted HTML email based on a detailed report. | |
| You will be provided with a detailed report. You should use your tool to send one email, providing the | |
| report converted into clean, well presented HTML with an appropriate subject line.""" | |
| email_agent = Agent( | |
| name="Email agent", | |
| instructions=INSTRUCTIONS, | |
| tools=[send_email], | |
| model="gpt-4o-mini", | |
| ) | |