forked from bhancockio/crewai-updated-tutorial-hierarchical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (37 loc) · 1.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from crewai import Crew, Process
from langchain_openai import ChatOpenAI
from agents import AINewsLetterAgents
from tasks import AINewsLetterTasks
from file_io import save_markdown
from dotenv import load_dotenv
load_dotenv()
# Initialize the agents and tasks
agents = AINewsLetterAgents()
tasks = AINewsLetterTasks()
# Initialize the OpenAI GPT-4 language model
OpenAIGPT4 = ChatOpenAI(
model="gpt-4"
)
# Instantiate the agents
editor = agents.editor_agent()
news_fetcher = agents.news_fetcher_agent()
news_analyzer = agents.news_analyzer_agent()
newsletter_compiler = agents.newsletter_compiler_agent()
# Instantiate the tasks
fetch_news_task = tasks.fetch_news_task(news_fetcher)
analyze_news_task = tasks.analyze_news_task(news_analyzer, [fetch_news_task])
compile_newsletter_task = tasks.compile_newsletter_task(
newsletter_compiler, [analyze_news_task], save_markdown)
# Form the crew
crew = Crew(
agents=[editor, news_fetcher, news_analyzer, newsletter_compiler],
tasks=[fetch_news_task, analyze_news_task, compile_newsletter_task],
process=Process.hierarchical,
manager_llm=OpenAIGPT4,
verbose=2
)
# Kick off the crew's work
results = crew.kickoff()
# Print the results
print("Crew Work Results:")
print(results)