Update app.py
Browse files
app.py
CHANGED
@@ -44,97 +44,100 @@ def web_scrapper(url: str):
|
|
44 |
return ScrapeWebsiteTool(website_url=url)
|
45 |
|
46 |
def kickoff_crew(topic: str) -> dict:
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Define Agents with Groq LLM
|
57 |
-
researcher = Agent(
|
58 |
-
role='Researcher',
|
59 |
-
goal='Collect detailed information on {topic}',
|
60 |
-
tools=[search, search_results, web_scrapper],
|
61 |
-
llm=groq_llm, # Assigning the Groq LLM here
|
62 |
-
backstory=(
|
63 |
-
"As a diligent researcher, you explore the depths of the internet to "
|
64 |
-
"unearth crucial information and insights on the assigned topics. "
|
65 |
-
"With a keen eye for detail and a commitment to accuracy, you meticulously document every source "
|
66 |
-
"and piece of data gathered. Your research is thorough, ensuring that no stone is left unturned. "
|
67 |
-
"This dedication not only enhances the quality of the information but also ensures "
|
68 |
-
"reliability and trustworthiness in your findings."
|
69 |
-
),
|
70 |
-
allow_delegation=False,
|
71 |
-
max_iter=5,
|
72 |
-
verbose=True, # Optional
|
73 |
-
)
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
"Utilize the WebScrapper tool to extract additional information and insights from all links or URLs that appear significant regarding {topic} after analyzing the snippets of the search results. "
|
98 |
-
"Compile your findings into an initial draft, ensuring to include all sources with their titles and links relevant to the topic. "
|
99 |
-
"Throughout this process, maintain a high standard of accuracy and ensure that no information is fabricated or misrepresented."
|
100 |
-
),
|
101 |
-
expected_output=(
|
102 |
-
"A draft report containing all relevant information about the topic and sources used. "
|
103 |
-
"The report should be well-structured, including an introduction, a detailed body with organized sections according to different aspects of the topic, and a conclusion. "
|
104 |
-
"Each section should cite sources accurately and provide a comprehensive overview of the findings."
|
105 |
-
),
|
106 |
-
agent=researcher
|
107 |
-
)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
"Enhance the readability of the report by improving language clarity, adjusting sentence structure, and ensuring consistency in tone. "
|
115 |
-
"Include a dedicated section that lists all sources used in the research_task. "
|
116 |
-
"Each source used in the analysis should be presented as a bullet point in the format: title: link "
|
117 |
-
"Ensure that all sources you include in the final report exist by scrapping them if necessary. "
|
118 |
-
"This section should be comprehensive, clearly formatted, and easy to navigate, providing full transparency on the references used."
|
119 |
-
),
|
120 |
-
expected_output=(
|
121 |
-
"A finalized comprehensive report on ## {topic} ##. The report should be polished, with a clear and engaging narrative "
|
122 |
-
"that accurately reflects the research findings. It should include an introduction, a detailed and extensive discussion section, a concise conclusion, "
|
123 |
-
"and a well-organized source list. The document should be free of grammatical errors and ready for publication or presentation."
|
124 |
-
),
|
125 |
-
agent=editor,
|
126 |
-
context=[research_task]
|
127 |
-
)
|
128 |
-
|
129 |
-
# Forming the Crew
|
130 |
-
crew = Crew(
|
131 |
-
agents=[researcher, editor],
|
132 |
-
tasks=[research_task, edit_task]
|
133 |
-
)
|
134 |
-
|
135 |
-
# Kick-off the research process
|
136 |
-
result = crew.kickoff(inputs={'topic': topic})
|
137 |
-
return result
|
138 |
|
139 |
def main():
|
140 |
"""Set up the Gradio interface for the CrewAI Research Tool."""
|
|
|
44 |
return ScrapeWebsiteTool(website_url=url)
|
45 |
|
46 |
def kickoff_crew(topic: str) -> dict:
|
47 |
+
try:
|
48 |
+
"""Kickoff the research process for a given topic using CrewAI components."""
|
49 |
+
# Retrieve the API key from the environment variables
|
50 |
+
groq_api_key = os.environ.get("GROQ_API_KEY")
|
51 |
+
if not groq_api_key:
|
52 |
+
raise ValueError("API Key for Groq is not set in environment variables")
|
53 |
+
|
54 |
+
# Initialize the Groq large language model
|
55 |
+
groq_llm = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-70b-8192")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
# Define Agents with Groq LLM
|
58 |
+
researcher = Agent(
|
59 |
+
role='Researcher',
|
60 |
+
goal='Collect detailed information on {topic}',
|
61 |
+
tools=[search, search_results, web_scrapper],
|
62 |
+
llm=groq_llm, # Assigning the Groq LLM here
|
63 |
+
backstory=(
|
64 |
+
"As a diligent researcher, you explore the depths of the internet to "
|
65 |
+
"unearth crucial information and insights on the assigned topics. "
|
66 |
+
"With a keen eye for detail and a commitment to accuracy, you meticulously document every source "
|
67 |
+
"and piece of data gathered. Your research is thorough, ensuring that no stone is left unturned. "
|
68 |
+
"This dedication not only enhances the quality of the information but also ensures "
|
69 |
+
"reliability and trustworthiness in your findings."
|
70 |
+
),
|
71 |
+
allow_delegation=False,
|
72 |
+
max_iter=5,
|
73 |
+
verbose=True, # Optional
|
74 |
+
)
|
75 |
+
|
76 |
+
editor = Agent(
|
77 |
+
role='Editor',
|
78 |
+
goal='Compile and refine the information into a comprehensive report on {topic}',
|
79 |
+
llm=groq_llm, # Assigning the Groq LLM here
|
80 |
+
backstory=(
|
81 |
+
"With a keen eye for detail and a strong command of language, you transform "
|
82 |
+
"raw data into polished, insightful reports that are both informative and engaging. "
|
83 |
+
"Your expertise in editing ensures that every report is not only thorough but also "
|
84 |
+
"clearly communicates the key findings in a manner that is accessible to all readers. "
|
85 |
+
"As an editor, your role is crucial in shaping the final presentation of data, making "
|
86 |
+
"complex information easy to understand and appealing to the audience."
|
87 |
+
),
|
88 |
+
allow_delegation=False,
|
89 |
+
max_iter=3,
|
90 |
+
verbose=True, # Optional
|
91 |
+
)
|
92 |
+
|
93 |
+
# Define Tasks
|
94 |
+
research_task = Task(
|
95 |
+
description=(
|
96 |
+
"Use DuckDuckGoSearch tool to gather initial information about {topic}. "
|
97 |
+
"Next, employ DuckDuckGoResults tool to gather full details of the insights from search results, reading them carefully and preparing detailed summaries on {topic}. "
|
98 |
+
"Utilize the WebScrapper tool to extract additional information and insights from all links or URLs that appear significant regarding {topic} after analyzing the snippets of the search results. "
|
99 |
+
"Compile your findings into an initial draft, ensuring to include all sources with their titles and links relevant to the topic. "
|
100 |
+
"Throughout this process, maintain a high standard of accuracy and ensure that no information is fabricated or misrepresented."
|
101 |
+
),
|
102 |
+
expected_output=(
|
103 |
+
"A draft report containing all relevant information about the topic and sources used. "
|
104 |
+
"The report should be well-structured, including an introduction, a detailed body with organized sections according to different aspects of the topic, and a conclusion. "
|
105 |
+
"Each section should cite sources accurately and provide a comprehensive overview of the findings."
|
106 |
+
),
|
107 |
+
agent=researcher
|
108 |
+
)
|
109 |
+
|
110 |
+
edit_task = Task(
|
111 |
+
description=(
|
112 |
+
"Review and refine the draft report produced by the research task. Organize the content methodically, "
|
113 |
+
"ensuring that the structure is logical and enhances the flow of information. Check all factual data for accuracy, "
|
114 |
+
"correct any discrepancies, and ensure that the information is current and well-supported by sources. "
|
115 |
+
"Enhance the readability of the report by improving language clarity, adjusting sentence structure, and ensuring consistency in tone. "
|
116 |
+
"Include a dedicated section that lists all sources used in the research_task. "
|
117 |
+
"Each source used in the analysis should be presented as a bullet point in the format: title: link "
|
118 |
+
"Ensure that all sources you include in the final report exist by scrapping them if necessary. "
|
119 |
+
"This section should be comprehensive, clearly formatted, and easy to navigate, providing full transparency on the references used."
|
120 |
+
),
|
121 |
+
expected_output=(
|
122 |
+
"A finalized comprehensive report on ## {topic} ##. The report should be polished, with a clear and engaging narrative "
|
123 |
+
"that accurately reflects the research findings. It should include an introduction, a detailed and extensive discussion section, a concise conclusion, "
|
124 |
+
"and a well-organized source list. The document should be free of grammatical errors and ready for publication or presentation."
|
125 |
+
),
|
126 |
+
agent=editor,
|
127 |
+
context=[research_task]
|
128 |
+
)
|
129 |
|
130 |
+
# Forming the Crew
|
131 |
+
crew = Crew(
|
132 |
+
agents=[researcher, editor],
|
133 |
+
tasks=[research_task, edit_task]
|
134 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
+
# Kick-off the research process
|
137 |
+
result = crew.kickoff(inputs={'topic': topic})
|
138 |
+
return result
|
139 |
+
except Exception as e:
|
140 |
+
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
def main():
|
143 |
"""Set up the Gradio interface for the CrewAI Research Tool."""
|