Skip to content

Commit 85f0a4d

Browse files
committed
Make duckduckgo the default one
1 parent 349ff3b commit 85f0a4d

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

tutorials/45_Creating_a_Multi_Agent_System.ipynb

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"\n",
1111
"- **Level**: Advanced\n",
1212
"- **Time to complete**: 20 minutes\n",
13-
"- **Components Used**: [`Agent`](https://docs.haystack.deepset.ai/docs/agent), [`SerperDevWebSearch`](https://docs.haystack.deepset.ai/docs/serperdevwebsearch), [`OpenAIChatGenerator`](https://docs.haystack.deepset.ai/docs/openaichatgenerator), [`DocumentWriter`](https://docs.haystack.deepset.ai/docs/documentwriter)\n",
14-
"- **Prerequisites**: You need an [OpenAI API Key](https://platform.openai.com/api-keys), a [Serper API Key](https://serper.dev/api-key) and a [Notion Integration](https://developers.notion.com/docs/create-a-notion-integration#getting-started) set up beforehand\n",
13+
"- **Components Used**: [`Agent`](https://docs.haystack.deepset.ai/docs/agent), [`DuckduckgoApiWebSearch`](https://haystack.deepset.ai/integrations/duckduckgo-api-websearch), [`OpenAIChatGenerator`](https://docs.haystack.deepset.ai/docs/openaichatgenerator), [`DocumentWriter`](https://docs.haystack.deepset.ai/docs/documentwriter)\n",
14+
"- **Prerequisites**: You need an [OpenAI API Key](https://platform.openai.com/api-keys), and a [Notion Integration](https://developers.notion.com/docs/create-a-notion-integration#getting-started) set up beforehand\n",
1515
"- **Goal**: After completing this tutorial, you'll have learned how to build a multi-agent system in Haystack where each agent is specialized for a specific task.\n",
1616
"\n",
1717
"## Overview\n",
@@ -37,12 +37,12 @@
3737
"source": [
3838
"## Preparing the Environment\n",
3939
"\n",
40-
"First, let's install Haystack:"
40+
"First, let's install required packages:"
4141
]
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 2,
45+
"execution_count": null,
4646
"metadata": {
4747
"colab": {
4848
"base_uri": "https://localhost:8080/"
@@ -64,7 +64,7 @@
6464
}
6565
],
6666
"source": [
67-
"!pip install -q haystack-ai"
67+
"!pip install -q haystack-ai duckduckgo-api-haystack"
6868
]
6969
},
7070
{
@@ -80,33 +80,21 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": 1,
83+
"execution_count": null,
8484
"metadata": {
8585
"colab": {
8686
"base_uri": "https://localhost:8080/"
8787
},
8888
"id": "PU26Ayr8rI3t",
8989
"outputId": "eea1c012-870f-4376-ac9c-879d4e4a14e2"
9090
},
91-
"outputs": [
92-
{
93-
"name": "stdout",
94-
"output_type": "stream",
95-
"text": [
96-
"Enter your OpenAI API key:··········\n",
97-
"Enter your SERPER API key:··········\n",
98-
"Enter your NOTION API key:··········\n"
99-
]
100-
}
101-
],
91+
"outputs": [],
10292
"source": [
10393
"from getpass import getpass\n",
10494
"import os\n",
10595
"\n",
10696
"if not os.environ.get(\"OPENAI_API_KEY\"):\n",
10797
" os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter your OpenAI API key:\")\n",
108-
"if not os.environ.get(\"SERPERDEV_API_KEY\"): # skip this if you want to use DuckDuckGo instead\n",
109-
" os.environ[\"SERPERDEV_API_KEY\"] = getpass(\"Enter your SERPER API key:\")\n",
11098
"if not os.environ.get(\"NOTION_API_KEY\"):\n",
11199
" os.environ[\"NOTION_API_KEY\"] = getpass(\"Enter your NOTION API key:\")"
112100
]
@@ -121,22 +109,21 @@
121109
"\n",
122110
"Let's set up the tools for your research agent. Its job is to gather information on a topic, and in this tutorial, it will use just two sources: the whole web and Wikipedia. In other scenarios, it could also connect to a retrieval or RAG pipeline linked to a document store.\n",
123111
"\n",
124-
"You'll create two [`ComponentTool`s](https://docs.haystack.deepset.ai/docs/componenttool) using the `SerperDevWebSearch` component: one for general web search, and one limited to Wikipedia by setting `allowed_domains`.\n",
112+
"You'll create two [`ComponentTool`s](https://docs.haystack.deepset.ai/docs/componenttool) using the [DuckduckgoApiWebSearch](https://haystack.deepset.ai/integrations/duckduckgo-api-websearch) component: one for general web search, and one limited to Wikipedia by setting `allowed_domain`.\n",
125113
"\n",
126-
"One more step before wrapping up: `SerperDevWebSearch` returns a list of documents, but the `Agent` works best when tools return a single string in this setting. To handle that, define a `doc_to_string` function that converts the Document list into a string. This function, used as the `outputs_to_string` handler, can also add custom elements like filenames or links before returning the output.\n",
127-
"\n"
114+
"One more step before wrapping up: `DuckduckgoApiWebSearch` returns a list of documents, but the `Agent` works best when tools return a single string in this setting. To handle that, define a `doc_to_string` function that converts the Document list into a string. This function, used as the `outputs_to_string` handler, can also add custom elements like filenames or links before returning the output."
128115
]
129116
},
130117
{
131118
"cell_type": "code",
132-
"execution_count": 58,
119+
"execution_count": null,
133120
"metadata": {
134121
"id": "YRREx0yzRaE2"
135122
},
136123
"outputs": [],
137124
"source": [
138125
"from haystack.tools import ComponentTool\n",
139-
"from haystack.components.websearch import SerperDevWebSearch\n",
126+
"from haystack.components.websearch import DuckduckgoApiWebSearch\n",
140127
"\n",
141128
"\n",
142129
"def doc_to_string(documents) -> str:\n",
@@ -154,14 +141,14 @@
154141
"\n",
155142
"\n",
156143
"web_search = ComponentTool(\n",
157-
" component=SerperDevWebSearch(top_k=5),\n",
144+
" component=DuckduckgoApiWebSearch(top_k=5, backend=\"lite\"),\n",
158145
" name=\"web_search\",\n",
159146
" description=\"Search the web\",\n",
160147
" outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string},\n",
161148
")\n",
162149
"\n",
163150
"wiki_search = ComponentTool(\n",
164-
" component=SerperDevWebSearch(top_k=5, allowed_domains=[\"https://www.wikipedia.org/\", \"https://en.wikipedia.org\"]),\n",
151+
" component=DuckduckgoApiWebSearch(top_k=5, backend=\"lite\", allowed_domain=\"https://en.wikipedia.org\"),\n",
165152
" name=\"wiki_search\",\n",
166153
" description=\"Search Wikipedia\",\n",
167154
" outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string},\n",
@@ -174,7 +161,7 @@
174161
"id": "C5qn6kyJ2hSX"
175162
},
176163
"source": [
177-
"Alternatively, you can use [DuckDuckGo](https://haystack.deepset.ai/integrations/duckduckgo-api-websearch) as your websearch component for these tools. Just keep in mind that it's more prone to hitting rate limits as it's completely free."
164+
"If you're hitting rate limits with DuckDuckGo, you can use [`SerperDevWebSearch`](https://docs.haystack.deepset.ai/docs/serperdevwebsearch) as your websearch component for these tools. You need to enter the free [Serper API Key](https://serper.dev/api-key) to use `SerperDevWebSearch`. "
178165
]
179166
},
180167
{
@@ -185,23 +172,27 @@
185172
},
186173
"outputs": [],
187174
"source": [
188-
"# !pip install duckduckgo-api-haystack\n",
189-
"#\n",
190-
"# from duckduckgo_api_haystack import DuckduckgoApiWebSearch\n",
175+
"# from getpass import getpass\n",
176+
"# import os\n",
177+
"\n",
178+
"# from haystack.components.websearch import SerperDevWebSearch\n",
191179
"# from haystack.tools import ComponentTool\n",
192-
"#\n",
180+
"\n",
181+
"# if not os.environ.get(\"SERPERDEV_API_KEY\"):\n",
182+
"# os.environ[\"SERPERDEV_API_KEY\"] = getpass(\"Enter your SERPER API key:\")\n",
183+
"\n",
193184
"# web_search = ComponentTool(\n",
194-
"# component=DuckduckgoApiWebSearch(top_k=5, backend=\"lite\"),\n",
185+
"# component=SerperDevWebSearch(top_k=5),\n",
195186
"# name=\"web_search\",\n",
196187
"# description=\"Search the web\",\n",
197-
"# outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string}\n",
188+
"# outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string},\n",
198189
"# )\n",
199190
"\n",
200191
"# wiki_search = ComponentTool(\n",
201-
"# component=DuckduckgoApiWebSearch(top_k=5, backend=\"lite\", allowed_domain=\"https://www.wikipedia.org/\"),\n",
192+
"# component=SerperDevWebSearch(top_k=5, allowed_domains=[\"https://www.wikipedia.org/\", \"https://en.wikipedia.org\"]),\n",
202193
"# name=\"wiki_search\",\n",
203194
"# description=\"Search Wikipedia\",\n",
204-
"# outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string}\n",
195+
"# outputs_to_string={\"source\": \"documents\", \"handler\": doc_to_string},\n",
205196
"# )"
206197
]
207198
},
@@ -655,7 +646,7 @@
655646
},
656647
{
657648
"cell_type": "code",
658-
"execution_count": 51,
649+
"execution_count": null,
659650
"metadata": {
660651
"colab": {
661652
"base_uri": "https://localhost:8080/"
@@ -687,7 +678,7 @@
687678
" messages=[\n",
688679
" ChatMessage.from_user(\n",
689680
" \"\"\"\n",
690-
"Save the this text on Notion:\n",
681+
"Save this text on Notion:\n",
691682
"\n",
692683
"Florence Nightingale is widely recognized as the founder of modern nursing, and her contributions significantly transformed the field.\n",
693684
"Florence Nightingale's legacy endures, as she set professional standards that have shaped nursing into a respected and essential component of the healthcare system. Her influence is still felt in nursing education and practice today.\n",

0 commit comments

Comments
 (0)