Spaces:
Running
Running
Update email_automation.py
Browse files- email_automation.py +46 -46
email_automation.py
CHANGED
|
@@ -1,47 +1,47 @@
|
|
| 1 |
-
from crewai import Agent, Task, Crew
|
| 2 |
-
from langchain_groq import ChatGroq
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
import os
|
| 5 |
-
import logging
|
| 6 |
-
|
| 7 |
-
load_dotenv()
|
| 8 |
-
logging.basicConfig(filename="
|
| 9 |
-
|
| 10 |
-
llm = ChatGroq(
|
| 11 |
-
api_key=os.getenv("GROQ_API_KEY"),
|
| 12 |
-
model="llama3-70b-8192",
|
| 13 |
-
temperature=0.5,
|
| 14 |
-
max_tokens=1000
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
email_automation = Agent(
|
| 18 |
-
role="Email Automation Agent",
|
| 19 |
-
goal="Generate personalized, professional emails for candidates",
|
| 20 |
-
backstory="An expert in crafting tailored email communication",
|
| 21 |
-
llm=llm,
|
| 22 |
-
verbose=True,
|
| 23 |
-
allow_delegation=False
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
def simulate_email_api(email_content, recipient):
|
| 27 |
-
logging.info(f"Simulated email sent to {recipient}")
|
| 28 |
-
return {"status": "success", "message": f"Email sent to {recipient}"}
|
| 29 |
-
|
| 30 |
-
def create_email_task(candidate_name, email_type, job_title, details=None, recipient_email=None):
|
| 31 |
-
if email_type == "interview_invite":
|
| 32 |
-
prompt = f"Generate a personalized, professional email inviting {candidate_name} to an interview for the {job_title} position. Include the scheduled time: {details}. Address it to {candidate_name} and ensure it’s friendly yet formal. Use {recipient_email} as the recipient’s email in the salutation if provided."
|
| 33 |
-
else:
|
| 34 |
-
prompt = f"Generate a personalized email updating the hiring team about {candidate_name}’s status for the {job_title} position. Include details: {details}. Keep it concise and professional."
|
| 35 |
-
return Task(
|
| 36 |
-
description=prompt,
|
| 37 |
-
agent=email_automation,
|
| 38 |
-
expected_output="A fully drafted, personalized email."
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
if __name__ == "__main__":
|
| 42 |
-
task = create_email_task("John Doe", "interview_invite", "Senior Python Developer", "March 25, 2025, 10:00 AM", "[email protected]")
|
| 43 |
-
crew = Crew(agents=[email_automation], tasks=[task], verbose=True)
|
| 44 |
-
email_content = crew.kickoff()
|
| 45 |
-
result = simulate_email_api(email_content, "[email protected]")
|
| 46 |
-
print("Email Content:", email_content)
|
| 47 |
print("API Response:", result)
|
|
|
|
| 1 |
+
from crewai import Agent, Task, Crew
|
| 2 |
+
from langchain_groq import ChatGroq
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 9 |
+
|
| 10 |
+
llm = ChatGroq(
|
| 11 |
+
api_key=os.getenv("GROQ_API_KEY"),
|
| 12 |
+
model="llama3-70b-8192",
|
| 13 |
+
temperature=0.5,
|
| 14 |
+
max_tokens=1000
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
email_automation = Agent(
|
| 18 |
+
role="Email Automation Agent",
|
| 19 |
+
goal="Generate personalized, professional emails for candidates",
|
| 20 |
+
backstory="An expert in crafting tailored email communication",
|
| 21 |
+
llm=llm,
|
| 22 |
+
verbose=True,
|
| 23 |
+
allow_delegation=False
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
def simulate_email_api(email_content, recipient):
|
| 27 |
+
logging.info(f"Simulated email sent to {recipient}")
|
| 28 |
+
return {"status": "success", "message": f"Email sent to {recipient}"}
|
| 29 |
+
|
| 30 |
+
def create_email_task(candidate_name, email_type, job_title, details=None, recipient_email=None):
|
| 31 |
+
if email_type == "interview_invite":
|
| 32 |
+
prompt = f"Generate a personalized, professional email inviting {candidate_name} to an interview for the {job_title} position. Include the scheduled time: {details}. Address it to {candidate_name} and ensure it’s friendly yet formal. Use {recipient_email} as the recipient’s email in the salutation if provided."
|
| 33 |
+
else:
|
| 34 |
+
prompt = f"Generate a personalized email updating the hiring team about {candidate_name}’s status for the {job_title} position. Include details: {details}. Keep it concise and professional."
|
| 35 |
+
return Task(
|
| 36 |
+
description=prompt,
|
| 37 |
+
agent=email_automation,
|
| 38 |
+
expected_output="A fully drafted, personalized email."
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
task = create_email_task("John Doe", "interview_invite", "Senior Python Developer", "March 25, 2025, 10:00 AM", "[email protected]")
|
| 43 |
+
crew = Crew(agents=[email_automation], tasks=[task], verbose=True)
|
| 44 |
+
email_content = crew.kickoff()
|
| 45 |
+
result = simulate_email_api(email_content, "[email protected]")
|
| 46 |
+
print("Email Content:", email_content)
|
| 47 |
print("API Response:", result)
|