File size: 10,354 Bytes
3a8719f | 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 | {
"cells": [
{
"cell_type": "markdown",
"id": "674fa1cc",
"metadata": {},
"source": [
"# Testing Agent Components\n",
"\n",
"I used this notebook to test different tools and components. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88eccfb3",
"metadata": {},
"outputs": [],
"source": [
"from agents import manager_agent\n",
"manager_agent.visualize()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e1925d1f",
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"\n",
"#manager_agent.run(\"How many bird species are in this image?\", images=images)\n",
"manager_agent.run(\"In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c904403",
"metadata": {},
"outputs": [],
"source": [
"manager_agent.run('How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ca93462b",
"metadata": {},
"outputs": [],
"source": [
"DEFAULT_API_URL = \"https://agents-course-unit4-scoring.hf.space\"\n",
"question = \"What is the final numeric output from the attached Python code?\"\n",
"task_file_path = \"f918266a-b3e0-4914-865d-4faa564f1aef\"\n",
"filename = \"f918266a-b3e0-4914-865d-4faa564f1aef.py\"\n",
"context = f\"\"\"\n",
"Here is the question you need to answer: {question}\n",
"\n",
"This question has an associated file. You can download the file from \n",
"{DEFAULT_API_URL}/files/{task_file_path}\n",
"using the download_file_from_url tool and name it {filename}. \n",
"After downloading the file, use the save_and_read_file tool to read the contents of the file.\n",
"\n",
"Come up with a plan to analyze the file content above to answer the question. Execute that plan carefully and stay focused.\n",
"\"\"\"\n",
"full_prompt = f\"\"\"{context}\n",
"\n",
"When answering, provide ONLY the precise answer requested. \n",
"Do not include explanations, steps, reasoning, or additional text.\n",
"Be direct and specific. GAIA benchmark requires exact matching answers.\n",
"For example, if asked \"What is the capital of France?\", respond simply with \"Paris\".\n",
"\"\"\"\n",
"manager_agent.run(context)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e9bf1e6",
"metadata": {},
"outputs": [],
"source": [
"DEFAULT_API_URL = \"https://agents-course-unit4-scoring.hf.space\"\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 :(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",
"task_file_path = \"1f975693-876d-457b-a649-393859e79bf3\"\n",
"filename = \"1f975693-876d-457b-a649-393859e79bf3.mp3\"\n",
"context = f\"\"\"\n",
"Here is the question you need to answer: {question}\n",
"\n",
"This question has an associated file. You can download the file from \n",
"{DEFAULT_API_URL}/files/{task_file_path}\n",
"using the download_file_from_url tool and name it {filename}. \n",
"After downloading the file, use the save_and_read_file tool to read the contents of the file.\n",
"\n",
"Come up with a plan to analyze the file content above to answer the question. Execute that plan carefully and stay focused.\n",
"\"\"\"\n",
"full_prompt = f\"\"\"{context}\n",
"\n",
"When answering, provide ONLY the precise answer requested. \n",
"Do not include explanations, steps, reasoning, or additional text.\n",
"Be direct and specific. GAIA benchmark requires exact matching answers.\n",
"For example, if asked \"What is the capital of France?\", respond simply with \"Paris\".\n",
"\"\"\"\n",
"manager_agent.run(context)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8bf3f8eb",
"metadata": {},
"outputs": [],
"source": [
"DEFAULT_API_URL = \"https://agents-course-unit4-scoring.hf.space\"\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",
"task_file_path = \"7bd855d8-463d-4ed5-93ca-5fe35145f733\"\n",
"filename = \"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\"\n",
"context = f\"\"\"\n",
"Here is the question you need to answer: {question}\n",
"\n",
"This question has an associated file. You can download the file from \n",
"{DEFAULT_API_URL}/files/{task_file_path}\n",
"using the download_file_from_url tool and name it {filename}. \n",
"After downloading the file, use the save_and_read_file tool to read the contents of the file.\n",
"\n",
"Come up with a plan to analyze the file content above to answer the question. Execute that plan carefully and stay focused.\n",
"\"\"\"\n",
"full_prompt = f\"\"\"{context}\n",
"\n",
"When answering, provide ONLY the precise answer requested. \n",
"Do not include explanations, steps, reasoning, or additional text.\n",
"Be direct and specific. GAIA benchmark requires exact matching answers.\n",
"For example, if asked \"What is the capital of France?\", respond simply with \"Paris\".\n",
"\"\"\"\n",
"manager_agent.run(context)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51a53c63",
"metadata": {},
"outputs": [],
"source": [
"manager_agent.run(\"How many r's are in the word Strawberry?\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d45cd981",
"metadata": {},
"outputs": [],
"source": [
"from tools.tools import youtube_frames_to_images\n",
"results = youtube_frames_to_images('https://youtube.com/watch?v=L1vXCYZAYYM')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d806dfe",
"metadata": {},
"outputs": [],
"source": [
"from tools.tools import youtube_transcribe\n",
"results = youtube_transcribe('https://www.youtube.com/watch?v=1htKBjuUWec')\n",
"print(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b87ee5e6",
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"from os import walk, path\n",
"\n",
"# Path to image file\n",
"picture_path = './images'\n",
"\n",
"# List to hold images\n",
"images = []\n",
"\n",
"# Walk through the directory and get all .png files paths\n",
"for root, dirs, files in walk(picture_path):\n",
" for file in files:\n",
" if file.endswith('.png'):\n",
" # Construct full path of each png file\n",
" picture_file = path.join(root, file)\n",
" \n",
" try:\n",
" # Open image from path\n",
" img = Image.open(picture_file)\n",
" \n",
" # Append it to the list of images after converting it to RGB format\n",
" images.append(img.convert('RGB'))\n",
" except IOError as e:\n",
" print(f'Error opening {picture_file}: {e}')\n",
" continue\n",
"\n",
"\n",
"from tools.tools import use_vision_model\n",
"\n",
"query = \"Review these pictures. What is the highest number of bird species to appear in the same photo of these photos?\"\n",
"\n",
"tool_input = {\n",
" \"question\": query,\n",
" \"images\": images\n",
"}\n",
"\n",
"use_vision_model(**tool_input)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f294f90",
"metadata": {},
"outputs": [],
"source": [
"from tools.tools import download_file_from_url, transcribe_audio\n",
"\n",
"task_file_path = \"1f975693-876d-457b-a649-393859e79bf3\"\n",
"filename = \"1f975693-876d-457b-a649-393859e79bf3.mp3\"\n",
"url = f'{DEFAULT_API_URL}/files/{task_file_path}'\n",
"\n",
"tool_input = {\"url\": url}\n",
"\n",
"filename = download_file_from_url(**tool_input).strip(\"File downloaded to \").strip(\". You can now process this file.'\")\n",
"\n",
"tool_input = {\"audio_file_path\": filename}\n",
"\n",
"transcribe_audio(**tool_input)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b34b7bf2",
"metadata": {},
"outputs": [],
"source": [
"from tools.tools import read_file, download_file_from_url\n",
"\n",
"DEFAULT_API_URL = \"https://agents-course-unit4-scoring.hf.space\"\n",
"taskid = \"f918266a-b3e0-4914-865d-4faa564f1aef\"\n",
"filename = f\"{taskid}.py\"\n",
"url = f'{DEFAULT_API_URL}/files/{taskid}'\n",
"\n",
"tool_input = {\"url\": url, \"filename\": filename}\n",
"\n",
"filepath = download_file_from_url(**tool_input).strip(\"File downloaded to \").strip(\". You can now process this file.'\")\n",
"\n",
"\n",
"tool_input = {\"filepath\": filepath}\n",
"\n",
"output = read_file(**tool_input)\n",
"\n",
"print(output)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv (3.12.6)",
"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.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|