52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
from crewai import Crew
|
|
from textwrap import dedent
|
|
from agents import TalkingAgents
|
|
from tasks import TalkingTasks
|
|
from job_manager import append_event
|
|
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
|
|
class ChatCrew:
|
|
def __init__(self, job_id):
|
|
# Crew variables
|
|
self.job_id = job_id
|
|
self.crew = None
|
|
|
|
def setup_crew(self, company, contact, interests, city):
|
|
print(f'Initializing crew for {self.job_id} for comapny {company} with point of contact {contact}')
|
|
|
|
# Initialize agents
|
|
agents = TalkingAgents()
|
|
master_networker = agents.master_networker()
|
|
local_expert = agents.local_expert()
|
|
|
|
# Initialize tasks
|
|
tasks = TalkingTasks(self.job_id)
|
|
chat_tasks = [
|
|
tasks.research_topics(master_networker, company), tasks.gather_city_info(local_expert, city, interests)
|
|
]
|
|
|
|
# Initialize crew
|
|
self.crew = Crew(
|
|
agents=[master_networker, local_expert],
|
|
tasks=chat_tasks,
|
|
verbose=2
|
|
)
|
|
|
|
def kickoff(self):
|
|
if not self.crew:
|
|
print(f"No crew found for {self.job_id}")
|
|
return
|
|
|
|
append_event(self.job_id, "CREW STARTED")
|
|
try:
|
|
print(f'Running crew for {self.job_id}')
|
|
result = self.crew.kickoff()
|
|
append_event(self.job_id, "CREW COMPLETED")
|
|
return result
|
|
|
|
except Exception as e:
|
|
append_event(self.job_id, "ERROR ENCOUNTERED")
|
|
return str(e) |