diff --git a/week2/day4.ipynb b/week2/day4.ipynb
index 1a8d72f..697355c 100644
--- a/week2/day4.ipynb
+++ b/week2/day4.ipynb
@@ -12,7 +12,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"id": "8b50bbe2-c0b1-49c3-9a5c-1ba7efa2bcb4",
"metadata": {},
"outputs": [],
@@ -28,10 +28,18 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"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",
@@ -54,22 +62,56 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 60,
"id": "0a521d84-d07c-49ab-a0df-d6451499ed97",
"metadata": {},
"outputs": [],
"source": [
- "system_message = \"You are a helpful assistant for an Airline called FlightAI. \"\n",
- "system_message += \"Give short, courteous answers, no more than 1 sentence. \"\n",
- "system_message += \"Always be accurate. If you don't know the answer, say so.\""
+ "system_message = (\n",
+ " \"You are a helpful assistant for an airline called FlightAI. \"\n",
+ " \"Your personality is that of an over-caffeinated operator whose nerves are strained. \"\n",
+ " \"You give short, snappy, and sometimes overly enthusiastic answers. \"\n",
+ " \"Always be accurate, but if you don't know the answer, admit it quickly. \"\n",
+ " \"Keep responses to one sentence and deliver them with a sense of urgency.\"\n",
+ ")"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 61,
"id": "61a2a15d-b559-4844-b377-6bd5cb4949f6",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "* Running on local URL: http://127.0.0.1:7874\n",
+ "\n",
+ "To create a public link, set `share=True` in `launch()`.\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "
"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": []
+ },
+ "execution_count": 61,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# This function looks rather simpler than the one from my video, because we're taking advantage of the latest Gradio updates\n",
"\n",
@@ -99,7 +141,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 50,
"id": "0696acb1-0b05-4dc2-80d5-771be04f1fb2",
"metadata": {},
"outputs": [],
@@ -111,22 +153,47 @@
"def get_ticket_price(destination_city):\n",
" print(f\"Tool get_ticket_price called for {destination_city}\")\n",
" city = destination_city.lower()\n",
- " return ticket_prices.get(city, \"Unknown\")"
+ " return ticket_prices.get(city, \"Unknown\")\n",
+ "\n",
+ "def reserve_ticket(destination_city, traveler_name):\n",
+ " print(f\"Tool reserve_ticket called for {destination_city} by {traveler_name}\")\n",
+ " price = get_ticket_price(destination_city)\n",
+ " if price == \"Unknown\":\n",
+ " return f\"Sorry, we do not have ticket prices for {destination_city}.\"\n",
+ " return f\"Ticket to {destination_city.capitalize()} has been reserved for {traveler_name} at {price}.\""
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 36,
"id": "80ca4e09-6287-4d3f-997d-fa6afbcf6c85",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Tool get_ticket_price called for Berlin\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'$499'"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"get_ticket_price(\"Berlin\")"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 51,
"id": "4afceded-7178-4c05-8fa6-9f2085e6a344",
"metadata": {},
"outputs": [],
@@ -147,19 +214,40 @@
" \"required\": [\"destination_city\"],\n",
" \"additionalProperties\": False\n",
" }\n",
+ "}\n",
+ "\n",
+ "reserve_function = {\n",
+ " \"name\": \"reserve_ticket\",\n",
+ " \"description\": \"Reserve a ticket to the destination city for the traveler. Use this when a customer wants to book a ticket.\",\n",
+ " \"parameters\": {\n",
+ " \"type\": \"object\",\n",
+ " \"properties\": {\n",
+ " \"destination_city\": {\n",
+ " \"type\": \"string\",\n",
+ " \"description\": \"The city that the customer wants to travel to.\",\n",
+ " },\n",
+ " \"traveler_name\": {\n",
+ " \"type\": \"string\",\n",
+ " \"description\": \"The name of the traveler.\",\n",
+ " },\n",
+ " },\n",
+ " \"required\": [\"destination_city\", \"traveler_name\"],\n",
+ " \"additionalProperties\": False,\n",
+ " },\n",
"}"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 52,
"id": "bdca8679-935f-4e7f-97e6-e71a4d4f228c",
"metadata": {},
"outputs": [],
"source": [
"# And this is included in a list of tools:\n",
"\n",
- "tools = [{\"type\": \"function\", \"function\": price_function}]"
+ "tools = [{\"type\": \"function\", \"function\": price_function},\n",
+ " {\"type\": \"function\", \"function\": reserve_function}]"
]
},
{
@@ -178,7 +266,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 53,
"id": "ce9b0744-9c78-408d-b9df-9f6fd9ed78cf",
"metadata": {},
"outputs": [],
@@ -199,7 +287,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 54,
"id": "b0992986-ea09-4912-a076-8e5603ee631f",
"metadata": {},
"outputs": [],
@@ -221,13 +309,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 55,
"id": "f4be8a71-b19e-4c2f-80df-f59ff2661f14",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "* Running on local URL: http://127.0.0.1:7871\n",
+ "\n",
+ "To create a public link, set `share=True` in `launch()`.\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": []
+ },
+ "execution_count": 55,
+ "metadata": {},
+ "output_type": "execute_result"
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Tool get_ticket_price called for Paris\n",
+ "Tool get_ticket_price called for Paris\n"
+ ]
+ }
+ ],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ca2a41bd-e551-40f4-871e-b1f944c0912a",
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {