diff --git a/week2/community-contributions/AI Booking Chatbot.ipynb b/week2/community-contributions/AI Booking Chatbot.ipynb index 16deb05..ced7d18 100644 --- a/week2/community-contributions/AI Booking Chatbot.ipynb +++ b/week2/community-contributions/AI Booking Chatbot.ipynb @@ -81,7 +81,7 @@ "outputs": [], "source": [ "system_message = \"You are a helpful assistant. \"\n", - "system_message += \"Give short, courteous answers. You can check ticket price, availability, and reserve tickets for users. \"\n", + "system_message += \"Give short, courteous answers. You can check ticket price, ticket availability, and reserve tickets for users. \"\n", "system_message += \"Always be accurate. If you don't know the answer, say so.\"" ] }, @@ -151,12 +151,12 @@ " status=\"\"\n", " if availability == 0:\n", " status=\"Cannot book a ticket, no seat available\\n\"\n", - " elif int(availability)-int(no_of_tickets) <= 0:\n", + " elif (int(availability)-int(no_of_tickets)) < 0:\n", " status=\"Cannot book a ticket, no seat available\\n\"\n", " else:\n", " print(f\"Tool book_function called for {destination_city}\")\n", " f = open(\"C:/Users/aruna/Desktop/book_status.txt\", \"a\")\n", - " f.write(f\"{no_of_tickets} ticket/s to {destination_city} booked for {price}, currently available - {int(availability)-int(no_of_tickets)}\")\n", + " f.write(f\"{no_of_tickets} ticket/s to {destination_city} booked for {price} x {no_of_tickets}, currently available - {int(availability)-int(no_of_tickets)}\")\n", " f.write(\"\\n\")\n", " f.close()\n", " ticket_availability[destination_city.lower()]=str(int(availability)-int(no_of_tickets))\n", @@ -175,9 +175,9 @@ "book_function = {\n", " \"name\": \"book_ticket\",\n", " \"description\": \"Book the ticket based on the ticket price and/ or availability as requested by the user. For example, when a \\\n", - " customer asks to purchase one or more tickets to Tokyo after getting to know the ticket price and/or the availability, then \\\n", - " proceed with this tool call. Please help the customer in booking the ticket/s if tickets are available. But please each time you \\\n", - " book, ask confirmation from the user before proceeding with booking\",\n", + " user asks to purchase one or more tickets to Tokyo after getting to know the ticket price and/or the availability, then \\\n", + " proceed with this tool call. Else, request the user to either ask for ticket price or availability first. Please help the customer in booking the ticket/s if tickets are available. But before each time\\\n", + " you book, ask confirmation from the user before proceeding with booking.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", @@ -397,7 +397,7 @@ " messages.append(message)\n", " messages.append(response)\n", " # image = artist(city)\n", - " response = openai.chat.completions.create(model=gpt_model, messages=messages)\n", + " response = openai.chat.completions.create(model=gpt_model, messages=messages, tools=tools)\n", " elif name.replace('\"','') == \"get_ticket_price_availability\":\n", " price = get_ticket_price(city)\n", " availability = get_ticket_availability(city)\n", @@ -409,13 +409,13 @@ " messages.append(message)\n", " messages.append(response)\n", " print(messages)\n", - " response = openai.chat.completions.create(model=gpt_model, messages=messages) \n", + " response = openai.chat.completions.create(model=gpt_model, messages=messages, tools=tools) \n", " else: \n", " response, city = handle_tool_call1(message)\n", " messages.append(message)\n", " messages.append(response)\n", " # image = artist(city)\n", - " response = openai.chat.completions.create(model=gpt_model, messages=messages)\n", + " response = openai.chat.completions.create(model=gpt_model, messages=messages, tools=tools)\n", " \n", " reply = response.choices[0].message.content\n", " history += [{\"role\":\"assistant\", \"content\":reply}]\n", @@ -681,42 +681,39 @@ "text": [ "{'london': '20', 'paris': '90', 'tokyo': '100', 'berlin': '2'}\n", "Speak now...\n", - "You said: ticket price to London\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_sLAcmufug2cPxfVZyOuYee4X', function=Function(arguments='{\"destination_city\":\"London\"}', name='get_ticket_price'), type='function')])\n", + "You said: price of tickets to Tokyo\n", + "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_ddXzm2cPBJ9SOsV8qI4L2FcB', function=Function(arguments='{\"destination_city\":\"Tokyo\"}', name='get_ticket_price'), type='function')])\n", + "Tool get_ticket_price called for Tokyo\n", + "Speak now...\n", + "You said: what is the price of two tickets to London\n", + "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_lSNZCwaUdckvk3V0eTBlotRN', function=Function(arguments='{\"destination_city\":\"London\"}', name='get_ticket_price'), type='function')])\n", "Tool get_ticket_price called for London\n", "Speak now...\n", - "You said: can you please resolve two tickets for me to London\n", + "You said: can you please reserve two tickets for me to London\n", + "ChatCompletionMessage(content='First, I need to check the availability for the two tickets to London. Please hold on a moment.', refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_iA0D9tm2cTMf8J8KJc4gipFn', function=Function(arguments='{\"destination_city\":\"London\"}', name='get_ticket_availability'), type='function')])\n", + "Tool get_ticket_availability called for London\n", "Speak now...\n", "You said: yes please proceed\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_gOnuOwDEsE6lUIQZhZ15mSzR', function=Function(arguments='{\"destination_city\":\"London\",\"price\":\"$799\",\"availability\":\"available\",\"no_of_tickets\":\"2\"}', name='book_ticket'), type='function')])\n", + "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_JzJXFWFGhtG1jXiFlKtmZhGi', function=Function(arguments='{\"destination_city\":\"London\",\"price\":\"$799\",\"availability\":\"20 tickets available\",\"no_of_tickets\":\"2\"}', 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", "Speak now...\n", - "You said: what is the current ticket availability to\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_EYind2wu2Mc1ILAOlzgyO9MT', function=Function(arguments='{\"destination_city\":\"London\"}', name='get_ticket_availability'), type='function')])\n", + "You said: what is the current availability of tickets to London\n", + "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_eiHPAGAcbaFq3qzDf0a6idzG', function=Function(arguments='{\"destination_city\":\"London\"}', name='get_ticket_availability'), type='function')])\n", "Tool get_ticket_availability called for London\n", "Speak now...\n", - "You said: yes can you please reserve 19 tickets for me to London\n", - "Speak now...\n", - "You said: no I think this is fine for\n", - "Speak now...\n", - "You said: what is the ticket availability to Ber\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_UvchMEkQjeTZ5ou6uURYmKSz', function=Function(arguments='{\"destination_city\":\"Ber\"}', name='get_ticket_availability'), type='function')])\n", - "Tool get_ticket_availability called for Ber\n", + "You said: can you please reserve the remaining 18 tickets for me to London\n", "Speak now...\n", - "You said: ticket availability to Berlin\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_4qiigA8seXHWgKhYGZNDeXV8', function=Function(arguments='{\"destination_city\":\"Berlin\"}', name='get_ticket_availability'), type='function')])\n", - "Tool get_ticket_availability called for Berlin\n", - "Speak now...\n", - "You said: I would like to reserve two tickets to Berlin\n", + "You said: yes I do confirm\n", + "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_8uCQ91FCOGf4HjQnLNafmSs6', function=Function(arguments='{\"destination_city\":\"London\",\"price\":\"799\",\"availability\":\"18\",\"no_of_tickets\":\"18\"}', 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", "Speak now...\n", - "You said: yes please please proceed\n", - "ChatCompletionMessage(content=None, refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_hlJhpoFCJ1g70ASa62SzCFYV', function=Function(arguments='{\"destination_city\":\"Berlin\",\"price\":\"450\",\"availability\":\"2\",\"no_of_tickets\":\"2\"}', name='book_ticket'), type='function')])\n", - "Tool get_ticket_price called for Berlin\n", - "Tool get_ticket_availability called for Berlin\n", + "You said: what is the current availability of tickets to London\n", "Speak now...\n", - "You said: no that will be fine now thank you\n" + "You said: that will be off thank you very much\n" ] } ],