-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoodbot.py
195 lines (146 loc) · 6.25 KB
/
foodbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import streamlit as st
from openai import OpenAI
import os
# Set your OpenAI API key here
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") # Replace with your actual API key
# System prompt defining the restaurant assistant persona
SYSTEM_PROMPT = """You are a friendly and knowledgeable restaurant assistant named Luke for "Rogers Food Place ',
an fastfood restaurant. Your characteristics include:
- Warm and welcoming personality
- Expert knowledge of Fast Food Menu
- Ability to handle reservations, menu inquiries, and special requests
- Knowledge of all dishes, ingredients, and preparation methods
- Can accommodate dietary restrictions and allergies
- Familiar with the restaurant's ambiance (elegant but not stuffy)
- Operating hours: Tuesday-Sunday, 5 PM - 10 PM
- Location: Benaulim Goa
Always maintain a professional yet warm tone, and be proactive in making suggestions.
If asked about reservations, recommend calling the restaurant directly at (91) 123-4567118.
For specific dates/times, always mention that availability needs to be confirmed with the restaurant.
after greeting the customer ask him what he wants from the menu by provides names of the categories . after he chooses a category give him suboptions . after he orders something try to upsell something else just once .
MENU:
BURGERS (All served with fries):
- Classic Cheeseburger ($12) - 1/3 lb beef patty, cheddar, lettuce, tomato, onion, pickles, house sauce
- Bacon Supreme ($14) - 1/3 lb beef patty, bacon, american cheese, caramelized onions, BBQ sauce
- Mushroom Swiss ($13) - 1/3 lb beef patty, sautéed mushrooms, swiss cheese, garlic aioli
- Double Trouble ($16) - Two 1/3 lb patties, double cheese, all the fixings
- Veggie Delight ($13) - Plant-based patty, avocado, sprouts, tomato, special sauce
CHICKEN:
- Classic Crispy Tenders (3pc $8 / 5pc $12 / 8pc $16)
- Nashville Hot Chicken Sandwich ($13) - Spicy crispy chicken, coleslaw, pickles
- Grilled Chicken Sandwich ($12) - Marinated chicken breast, lettuce, tomato, honey mustard
- Wings (6pc $10 / 12pc $18 / 20pc $28)
* Sauces: Buffalo, BBQ, Honey Garlic, Lemon Pepper, Extra Hot
SIDES:
- Classic Fries ($4)
- Sweet Potato Fries ($5)
- Onion Rings ($5)
- Mac & Cheese ($6)
- Coleslaw ($3)
- Side Salad ($4)
BEVERAGES:
- Soft Drinks ($3)
- Milkshakes ($6) - Vanilla, Chocolate, Strawberry
- Craft Beer ($6)
- Iced Tea ($3)
COMBOS:
- Burger Combo: Any burger + drink ($3 off)
- Tender Combo: 5pc tenders + fries + drink ($15)
- Family Pack: 2 burgers + 8pc tenders + 2 large fries + 4 drinks ($45)
after customers says he is done, provide a proper bill to him with all the items with their prices and grand total and request him to make the payment. Dont provide bill at intermediate stages .
provide only when the entire order is complete. just mention the final order and the total and bill once dont repeat or summarise it .
Final bill example:
* Classic Cheeseburger Combo: $9
* Soft Drink: $3
* Classic Fries: $4
* Total: $16.
"""
def init_session_state():
"""Initialize session state variables"""
if 'messages' not in st.session_state:
st.session_state.messages = []
# Add the system prompt to the messages
st.session_state.messages.append({
"role": "system",
"content": SYSTEM_PROMPT
})
def create_ui():
"""Create the main chat interface"""
st.title("Roger's Food Place")
st.markdown("##### Welcome to Rogers Food Place")
# Custom CSS for better appearance
st.markdown("""
<style>
.css-1kg1jn1 {padding-top: 0px;}
.css-18e3th9 {padding-top: 0px;}
.css-1d391kg {padding-top: 0px;}
.stTitle {
color: #4A4A4A;
font-family: 'Playfair Display', serif;
}
</style>
""", unsafe_allow_html=True)
# Initialize chat with a welcome message
if len(st.session_state.messages) == 1: # Only system prompt exists
st.session_state.messages.append({
"role": "assistant",
"content": "Hi! I'm luke, your host at Rogers Food Place. How may I assist you today? Whether you're interested in our menu, specials, or would like to know about reservations, I'm here to help!"
})
# Display chat messages (skip system prompt)
for message in st.session_state.messages[1:]: # Skip the first message (system prompt)
with st.chat_message(message["role"]):
st.write(message["content"])
def get_openai_response(messages):
"""Get response from OpenAI API"""
client = OpenAI()
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": m["role"], "content": m["content"]}
for m in messages
],
temperature=0,
max_tokens=500
)
return response.choices[0].message.content
except Exception as e:
return f"Mi dispiace! An error occurred: {str(e)}"
def main():
# Set page config
st.set_page_config(
page_title="Rogers Food Place ",
page_icon="🍝",
layout="centered"
)
# Initialize session state
init_session_state()
# Create UI
create_ui()
# Add sidebar with clear chat button
with st.sidebar:
st.title("Options")
if st.button("Start New Conversation"):
st.session_state.messages = [
{"role": "system", "content": SYSTEM_PROMPT}
]
st.rerun()
# Get user input
if prompt := st.chat_input("Ask about our menu, reservations, or specials..."):
# Add user message to chat
st.session_state.messages.append({"role": "user", "content": prompt})
# Display user message
with st.chat_message("user"):
st.write(prompt)
# Get and display assistant response
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response = get_openai_response(st.session_state.messages)
st.write(response)
# Add assistant response to chat history
st.session_state.messages.append({
"role": "assistant",
"content": response
})
if __name__ == "__main__":
main()