|
32 | 32 | "```\n",
|
33 | 33 | "Let's set up this system. \n",
|
34 | 34 | "\n",
|
| 35 | +<<<<<<< Updated upstream |
| 36 | +======= |
| 37 | + "⚡️ Our agent will be powered by [meta-llama/Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) using `HfApiModel` class that uses HF's Inference API: the Inference API allows to quickly and easily run any OS model.\n", |
| 38 | + "\n", |
| 39 | +>>>>>>> Stashed changes |
35 | 40 | "Run the line below to install the required dependencies:"
|
36 | 41 | ]
|
37 | 42 | },
|
|
41 | 46 | "metadata": {},
|
42 | 47 | "outputs": [],
|
43 | 48 | "source": [
|
44 |
| - "!pip install markdownify duckduckgo-search \"transformers[agents]\" --upgrade -q" |
| 49 | + "!pip install markdownify duckduckgo-search smolagents --upgrade -q" |
45 | 50 | ]
|
46 | 51 | },
|
47 | 52 | {
|
|
104 | 109 | "import requests\n",
|
105 | 110 | "from markdownify import markdownify as md\n",
|
106 | 111 | "from requests.exceptions import RequestException\n",
|
107 |
| - "from transformers.agents import tool\n", |
| 112 | + "from smolagents import tool\n", |
108 | 113 | "\n",
|
109 | 114 | "\n",
|
110 | 115 | "@tool\n",
|
|
187 | 192 | "Now that we have all the tools `search` and `visit_webpage`, we can use them to create the web agent.\n",
|
188 | 193 | "\n",
|
189 | 194 | "Which configuration to choose for this agent?\n",
|
190 |
| - "- Web browsing is a single-timeline task that does not require parallel tool calls, so JSON tool calling works well for that. We thus choose a `ReactJsonAgent`.\n", |
| 195 | + "- Web browsing is a single-timeline task that does not require parallel tool calls, so JSON tool calling works well for that. We thus choose a `ToolCallingAgent`.\n", |
191 | 196 | "- Also, since sometimes web search requires exploring many pages before finding the correct answer, we prefer to increase the number of `max_iterations` to 10."
|
192 | 197 | ]
|
193 | 198 | },
|
|
197 | 202 | "metadata": {},
|
198 | 203 | "outputs": [],
|
199 | 204 | "source": [
|
200 |
| - "from transformers.agents import (\n", |
201 |
| - " ReactCodeAgent,\n", |
202 |
| - " ReactJsonAgent,\n", |
203 |
| - " HfApiEngine,\n", |
| 205 | + "from smolagents import (\n", |
| 206 | + " CodeAgent,\n", |
| 207 | + " ToolCallingAgent,\n", |
| 208 | + " HfApiModel,\n", |
204 | 209 | " ManagedAgent,\n",
|
205 | 210 | ")\n",
|
206 |
| - "from transformers.agents.search import DuckDuckGoSearchTool\n", |
| 211 | + "from smolagents.search import DuckDuckGoSearchTool\n", |
207 | 212 | "\n",
|
208 |
| - "llm_engine = HfApiEngine(model)\n", |
| 213 | + "model = HfApiModel(model)\n", |
209 | 214 | "\n",
|
210 |
| - "web_agent = ReactJsonAgent(\n", |
| 215 | + "web_agent = ToolCallingAgent(\n", |
211 | 216 | " tools=[DuckDuckGoSearchTool(), visit_webpage],\n",
|
212 |
| - " llm_engine=llm_engine,\n", |
| 217 | + " model=model,\n", |
213 | 218 | " max_iterations=10,\n",
|
214 | 219 | ")"
|
215 | 220 | ]
|
|
240 | 245 | "source": [
|
241 | 246 | "Finally we create a manager agent, and upon initialization we pass our managed agent to it in its `managed_agents` argument.\n",
|
242 | 247 | "\n",
|
243 |
| - "Since this agent is the one tasked with the planning and thinking, advanced reasoning will be beneficial, so a `ReactCodeAgent` will be the best choice.\n", |
| 248 | + "Since this agent is the one tasked with the planning and thinking, advanced reasoning will be beneficial, so a `CodeAgent` will be the best choice.\n", |
244 | 249 | "\n",
|
245 | 250 | "Also, we want to ask a question that involves the current year: so let us add `additional_authorized_imports=[\"time\", \"datetime\"]`"
|
246 | 251 | ]
|
|
251 | 256 | "metadata": {},
|
252 | 257 | "outputs": [],
|
253 | 258 | "source": [
|
254 |
| - "manager_agent = ReactCodeAgent(\n", |
| 259 | + "manager_agent = CodeAgent(\n", |
255 | 260 | " tools=[],\n",
|
256 |
| - " llm_engine=llm_engine,\n", |
| 261 | + " model=model,\n", |
257 | 262 | " managed_agents=[managed_web_agent],\n",
|
258 | 263 | " additional_authorized_imports=[\"time\", \"datetime\"],\n",
|
259 | 264 | ")"
|
|
0 commit comments