Project Overview Creating a Chatbot for a Restaurant
This tutorial guides you in building a fast-food ordering chatbot named BurgerBot using OpenAI Chat API and HoloViz Panel in a Jupyter notebook.
In this tutorial, you’ll build a fast-food ordering chatbot—BurgerBot—using the OpenAI Chat API and HoloViz Panel within a Jupyter notebook. We’ll start by experiencing the end-user flow and then break down each implementation step: environment setup, API integration, instruction design, state management, and UI assembly.
Inside the notebook, Panel presents a simple chat interface. A typical conversation might look like this:
Copy
Ask AI
User: HelloAssistant: Hello there! Welcome to Burger Bliss. How can I assist you today?User: I want to order a chicken burger.Assistant: We have two options: Crispy Chicken Burger and BB Grilled Chicken Burger. Which one would you like?User: I’ll have the Spicy Crispy Chicken Burger.Assistant: Excellent choice! Anything else you’d like to add, like extra fries or a drink?User: Can I have extra fries please?Assistant: Of course! Would you like anything to drink? We have Coke, Fanta, Sprite, and Bottled Water.User: I am done.Assistant: Alright, that’s a Spicy Crispy Chicken Burger with extra fries. Pickup or delivery?User: It’s for pickup.Assistant: Great! When would you like to pick it up?User: In 10 minutes.Assistant: Perfect. Your order will be ready for pickup in 10 minutes. Thank you for choosing Burger Bliss!
Create a helper function to send messages to the Chat API and return the assistant’s reply:
Copy
Ask AI
def get_chat_completion(messages): """ Sends a list of messages to OpenAI’s ChatCompletion API and returns the assistant’s response text. """ response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages ) return response.choices[0].message.content
Define system-level instructions to guide BurgerBot’s behavior:
Copy
Ask AI
bot_instructions = """You are BurgerBot, an automated service to collect orders at Burger Bliss.1. Greet the customer.2. Gather the full order; summarize before confirmation.3. Ask for pickup or delivery (if delivery, request address).4. Confirm payment details.5. Clarify menu options with unique item identifiers."""
Initialize the conversation context and Panel widgets:
Copy
Ask AI
# Starting context with system instructionscontext = [{"role": "system", "content": bot_instructions}]# TextInput widget for user messagesuser_input = pn.widgets.TextInput( placeholder="Type your message here...", width=400)# List to hold UI panels for each messagepanels = []
Bind the message handler to a button and assemble the UI:
Copy
Ask AI
# Button to send messageschat_button = pn.widgets.Button(name="Send", button_type="primary")# Bind the function to the button clickinteractive_chat = pn.bind(collect_messages, chat_button)# Layout the dashboarddashboard = pn.Column( user_input, pn.Row(chat_button), pn.panel(interactive_chat, loading_indicator=True, height=300),)dashboard
Run this cell in your Jupyter notebook. Click Send after typing each message to interact with BurgerBot.