Week 2 Learnings (#2)

* Add week 2 day 1

* Add week 2 day 2

* Add week 2 day 3

* Add week 2 day 4

* Add week 2 day 5

* Add week 2 exercise solution
This commit is contained in:
Stephen Muthama
2025-10-23 09:45:38 +03:00
committed by GitHub
parent a9e9453e57
commit a63143df82
6 changed files with 1845 additions and 167 deletions

View File

@@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "8b50bbe2-c0b1-49c3-9a5c-1ba7efa2bcb4",
"metadata": {},
"outputs": [],
@@ -26,10 +26,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "747e8786-9da8-4342-b6c9-f5f69c2e22ae",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI API Key exists and begins sk-proj-\n"
]
}
],
"source": [
"# Initialization\n",
"\n",
@@ -52,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "0a521d84-d07c-49ab-a0df-d6451499ed97",
"metadata": {},
"outputs": [],
@@ -66,10 +74,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "61a2a15d-b559-4844-b377-6bd5cb4949f6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7866\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def chat(message, history):\n",
" history = [{\"role\":h[\"role\"], \"content\":h[\"content\"]} for h in history]\n",
@@ -98,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "0696acb1-0b05-4dc2-80d5-771be04f1fb2",
"metadata": {},
"outputs": [],
@@ -115,17 +152,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "80ca4e09-6287-4d3f-997d-fa6afbcf6c85",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tool called for city London\n"
]
},
{
"data": {
"text/plain": [
"'The price of a ticket to London is $799'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_ticket_price(\"London\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "4afceded-7178-4c05-8fa6-9f2085e6a344",
"metadata": {},
"outputs": [],
@@ -151,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "bdca8679-935f-4e7f-97e6-e71a4d4f228c",
"metadata": {},
"outputs": [],
@@ -163,10 +218,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "818b4b2b",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'function',\n",
" 'function': {'name': 'get_ticket_price',\n",
" 'description': 'Get the price of a return ticket to the destination city.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'destination_city': {'type': 'string',\n",
" 'description': 'The city that the customer wants to travel to'}},\n",
" 'required': ['destination_city'],\n",
" 'additionalProperties': False}}}]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tools"
]
@@ -187,7 +260,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "ce9b0744-9c78-408d-b9df-9f6fd9ed78cf",
"metadata": {},
"outputs": [],
@@ -209,7 +282,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "b0992986-ea09-4912-a076-8e5603ee631f",
"metadata": {},
"outputs": [],
@@ -232,10 +305,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "f4be8a71-b19e-4c2f-80df-f59ff2661f14",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7867\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7867/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tool called for city London\n"
]
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
@@ -254,7 +363,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "b6f5c860",
"metadata": {},
"outputs": [],
@@ -276,7 +385,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "9c46a861",
"metadata": {},
"outputs": [],
@@ -308,7 +417,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "cf262abc",
"metadata": {},
"outputs": [],
@@ -330,7 +439,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "47d50e70",
"metadata": {},
"outputs": [],
@@ -340,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "bb61a45d",
"metadata": {},
"outputs": [],
@@ -355,7 +464,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "12c73b6a",
"metadata": {},
"outputs": [],
@@ -371,17 +480,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"id": "7cb2e079",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DATABASE TOOL CALLED: Getting price for London\n"
]
},
{
"data": {
"text/plain": [
"'No price data available for this city'"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_ticket_price(\"London\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "46e43463",
"metadata": {},
"outputs": [],
@@ -395,7 +522,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "9185228e",
"metadata": {},
"outputs": [],
@@ -407,10 +534,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"id": "cda459b9",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DATABASE TOOL CALLED: Getting price for Tokyo\n"
]
},
{
"data": {
"text/plain": [
"'Ticket price to Tokyo is $1420.0'"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_ticket_price(\"Tokyo\")"
]
@@ -420,7 +565,44 @@
"execution_count": null,
"id": "bfbfa251",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7868\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7868/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"DATABASE TOOL CALLED: Getting price for London\n",
"DATABASE TOOL CALLED: Getting price for tokyo\n"
]
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
@@ -470,7 +652,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
"version": "3.12.12"
}
},
"nbformat": 4,