Upload dummy_agent_library.ipynb (#124)
Browse files- Upload dummy_agent_library.ipynb (a9e515e3f6ab4dbde18db2540d89a19695436616)
- unit1/dummy_agent_library.ipynb +34 -34
unit1/dummy_agent_library.ipynb
CHANGED
|
@@ -68,13 +68,13 @@
|
|
| 68 |
},
|
| 69 |
{
|
| 70 |
"cell_type": "markdown",
|
| 71 |
-
"
|
| 72 |
-
"We use the `chat` method since is a convenient and reliable way to apply chat templates:"
|
| 73 |
-
],
|
| 74 |
"metadata": {
|
| 75 |
"id": "0Iuue-02fCzq"
|
| 76 |
},
|
| 77 |
-
"
|
|
|
|
|
|
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
|
@@ -90,8 +90,8 @@
|
|
| 90 |
},
|
| 91 |
"outputs": [
|
| 92 |
{
|
| 93 |
-
"output_type": "stream",
|
| 94 |
"name": "stdout",
|
|
|
|
| 95 |
"text": [
|
| 96 |
"Paris.\n"
|
| 97 |
]
|
|
@@ -194,18 +194,18 @@
|
|
| 194 |
},
|
| 195 |
{
|
| 196 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
"source": [
|
| 198 |
"messages = [\n",
|
| 199 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
| 200 |
" {\"role\": \"user\", \"content\": \"What's the weather in London?\"},\n",
|
| 201 |
"]"
|
| 202 |
-
]
|
| 203 |
-
"metadata": {
|
| 204 |
-
"id": "UHs7XfzMfoY7"
|
| 205 |
-
},
|
| 206 |
-
"id": "UHs7XfzMfoY7",
|
| 207 |
-
"execution_count": null,
|
| 208 |
-
"outputs": []
|
| 209 |
},
|
| 210 |
{
|
| 211 |
"cell_type": "markdown",
|
|
@@ -230,7 +230,6 @@
|
|
| 230 |
},
|
| 231 |
"outputs": [
|
| 232 |
{
|
| 233 |
-
"output_type": "execute_result",
|
| 234 |
"data": {
|
| 235 |
"text/plain": [
|
| 236 |
"[{'role': 'system',\n",
|
|
@@ -240,8 +239,9 @@
|
|
| 240 |
" 'content': 'Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\\n\\nAction:\\n```json\\n{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"London\"}\\n}\\n```\\n\\nthe weather in London is sunny with low temperatures. \\n'}]"
|
| 241 |
]
|
| 242 |
},
|
|
|
|
| 243 |
"metadata": {},
|
| 244 |
-
"
|
| 245 |
}
|
| 246 |
],
|
| 247 |
"source": [
|
|
@@ -272,8 +272,8 @@
|
|
| 272 |
},
|
| 273 |
"outputs": [
|
| 274 |
{
|
| 275 |
-
"output_type": "stream",
|
| 276 |
"name": "stdout",
|
|
|
|
| 277 |
"text": [
|
| 278 |
"Thought: To find out the weather in London, I should use the `get_weather` tool with the location set to \"London\".\n",
|
| 279 |
"\n",
|
|
@@ -330,8 +330,8 @@
|
|
| 330 |
},
|
| 331 |
"outputs": [
|
| 332 |
{
|
| 333 |
-
"output_type": "stream",
|
| 334 |
"name": "stdout",
|
|
|
|
| 335 |
"text": [
|
| 336 |
"Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\n",
|
| 337 |
"\n",
|
|
@@ -385,23 +385,23 @@
|
|
| 385 |
},
|
| 386 |
"outputs": [
|
| 387 |
{
|
| 388 |
-
"output_type": "execute_result",
|
| 389 |
"data": {
|
| 390 |
-
"text/plain": [
|
| 391 |
-
"'the weather in London is sunny with low temperatures. \\n'"
|
| 392 |
-
],
|
| 393 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 394 |
"type": "string"
|
| 395 |
-
}
|
|
|
|
|
|
|
|
|
|
| 396 |
},
|
|
|
|
| 397 |
"metadata": {},
|
| 398 |
-
"
|
| 399 |
}
|
| 400 |
],
|
| 401 |
"source": [
|
| 402 |
"# Dummy function\n",
|
| 403 |
"def get_weather(location):\n",
|
| 404 |
-
" return f\"
|
| 405 |
"\n",
|
| 406 |
"get_weather('London')"
|
| 407 |
]
|
|
@@ -430,18 +430,18 @@
|
|
| 430 |
},
|
| 431 |
"outputs": [
|
| 432 |
{
|
| 433 |
-
"output_type": "execute_result",
|
| 434 |
"data": {
|
| 435 |
"text/plain": [
|
| 436 |
"[{'role': 'system',\n",
|
| 437 |
" 'content': 'Answer the following questions as best you can. You have access to the following tools:\\n\\nget_weather: Get the current weather in a given location\\n\\nThe way you use the tools is by specifying a json blob.\\nSpecifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).\\n\\nThe only values that should be in the \"action\" field are:\\nget_weather: Get the current weather in a given location, args: {{\"location\": {{\"type\": \"string\"}}}}\\nexample use :\\n```\\n{{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"New York\"}\\n}}\\n\\nALWAYS use the following format:\\n\\nQuestion: the input question you must answer\\nThought: you should always think about one action to take. Only one action at a time in this format:\\nAction:\\n```\\n$JSON_BLOB\\n```\\nObservation: the result of the action. This Observation is unique, complete, and the source of truth.\\n... (this Thought/Action/Observation can repeat N times, you should take several steps when needed. The $JSON_BLOB must be formatted as markdown and only use a SINGLE action at a time.)\\n\\nYou must always end your output with the following format:\\n\\nThought: I now know the final answer\\nFinal Answer: the final answer to the original input question\\n\\nNow begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer. '},\n",
|
| 438 |
" {'role': 'user', 'content': \"What's the weather in London ?\"},\n",
|
| 439 |
" {'role': 'assistant',\n",
|
| 440 |
-
" 'content': 'Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\\n\\nAction:\\n```json\\n{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"London\"}\\n}\\n```\\n\\
|
| 441 |
]
|
| 442 |
},
|
|
|
|
| 443 |
"metadata": {},
|
| 444 |
-
"
|
| 445 |
}
|
| 446 |
],
|
| 447 |
"source": [
|
|
@@ -449,7 +449,7 @@
|
|
| 449 |
"messages=[\n",
|
| 450 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
| 451 |
" {\"role\": \"user\", \"content\": \"What's the weather in London ?\"},\n",
|
| 452 |
-
" {\"role\": \"assistant\", \"content\": output.choices[0].message.content
|
| 453 |
"]\n",
|
| 454 |
"messages"
|
| 455 |
]
|
|
@@ -478,8 +478,8 @@
|
|
| 478 |
},
|
| 479 |
"outputs": [
|
| 480 |
{
|
| 481 |
-
"output_type": "stream",
|
| 482 |
"name": "stdout",
|
|
|
|
| 483 |
"text": [
|
| 484 |
"Observation: I have received the current weather conditions for London.\n",
|
| 485 |
"\n",
|
|
@@ -501,15 +501,15 @@
|
|
| 501 |
},
|
| 502 |
{
|
| 503 |
"cell_type": "markdown",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
"source": [
|
| 505 |
"We learned how we can create Agents from scratch using Python code, and we **saw just how tedious that process can be**. Fortunately, many Agent libraries simplify this work by handling much of the heavy lifting for you.\n",
|
| 506 |
"\n",
|
| 507 |
"Now, we're ready **to create our first real Agent** using the `smolagents` library."
|
| 508 |
-
]
|
| 509 |
-
"metadata": {
|
| 510 |
-
"id": "A23LiGG0jmNb"
|
| 511 |
-
},
|
| 512 |
-
"id": "A23LiGG0jmNb"
|
| 513 |
}
|
| 514 |
],
|
| 515 |
"metadata": {
|
|
@@ -536,4 +536,4 @@
|
|
| 536 |
},
|
| 537 |
"nbformat": 4,
|
| 538 |
"nbformat_minor": 5
|
| 539 |
-
}
|
|
|
|
| 68 |
},
|
| 69 |
{
|
| 70 |
"cell_type": "markdown",
|
| 71 |
+
"id": "0Iuue-02fCzq",
|
|
|
|
|
|
|
| 72 |
"metadata": {
|
| 73 |
"id": "0Iuue-02fCzq"
|
| 74 |
},
|
| 75 |
+
"source": [
|
| 76 |
+
"We use the `chat` method since is a convenient and reliable way to apply chat templates:"
|
| 77 |
+
]
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
|
|
|
| 90 |
},
|
| 91 |
"outputs": [
|
| 92 |
{
|
|
|
|
| 93 |
"name": "stdout",
|
| 94 |
+
"output_type": "stream",
|
| 95 |
"text": [
|
| 96 |
"Paris.\n"
|
| 97 |
]
|
|
|
|
| 194 |
},
|
| 195 |
{
|
| 196 |
"cell_type": "code",
|
| 197 |
+
"execution_count": null,
|
| 198 |
+
"id": "UHs7XfzMfoY7",
|
| 199 |
+
"metadata": {
|
| 200 |
+
"id": "UHs7XfzMfoY7"
|
| 201 |
+
},
|
| 202 |
+
"outputs": [],
|
| 203 |
"source": [
|
| 204 |
"messages = [\n",
|
| 205 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
| 206 |
" {\"role\": \"user\", \"content\": \"What's the weather in London?\"},\n",
|
| 207 |
"]"
|
| 208 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
},
|
| 210 |
{
|
| 211 |
"cell_type": "markdown",
|
|
|
|
| 230 |
},
|
| 231 |
"outputs": [
|
| 232 |
{
|
|
|
|
| 233 |
"data": {
|
| 234 |
"text/plain": [
|
| 235 |
"[{'role': 'system',\n",
|
|
|
|
| 239 |
" 'content': 'Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\\n\\nAction:\\n```json\\n{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"London\"}\\n}\\n```\\n\\nthe weather in London is sunny with low temperatures. \\n'}]"
|
| 240 |
]
|
| 241 |
},
|
| 242 |
+
"execution_count": 22,
|
| 243 |
"metadata": {},
|
| 244 |
+
"output_type": "execute_result"
|
| 245 |
}
|
| 246 |
],
|
| 247 |
"source": [
|
|
|
|
| 272 |
},
|
| 273 |
"outputs": [
|
| 274 |
{
|
|
|
|
| 275 |
"name": "stdout",
|
| 276 |
+
"output_type": "stream",
|
| 277 |
"text": [
|
| 278 |
"Thought: To find out the weather in London, I should use the `get_weather` tool with the location set to \"London\".\n",
|
| 279 |
"\n",
|
|
|
|
| 330 |
},
|
| 331 |
"outputs": [
|
| 332 |
{
|
|
|
|
| 333 |
"name": "stdout",
|
| 334 |
+
"output_type": "stream",
|
| 335 |
"text": [
|
| 336 |
"Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\n",
|
| 337 |
"\n",
|
|
|
|
| 385 |
},
|
| 386 |
"outputs": [
|
| 387 |
{
|
|
|
|
| 388 |
"data": {
|
|
|
|
|
|
|
|
|
|
| 389 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 390 |
"type": "string"
|
| 391 |
+
},
|
| 392 |
+
"text/plain": [
|
| 393 |
+
"'the weather in London is sunny with low temperatures. \\n'"
|
| 394 |
+
]
|
| 395 |
},
|
| 396 |
+
"execution_count": 16,
|
| 397 |
"metadata": {},
|
| 398 |
+
"output_type": "execute_result"
|
| 399 |
}
|
| 400 |
],
|
| 401 |
"source": [
|
| 402 |
"# Dummy function\n",
|
| 403 |
"def get_weather(location):\n",
|
| 404 |
+
" return f\"the weather in {location} is sunny with low temperatures. \\n\"\n",
|
| 405 |
"\n",
|
| 406 |
"get_weather('London')"
|
| 407 |
]
|
|
|
|
| 430 |
},
|
| 431 |
"outputs": [
|
| 432 |
{
|
|
|
|
| 433 |
"data": {
|
| 434 |
"text/plain": [
|
| 435 |
"[{'role': 'system',\n",
|
| 436 |
" 'content': 'Answer the following questions as best you can. You have access to the following tools:\\n\\nget_weather: Get the current weather in a given location\\n\\nThe way you use the tools is by specifying a json blob.\\nSpecifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).\\n\\nThe only values that should be in the \"action\" field are:\\nget_weather: Get the current weather in a given location, args: {{\"location\": {{\"type\": \"string\"}}}}\\nexample use :\\n```\\n{{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"New York\"}\\n}}\\n\\nALWAYS use the following format:\\n\\nQuestion: the input question you must answer\\nThought: you should always think about one action to take. Only one action at a time in this format:\\nAction:\\n```\\n$JSON_BLOB\\n```\\nObservation: the result of the action. This Observation is unique, complete, and the source of truth.\\n... (this Thought/Action/Observation can repeat N times, you should take several steps when needed. The $JSON_BLOB must be formatted as markdown and only use a SINGLE action at a time.)\\n\\nYou must always end your output with the following format:\\n\\nThought: I now know the final answer\\nFinal Answer: the final answer to the original input question\\n\\nNow begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer. '},\n",
|
| 437 |
" {'role': 'user', 'content': \"What's the weather in London ?\"},\n",
|
| 438 |
" {'role': 'assistant',\n",
|
| 439 |
+
" 'content': 'Thought: To find out the weather in London, I should use the `get_weather` tool with \"London\" as the location.\\n\\nAction:\\n```json\\n{\\n \"action\": \"get_weather\",\\n \"action_input\": {\"location\": \"London\"}\\n}\\n```\\n\\nthe weather in London is sunny with low temperatures. \\n'}]"
|
| 440 |
]
|
| 441 |
},
|
| 442 |
+
"execution_count": 18,
|
| 443 |
"metadata": {},
|
| 444 |
+
"output_type": "execute_result"
|
| 445 |
}
|
| 446 |
],
|
| 447 |
"source": [
|
|
|
|
| 449 |
"messages=[\n",
|
| 450 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
| 451 |
" {\"role\": \"user\", \"content\": \"What's the weather in London ?\"},\n",
|
| 452 |
+
" {\"role\": \"assistant\", \"content\": output.choices[0].message.content+\"Observation:\\n\"+get_weather('London')},\n",
|
| 453 |
"]\n",
|
| 454 |
"messages"
|
| 455 |
]
|
|
|
|
| 478 |
},
|
| 479 |
"outputs": [
|
| 480 |
{
|
|
|
|
| 481 |
"name": "stdout",
|
| 482 |
+
"output_type": "stream",
|
| 483 |
"text": [
|
| 484 |
"Observation: I have received the current weather conditions for London.\n",
|
| 485 |
"\n",
|
|
|
|
| 501 |
},
|
| 502 |
{
|
| 503 |
"cell_type": "markdown",
|
| 504 |
+
"id": "A23LiGG0jmNb",
|
| 505 |
+
"metadata": {
|
| 506 |
+
"id": "A23LiGG0jmNb"
|
| 507 |
+
},
|
| 508 |
"source": [
|
| 509 |
"We learned how we can create Agents from scratch using Python code, and we **saw just how tedious that process can be**. Fortunately, many Agent libraries simplify this work by handling much of the heavy lifting for you.\n",
|
| 510 |
"\n",
|
| 511 |
"Now, we're ready **to create our first real Agent** using the `smolagents` library."
|
| 512 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
}
|
| 514 |
],
|
| 515 |
"metadata": {
|
|
|
|
| 536 |
},
|
| 537 |
"nbformat": 4,
|
| 538 |
"nbformat_minor": 5
|
| 539 |
+
}
|