Browse Source

Updated AI Chatbot

Updated AI Chatbot code
pull/295/head
arunabeshc 1 month ago
parent
commit
cc9d6cf1bc
  1. 136
      week2/community-contributions/AI Booking Chatbot.ipynb

136
week2/community-contributions/AI Booking Chatbot.ipynb

@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"id": "a07e7793-b8f5-44f4-aded-5562f633271a", "id": "a07e7793-b8f5-44f4-aded-5562f633271a",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -43,18 +43,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"id": "717ea9d4-1e72-4035-b7c5-5d61da5b8ea3", "id": "717ea9d4-1e72-4035-b7c5-5d61da5b8ea3",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI API Key exists and begins sk-proj-\n"
]
}
],
"source": [ "source": [
"# Initialization\n", "# Initialization\n",
"\n", "\n",
@ -75,7 +67,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "cc78f4fd-9920-4872-9117-90cd2aeb2a06", "id": "cc78f4fd-9920-4872-9117-90cd2aeb2a06",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -87,7 +79,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"id": "b2701cc0-6403-4880-9b31-e6e39e89feb4", "id": "b2701cc0-6403-4880-9b31-e6e39e89feb4",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -104,7 +96,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"id": "5e33902f-c2c3-4fb0-b01d-a346a4dff811", "id": "5e33902f-c2c3-4fb0-b01d-a346a4dff811",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -114,7 +106,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"id": "27dfca47-2a38-49f3-8905-f583d98710a5", "id": "27dfca47-2a38-49f3-8905-f583d98710a5",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -128,7 +120,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"id": "6ae7371b-031e-47d7-afaf-42d6758ccd92", "id": "6ae7371b-031e-47d7-afaf-42d6758ccd92",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -142,7 +134,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"id": "c919b13a-50b6-4510-8e9d-02cdfd95cb98", "id": "c919b13a-50b6-4510-8e9d-02cdfd95cb98",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -165,7 +157,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"id": "d2628781-6f5e-4ac1-bbe3-2e08aa0aae0d", "id": "d2628781-6f5e-4ac1-bbe3-2e08aa0aae0d",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -199,7 +191,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"id": "480de296-4a36-4ec4-a5f6-149fc198c7a8", "id": "480de296-4a36-4ec4-a5f6-149fc198c7a8",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -225,7 +217,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"id": "cf1b3e35-08ee-478e-aa1c-534418d78daf", "id": "cf1b3e35-08ee-478e-aa1c-534418d78daf",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -249,7 +241,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"id": "73e4c8a2-c034-41a4-9b97-7b2aa4aca504", "id": "73e4c8a2-c034-41a4-9b97-7b2aa4aca504",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -274,7 +266,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"id": "1d5d74a0-9c25-46a4-84ee-1f700bd55fa7", "id": "1d5d74a0-9c25-46a4-84ee-1f700bd55fa7",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -289,7 +281,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": null,
"id": "fa18f535-f8a7-4386-b39a-df0f84d23406", "id": "fa18f535-f8a7-4386-b39a-df0f84d23406",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -326,7 +318,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"id": "b588d711-5f20-4a3a-9422-81a1fda8d5b0", "id": "b588d711-5f20-4a3a-9422-81a1fda8d5b0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -368,7 +360,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": null,
"id": "e74eee70-f89e-4c03-922c-74f9ab567a4c", "id": "e74eee70-f89e-4c03-922c-74f9ab567a4c",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -421,7 +413,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": null,
"id": "b8f25812-2609-4e26-b929-9cee2d1e4467", "id": "b8f25812-2609-4e26-b929-9cee2d1e4467",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -448,7 +440,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": null,
"id": "1728e70b-596c-4048-8c02-ac3c26756470", "id": "1728e70b-596c-4048-8c02-ac3c26756470",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -511,7 +503,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"id": "a2547bb0-43a5-4b1d-8b9a-95da15a11040", "id": "a2547bb0-43a5-4b1d-8b9a-95da15a11040",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -527,17 +519,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": null,
"id": "07f72649-9d2f-4bf5-b76f-97e52e2f01aa",
"metadata": {},
"outputs": [],
"source": [
"# gr.ChatInterface(fn=chat1, type=\"messages\").launch(inbrowser=True)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "23b102a4-e544-4560-acc8-a15620478582", "id": "23b102a4-e544-4560-acc8-a15620478582",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -574,40 +556,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": null,
"id": "133904cf-4d72-4552-84a8-76650f334857", "id": "133904cf-4d72-4552-84a8-76650f334857",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7860\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7860/\" 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": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"with gr.Blocks() as ui:\n", "with gr.Blocks() as ui:\n",
" with gr.Row():\n", " with gr.Row():\n",
@ -646,51 +598,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": null,
"id": "dc4a3844-194c-4af7-8ca8-2fc4edb74c11", "id": "dc4a3844-194c-4af7-8ca8-2fc4edb74c11",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'london': '20', 'paris': '90', 'tokyo': '100', 'berlin': '0'}\n",
"ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_JyBDI7OInb83ggVApUkRxj08', function=Function(arguments='{\"destination_city\":\"Kolkata\"}', name='get_ticket_availability'), type='function')])\n",
"Tool get_ticket_availability called for Kolkata\n",
"ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_RXeyUBFKQ2wgLARXb0zfFTeS', function=Function(arguments='{\"destination_city\":\"London\",\"price\":\"$799\",\"availability\":\"20 tickets available\"}', name='book_ticket'), type='function')])\n",
"Tool get_ticket_price called for London\n",
"Tool get_ticket_availability called for London\n",
"Tool book_function called for London\n"
]
}
],
"source": [ "source": [
"print(ticket_availability)" "print(ticket_availability)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4db3a6f9-3b6f-4825-8172-9439020b154f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2cb145cc-cef0-42d5-902d-72a0af622dcb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d8af88fd-c199-4ca3-ba7c-7934054bac8f",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {

Loading…
Cancel
Save