Spaces:
Sleeping
Sleeping
File size: 8,030 Bytes
1691123 |
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 |
{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-05-03T18:40:33.108625Z",
"start_time": "2025-05-03T18:40:29.698376Z"
}
},
"source": [
"from io import StringIO\n",
"\n",
"from dotenv import load_dotenv\n",
"from gradio.server_messages import BaseMessage\n",
"from jinja2 import BaseLoader\n",
"\n",
"from agent import *\n",
"\n",
"load_dotenv()\n",
"\n",
"llm = get_llm()\n",
"\n",
"graph = get_graph(llm)\n",
"\n",
"# graph.invoke({\"messages\": [HumanMessage(content=question),]})\n"
],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/dennis/PycharmProjects/Final_Assignment_Template/.venv/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-05-03T18:41:12.685273Z",
"start_time": "2025-05-03T18:40:33.126333Z"
}
},
"cell_type": "code",
"source": [
"result = graph.invoke(\n",
" {\n",
" \"messages\": [\n",
" HumanMessage(\n",
" content=\"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",
" ),\n",
" ]\n",
" }\n",
")"
],
"id": "96cdb32d9145e6b3",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"-------------------- Starting to create a plan --------------------\n",
"\n",
"Waiting for 5 seconds...\n",
"The plan is: 1. Access the English Wikipedia (2022 version if available).\n",
"2. Search for \"Mercedes Sosa discography\".\n",
"3. Identify the section listing studio albums.\n",
"4. Filter the list to include only albums released between 2000 and 2009 (inclusive).\n",
"5. Count the number of albums that meet the criteria.\n",
"6. Provide the count as the answer.\n",
"\n",
"-------------------- Agent has been called -----------------------------------\n",
"\n",
"Waiting for 5 seconds...\n",
"Agent has made a decision:\n",
" [{'name': 'wiki_search', 'args': {'query': 'Mercedes Sosa discography'}, 'id': '416cac28-6fa8-4f45-a5db-f6bc6d8e1d1a', 'type': 'tool_call'}]\n",
"\n",
"-------------------- Decision of forwarding has been made --------------------\n",
"\n",
"Waiting for 2 seconds...\n",
"This is round: 2\n",
"The last message is: content='' additional_kwargs={'function_call': {'name': 'wiki_search', 'arguments': '{\"query\": \"Mercedes Sosa discography\"}'}} response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.0-flash', 'safety_ratings': []} id='run-80c57808-f76d-495c-bc1a-e22b89556475-0' tool_calls=[{'name': 'wiki_search', 'args': {'query': 'Mercedes Sosa discography'}, 'id': '416cac28-6fa8-4f45-a5db-f6bc6d8e1d1a', 'type': 'tool_call'}] usage_metadata={'input_tokens': 622, 'output_tokens': 7, 'total_tokens': 629, 'input_token_details': {'cache_read': 0}}\n",
"\n",
"-------------------- Tool (Wikipedia) has been called --------------------\n",
"\n",
"---------------------------------\n",
"Loading tables from: https://en.wikipedia.org/wiki/Mercedes_Sosa\n",
"---------------------------------\n",
"---------------------------------\n",
"Loading tables from: https://en.wikipedia.org/wiki/Joan_Baez_discography\n",
"---------------------------------\n",
"\n",
"-------------------- Agent has been called -----------------------------------\n",
"\n",
"Waiting for 5 seconds...\n",
"Agent has made a decision:\n",
" [{'name': 'wiki_search', 'args': {'query': 'Mercedes Sosa discography'}, 'id': '77eb4086-528b-48ea-b139-70382e84a80c', 'type': 'tool_call'}]\n",
"\n",
"-------------------- Decision of forwarding has been made --------------------\n",
"\n",
"Waiting for 2 seconds...\n",
"This is round: 3\n",
"The last message is: content='' additional_kwargs={'function_call': {'name': 'wiki_search', 'arguments': '{\"query\": \"Mercedes Sosa discography\"}'}} response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.0-flash', 'safety_ratings': []} id='run-3240832b-3a9d-48b5-9c58-0f9aa5dd8658-0' tool_calls=[{'name': 'wiki_search', 'args': {'query': 'Mercedes Sosa discography'}, 'id': '77eb4086-528b-48ea-b139-70382e84a80c', 'type': 'tool_call'}] usage_metadata={'input_tokens': 17925, 'output_tokens': 7, 'total_tokens': 17932, 'input_token_details': {'cache_read': 0}}\n",
"\n",
"-------------------- Tool (Wikipedia) has been called --------------------\n",
"\n",
"---------------------------------\n",
"Loading tables from: https://en.wikipedia.org/wiki/Mercedes_Sosa\n",
"---------------------------------\n",
"---------------------------------\n",
"Loading tables from: https://en.wikipedia.org/wiki/Joan_Baez_discography\n",
"---------------------------------\n",
"\n",
"-------------------- Agent has been called -----------------------------------\n",
"\n",
"Waiting for 5 seconds...\n",
"Agent has made a decision:\n",
" Based on the Wikipedia search results for \"Mercedes Sosa discography\", the studio albums published by Mercedes Sosa between 2000 and 2009 (inclusive) are:\n",
"\n",
"* 2005 - Corazón Libre\n",
"* 2009 - Cantora 1\n",
"* 2009 - Cantora 2\n",
"\n",
"Therefore, the answer is 3. []\n",
"\n",
"-------------------- Decision of forwarding has been made --------------------\n",
"\n",
"Waiting for 2 seconds...\n",
"This is round: 4\n",
"The last message is: content='Based on the Wikipedia search results for \"Mercedes Sosa discography\", the studio albums published by Mercedes Sosa between 2000 and 2009 (inclusive) are:\\n\\n* 2005 - Corazón Libre\\n* 2009 - Cantora 1\\n* 2009 - Cantora 2\\n\\nTherefore, the answer is 3.' additional_kwargs={} response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.0-flash', 'safety_ratings': []} id='run-59b32104-a935-46ed-a8fc-c530bbe2816e-0' usage_metadata={'input_tokens': 35228, 'output_tokens': 79, 'total_tokens': 35307, 'input_token_details': {'cache_read': 0}}\n",
"\n",
"-------------------- Generating Answer -----------------------------------\n",
"\n",
"Waiting for 5 seconds...\n",
"The final answer is: 3\n"
]
}
],
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-03T18:30:59.650996Z",
"start_time": "2025-05-03T18:30:59.647709Z"
}
},
"cell_type": "code",
"source": "",
"id": "ce8f566e12feb242",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "27e7946b3191e98f"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|