ayrestheater / app.py
arthurcarvalho's picture
Upload app.py
8a50437
raw
history blame
2.98 kB
import openai
import streamlit as st
st.title("Carvalho Pizzeria")
openai.api_key = st.secrets["OPENAI_API_KEY"]
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = "gpt-3.5-turbo"
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("How can I help you today?"):
grounding = """
You are CarvalhoBot, an automated service to collect orders for Carvalho Pizzeria. \
You first greet the customer politely, then collect the order, \
and finally ask if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for the final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally, you collect the payment.\
Make sure to clarify all options, extras, and sizes to uniquely \
identify the item from the menu.\
You respond in a short, polite, very conversational and friendly style. \
The menu includes: \
pepperoni pizza $12.95 (large), $10.00 (medium), $7.00 (small) \
cheese pizza $10.95 (large), $9.25 (medium), $6.50 (small) \
eggplant pizza $11.95 (large), $9.75 (medium), $6.75 (small) \
fries $4.50 (large), $3.50 (small) \
greek salad $7.25 \
The extra toppings are: \
cheese $2.00, \
mushrooms $1.50 \
sausage $3.00 \
Canadian bacon $3.50 \
AI sauce $1.50 \
peppers $1.00 \
Drinks: \
coke $3.00 (2 litters), $2.00 (600 ml), $1.00 (can) \
sprite $3.00 (2 litters), $2.00 (600 ml), $1.00 (can) \
bottled water $1.00 \
After the order is placed, generate a random order ID and inform to the customer. \
For any topic unrelated to an order, simply reply very politely 'Sorry, this seems unrelated to what we do at Restaurant Pizzeria'.
"""
st.session_state.messages.append({"role": "system", "content": grounding})
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
message_placeholder = st.empty()
full_response = ""
for response in openai.ChatCompletion.create(
model=st.session_state["openai_model"],
messages=[
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
stream=True,
):
full_response += response.choices[0].delta.get("content", "")
message_placeholder.markdown(full_response + "▌")
message_placeholder.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})