"
+ ]
+ },
+ "execution_count": 109,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "Audio(filename=\"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "c703d39d-6f11-49f2-877f-8210a31ba792",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T14:16:20.289766Z",
+ "iopub.status.busy": "2025-06-01T14:16:20.288219Z",
+ "iopub.status.idle": "2025-06-01T14:16:20.302767Z",
+ "shell.execute_reply": "2025-06-01T14:16:20.299487Z",
+ "shell.execute_reply.started": "2025-06-01T14:16:20.289703Z"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from smolagents import SpeechToTextTool, AgentAudio, AgentImage"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "17185388-4faf-4e4c-ba50-7724ea8592c2",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T14:15:59.666336Z",
+ "iopub.status.busy": "2025-06-01T14:15:59.665657Z",
+ "iopub.status.idle": "2025-06-01T14:16:00.610811Z",
+ "shell.execute_reply": "2025-06-01T14:16:00.607919Z",
+ "shell.execute_reply.started": "2025-06-01T14:15:59.666276Z"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "tensor([ 0.0000e+00, -2.0132e-13, -1.0895e-13, ..., -6.8355e-08,\n",
+ " 8.8679e-09, -9.8580e-09], dtype=torch.float64)"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "AgentAudio(\"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "afd9c472-21d1-450e-a51f-5672e7f00188",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "47d972cc-9ff5-4b97-91b5-5be45b73517e",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T14:26:13.821240Z",
+ "iopub.status.busy": "2025-06-01T14:26:13.819987Z",
+ "iopub.status.idle": "2025-06-01T14:26:14.203525Z",
+ "shell.execute_reply": "2025-06-01T14:26:14.202418Z",
+ "shell.execute_reply.started": "2025-06-01T14:26:13.821120Z"
+ },
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "INFO:wikipediaapi:Wikipedia: language=en, user_agent: WikiAssistant (merlin@example.com) (Wikipedia-API/0.8.1; https://github.com/martin-majlis/Wikipedia-API/), extract_format=1\n"
+ ]
+ }
+ ],
+ "source": [
+ "ultimate_agent = CodeAgent(\n",
+ " tools=[FinalAnswerTool(), PythonInterpreterTool(), VisitWebpageTool(),\n",
+ " DuckDuckGoSearchTool(), WikipediaSearchTool(user_agent=\"WikiAssistant (merlin@example.com)\")],\n",
+ " additional_authorized_imports=[\"os\", \"json\", \"pandas\"],\n",
+ " model=InferenceClientModel(\n",
+ " model_id=\"Qwen/Qwen3-235B-A22B\",\n",
+ " bill_to=\"VitalNest\",\n",
+ " temperature=0.1,\n",
+ " ),\n",
+ " max_steps=10,\n",
+ " planning_interval=2,\n",
+ " verbosity_level=0,\n",
+ " add_base_tools=True,\n",
+ " name=\"Versatile_Multi_Agent\",\n",
+ " description=\"\"\"You are a general AI assistant.\"\"\",\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f3739d3e-d652-415c-94e7-3c10f27c9fe7",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T12:00:26.517556Z",
+ "iopub.status.busy": "2025-06-01T12:00:26.515902Z",
+ "iopub.status.idle": "2025-06-01T12:00:26.530150Z",
+ "shell.execute_reply": "2025-06-01T12:00:26.527326Z",
+ "shell.execute_reply.started": "2025-06-01T12:00:26.517475Z"
+ },
+ "scrolled": true
+ },
+ "source": [
+ "ultimate_agent.prompt_templates[\"system_prompt\"] = ultimate_agent.prompt_templates[\"system_prompt\"][:8834] + \"\"\"\n",
+ "\\n\\n\\n ALWAYS follow this ```Answer format```:\\nALWAYS Report your thoughts, and finish your answer with the following template:\\nANSWER: [YOUR ANSWER].\\nYOUR ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.\\nIf you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations(e.g. for cities), and write the digits in plain text unless specified otherwise.\\nIf you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\\n\\nNow Begin!\n",
+ "\"\"\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ebd88c4d-f05b-46a5-9a43-be69d1bdaa37",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T12:03:44.420453Z",
+ "iopub.status.busy": "2025-06-01T12:03:44.419861Z",
+ "iopub.status.idle": "2025-06-01T12:03:44.445366Z",
+ "shell.execute_reply": "2025-06-01T12:03:44.444175Z",
+ "shell.execute_reply.started": "2025-06-01T12:03:44.420396Z"
+ },
+ "scrolled": true
+ },
+ "source": [
+ "ultimate_agent.system_prompt = ultimate_agent.initialize_system_prompt()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6931a7a4-a1c7-4211-b2d0-da67b1e277f4",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T12:09:40.240675Z",
+ "iopub.status.busy": "2025-06-01T12:09:40.239413Z",
+ "iopub.status.idle": "2025-06-01T12:09:40.275581Z",
+ "shell.execute_reply": "2025-06-01T12:09:40.273862Z",
+ "shell.execute_reply.started": "2025-06-01T12:09:40.240554Z"
+ },
+ "scrolled": true
+ },
+ "source": [
+ "pprint(ultimate_agent.system_prompt)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "5731e0bc-bb28-4d52-a683-01c21677d018",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T14:26:18.224798Z",
+ "iopub.status.busy": "2025-06-01T14:26:18.223444Z",
+ "iopub.status.idle": "2025-06-01T14:26:18.233689Z",
+ "shell.execute_reply": "2025-06-01T14:26:18.230869Z",
+ "shell.execute_reply.started": "2025-06-01T14:26:18.224744Z"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "custom_instructions = \"\"\"\n",
+ "\\n\\n\\n ALWAYS follow this ```Answer format```:\\nALWAYS Report your thoughts, and finish your answer with the following template:\\nANSWER: [YOUR ANSWER].\\nYOUR ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.\\nIf you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations(e.g. for cities), and write the digits in plain text unless specified otherwise.\\nIf you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n",
+ "\"\"\"\n",
+ "\n",
+ "# Set in pre_messages (recommended, so it's always seen by the model before answering)\n",
+ "ultimate_agent.prompt_templates[\"final_answer\"][\"pre_messages\"] = custom_instructions\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 92,
+ "id": "c8c80f80-5af2-48f2-af99-25ece66d9176",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T13:09:30.874873Z",
+ "iopub.status.busy": "2025-06-01T13:09:30.872836Z",
+ "iopub.status.idle": "2025-06-01T13:13:40.564236Z",
+ "shell.execute_reply": "2025-06-01T13:13:40.562630Z",
+ "shell.execute_reply.started": "2025-06-01T13:09:30.874777Z"
+ },
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "INFO:primp:response: https://html.duckduckgo.com/html 200\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "Code execution failed at line 'search_results = web_search(query='\"https://www.youtube.com/watch?v=L1vXCYZAYYM\" \n",
+ "\"bird species count\"')' due to: Exception: No results found! Try a less restrictive/shorter query.\n",
+ "
\n"
+ ],
+ "text/plain": [
+ "\u001b[1;31mCode execution failed at line \u001b[0m\u001b[32m'search_results = web_search\u001b[0m\u001b[32m(\u001b[0m\u001b[32mquery\u001b[0m\u001b[32m='\u001b[0m\u001b[32m\"https://www.youtube.com/watch?\u001b[0m\u001b[32mv\u001b[0m\u001b[32m=\u001b[0m\u001b[32mL1vXCYZAYYM\"\u001b[0m\u001b[1;31m \u001b[0m\n",
+ "\u001b[32m\"bird species count\"\u001b[0m\u001b[32m'\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[1;31m due to: Exception: No results found! Try a less restrictive/shorter query.\u001b[0m\n"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "INFO:primp:response: https://lite.duckduckgo.com/lite/ 200\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "3"
+ ]
+ },
+ "execution_count": 92,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "ultimate_agent.run(task=all_questions[1]['question'],\n",
+ " additional_args={\"file_url\":f'{all_questions[1]['file_name']}'} if all_questions[1]['file_name'] else None\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 87,
+ "id": "6f9e9709-41bf-48ab-b0f1-72ece35b251d",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T13:04:37.953256Z",
+ "iopub.status.busy": "2025-06-01T13:04:37.951156Z",
+ "iopub.status.idle": "2025-06-01T13:04:37.972233Z",
+ "shell.execute_reply": "2025-06-01T13:04:37.971246Z",
+ "shell.execute_reply.started": "2025-06-01T13:04:37.953169Z"
+ },
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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\\nprovide 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",
+ " {'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2',\n",
+ " 'question': 'Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\\n\\nWhat does Teal\\'c say in response to the question \"Isn\\'t that hot?\"',\n",
+ " 'Level': '1',\n",
+ " 'file_name': ''},\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",
+ " {'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\\nmilk, 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\\nI 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",
+ " {'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\\nIn 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\\nPlease 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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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\\nCould 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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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",
+ " {'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": 87,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "all_questions[:]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b3d4fe5b-23be-4617-8738-374846281e94",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 93,
+ "id": "ef147340-064a-4c3d-b7b8-bf47cae4a99b",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T13:18:06.730006Z",
+ "iopub.status.busy": "2025-06-01T13:18:06.729139Z",
+ "iopub.status.idle": "2025-06-01T13:18:06.744206Z",
+ "shell.execute_reply": "2025-06-01T13:18:06.739120Z",
+ "shell.execute_reply.started": "2025-06-01T13:18:06.729935Z"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from huggingface_hub import InferenceClient"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 101,
+ "id": "3a24479e-bad1-448e-996f-0bd178b1f8f0",
+ "metadata": {
+ "execution": {
+ "iopub.execute_input": "2025-06-01T13:56:28.271646Z",
+ "iopub.status.busy": "2025-06-01T13:56:28.270762Z",
+ "iopub.status.idle": "2025-06-01T13:56:29.364865Z",
+ "shell.execute_reply": "2025-06-01T13:56:29.356268Z",
+ "shell.execute_reply.started": "2025-06-01T13:56:28.271610Z"
+ },
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "ename": "HfHubHTTPError",
+ "evalue": "402 Client Error: Payment Required for url: https://router.huggingface.co/hyperbolic/v1/chat/completions (Request ID: Root=1-683c5c0c-288511e646e237be316a1038;83e338e0-e25e-45c3-90a0-0675c28886f5)",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
+ "\u001b[31mHTTPError\u001b[39m Traceback (most recent call last)",
+ "\u001b[36mFile \u001b[39m\u001b[32m~/repos/misc_project/.venv/lib/python3.12/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~/repos/misc_project/.venv/lib/python3.12/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: 402 Client Error: Payment Required for url: https://router.huggingface.co/hyperbolic/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[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[101]\u001b[39m\u001b[32m, line 30\u001b[39m\n\u001b[32m 1\u001b[39m client = InferenceClient(\n\u001b[32m 2\u001b[39m \u001b[38;5;66;03m# provider=\"hyperbolic\",\u001b[39;00m\n\u001b[32m 3\u001b[39m bill_to=\u001b[33m\"\u001b[39m\u001b[33mVitalNest\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 4\u001b[39m )\n\u001b[32m 5\u001b[39m chat_template = [\n\u001b[32m 6\u001b[39m \u001b[38;5;66;03m# {\u001b[39;00m\n\u001b[32m 7\u001b[39m \u001b[38;5;66;03m# \"role\": \"user\",\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 28\u001b[39m }\n\u001b[32m 29\u001b[39m ]\n\u001b[32m---> \u001b[39m\u001b[32m30\u001b[39m completion = \u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompletions\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 31\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mQwen/Qwen2.5-VL-72B-Instruct\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 32\u001b[39m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mchat_template\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 33\u001b[39m \u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m0.1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 34\u001b[39m \u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m10_000\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 35\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 36\u001b[39m answer = completion.choices[\u001b[32m0\u001b[39m].message.content\n\u001b[32m 37\u001b[39m answer\n",
+ "\u001b[36mFile \u001b[39m\u001b[32m~/repos/misc_project/.venv/lib/python3.12/site-packages/huggingface_hub/inference/_client.py:924\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 896\u001b[39m parameters = {\n\u001b[32m 897\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mmodel\u001b[39m\u001b[33m\"\u001b[39m: payload_model,\n\u001b[32m 898\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mfrequency_penalty\u001b[39m\u001b[33m\"\u001b[39m: frequency_penalty,\n\u001b[32m (...)\u001b[39m\u001b[32m 915\u001b[39m **(extra_body \u001b[38;5;129;01mor\u001b[39;00m {}),\n\u001b[32m 916\u001b[39m }\n\u001b[32m 917\u001b[39m request_parameters = provider_helper.prepare_request(\n\u001b[32m 918\u001b[39m inputs=messages,\n\u001b[32m 919\u001b[39m parameters=parameters,\n\u001b[32m (...)\u001b[39m\u001b[32m 922\u001b[39m api_key=\u001b[38;5;28mself\u001b[39m.token,\n\u001b[32m 923\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m924\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 926\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m stream:\n\u001b[32m 927\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m _stream_chat_completion_response(data) \u001b[38;5;66;03m# type: ignore[arg-type]\u001b[39;00m\n",
+ "\u001b[36mFile \u001b[39m\u001b[32m~/repos/misc_project/.venv/lib/python3.12/site-packages/huggingface_hub/inference/_client.py:280\u001b[39m, in \u001b[36mInferenceClient._inner_post\u001b[39m\u001b[34m(self, request_parameters, stream)\u001b[39m\n\u001b[32m 277\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m InferenceTimeoutError(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mInference call timed out: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrequest_parameters.url\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01merror\u001b[39;00m \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[32m 279\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m280\u001b[39m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 281\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[32m 282\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m error:\n",
+ "\u001b[36mFile \u001b[39m\u001b[32m~/repos/misc_project/.venv/lib/python3.12/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 478\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m _format(HfHubHTTPError, message, response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\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: 402 Client Error: Payment Required for url: https://router.huggingface.co/hyperbolic/v1/chat/completions (Request ID: Root=1-683c5c0c-288511e646e237be316a1038;83e338e0-e25e-45c3-90a0-0675c28886f5)"
+ ]
+ }
+ ],
+ "source": [
+ "client = InferenceClient(\n",
+ " provider=\"hyperbolic\",\n",
+ " bill_to=\"VitalNest\",\n",
+ " )\n",
+ "chat_template = [\n",
+ " # {\n",
+ " # \"role\": \"user\",\n",
+ " # \"content\": [\n",
+ " # {\n",
+ " # \"type\": \"image\",\n",
+ " # \"image_url\": [\n",
+ " # \"https://www.youtube.com/watch?v=L1vXCYZAYYM\",\n",
+ " # ],\n",
+ " # },\n",
+ " \n",
+ " # {\"type\": \"text\", \"text\": all_questions[1][\"question\"]}\n",
+ " # ]\n",
+ " # },\n",
+ " {\n",
+ " \"role\": \"user\",\n",
+ " \"content\": [\n",
+ " {\n",
+ " \"type\": \"video\",\n",
+ " \"video\": \"https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4\",\n",
+ " },\n",
+ " {\"type\": \"text\", \"text\": \"Describe this video.\"},\n",
+ " ],\n",
+ " }\n",
+ "]\n",
+ "completion = client.chat.completions.create(\n",
+ " model=\"Qwen/Qwen2.5-VL-72B-Instruct\",\n",
+ " messages=chat_template,\n",
+ " temperature=0.1,\n",
+ " max_tokens=10_000,\n",
+ ")\n",
+ "answer = completion.choices[0].message.content\n",
+ "answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8f09487e-e729-46a7-849c-4d5ad87e396b",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c3b5f100-893f-405a-920f-a32461ac7277",
+ "metadata": {},
+ "source": [
+ "# Async Task"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2581df7f-63d2-4d06-9caf-92afc92eb01c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from concurrent.futures import ThreadPoolExecutor, as_completed\n",
+ "\n",
+ "questions = [\n",
+ " \"What is a system prompt?\",\n",
+ " \"How does tool calling work?\",\n",
+ " # ... more questions\n",
+ "]\n",
+ "\n",
+ "with ThreadPoolExecutor(max_workers=8) as executor:\n",
+ " futures = {executor.submit(agent.run, q): q for q in questions}\n",
+ " results = {}\n",
+ " for future in as_completed(futures):\n",
+ " question = futures[future]\n",
+ " result = future.result()\n",
+ " results[question] = result\n",
+ "\n",
+ "print(results)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "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.10"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}