zonca commited on
Commit
b7f6754
ยท
1 Parent(s): 4601922

use gemini and wait 60s to avoid quota

Browse files
Files changed (3) hide show
  1. .env +2 -0
  2. app.py +31 -3
  3. test_notebook.ipynb +318 -0
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GEMINI_API_KEY=AIzaSyAV85Sy_lNSvDJFiNmppB1VqLXvJr6mz3k
2
+ GOOGLE_API_KEY=AIzaSyAV85Sy_lNSvDJFiNmppB1VqLXvJr6mz3k
app.py CHANGED
@@ -3,15 +3,20 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
6
 
7
  # Updated smolagents import
8
  from smolagents import (
9
  CodeAgent,
10
  DuckDuckGoSearchTool,
11
  VisitWebpageTool,
12
- HfApiModel,
13
  )
14
 
 
 
 
15
  # (Keep Constants as is)
16
  # --- Constants ---
17
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -31,7 +36,17 @@ class MyAgent:
31
  def __init__(self):
32
  print("MyAgent initialized.")
33
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
34
- self.model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
 
 
 
 
 
 
 
 
 
 
35
  self.agent = CodeAgent(tools=self.tools, model=self.model)
36
 
37
  def __call__(self, question: str) -> str:
@@ -94,12 +109,17 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
94
  results_log = []
95
  answers_payload = []
96
  print(f"Running agent on {len(questions_data)} questions...")
97
- for item in questions_data:
98
  task_id = item.get("task_id")
99
  question_text = item.get("question")
100
  if not task_id or question_text is None:
101
  print(f"Skipping item with missing task_id or question: {item}")
102
  continue
 
 
 
 
 
103
  try:
104
  submitted_answer = agent(question_text)
105
  answers_payload.append(
@@ -112,6 +132,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
112
  "Submitted Answer": submitted_answer,
113
  }
114
  )
 
 
 
115
  except Exception as e:
116
  print(f"Error running agent on task {task_id}: {e}")
117
  results_log.append(
@@ -122,6 +145,11 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
122
  }
123
  )
124
 
 
 
 
 
 
125
  if not answers_payload:
126
  print("Agent did not produce any answers to submit.")
127
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from dotenv import load_dotenv
7
+ import time # Add this import
8
 
9
  # Updated smolagents import
10
  from smolagents import (
11
  CodeAgent,
12
  DuckDuckGoSearchTool,
13
  VisitWebpageTool,
14
+ LiteLLMModel, # Add this import
15
  )
16
 
17
+ # Load environment variables from .env file
18
+ load_dotenv() # Add this line
19
+
20
  # (Keep Constants as is)
21
  # --- Constants ---
22
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
36
  def __init__(self):
37
  print("MyAgent initialized.")
38
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
39
+ # Replace HfApiModel with LiteLLMModel
40
+ gemini_api_key = os.getenv("GEMINI_API_KEY")
41
+ if not gemini_api_key:
42
+ raise ValueError("GEMINI_API_KEY environment variable not set.")
43
+ self.model = LiteLLMModel(
44
+ model_id="gemini/gemini-2.0-flash",
45
+ api_key=gemini_api_key,
46
+ # You might need to adjust max_tokens depending on the model and task
47
+ max_tokens=8192,
48
+ temperature=0.2,
49
+ )
50
  self.agent = CodeAgent(tools=self.tools, model=self.model)
51
 
52
  def __call__(self, question: str) -> str:
 
109
  results_log = []
110
  answers_payload = []
111
  print(f"Running agent on {len(questions_data)} questions...")
112
+ for i, item in enumerate(questions_data): # Use enumerate to track progress
113
  task_id = item.get("task_id")
114
  question_text = item.get("question")
115
  if not task_id or question_text is None:
116
  print(f"Skipping item with missing task_id or question: {item}")
117
  continue
118
+
119
+ print(
120
+ f"Processing question {i+1}/{len(questions_data)} (Task ID: {task_id})..."
121
+ ) # Add progress print
122
+
123
  try:
124
  submitted_answer = agent(question_text)
125
  answers_payload.append(
 
132
  "Submitted Answer": submitted_answer,
133
  }
134
  )
135
+ print(
136
+ f" -> Answer generated for Task ID {task_id}."
137
+ ) # Indicate completion
138
  except Exception as e:
139
  print(f"Error running agent on task {task_id}: {e}")
140
  results_log.append(
 
145
  }
146
  )
147
 
148
+ # Add a 60-second delay after processing each question
149
+ if i < len(questions_data) - 1: # Don't wait after the last question
150
+ print(f"Waiting 60 seconds before next question...")
151
+ time.sleep(60)
152
+
153
  if not answers_payload:
154
  print("Agent did not produce any answers to submit.")
155
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
test_notebook.ipynb ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "995f4d22",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/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",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "from smolagents import LiteLLMModel\n",
20
+ "from dotenv import load_dotenv\n",
21
+ "import os\n",
22
+ "\n",
23
+ "load_dotenv()\n",
24
+ "\n",
25
+ "# Replace all calls to HfApiModel\n",
26
+ "llm_model = LiteLLMModel(\n",
27
+ " 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",
28
+ " api_key=os.getenv(\"GEMINI_API_KEY\"),\n",
29
+ " max_tokens=8192\n",
30
+ ")"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 2,
36
+ "id": "38e0f80a",
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "name": "stdout",
41
+ "output_type": "stream",
42
+ "text": [
43
+ "The capital of France is **Paris**.\n",
44
+ "\n"
45
+ ]
46
+ }
47
+ ],
48
+ "source": [
49
+ "response = llm_model([\n",
50
+ " {\"role\": \"user\", \"content\": \"What is the capital of France?\"}\n",
51
+ "])\n",
52
+ "print(response.content)"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 7,
58
+ "id": "939309dd",
59
+ "metadata": {},
60
+ "outputs": [
61
+ {
62
+ "data": {
63
+ "text/html": [
64
+ "<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",
65
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span>\n",
66
+ "<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",
67
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span>\n",
68
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ•ฐโ”€ HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ</span>\n",
69
+ "</pre>\n"
70
+ ],
71
+ "text/plain": [
72
+ "\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",
73
+ "\u001b[38;2;212;183;2mโ”‚\u001b[0m \u001b[38;2;212;183;2mโ”‚\u001b[0m\n",
74
+ "\u001b[38;2;212;183;2mโ”‚\u001b[0m \u001b[1mCall echo with 'hello'\u001b[0m \u001b[38;2;212;183;2mโ”‚\u001b[0m\n",
75
+ "\u001b[38;2;212;183;2mโ”‚\u001b[0m \u001b[38;2;212;183;2mโ”‚\u001b[0m\n",
76
+ "\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"
77
+ ]
78
+ },
79
+ "metadata": {},
80
+ "output_type": "display_data"
81
+ },
82
+ {
83
+ "data": {
84
+ "text/html": [
85
+ "<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",
86
+ "</pre>\n"
87
+ ],
88
+ "text/plain": [
89
+ "\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"
90
+ ]
91
+ },
92
+ "metadata": {},
93
+ "output_type": "display_data"
94
+ },
95
+ {
96
+ "data": {
97
+ "text/html": [
98
+ "<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",
99
+ "<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",
100
+ "</pre>\n"
101
+ ],
102
+ "text/plain": [
103
+ "\u001b[1;31mError in generating model output:\u001b[0m\n",
104
+ "\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"
105
+ ]
106
+ },
107
+ "metadata": {},
108
+ "output_type": "display_data"
109
+ },
110
+ {
111
+ "data": {
112
+ "text/html": [
113
+ "<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",
114
+ "</pre>\n"
115
+ ],
116
+ "text/plain": [
117
+ "\u001b[2m[Step 1: Duration 0.01 seconds]\u001b[0m\n"
118
+ ]
119
+ },
120
+ "metadata": {},
121
+ "output_type": "display_data"
122
+ },
123
+ {
124
+ "ename": "AgentGenerationError",
125
+ "evalue": "Error in generating model output:\nInferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'",
126
+ "output_type": "error",
127
+ "traceback": [
128
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
129
+ "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
130
+ "\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",
131
+ "\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",
132
+ "\u001b[31mTypeError\u001b[39m: InferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'",
133
+ "\nThe above exception was the direct cause of the following exception:\n",
134
+ "\u001b[31mAgentGenerationError\u001b[39m Traceback (most recent call last)",
135
+ "\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",
136
+ "\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",
137
+ "\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",
138
+ "\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",
139
+ "\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",
140
+ "\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",
141
+ "\u001b[31mAgentGenerationError\u001b[39m: Error in generating model output:\nInferenceClient.chat_completion() got an unexpected keyword argument 'repo_id'"
142
+ ]
143
+ }
144
+ ],
145
+ "source": [
146
+ "import os\n",
147
+ "from smolagents import CodeAgent, HfApiModel, tool\n",
148
+ "\n",
149
+ "# Set your Hugging Face API token\n",
150
+ "os.environ[\"HF_API_TOKEN\"] = \"<your-huggingface-token>\"\n",
151
+ "\n",
152
+ "# Define a simple tool\n",
153
+ "@tool\n",
154
+ "def echo(text: str) -> str:\n",
155
+ " \"\"\"\n",
156
+ " Echo the input text.\n",
157
+ "\n",
158
+ " Args:\n",
159
+ " text (str): The text to echo.\n",
160
+ "\n",
161
+ " Returns:\n",
162
+ " str: The same text that was input.\n",
163
+ " \"\"\"\n",
164
+ " return text\n",
165
+ "\n",
166
+ "# Initialize the model\n",
167
+ "model = HfApiModel(repo_id=\"HuggingFaceH4/zephyr-7b-beta\") # or another supported model\n",
168
+ "\n",
169
+ "# Create the agent with the tool\n",
170
+ "agent = CodeAgent(tools=[echo], model=model)\n",
171
+ "\n",
172
+ "# Run the agent with a prompt\n",
173
+ "response = agent.run(\"Call echo with 'hello'\")\n",
174
+ "print(response)"
175
+ ]
176
+ },
177
+ {
178
+ "cell_type": "code",
179
+ "execution_count": 8,
180
+ "id": "9f94c824",
181
+ "metadata": {},
182
+ "outputs": [
183
+ {
184
+ "data": {
185
+ "text/html": [
186
+ "<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",
187
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span>\n",
188
+ "<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",
189
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span> <span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ”‚</span>\n",
190
+ "<span style=\"color: #d4b702; text-decoration-color: #d4b702\">โ•ฐโ”€ InferenceClientModel - Qwen/Qwen2.5-Coder-32B-Instruct โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ</span>\n",
191
+ "</pre>\n"
192
+ ],
193
+ "text/plain": [
194
+ "\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",
195
+ "\u001b[38;2;212;183;2mโ”‚\u001b[0m \u001b[38;2;212;183;2mโ”‚\u001b[0m\n",
196
+ "\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",
197
+ "\u001b[38;2;212;183;2mโ”‚\u001b[0m \u001b[38;2;212;183;2mโ”‚\u001b[0m\n",
198
+ "\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"
199
+ ]
200
+ },
201
+ "metadata": {},
202
+ "output_type": "display_data"
203
+ },
204
+ {
205
+ "data": {
206
+ "text/html": [
207
+ "<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",
208
+ "</pre>\n"
209
+ ],
210
+ "text/plain": [
211
+ "\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"
212
+ ]
213
+ },
214
+ "metadata": {},
215
+ "output_type": "display_data"
216
+ },
217
+ {
218
+ "data": {
219
+ "text/html": [
220
+ "<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",
221
+ "<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",
222
+ "<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",
223
+ "<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",
224
+ "</pre>\n"
225
+ ],
226
+ "text/plain": [
227
+ "\u001b[1;31mError in generating model output:\u001b[0m\n",
228
+ "\u001b[1;36m404\u001b[0m\u001b[1;31m Client Error: Not Found for url: \u001b[0m\n",
229
+ "\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",
230
+ "\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"
231
+ ]
232
+ },
233
+ "metadata": {},
234
+ "output_type": "display_data"
235
+ },
236
+ {
237
+ "data": {
238
+ "text/html": [
239
+ "<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",
240
+ "</pre>\n"
241
+ ],
242
+ "text/plain": [
243
+ "\u001b[2m[Step 1: Duration 0.57 seconds]\u001b[0m\n"
244
+ ]
245
+ },
246
+ "metadata": {},
247
+ "output_type": "display_data"
248
+ },
249
+ {
250
+ "ename": "AgentGenerationError",
251
+ "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)",
252
+ "output_type": "error",
253
+ "traceback": [
254
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
255
+ "\u001b[31mHTTPError\u001b[39m Traceback (most recent call last)",
256
+ "\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",
257
+ "\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",
258
+ "\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",
259
+ "\nThe above exception was the direct cause of the following exception:\n",
260
+ "\u001b[31mHfHubHTTPError\u001b[39m Traceback (most recent call last)",
261
+ "\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",
262
+ "\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",
263
+ "\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",
264
+ "\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",
265
+ "\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",
266
+ "\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)",
267
+ "\nThe above exception was the direct cause of the following exception:\n",
268
+ "\u001b[31mAgentGenerationError\u001b[39m Traceback (most recent call last)",
269
+ "\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",
270
+ "\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",
271
+ "\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",
272
+ "\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",
273
+ "\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",
274
+ "\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",
275
+ "\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)"
276
+ ]
277
+ }
278
+ ],
279
+ "source": [
280
+ "from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel\n",
281
+ "\n",
282
+ "model = InferenceClientModel()\n",
283
+ "agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)\n",
284
+ "\n",
285
+ "agent.run(\"How many seconds would it take for a leopard at full speed to run through Pont des Arts?\")"
286
+ ]
287
+ },
288
+ {
289
+ "cell_type": "code",
290
+ "execution_count": null,
291
+ "id": "9b9fc943",
292
+ "metadata": {},
293
+ "outputs": [],
294
+ "source": []
295
+ }
296
+ ],
297
+ "metadata": {
298
+ "kernelspec": {
299
+ "display_name": ".venv",
300
+ "language": "python",
301
+ "name": "python3"
302
+ },
303
+ "language_info": {
304
+ "codemirror_mode": {
305
+ "name": "ipython",
306
+ "version": 3
307
+ },
308
+ "file_extension": ".py",
309
+ "mimetype": "text/x-python",
310
+ "name": "python",
311
+ "nbconvert_exporter": "python",
312
+ "pygments_lexer": "ipython3",
313
+ "version": "3.13.1"
314
+ }
315
+ },
316
+ "nbformat": 4,
317
+ "nbformat_minor": 5
318
+ }