{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-06-16T14:22:31.049405Z", "start_time": "2025-06-16T14:22:29.311032Z" } }, "source": [ "import time\n", "import concurrent\n", "from concurrent import futures\n", "from typing import Any, List, Dict, Tuple\n", "\n", "from PIL import Image\n", "from openai import AzureOpenAI\n", "from tqdm.auto import tqdm\n", "\n", "import json\n", "from pathlib import Path\n", "\n", "import pandas as pd\n", "import requests\n", "from dotenv import dotenv_values\n", "from smolagents import tool, DuckDuckGoSearchTool\n", "import wikipediaapi\n", "\n", "\n", "\n", "test_api_base = \"https://agents-course-unit4-scoring.hf.space\"\n", "\n", "def get_random_question():\n", " url = f\"{test_api_base}/random-question\"\n", "\n", "\n", " try:\n", " # Fetch the random question\n", " response = requests.get(url, timeout=10)\n", " response.raise_for_status()\n", " question_data = response.json()\n", "\n", " # Check if there's an associated file to download\n", " if question_data.get(\"file_name\") and question_data.get(\"task_id\"):\n", " task_id = question_data[\"task_id\"]\n", " file_url = f\"{test_api_base}/files/{task_id}\"\n", "\n", " # Create a directory for downloaded files if it doesn't exist\n", " download_dir = Path(\"downloaded_files\")\n", " download_dir.mkdir(exist_ok=True)\n", "\n", " # Download the file\n", " file_response = requests.get(file_url, timeout=30)\n", " file_response.raise_for_status()\n", "\n", " # Get filename from content-disposition header or use task_id\n", " content_disposition = file_response.headers.get('content-disposition', '')\n", " filename = content_disposition.split('filename=')[1].strip('\"')\n", " file_path = download_dir / filename\n", "\n", " # Save the file\n", " with open(file_path, 'wb') as f:\n", " f.write(file_response.content)\n", "\n", " # Add the file path to the question data\n", " question_data['downloaded_file_path'] = str(file_path)\n", " print(f\"Downloaded file to: {file_path}\")\n", "\n", " return question_data\n", "\n", " except requests.exceptions.RequestException as e:\n", " print(f\"Error fetching question: {e}\")\n", " return None\n", " except json.JSONDecodeError as e:\n", " print(f\"Error parsing JSON response: {e}\")\n", " return None\n", " except Exception as e:\n", " print(f\"Unexpected error: {e}\")\n", " return None" ], "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/vladi/miniconda3/envs/gaia/lib/python3.11/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" ] } ], "execution_count": 1 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-16T14:22:32.140555Z", "start_time": "2025-06-16T14:22:31.056873Z" } }, "cell_type": "code", "source": [ "question = get_random_question()\n", "if question:\n", " print(f\"Task ID: {question.get('task_id')}\")\n", " print(f\"Question: {question.get('question')}\")\n", " print(f\"Level: {question.get('Level')}\")\n", " if 'downloaded_file_path' in question:\n", " print(f\"Downloaded file: {question['downloaded_file_path']}\")" ], "id": "55d7941445304e9b", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloaded file to: downloaded_files/99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\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", "Downloaded file: downloaded_files/99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\n" ] } ], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-16T14:22:36.176421Z", "start_time": "2025-06-16T14:22:36.148111Z" } }, "cell_type": "code", "source": [ "config = dotenv_values()\n", "\n", "client = AzureOpenAI(\n", " api_key=config[\"AZURE_OPENAI_API_KEY\"],\n", " azure_endpoint=config[\"AZURE_OPENAI_API_BASE\"],\n", " api_version=config[\"AZURE_OPENAI_API_VERSION\"]\n", ")\n", "model_id=config[\"AZURE_OPENAI_CHAT_MODEL\"]" ], "id": "99393f634f21563f", "outputs": [], "execution_count": 3 }, { "metadata": {}, "cell_type": "markdown", "source": "# Question Processing", "id": "1290570b730fda4" }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-16T14:22:43.615612Z", "start_time": "2025-06-16T14:22:43.204200Z" } }, "cell_type": "code", "source": [ "response = requests.get(f\"{test_api_base}/questions\", timeout=15)\n", "response.raise_for_status()\n", "\n", "questions_data = response.json()" ], "id": "9f6fe414bc8fb090", "outputs": [], "execution_count": 4 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-16T14:22:43.692064Z", "start_time": "2025-06-16T14:22:43.684720Z" } }, "cell_type": "code", "source": "pd.DataFrame(questions_data)", "id": "3d0ab116de02315e", "outputs": [ { "data": { "text/plain": [ " task_id \\\n", "0 8e867cd7-cff9-4e6c-867a-ff5ddc2550be \n", "1 a1e91b78-d3d8-4675-bb8d-62741b4b68a6 \n", "2 2d83110e-a098-4ebb-9987-066c06fa42d0 \n", "3 cca530fc-4052-43b2-b130-b30968d8aa44 \n", "4 4fc2f1ae-8625-45b5-ab34-ad4433bc21f8 \n", "5 6f37996b-2ac7-44b0-8e68-6d28256631b4 \n", "6 9d191bce-651d-4746-be2d-7ef8ecadb9c2 \n", "7 cabe07ed-9eca-40ea-8ead-410ef5e83f91 \n", "8 3cef3a44-215e-4aed-8e3b-b1e3f08063b7 \n", "9 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3 \n", "10 305ac316-eef6-4446-960a-92d80d542f82 \n", "11 f918266a-b3e0-4914-865d-4faa564f1aef \n", "12 3f57289b-8c60-48be-bd80-01f8099ca449 \n", "13 1f975693-876d-457b-a649-393859e79bf3 \n", "14 840bfca7-4f7b-481a-8794-c560c340185d \n", "15 bda648d7-d618-4883-88f4-3466eabd860e \n", "16 cf106601-ab4f-4af9-b045-5295fe67b37d \n", "17 a0c07678-e491-4bbc-8f0b-07405144218f \n", "18 7bd855d8-463d-4ed5-93ca-5fe35145f733 \n", "19 5a0c1adf-205e-4841-a666-7c3ef95def9d \n", "\n", " question Level \\\n", "0 How many studio albums were published by Merce... 1 \n", "1 In the video https://www.youtube.com/watch?v=L... 1 \n", "2 .rewsna eht sa \"tfel\" drow eht fo etisoppo eht... 1 \n", "3 Review the chess position provided in the imag... 1 \n", "4 Who nominated the only Featured Article on Eng... 1 \n", "5 Given this table defining * on the set S = {a,... 1 \n", "6 Examine the video at https://www.youtube.com/w... 1 \n", "7 What is the surname of the equine veterinarian... 1 \n", "8 I'm making a grocery list for my mom, but she'... 1 \n", "9 Hi, I'm making a pie but I could use some help... 1 \n", "10 Who did the actor who played Ray in the Polish... 1 \n", "11 What is the final numeric output from the atta... 1 \n", "12 How many at bats did the Yankee with the most ... 1 \n", "13 Hi, I was out sick from my classes on Friday, ... 1 \n", "14 On June 6, 2023, an article by Carolyn Collins... 1 \n", "15 Where were the Vietnamese specimens described ... 1 \n", "16 What country had the least number of athletes ... 1 \n", "17 Who are the pitchers with the number before an... 1 \n", "18 The attached Excel file contains the sales of ... 1 \n", "19 What is the first name of the only Malko Compe... 1 \n", "\n", " file_name \n", "0 \n", "1 \n", "2 \n", "3 cca530fc-4052-43b2-b130-b30968d8aa44.png \n", "4 \n", "5 \n", "6 \n", "7 \n", "8 \n", "9 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3 \n", "10 \n", "11 f918266a-b3e0-4914-865d-4faa564f1aef.py \n", "12 \n", "13 1f975693-876d-457b-a649-393859e79bf3.mp3 \n", "14 \n", "15 \n", "16 \n", "17 \n", "18 7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx \n", "19 " ], "text/html": [ "
\n", " | task_id | \n", "question | \n", "Level | \n", "file_name | \n", "
---|---|---|---|---|
0 | \n", "8e867cd7-cff9-4e6c-867a-ff5ddc2550be | \n", "How many studio albums were published by Merce... | \n", "1 | \n", "\n", " |
1 | \n", "a1e91b78-d3d8-4675-bb8d-62741b4b68a6 | \n", "In the video https://www.youtube.com/watch?v=L... | \n", "1 | \n", "\n", " |
2 | \n", "2d83110e-a098-4ebb-9987-066c06fa42d0 | \n", ".rewsna eht sa \"tfel\" drow eht fo etisoppo eht... | \n", "1 | \n", "\n", " |
3 | \n", "cca530fc-4052-43b2-b130-b30968d8aa44 | \n", "Review the chess position provided in the imag... | \n", "1 | \n", "cca530fc-4052-43b2-b130-b30968d8aa44.png | \n", "
4 | \n", "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8 | \n", "Who nominated the only Featured Article on Eng... | \n", "1 | \n", "\n", " |
5 | \n", "6f37996b-2ac7-44b0-8e68-6d28256631b4 | \n", "Given this table defining * on the set S = {a,... | \n", "1 | \n", "\n", " |
6 | \n", "9d191bce-651d-4746-be2d-7ef8ecadb9c2 | \n", "Examine the video at https://www.youtube.com/w... | \n", "1 | \n", "\n", " |
7 | \n", "cabe07ed-9eca-40ea-8ead-410ef5e83f91 | \n", "What is the surname of the equine veterinarian... | \n", "1 | \n", "\n", " |
8 | \n", "3cef3a44-215e-4aed-8e3b-b1e3f08063b7 | \n", "I'm making a grocery list for my mom, but she'... | \n", "1 | \n", "\n", " |
9 | \n", "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3 | \n", "Hi, I'm making a pie but I could use some help... | \n", "1 | \n", "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3 | \n", "
10 | \n", "305ac316-eef6-4446-960a-92d80d542f82 | \n", "Who did the actor who played Ray in the Polish... | \n", "1 | \n", "\n", " |
11 | \n", "f918266a-b3e0-4914-865d-4faa564f1aef | \n", "What is the final numeric output from the atta... | \n", "1 | \n", "f918266a-b3e0-4914-865d-4faa564f1aef.py | \n", "
12 | \n", "3f57289b-8c60-48be-bd80-01f8099ca449 | \n", "How many at bats did the Yankee with the most ... | \n", "1 | \n", "\n", " |
13 | \n", "1f975693-876d-457b-a649-393859e79bf3 | \n", "Hi, I was out sick from my classes on Friday, ... | \n", "1 | \n", "1f975693-876d-457b-a649-393859e79bf3.mp3 | \n", "
14 | \n", "840bfca7-4f7b-481a-8794-c560c340185d | \n", "On June 6, 2023, an article by Carolyn Collins... | \n", "1 | \n", "\n", " |
15 | \n", "bda648d7-d618-4883-88f4-3466eabd860e | \n", "Where were the Vietnamese specimens described ... | \n", "1 | \n", "\n", " |
16 | \n", "cf106601-ab4f-4af9-b045-5295fe67b37d | \n", "What country had the least number of athletes ... | \n", "1 | \n", "\n", " |
17 | \n", "a0c07678-e491-4bbc-8f0b-07405144218f | \n", "Who are the pitchers with the number before an... | \n", "1 | \n", "\n", " |
18 | \n", "7bd855d8-463d-4ed5-93ca-5fe35145f733 | \n", "The attached Excel file contains the sales of ... | \n", "1 | \n", "7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx | \n", "
19 | \n", "5a0c1adf-205e-4841-a666-7c3ef95def9d | \n", "What is the first name of the only Malko Compe... | \n", "1 | \n", "\n", " |