dromerosm commited on
Commit
e7c7689
1 Parent(s): a182e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -29
app.py CHANGED
@@ -11,17 +11,37 @@ def search(search_query: str):
11
  """Search the web for information on a given topic."""
12
  return DuckDuckGoSearchRun().run(search_query)
13
 
14
- # Define the DuckDuckGoSearchResults tool
15
- @tool('DuckDuckGoSearchResults')
16
  def search_results(search_query: str):
17
- """Search the web for information and sources on a given topic with links and titles."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  return DuckDuckGoSearchResults().run(search_query)
19
 
 
20
  # Define the WebScrapper tool
21
  @tool('WebScrapper')
22
  def web_scrapper(url: str):
23
- """Download information from a web page using its URL"""
24
- return SeleniumScrapingTool(website_url=url)
 
 
 
 
25
 
26
  def kickoff_crew(topic: str) -> dict:
27
  """Kickoff the research process for a given topic using CrewAI components."""
@@ -33,56 +53,73 @@ def kickoff_crew(topic: str) -> dict:
33
  # Initialize the Groq large language model
34
  groq_llm = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-70b-8192")
35
 
36
- # Define Agents
37
  researcher = Agent(
38
  role='Researcher',
39
- goal=f'Collect detailed information on {topic}',
40
  tools=[search, search_results, web_scrapper],
41
- llm=groq_llm,
42
  backstory=(
43
  "As a diligent researcher, you explore the depths of the internet to "
44
  "unearth crucial information and insights on the assigned topics. "
45
- "Attention to detail and accuracy is critical and requires that you keep a record of all the sources you use."
 
 
 
46
  ),
47
  allow_delegation=False,
48
  max_iter=5,
49
- verbose=True
50
  )
51
-
52
  editor = Agent(
53
  role='Editor',
54
- goal='Compile and refine the information into a comprehensive and elaborated report on {topic}',
55
- llm=groq_llm,
56
  backstory=(
57
  "With a keen eye for detail and a strong command of language, you transform "
58
- "raw data into polished, insightful reports that are both informative and engaging."
59
- "The length of each section shall be at least 3 paragraphs."
 
 
 
60
  ),
61
  allow_delegation=False,
62
- max_iter=5,
63
- verbose=True
64
  )
65
-
66
  # Define Tasks
67
  research_task = Task(
68
  description=(
69
- "Use DuckDuckGoSearch and DuckDuckGoSearchResults to gather information about {topic}."
70
- "Use WebScrapper to extract information and insights from links or urls."
71
- "Compile your findings into an initial draft. "
72
- "Gather all the sources with title and link relevant to the topic. "
73
- "Be sure you don't make up or invent any information."
 
 
 
 
 
74
  ),
75
- expected_output='A draft report containing all relevant information about the topic and sources used',
76
  agent=researcher
77
  )
78
-
79
  edit_task = Task(
80
  description=(
81
- "Review and refine the draft report. Organize the content, check for accuracy, "
82
- "and enhance readability. "
83
- "Include a section with all the sources used in the report from research_task as bullets: (title)[link]"
 
 
 
 
 
 
 
 
84
  ),
85
- expected_output='A finalized comprehensive report on ## {topic} ##',
86
  agent=editor,
87
  context=[research_task]
88
  )
 
11
  """Search the web for information on a given topic."""
12
  return DuckDuckGoSearchRun().run(search_query)
13
 
14
+ # Define the DuckDuckGoSearch tool
15
+ @tool('DuckDuckGoResults')
16
  def search_results(search_query: str):
17
+ """
18
+ Performs a web search using the DuckDuckGo search engine to gather and return a collection of search results.
19
+ This tool automates the retrieval of web-based information related to a specified query.
20
+
21
+ Parameters:
22
+ - search_query (str): The query string that specifies the information to be searched on the web. This should be a clear and concise expression of the user's information needs.
23
+
24
+ Returns:
25
+ - list: A list of dictionaries, where each dictionary represents a search result. Each dictionary includes at least the 'title' of the page and the 'url' linking to it. Additional information such as a brief summary or snippet from the page might also be included depending on the specifics of the DuckDuckGo API response.
26
+
27
+ Example:
28
+ - Input: search_results(""Generative AI in Telecom and Media")
29
+ - Output: [snippet: The telecommunications and media industry is at the forefront of integrating generative AI into their operations, viewing it as a catalyst for growth and innovation. Industry leaders are enthusiastic about its ability to not only enhance the current processes but also spearhead new innovations, create new opportunities, unlock new sources of ..., title: Generative AI in the telecom industry | Google Cloud Blog, link: https://cloud.google.com/blog/topics/telecommunications/generative-ai-in-the-telecom-industry], ...]
30
+
31
+ Use this tool to quickly gather a variety of sources on any topic without needing to manually search through a web browser. It can be especially useful in automated data gathering, research, and in contexts where multiple web sources need to be quickly consulted.
32
+ """
33
  return DuckDuckGoSearchResults().run(search_query)
34
 
35
+
36
  # Define the WebScrapper tool
37
  @tool('WebScrapper')
38
  def web_scrapper(url: str):
39
+ """
40
+ A tool designed to extract and read the content of a specified website.
41
+ It is capable of handling various types of web pages by making HTTP requests and parsing the received HTML content.
42
+ This tool can be particularly useful for web scraping tasks, data collection, or extracting specific information from websites.
43
+ """
44
+ return ScrapeWebsiteTool(website_url=url)
45
 
46
  def kickoff_crew(topic: str) -> dict:
47
  """Kickoff the research process for a given topic using CrewAI components."""
 
53
  # Initialize the Groq large language model
54
  groq_llm = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-70b-8192")
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
  editor = Agent(
76
  role='Editor',
77
+ goal='Compile and refine the information into a comprehensive report on {topic}',
78
+ llm=groq_llm, # Assigning the Groq LLM here
79
  backstory=(
80
  "With a keen eye for detail and a strong command of language, you transform "
81
+ "raw data into polished, insightful reports that are both informative and engaging. "
82
+ "Your expertise in editing ensures that every report is not only thorough but also "
83
+ "clearly communicates the key findings in a manner that is accessible to all readers. "
84
+ "As an editor, your role is crucial in shaping the final presentation of data, making "
85
+ "complex information easy to understand and appealing to the audience."
86
  ),
87
  allow_delegation=False,
88
+ max_iter=3,
89
+ verbose=True, # Optional
90
  )
91
+
92
  # Define Tasks
93
  research_task = Task(
94
  description=(
95
+ "Use DuckDuckGoSearch to gather initial information about {topic}. "
96
+ "Next, employ DuckDuckGoResults to gather full details of the insights from search results, reading them carefully and preparing detailed summaries on {topic}. "
97
+ "Utilize the WebScrapper 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
  edit_task = Task(
110
  description=(
111
+ "Review and refine the draft report produced by the research task. Organize the content methodically, "
112
+ "ensuring that the structure is logical and enhances the flow of information. Check all factual data for accuracy, "
113
+ "correct any discrepancies, and ensure that the information is current and well-supported by sources. "
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. Each source should be presented as a bullet point in the format: (title)[link]. "
116
+ "This section should be comprehensive, clearly formatted, and easy to navigate, providing full transparency on the references used."
117
+ ),
118
+ expected_output=(
119
+ "A finalized comprehensive report on ## {topic} ##. The report should be polished, with a clear and engaging narrative "
120
+ "that accurately reflects the research findings. It should include an introduction, a detailed discussion section, a concise conclusion, "
121
+ "and a well-organized source list. The document should be free of grammatical errors and ready for publication or presentation."
122
  ),
 
123
  agent=editor,
124
  context=[research_task]
125
  )