Spaces:
Sleeping
Sleeping
File size: 43,761 Bytes
b7f6754 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | {
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "995f4d22",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/zonca/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"from smolagents import LiteLLMModel\n",
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"load_dotenv()\n",
"\n",
"# Replace all calls to HfApiModel\n",
"llm_model = LiteLLMModel(\n",
" model_id=\"gemini/gemini-2.0-flash\", # you can see other model names here: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models. It is important to prefix the name with \"gemini/\"\n",
" api_key=os.getenv(\"GEMINI_API_KEY\"),\n",
" max_tokens=8192\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "38e0f80a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The capital of France is **Paris**.\n",
"\n"
]
}
],
"source": [
"response = llm_model([\n",
" {\"role\": \"user\", \"content\": \"What is the capital of France?\"}\n",
"])\n",
"print(response.content)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "939309dd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d4b702; text-decoration-color: #d4b702\">โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ </span><span style=\"color: #d4b702; text-decoration-color: #d4b702; font-weight: bold\">New run</span><span style=\"color: #d4b702; text-decoration-color: #d4b702\"> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"font-weight: bold\">Call echo with 'hello'</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โฐโ HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[38;2;212;183;2mโญโ\u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2mโโฎ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[1mCall echo with 'hello'\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโฐโ\u001b[0m\u001b[38;2;212;183;2m HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct \u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2mโโฏ\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d4b702; text-decoration-color: #d4b702\">โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ </span><span style=\"font-weight: bold\">Step </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"color: #d4b702; text-decoration-color: #d4b702\"> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">Error in generating model output:</span>\n",
"<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">InferenceClient.chat_completion</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">() got an unexpected keyword argument </span><span style=\"color: #008000; text-decoration-color: #008000\">'repo_id'</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[1;31mError in generating model output:\u001b[0m\n",
"\u001b[1;35mInferenceClient.chat_completion\u001b[0m\u001b[1;31m(\u001b[0m\u001b[1;31m)\u001b[0m\u001b[1;31m got an unexpected keyword argument \u001b[0m\u001b[32m'repo_id'\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">[Step 1: Duration 0.01 seconds]</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[2m[Step 1: Duration 0.01 seconds]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"ename": "AgentGenerationError",
"evalue": "Error in generating model output:\nInferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:1266\u001b[39m, in \u001b[36mCodeAgent.step\u001b[39m\u001b[34m(self, memory_step)\u001b[39m\n\u001b[32m 1265\u001b[39m additional_args = {\u001b[33m\"\u001b[39m\u001b[33mgrammar\u001b[39m\u001b[33m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m.grammar} \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.grammar \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m {}\n\u001b[32m-> \u001b[39m\u001b[32m1266\u001b[39m chat_message: ChatMessage = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1267\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43minput_messages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1268\u001b[39m \u001b[43m \u001b[49m\u001b[43mstop_sequences\u001b[49m\u001b[43m=\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m<end_code>\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mObservation:\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mCalling tools:\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1269\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43madditional_args\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1270\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1271\u001b[39m memory_step.model_output_message = chat_message\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/models.py:1090\u001b[39m, in \u001b[36mInferenceClientModel.__call__\u001b[39m\u001b[34m(self, messages, stop_sequences, grammar, tools_to_call_from, **kwargs)\u001b[39m\n\u001b[32m 1081\u001b[39m completion_kwargs = \u001b[38;5;28mself\u001b[39m._prepare_completion_kwargs(\n\u001b[32m 1082\u001b[39m messages=messages,\n\u001b[32m 1083\u001b[39m stop_sequences=stop_sequences,\n\u001b[32m (...)\u001b[39m\u001b[32m 1088\u001b[39m **kwargs,\n\u001b[32m 1089\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1090\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat_completion\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mcompletion_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1092\u001b[39m \u001b[38;5;28mself\u001b[39m.last_input_token_count = response.usage.prompt_tokens\n",
"\u001b[31mTypeError\u001b[39m: InferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[31mAgentGenerationError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 28\u001b[39m\n\u001b[32m 25\u001b[39m agent = CodeAgent(tools=[echo], model=model)\n\u001b[32m 27\u001b[39m \u001b[38;5;66;03m# Run the agent with a prompt\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m28\u001b[39m response = \u001b[43magent\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mCall echo with \u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mhello\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 29\u001b[39m \u001b[38;5;28mprint\u001b[39m(response)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:341\u001b[39m, in \u001b[36mMultiStepAgent.run\u001b[39m\u001b[34m(self, task, stream, reset, images, additional_args, max_steps)\u001b[39m\n\u001b[32m 339\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._run(task=\u001b[38;5;28mself\u001b[39m.task, max_steps=max_steps, images=images)\n\u001b[32m 340\u001b[39m \u001b[38;5;66;03m# Outputs are returned only at the end. We only look at the last step.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m341\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdeque\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_run\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_steps\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmax_steps\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mimages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mimages\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmaxlen\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[43m)\u001b[49m[\u001b[32m0\u001b[39m].final_answer\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:365\u001b[39m, in \u001b[36mMultiStepAgent._run\u001b[39m\u001b[34m(self, task, max_steps, images)\u001b[39m\n\u001b[32m 362\u001b[39m final_answer = \u001b[38;5;28mself\u001b[39m._execute_step(task, action_step)\n\u001b[32m 363\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentGenerationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 364\u001b[39m \u001b[38;5;66;03m# Agent generation errors are not caused by a Model error but an implementation error: so we should raise them and exit.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m365\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[32m 366\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 367\u001b[39m \u001b[38;5;66;03m# Other AgentError types are caused by the Model, so we should log them and iterate.\u001b[39;00m\n\u001b[32m 368\u001b[39m action_step.error = e\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:362\u001b[39m, in \u001b[36mMultiStepAgent._run\u001b[39m\u001b[34m(self, task, max_steps, images)\u001b[39m\n\u001b[32m 360\u001b[39m action_step = \u001b[38;5;28mself\u001b[39m._create_action_step(step_start_time, images)\n\u001b[32m 361\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m362\u001b[39m final_answer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_execute_step\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maction_step\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 363\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentGenerationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 364\u001b[39m \u001b[38;5;66;03m# Agent generation errors are not caused by a Model error but an implementation error: so we should raise them and exit.\u001b[39;00m\n\u001b[32m 365\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:385\u001b[39m, in \u001b[36mMultiStepAgent._execute_step\u001b[39m\u001b[34m(self, task, memory_step)\u001b[39m\n\u001b[32m 383\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_execute_step\u001b[39m(\u001b[38;5;28mself\u001b[39m, task: \u001b[38;5;28mstr\u001b[39m, memory_step: ActionStep) -> Union[\u001b[38;5;28;01mNone\u001b[39;00m, Any]:\n\u001b[32m 384\u001b[39m \u001b[38;5;28mself\u001b[39m.logger.log_rule(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mStep \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m.step_number\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m, level=LogLevel.INFO)\n\u001b[32m--> \u001b[39m\u001b[32m385\u001b[39m final_answer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmemory_step\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 386\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m final_answer \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m.final_answer_checks:\n\u001b[32m 387\u001b[39m \u001b[38;5;28mself\u001b[39m._validate_final_answer(final_answer)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:1282\u001b[39m, in \u001b[36mCodeAgent.step\u001b[39m\u001b[34m(self, memory_step)\u001b[39m\n\u001b[32m 1280\u001b[39m memory_step.model_output = model_output\n\u001b[32m 1281\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m-> \u001b[39m\u001b[32m1282\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m AgentGenerationError(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mError in generating model output:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00me\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m, \u001b[38;5;28mself\u001b[39m.logger) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n\u001b[32m 1284\u001b[39m \u001b[38;5;28mself\u001b[39m.logger.log_markdown(\n\u001b[32m 1285\u001b[39m content=model_output,\n\u001b[32m 1286\u001b[39m title=\u001b[33m\"\u001b[39m\u001b[33mOutput message of the LLM:\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 1287\u001b[39m level=LogLevel.DEBUG,\n\u001b[32m 1288\u001b[39m )\n\u001b[32m 1290\u001b[39m \u001b[38;5;66;03m# Parse\u001b[39;00m\n",
"\u001b[31mAgentGenerationError\u001b[39m: Error in generating model output:\nInferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'"
]
}
],
"source": [
"import os\n",
"from smolagents import CodeAgent, HfApiModel, tool\n",
"\n",
"# Set your Hugging Face API token\n",
"os.environ[\"HF_API_TOKEN\"] = \"<your-huggingface-token>\"\n",
"\n",
"# Define a simple tool\n",
"@tool\n",
"def echo(text: str) -> str:\n",
" \"\"\"\n",
" Echo the input text.\n",
"\n",
" Args:\n",
" text (str): The text to echo.\n",
"\n",
" Returns:\n",
" str: The same text that was input.\n",
" \"\"\"\n",
" return text\n",
"\n",
"# Initialize the model\n",
"model = HfApiModel(repo_id=\"HuggingFaceH4/zephyr-7b-beta\") # or another supported model\n",
"\n",
"# Create the agent with the tool\n",
"agent = CodeAgent(tools=[echo], model=model)\n",
"\n",
"# Run the agent with a prompt\n",
"response = agent.run(\"Call echo with 'hello'\")\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9f94c824",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d4b702; text-decoration-color: #d4b702\">โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ </span><span style=\"color: #d4b702; text-decoration-color: #d4b702; font-weight: bold\">New run</span><span style=\"color: #d4b702; text-decoration-color: #d4b702\"> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"font-weight: bold\">How many seconds would it take for a leopard at full speed to run through Pont des Arts?</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ</span>\n",
"<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โฐโ InferenceClientModel - Qwen/Qwen2.5-Coder-32B-Instruct โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[38;2;212;183;2mโญโ\u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2mโโฎ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[1mHow many seconds would it take for a leopard at full speed to run through Pont des Arts?\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโ\u001b[0m \u001b[38;2;212;183;2mโ\u001b[0m\n",
"\u001b[38;2;212;183;2mโฐโ\u001b[0m\u001b[38;2;212;183;2m InferenceClientModel - Qwen/Qwen2.5-Coder-32B-Instruct \u001b[0m\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\u001b[38;2;212;183;2mโโฏ\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d4b702; text-decoration-color: #d4b702\">โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ </span><span style=\"font-weight: bold\">Step </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"color: #d4b702; text-decoration-color: #d4b702\"> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[38;2;212;183;2mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">Error in generating model output:</span>\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">404</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\"> Client Error: Not Found for url: </span>\n",
"<span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\"> (Request ID: </span>\n",
"<span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">Root</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">=</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">-681045d9-038c834f3e57cf572c3f9c02;</span><span style=\"color: #ffff00; text-decoration-color: #ffff00\">195ac9a0-e49e-48f8-a238-84c03d4c9606</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">)</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[1;31mError in generating model output:\u001b[0m\n",
"\u001b[1;36m404\u001b[0m\u001b[1;31m Client Error: Not Found for url: \u001b[0m\n",
"\u001b[4;94mhttps://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions\u001b[0m\u001b[1;31m \u001b[0m\u001b[1;31m(\u001b[0m\u001b[1;31mRequest ID: \u001b[0m\n",
"\u001b[1;33mRoot\u001b[0m\u001b[1;31m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;31m-681045d9-038c834f3e57cf572c3f9c02;\u001b[0m\u001b[93m195ac9a0-e49e-48f8-a238-84c03d4c9606\u001b[0m\u001b[1;31m)\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">[Step 1: Duration 0.57 seconds]</span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[2m[Step 1: Duration 0.57 seconds]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"ename": "AgentGenerationError",
"evalue": "Error in generating model output:\n404 Client Error: Not Found for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Root=1-681045d9-038c834f3e57cf572c3f9c02;195ac9a0-e49e-48f8-a238-84c03d4c9606)",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mHTTPError\u001b[39m Traceback (most recent call last)",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/huggingface_hub/utils/_http.py:409\u001b[39m, in \u001b[36mhf_raise_for_status\u001b[39m\u001b[34m(response, endpoint_name)\u001b[39m\n\u001b[32m 408\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m409\u001b[39m \u001b[43mresponse\u001b[49m\u001b[43m.\u001b[49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 410\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/requests/models.py:1024\u001b[39m, in \u001b[36mResponse.raise_for_status\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1023\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[32m-> \u001b[39m\u001b[32m1024\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response=\u001b[38;5;28mself\u001b[39m)\n",
"\u001b[31mHTTPError\u001b[39m: 404 Client Error: Not Found for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[31mHfHubHTTPError\u001b[39m Traceback (most recent call last)",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:1266\u001b[39m, in \u001b[36mCodeAgent.step\u001b[39m\u001b[34m(self, memory_step)\u001b[39m\n\u001b[32m 1265\u001b[39m additional_args = {\u001b[33m\"\u001b[39m\u001b[33mgrammar\u001b[39m\u001b[33m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m.grammar} \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.grammar \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m {}\n\u001b[32m-> \u001b[39m\u001b[32m1266\u001b[39m chat_message: ChatMessage = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1267\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43minput_messages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1268\u001b[39m \u001b[43m \u001b[49m\u001b[43mstop_sequences\u001b[49m\u001b[43m=\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m<end_code>\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mObservation:\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mCalling tools:\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1269\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43madditional_args\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1270\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1271\u001b[39m memory_step.model_output_message = chat_message\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/models.py:1090\u001b[39m, in \u001b[36mInferenceClientModel.__call__\u001b[39m\u001b[34m(self, messages, stop_sequences, grammar, tools_to_call_from, **kwargs)\u001b[39m\n\u001b[32m 1081\u001b[39m completion_kwargs = \u001b[38;5;28mself\u001b[39m._prepare_completion_kwargs(\n\u001b[32m 1082\u001b[39m messages=messages,\n\u001b[32m 1083\u001b[39m stop_sequences=stop_sequences,\n\u001b[32m (...)\u001b[39m\u001b[32m 1088\u001b[39m **kwargs,\n\u001b[32m 1089\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1090\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat_completion\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mcompletion_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1092\u001b[39m \u001b[38;5;28mself\u001b[39m.last_input_token_count = response.usage.prompt_tokens\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/huggingface_hub/inference/_client.py:992\u001b[39m, in \u001b[36mInferenceClient.chat_completion\u001b[39m\u001b[34m(self, messages, model, stream, frequency_penalty, logit_bias, logprobs, max_tokens, n, presence_penalty, response_format, seed, stop, stream_options, temperature, tool_choice, tool_prompt, tools, top_logprobs, top_p, extra_body)\u001b[39m\n\u001b[32m 985\u001b[39m request_parameters = provider_helper.prepare_request(\n\u001b[32m 986\u001b[39m inputs=messages,\n\u001b[32m 987\u001b[39m parameters=parameters,\n\u001b[32m (...)\u001b[39m\u001b[32m 990\u001b[39m api_key=\u001b[38;5;28mself\u001b[39m.token,\n\u001b[32m 991\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m992\u001b[39m data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_inner_post\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest_parameters\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 994\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m stream:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/huggingface_hub/inference/_client.py:357\u001b[39m, in \u001b[36mInferenceClient._inner_post\u001b[39m\u001b[34m(self, request_parameters, stream)\u001b[39m\n\u001b[32m 356\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m357\u001b[39m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 358\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m response.iter_lines() \u001b[38;5;28;01mif\u001b[39;00m stream \u001b[38;5;28;01melse\u001b[39;00m response.content\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/huggingface_hub/utils/_http.py:482\u001b[39m, in \u001b[36mhf_raise_for_status\u001b[39m\u001b[34m(response, endpoint_name)\u001b[39m\n\u001b[32m 480\u001b[39m \u001b[38;5;66;03m# Convert `HTTPError` into a `HfHubHTTPError` to display request information\u001b[39;00m\n\u001b[32m 481\u001b[39m \u001b[38;5;66;03m# as well (request id and/or server error message)\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m482\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m _format(HfHubHTTPError, \u001b[38;5;28mstr\u001b[39m(e), response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n",
"\u001b[31mHfHubHTTPError\u001b[39m: 404 Client Error: Not Found for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Root=1-681045d9-038c834f3e57cf572c3f9c02;195ac9a0-e49e-48f8-a238-84c03d4c9606)",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[31mAgentGenerationError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[8]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 3\u001b[39m model = InferenceClientModel()\n\u001b[32m 4\u001b[39m agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[43magent\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mHow many seconds would it take for a leopard at full speed to run through Pont des Arts?\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:341\u001b[39m, in \u001b[36mMultiStepAgent.run\u001b[39m\u001b[34m(self, task, stream, reset, images, additional_args, max_steps)\u001b[39m\n\u001b[32m 339\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._run(task=\u001b[38;5;28mself\u001b[39m.task, max_steps=max_steps, images=images)\n\u001b[32m 340\u001b[39m \u001b[38;5;66;03m# Outputs are returned only at the end. We only look at the last step.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m341\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdeque\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_run\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_steps\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmax_steps\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mimages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mimages\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmaxlen\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[43m)\u001b[49m[\u001b[32m0\u001b[39m].final_answer\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:365\u001b[39m, in \u001b[36mMultiStepAgent._run\u001b[39m\u001b[34m(self, task, max_steps, images)\u001b[39m\n\u001b[32m 362\u001b[39m final_answer = \u001b[38;5;28mself\u001b[39m._execute_step(task, action_step)\n\u001b[32m 363\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentGenerationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 364\u001b[39m \u001b[38;5;66;03m# Agent generation errors are not caused by a Model error but an implementation error: so we should raise them and exit.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m365\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[32m 366\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 367\u001b[39m \u001b[38;5;66;03m# Other AgentError types are caused by the Model, so we should log them and iterate.\u001b[39;00m\n\u001b[32m 368\u001b[39m action_step.error = e\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:362\u001b[39m, in \u001b[36mMultiStepAgent._run\u001b[39m\u001b[34m(self, task, max_steps, images)\u001b[39m\n\u001b[32m 360\u001b[39m action_step = \u001b[38;5;28mself\u001b[39m._create_action_step(step_start_time, images)\n\u001b[32m 361\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m362\u001b[39m final_answer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_execute_step\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maction_step\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 363\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m AgentGenerationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 364\u001b[39m \u001b[38;5;66;03m# Agent generation errors are not caused by a Model error but an implementation error: so we should raise them and exit.\u001b[39;00m\n\u001b[32m 365\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:385\u001b[39m, in \u001b[36mMultiStepAgent._execute_step\u001b[39m\u001b[34m(self, task, memory_step)\u001b[39m\n\u001b[32m 383\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_execute_step\u001b[39m(\u001b[38;5;28mself\u001b[39m, task: \u001b[38;5;28mstr\u001b[39m, memory_step: ActionStep) -> Union[\u001b[38;5;28;01mNone\u001b[39;00m, Any]:\n\u001b[32m 384\u001b[39m \u001b[38;5;28mself\u001b[39m.logger.log_rule(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mStep \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m.step_number\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m, level=LogLevel.INFO)\n\u001b[32m--> \u001b[39m\u001b[32m385\u001b[39m final_answer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmemory_step\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 386\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m final_answer \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m.final_answer_checks:\n\u001b[32m 387\u001b[39m \u001b[38;5;28mself\u001b[39m._validate_final_answer(final_answer)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/p/software/Final_Assignment_Template/.venv/lib/python3.13/site-packages/smolagents/agents.py:1282\u001b[39m, in \u001b[36mCodeAgent.step\u001b[39m\u001b[34m(self, memory_step)\u001b[39m\n\u001b[32m 1280\u001b[39m memory_step.model_output = model_output\n\u001b[32m 1281\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m-> \u001b[39m\u001b[32m1282\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m AgentGenerationError(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mError in generating model output:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00me\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m, \u001b[38;5;28mself\u001b[39m.logger) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n\u001b[32m 1284\u001b[39m \u001b[38;5;28mself\u001b[39m.logger.log_markdown(\n\u001b[32m 1285\u001b[39m content=model_output,\n\u001b[32m 1286\u001b[39m title=\u001b[33m\"\u001b[39m\u001b[33mOutput message of the LLM:\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 1287\u001b[39m level=LogLevel.DEBUG,\n\u001b[32m 1288\u001b[39m )\n\u001b[32m 1290\u001b[39m \u001b[38;5;66;03m# Parse\u001b[39;00m\n",
"\u001b[31mAgentGenerationError\u001b[39m: Error in generating model output:\n404 Client Error: Not Found for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Root=1-681045d9-038c834f3e57cf572c3f9c02;195ac9a0-e49e-48f8-a238-84c03d4c9606)"
]
}
],
"source": [
"from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel\n",
"\n",
"model = InferenceClientModel()\n",
"agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)\n",
"\n",
"agent.run(\"How many seconds would it take for a leopard at full speed to run through Pont des Arts?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b9fc943",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|