Spaces:
Running
Running
Update interview_scheduler.py
Browse files- interview_scheduler.py +70 -70
interview_scheduler.py
CHANGED
|
@@ -1,71 +1,71 @@
|
|
| 1 |
-
from crewai import Agent, Task, Crew
|
| 2 |
-
from langchain_groq import ChatGroq
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
import os
|
| 5 |
-
from datetime import datetime, timedelta
|
| 6 |
-
import logging
|
| 7 |
-
|
| 8 |
-
load_dotenv()
|
| 9 |
-
logging.basicConfig(filename="
|
| 10 |
-
|
| 11 |
-
llm = ChatGroq(
|
| 12 |
-
api_key=os.getenv("GROQ_API_KEY"),
|
| 13 |
-
model="llama3-70b-8192",
|
| 14 |
-
temperature=0.5,
|
| 15 |
-
max_tokens=1000
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
interview_scheduler = Agent(
|
| 19 |
-
role="Interview Scheduler",
|
| 20 |
-
goal="Schedule interviews based on candidate availability and provide summaries",
|
| 21 |
-
backstory="An expert in coordinating schedules for AI-driven interviews",
|
| 22 |
-
llm=llm,
|
| 23 |
-
verbose=True,
|
| 24 |
-
allow_delegation=False
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
# Simulated Google Calendar API
|
| 28 |
-
def simulate_calendar_api(candidate_name, job_title, start_time):
|
| 29 |
-
event = {
|
| 30 |
-
"summary": f"Interview: {candidate_name} for {job_title}",
|
| 31 |
-
"start": start_time.isoformat(),
|
| 32 |
-
"end": (start_time + timedelta(hours=1)).isoformat()
|
| 33 |
-
}
|
| 34 |
-
logging.info(f"Simulated Calendar Event Created: {event}")
|
| 35 |
-
return {"status": "success", "event": event}
|
| 36 |
-
|
| 37 |
-
# Task to suggest a time based on candidate availability
|
| 38 |
-
def create_schedule_time_task(job_title, candidate_name, candidate_availability):
|
| 39 |
-
prompt = f"Given the job title: {job_title} and candidate {candidate_name}'s availability: {candidate_availability}, suggest an interview time in the format 'March 25, 2025, 10:00 AM'. The interviewer is an AI chatbot, so only the candidate’s availability matters. Pick a suitable time within the provided range."
|
| 40 |
-
return Task(
|
| 41 |
-
description=prompt,
|
| 42 |
-
agent=interview_scheduler,
|
| 43 |
-
expected_output="A suggested interview time in the format 'March 25, 2025, 10:00 AM'."
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
# Task to generate a summary
|
| 47 |
-
def create_schedule_summary_task(candidate_name, job_title, scheduled_time):
|
| 48 |
-
prompt = f"Generate a concise summary for an interview scheduled for {candidate_name} for the role of {job_title} at {scheduled_time}. Keep it short and professional."
|
| 49 |
-
return Task(
|
| 50 |
-
description=prompt,
|
| 51 |
-
agent=interview_scheduler,
|
| 52 |
-
expected_output="A brief summary of the scheduled interview."
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
# Main scheduling function
|
| 56 |
-
def create_schedule_task(job_title, candidate_name, candidate_availability):
|
| 57 |
-
time_task = create_schedule_time_task(job_title, candidate_name, candidate_availability)
|
| 58 |
-
return time_task # Return only the time task; summary is generated separately in app.py
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
task = create_schedule_task(
|
| 62 |
-
"Senior Python Developer",
|
| 63 |
-
"John Doe",
|
| 64 |
-
"March 25, 2025, 9 AM - 12 PM"
|
| 65 |
-
)
|
| 66 |
-
crew = Crew(agents=[interview_scheduler], tasks=[task], verbose=True)
|
| 67 |
-
time = crew.kickoff()
|
| 68 |
-
scheduled_time = datetime.strptime(time, "%B %d, %Y, %I:%M %p")
|
| 69 |
-
result = simulate_calendar_api("John Doe", "Senior Python Developer", scheduled_time)
|
| 70 |
-
print("Scheduled Time:", time)
|
| 71 |
print("Calendar 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 |
+
from datetime import datetime, timedelta
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 10 |
+
|
| 11 |
+
llm = ChatGroq(
|
| 12 |
+
api_key=os.getenv("GROQ_API_KEY"),
|
| 13 |
+
model="llama3-70b-8192",
|
| 14 |
+
temperature=0.5,
|
| 15 |
+
max_tokens=1000
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
interview_scheduler = Agent(
|
| 19 |
+
role="Interview Scheduler",
|
| 20 |
+
goal="Schedule interviews based on candidate availability and provide summaries",
|
| 21 |
+
backstory="An expert in coordinating schedules for AI-driven interviews",
|
| 22 |
+
llm=llm,
|
| 23 |
+
verbose=True,
|
| 24 |
+
allow_delegation=False
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Simulated Google Calendar API
|
| 28 |
+
def simulate_calendar_api(candidate_name, job_title, start_time):
|
| 29 |
+
event = {
|
| 30 |
+
"summary": f"Interview: {candidate_name} for {job_title}",
|
| 31 |
+
"start": start_time.isoformat(),
|
| 32 |
+
"end": (start_time + timedelta(hours=1)).isoformat()
|
| 33 |
+
}
|
| 34 |
+
logging.info(f"Simulated Calendar Event Created: {event}")
|
| 35 |
+
return {"status": "success", "event": event}
|
| 36 |
+
|
| 37 |
+
# Task to suggest a time based on candidate availability
|
| 38 |
+
def create_schedule_time_task(job_title, candidate_name, candidate_availability):
|
| 39 |
+
prompt = f"Given the job title: {job_title} and candidate {candidate_name}'s availability: {candidate_availability}, suggest an interview time in the format 'March 25, 2025, 10:00 AM'. The interviewer is an AI chatbot, so only the candidate’s availability matters. Pick a suitable time within the provided range."
|
| 40 |
+
return Task(
|
| 41 |
+
description=prompt,
|
| 42 |
+
agent=interview_scheduler,
|
| 43 |
+
expected_output="A suggested interview time in the format 'March 25, 2025, 10:00 AM'."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Task to generate a summary
|
| 47 |
+
def create_schedule_summary_task(candidate_name, job_title, scheduled_time):
|
| 48 |
+
prompt = f"Generate a concise summary for an interview scheduled for {candidate_name} for the role of {job_title} at {scheduled_time}. Keep it short and professional."
|
| 49 |
+
return Task(
|
| 50 |
+
description=prompt,
|
| 51 |
+
agent=interview_scheduler,
|
| 52 |
+
expected_output="A brief summary of the scheduled interview."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Main scheduling function
|
| 56 |
+
def create_schedule_task(job_title, candidate_name, candidate_availability):
|
| 57 |
+
time_task = create_schedule_time_task(job_title, candidate_name, candidate_availability)
|
| 58 |
+
return time_task # Return only the time task; summary is generated separately in app.py
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
task = create_schedule_task(
|
| 62 |
+
"Senior Python Developer",
|
| 63 |
+
"John Doe",
|
| 64 |
+
"March 25, 2025, 9 AM - 12 PM"
|
| 65 |
+
)
|
| 66 |
+
crew = Crew(agents=[interview_scheduler], tasks=[task], verbose=True)
|
| 67 |
+
time = crew.kickoff()
|
| 68 |
+
scheduled_time = datetime.strptime(time, "%B %d, %Y, %I:%M %p")
|
| 69 |
+
result = simulate_calendar_api("John Doe", "Senior Python Developer", scheduled_time)
|
| 70 |
+
print("Scheduled Time:", time)
|
| 71 |
print("Calendar Response:", result)
|