sergiopaniego HF Staff commited on
Commit
f0c0b63
·
verified ·
1 Parent(s): 1695162

DuckDuckGoSearchTool --> WebSearchTool (#126)

Browse files

- DuckDuckGoSearchTool --> WebSearchTool (276139971e7a44672656254a9c6eacc5b0e44194)

unit2/smolagents/code_agents.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
unit2/smolagents/multiagent_notebook.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
unit2/smolagents/retrieval_agents.ipynb CHANGED
@@ -63,9 +63,9 @@
63
  "id": "toG-RqWX4sIx"
64
  },
65
  "source": [
66
- "## Basic Retrieval with DuckDuckGo\n",
67
  "\n",
68
- "Let's build a simple agent that can search the web using DuckDuckGo. This agent will retrieve information and synthesize responses to answer queries. With Agentic RAG, Alfred's agent can:\n",
69
  "\n",
70
  "* Search for latest superhero party trends\n",
71
  "* Refine results to include luxury elements\n",
@@ -1733,10 +1733,10 @@
1733
  }
1734
  ],
1735
  "source": [
1736
- "from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel\n",
1737
  "\n",
1738
  "# Initialize the search tool\n",
1739
- "search_tool = DuckDuckGoSearchTool()\n",
1740
  "\n",
1741
  "# Initialize the model\n",
1742
  "model = InferenceClientModel()\n",
@@ -1759,7 +1759,7 @@
1759
  "The agent follows this process:\n",
1760
  "\n",
1761
  "1. **Analyzes the Request:** Alfred’s agent identifies the key elements of the query—luxury superhero-themed party planning, with focus on decor, entertainment, and catering.\n",
1762
- "2. **Performs Retrieval:** The agent leverages DuckDuckGo to search for the most relevant and up-to-date information, ensuring it aligns with Alfred’s refined preferences for a luxurious event.\n",
1763
  "3. **Synthesizes Information:** After gathering the results, the agent processes them into a cohesive, actionable plan for Alfred, covering all aspects of the party.\n",
1764
  "4. **Stores for Future Reference:** The agent stores the retrieved information for easy access when planning future events, optimizing efficiency in subsequent tasks."
1765
  ],
 
63
  "id": "toG-RqWX4sIx"
64
  },
65
  "source": [
66
+ "## Basic Retrieval with WebSerach\n",
67
  "\n",
68
+ "Let's build a simple agent that can search the web. This agent will retrieve information and synthesize responses to answer queries. With Agentic RAG, Alfred's agent can:\n",
69
  "\n",
70
  "* Search for latest superhero party trends\n",
71
  "* Refine results to include luxury elements\n",
 
1733
  }
1734
  ],
1735
  "source": [
1736
+ "from smolagents import CodeAgent, WebSearchTool, InferenceClientModel\n",
1737
  "\n",
1738
  "# Initialize the search tool\n",
1739
+ "search_tool = WebSearchTool()\n",
1740
  "\n",
1741
  "# Initialize the model\n",
1742
  "model = InferenceClientModel()\n",
 
1759
  "The agent follows this process:\n",
1760
  "\n",
1761
  "1. **Analyzes the Request:** Alfred’s agent identifies the key elements of the query—luxury superhero-themed party planning, with focus on decor, entertainment, and catering.\n",
1762
+ "2. **Performs Retrieval:** The agent leverages WebSearchTool to search for the most relevant and up-to-date information, ensuring it aligns with Alfred’s refined preferences for a luxurious event.\n",
1763
  "3. **Synthesizes Information:** After gathering the results, the agent processes them into a cohesive, actionable plan for Alfred, covering all aspects of the party.\n",
1764
  "4. **Stores for Future Reference:** The agent stores the retrieved information for easy access when planning future events, optimizing efficiency in subsequent tasks."
1765
  ],
unit2/smolagents/tool_calling_agents.ipynb CHANGED
@@ -65,7 +65,7 @@
65
  "source": [
66
  "## Selecting a Playlist for the Party Using `smolagents` and a `ToolCallingAgent`\n",
67
  "\n",
68
- "Let's revisit the previous example where Alfred started party preparations, but this time we'll use a `ToolCallingAgent` to highlight the difference. We'll build an agent that can search the web using DuckDuckGo, just like in our Code Agent example. The only difference is the agent type - the framework handles everything else:"
69
  ]
70
  },
71
  {
@@ -550,9 +550,9 @@
550
  }
551
  ],
552
  "source": [
553
- "from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel\n",
554
  "\n",
555
- "agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool()], model=InferenceClientModel())\n",
556
  "\n",
557
  "agent.run(\"Search for the best music recommendations for a party at the Wayne's mansion.\")"
558
  ]
@@ -593,4 +593,4 @@
593
  },
594
  "nbformat": 4,
595
  "nbformat_minor": 0
596
- }
 
65
  "source": [
66
  "## Selecting a Playlist for the Party Using `smolagents` and a `ToolCallingAgent`\n",
67
  "\n",
68
+ "Let's revisit the previous example where Alfred started party preparations, but this time we'll use a `ToolCallingAgent` to highlight the difference. We'll build an agent that can search the web, just like in our Code Agent example. The only difference is the agent type - the framework handles everything else:"
69
  ]
70
  },
71
  {
 
550
  }
551
  ],
552
  "source": [
553
+ "from smolagents import ToolCallingAgent, WebSearchTool, InferenceClientModel\n",
554
  "\n",
555
+ "agent = ToolCallingAgent(tools=[WebSearchTool()], model=InferenceClientModel())\n",
556
  "\n",
557
  "agent.run(\"Search for the best music recommendations for a party at the Wayne's mansion.\")"
558
  ]
 
593
  },
594
  "nbformat": 4,
595
  "nbformat_minor": 0
596
+ }
unit2/smolagents/vision_web_browser.py CHANGED
@@ -9,14 +9,13 @@ from selenium import webdriver
9
  from selenium.webdriver.common.by import By
10
  from selenium.webdriver.common.keys import Keys
11
 
12
- from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
13
  from smolagents.agents import ActionStep
14
  from smolagents.cli import load_model
15
 
16
 
17
  alfred_guest_list_request = """
18
  I am Alfred, the butler of Wayne Manor, responsible for verifying the identity of guests at party. A superhero has arrived at the entrance claiming to be Wonder Woman, but I need to confirm if she is who she says she is.
19
-
20
  Please search for images of Wonder Woman and generate a detailed visual description based on those images. Additionally, navigate to Wikipedia to gather key details about her appearance. With this information, I can determine whether to grant her access to the event.
21
  """
22
 
@@ -111,7 +110,7 @@ def initialize_driver():
111
  def initialize_agent(model):
112
  """Initialize the CodeAgent with the specified model."""
113
  return CodeAgent(
114
- tools=[DuckDuckGoSearchTool(), go_back, close_popups, search_item_ctrl_f],
115
  model=model,
116
  additional_authorized_imports=["helium"],
117
  step_callbacks=[save_screenshot],
@@ -130,50 +129,42 @@ Code:
130
  ```py
131
  go_to('github.com/trending')
132
  ```<end_code>
133
-
134
  You can directly click clickable elements by inputting the text that appears on them.
135
  Code:
136
  ```py
137
  click("Top products")
138
  ```<end_code>
139
-
140
  If it's a link:
141
  Code:
142
  ```py
143
  click(Link("Top products"))
144
  ```<end_code>
145
-
146
  If you try to interact with an element and it's not found, you'll get a LookupError.
147
  In general stop your action after each button click to see what happens on your screenshot.
148
  Never try to login in a page.
149
-
150
  To scroll up or down, use scroll_down or scroll_up with as an argument the number of pixels to scroll from.
151
  Code:
152
  ```py
153
  scroll_down(num_pixels=1200) # This will scroll one viewport down
154
  ```<end_code>
155
-
156
  When you have pop-ups with a cross icon to close, don't try to click the close icon by finding its element or targeting an 'X' element (this most often fails).
157
  Just use your built-in tool `close_popups` to close them:
158
  Code:
159
  ```py
160
  close_popups()
161
  ```<end_code>
162
-
163
  You can use .exists() to check for the existence of an element. For example:
164
  Code:
165
  ```py
166
  if Text('Accept cookies?').exists():
167
  click('I accept')
168
  ```<end_code>
169
-
170
  Proceed in several steps rather than trying to solve the task in one shot.
171
  And at the end, only when you have your answer, return your final answer.
172
  Code:
173
  ```py
174
  final_answer("YOUR_ANSWER_HERE")
175
  ```<end_code>
176
-
177
  If pages seem stuck on loading, you might have to wait, for instance `import time` and run `time.sleep(5.0)`. But don't overuse this!
178
  To list elements on page, DO NOT try code-based element searches like 'contributors = find_all(S("ol > li"))': just look at the latest screenshot you have and read it visually, or use your tool search_item_ctrl_f.
179
  Of course, you can act on buttons like a user would do when navigating.
@@ -205,4 +196,4 @@ def main():
205
 
206
 
207
  if __name__ == "__main__":
208
- main()
 
9
  from selenium.webdriver.common.by import By
10
  from selenium.webdriver.common.keys import Keys
11
 
12
+ from smolagents import CodeAgent, WebSearchTool, tool
13
  from smolagents.agents import ActionStep
14
  from smolagents.cli import load_model
15
 
16
 
17
  alfred_guest_list_request = """
18
  I am Alfred, the butler of Wayne Manor, responsible for verifying the identity of guests at party. A superhero has arrived at the entrance claiming to be Wonder Woman, but I need to confirm if she is who she says she is.
 
19
  Please search for images of Wonder Woman and generate a detailed visual description based on those images. Additionally, navigate to Wikipedia to gather key details about her appearance. With this information, I can determine whether to grant her access to the event.
20
  """
21
 
 
110
  def initialize_agent(model):
111
  """Initialize the CodeAgent with the specified model."""
112
  return CodeAgent(
113
+ tools=[WebSearchTool(), go_back, close_popups, search_item_ctrl_f],
114
  model=model,
115
  additional_authorized_imports=["helium"],
116
  step_callbacks=[save_screenshot],
 
129
  ```py
130
  go_to('github.com/trending')
131
  ```<end_code>
 
132
  You can directly click clickable elements by inputting the text that appears on them.
133
  Code:
134
  ```py
135
  click("Top products")
136
  ```<end_code>
 
137
  If it's a link:
138
  Code:
139
  ```py
140
  click(Link("Top products"))
141
  ```<end_code>
 
142
  If you try to interact with an element and it's not found, you'll get a LookupError.
143
  In general stop your action after each button click to see what happens on your screenshot.
144
  Never try to login in a page.
 
145
  To scroll up or down, use scroll_down or scroll_up with as an argument the number of pixels to scroll from.
146
  Code:
147
  ```py
148
  scroll_down(num_pixels=1200) # This will scroll one viewport down
149
  ```<end_code>
 
150
  When you have pop-ups with a cross icon to close, don't try to click the close icon by finding its element or targeting an 'X' element (this most often fails).
151
  Just use your built-in tool `close_popups` to close them:
152
  Code:
153
  ```py
154
  close_popups()
155
  ```<end_code>
 
156
  You can use .exists() to check for the existence of an element. For example:
157
  Code:
158
  ```py
159
  if Text('Accept cookies?').exists():
160
  click('I accept')
161
  ```<end_code>
 
162
  Proceed in several steps rather than trying to solve the task in one shot.
163
  And at the end, only when you have your answer, return your final answer.
164
  Code:
165
  ```py
166
  final_answer("YOUR_ANSWER_HERE")
167
  ```<end_code>
 
168
  If pages seem stuck on loading, you might have to wait, for instance `import time` and run `time.sleep(5.0)`. But don't overuse this!
169
  To list elements on page, DO NOT try code-based element searches like 'contributors = find_all(S("ol > li"))': just look at the latest screenshot you have and read it visually, or use your tool search_item_ctrl_f.
170
  Of course, you can act on buttons like a user would do when navigating.
 
196
 
197
 
198
  if __name__ == "__main__":
199
+ main()