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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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7a9773ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6c2fd343",
   "metadata": {},
   "outputs": [],
   "source": [
    "DEFAULT_API_URL = \"https://agents-course-unit4-scoring.hf.space\"\n",
    "api_url = DEFAULT_API_URL\n",
    "questions_url = f\"{api_url}/questions\"\n",
    "submit_url = f\"{api_url}/submit\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3b583a55",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fetch Questions\n",
    "def fetch_questions():\n",
    "    \"\"\"\n",
    "    Fetch questions from the API.\n",
    "    Returns a tuple of (error_message, questions_data).\n",
    "    \"\"\"\n",
    "    # Check if the API URL is valid\n",
    "    if not api_url.startswith(\"http\"):\n",
    "        return \"Invalid API URL\", None\n",
    "\n",
    "    # Fetch questions from the API\n",
    "    print(f\"API URL: {api_url}\")\n",
    "    print(f\"Fetching questions from: {questions_url}\")\n",
    "    try:\n",
    "        response = requests.get(questions_url, timeout=15)\n",
    "        response.raise_for_status()\n",
    "        questions_data = response.json()\n",
    "        if not questions_data:\n",
    "                print(\"Fetched questions list is empty.\")\n",
    "                return \"Fetched questions list is empty or invalid format.\", None\n",
    "        print(f\"Fetched {len(questions_data)} questions.\")\n",
    "        return questions_data\n",
    "    except requests.exceptions.RequestException as e:\n",
    "        print(f\"Error fetching questions: {e}\")\n",
    "        return f\"Error fetching questions: {e}\", None\n",
    "    except requests.exceptions.JSONDecodeError as e:\n",
    "            print(f\"Error decoding JSON response from questions endpoint: {e}\")\n",
    "            print(f\"Response text: {response.text[:500]}\")\n",
    "            return f\"Error decoding server response for questions: {e}\", None\n",
    "    except Exception as e:\n",
    "        print(f\"An unexpected error occurred fetching questions: {e}\")\n",
    "        return f\"An unexpected error occurred fetching questions: {e}\", None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2efbd02d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "API URL: https://agents-course-unit4-scoring.hf.space\n",
      "Fetching questions from: https://agents-course-unit4-scoring.hf.space/questions\n",
      "Fetched 20 questions.\n"
     ]
    }
   ],
   "source": [
    "questions = fetch_questions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4b86373a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Task ID: 8e867cd7-cff9-4e6c-867a-ff5ddc2550be\n",
      "Question: How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: a1e91b78-d3d8-4675-bb8d-62741b4b68a6\n",
      "Question: In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 2d83110e-a098-4ebb-9987-066c06fa42d0\n",
      "Question: .rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: cca530fc-4052-43b2-b130-b30968d8aa44\n",
      "Question: Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.\n",
      "Level: 1\n",
      "File Name: cca530fc-4052-43b2-b130-b30968d8aa44.png\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 4fc2f1ae-8625-45b5-ab34-ad4433bc21f8\n",
      "Question: Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 6f37996b-2ac7-44b0-8e68-6d28256631b4\n",
      "Question: Given this table defining * on the set S = {a, b, c, d, e}\n",
      "\n",
      "|*|a|b|c|d|e|\n",
      "|---|---|---|---|---|---|\n",
      "|a|a|b|c|b|d|\n",
      "|b|b|c|a|e|c|\n",
      "|c|c|a|b|b|a|\n",
      "|d|b|e|b|e|d|\n",
      "|e|d|b|a|d|c|\n",
      "\n",
      "provide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 9d191bce-651d-4746-be2d-7ef8ecadb9c2\n",
      "Question: Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\n",
      "\n",
      "What does Teal'c say in response to the question \"Isn't that hot?\"\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: cabe07ed-9eca-40ea-8ead-410ef5e83f91\n",
      "Question: What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 3cef3a44-215e-4aed-8e3b-b1e3f08063b7\n",
      "Question: I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n",
      "\n",
      "milk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n",
      "\n",
      "I need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\n",
      "Question: Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n",
      "\n",
      "In your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n",
      "\n",
      "Please format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.\n",
      "Level: 1\n",
      "File Name: 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 305ac316-eef6-4446-960a-92d80d542f82\n",
      "Question: Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: f918266a-b3e0-4914-865d-4faa564f1aef\n",
      "Question: What is the final numeric output from the attached Python code?\n",
      "Level: 1\n",
      "File Name: f918266a-b3e0-4914-865d-4faa564f1aef.py\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 3f57289b-8c60-48be-bd80-01f8099ca449\n",
      "Question: How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 1f975693-876d-457b-a649-393859e79bf3\n",
      "Question: Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n",
      "\n",
      "Could you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.\n",
      "Level: 1\n",
      "File Name: 1f975693-876d-457b-a649-393859e79bf3.mp3\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 840bfca7-4f7b-481a-8794-c560c340185d\n",
      "Question: On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: bda648d7-d618-4883-88f4-3466eabd860e\n",
      "Question: Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: cf106601-ab4f-4af9-b045-5295fe67b37d\n",
      "Question: What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: a0c07678-e491-4bbc-8f0b-07405144218f\n",
      "Question: Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 7bd855d8-463d-4ed5-93ca-5fe35145f733\n",
      "Question: The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.\n",
      "Level: 1\n",
      "File Name: 7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 5a0c1adf-205e-4841-a666-7c3ef95def9d\n",
      "Question: What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?\n",
      "Level: 1\n",
      "File Name: \n",
      "----------------------------------------\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for question in questions:\n",
    "    print(f\"Task ID: {question['task_id']}\")\n",
    "    print(f\"Question: {question['question']}\")\n",
    "    print(f\"Level: {question['Level']}\")\n",
    "    print(f\"File Name: {question['file_name']}\")\n",
    "    print(\"-\" * 40 + \"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f8b2bba0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'task_id': '5a0c1adf-205e-4841-a666-7c3ef95def9d',\n",
       " 'question': 'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?',\n",
       " 'Level': '1',\n",
       " 'file_name': ''}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "question"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "535a725f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_question_file(question):\n",
    "    \"\"\"\n",
    "    Get the file associated with a question if it exists.\n",
    "    \n",
    "    Args:\n",
    "        question (dict): The question dictionary containing task_id and file_name\n",
    "    \n",
    "    Returns:\n",
    "        tuple: (file_content, file_path) if file exists, (None, None) otherwise\n",
    "    \"\"\"\n",
    "    if not question.get(\"file_name\"):\n",
    "        print(f\"No file associated with question {question['task_id']}\")\n",
    "        return None, None\n",
    "    \n",
    "    file_name = question[\"file_name\"]\n",
    "    task_id = question[\"task_id\"]\n",
    "    \n",
    "    # Construct file URL using the correct endpoint format\n",
    "    file_url = f\"{api_url}/files/{task_id}\"\n",
    "    \n",
    "    print(f\"Fetching file from: {file_url}\")\n",
    "    try:\n",
    "        response = requests.get(file_url, timeout=15)\n",
    "        response.raise_for_status()\n",
    "        \n",
    "        # Create a directory to store downloaded files if it doesn't exist\n",
    "        import os\n",
    "        os.makedirs(\"downloaded_files\", exist_ok=True)\n",
    "        \n",
    "        # Save the file locally\n",
    "        local_path = f\"./downloaded_files/{file_name}\"\n",
    "        with open(local_path, \"wb\") as f:\n",
    "            f.write(response.content)\n",
    "        print(f\"Saved file to {local_path}\")\n",
    "        return response.content, local_path\n",
    "            \n",
    "    except requests.exceptions.RequestException as e:\n",
    "        print(f\"Error fetching file {file_name}: {e}\")\n",
    "        return None, None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "11cac7d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Task ID: cca530fc-4052-43b2-b130-b30968d8aa44\n",
      "Question: Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.\n",
      "File Name: cca530fc-4052-43b2-b130-b30968d8aa44.png\n",
      "Fetching file from: https://agents-course-unit4-scoring.hf.space/files/cca530fc-4052-43b2-b130-b30968d8aa44\n",
      "Saved file to ./downloaded_files/cca530fc-4052-43b2-b130-b30968d8aa44.png\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\n",
      "Question: Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n",
      "\n",
      "In your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n",
      "\n",
      "Please format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.\n",
      "File Name: 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\n",
      "Fetching file from: https://agents-course-unit4-scoring.hf.space/files/99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\n",
      "Saved file to ./downloaded_files/99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: f918266a-b3e0-4914-865d-4faa564f1aef\n",
      "Question: What is the final numeric output from the attached Python code?\n",
      "File Name: f918266a-b3e0-4914-865d-4faa564f1aef.py\n",
      "Fetching file from: https://agents-course-unit4-scoring.hf.space/files/f918266a-b3e0-4914-865d-4faa564f1aef\n",
      "Saved file to ./downloaded_files/f918266a-b3e0-4914-865d-4faa564f1aef.py\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 1f975693-876d-457b-a649-393859e79bf3\n",
      "Question: Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n",
      "\n",
      "Could you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.\n",
      "File Name: 1f975693-876d-457b-a649-393859e79bf3.mp3\n",
      "Fetching file from: https://agents-course-unit4-scoring.hf.space/files/1f975693-876d-457b-a649-393859e79bf3\n",
      "Saved file to ./downloaded_files/1f975693-876d-457b-a649-393859e79bf3.mp3\n",
      "----------------------------------------\n",
      "\n",
      "Task ID: 7bd855d8-463d-4ed5-93ca-5fe35145f733\n",
      "Question: The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.\n",
      "File Name: 7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\n",
      "Fetching file from: https://agents-course-unit4-scoring.hf.space/files/7bd855d8-463d-4ed5-93ca-5fe35145f733\n",
      "Saved file to ./downloaded_files/7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\n",
      "----------------------------------------\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for question in questions:\n",
    "    if question['file_name']:\n",
    "        print(f\"Task ID: {question['task_id']}\")\n",
    "        print(f\"Question: {question['question']}\")\n",
    "        print(f\"File Name: {question['file_name']}\")\n",
    "\n",
    "        get_question_file(question)\n",
    "\n",
    "        print(\"-\" * 40 + \"\\n\")\n",
    "\n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "agents",
   "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.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}