arthurcarvalho commited on
Commit
c77bdbe
1 Parent(s): 3b6250f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +70 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import streamlit as st
3
+
4
+ st.title("Carvalho Pizzeria")
5
+
6
+ openai.api_key = st.secrets["OPENAI_API_KEY"]
7
+
8
+ grounding = """
9
+ You are CarvalhoBot, an automated service to collect orders for Carvalho Pizzeria. \
10
+ You first greet the customer, then collect the order, \
11
+ and then ask if it's a pickup or delivery. \
12
+ You wait to collect the entire order, then summarize it and check for a final \
13
+ time if the customer wants to add anything else. \
14
+ If it's a delivery, you ask for an address. \
15
+ Finally, you collect the payment.\
16
+ Make sure to clarify all options, extras, and sizes to uniquely \
17
+ identify the item from the menu.\
18
+ You respond in a short, very conversational friendly style. \
19
+ The menu includes \
20
+ pepperoni pizza 12.95, 10.00, 7.00 \
21
+ cheese pizza 10.95, 9.25, 6.50 \
22
+ eggplant pizza 11.95, 9.75, 6.75 \
23
+ fries 4.50, 3.50 \
24
+ greek salad 7.25 \
25
+ Toppings: \
26
+ extra cheese 2.00, \
27
+ mushrooms 1.50 \
28
+ sausage 3.00 \
29
+ Canadian bacon 3.50 \
30
+ AI sauce 1.50 \
31
+ peppers 1.00 \
32
+ Drinks: \
33
+ coke 3.00, 2.00, 1.00 \
34
+ sprite 3.00, 2.00, 1.00 \
35
+ bottled water 5.00 \
36
+ After the order is placed, generate a random order ID and inform to the customer. \
37
+ For any topic unrelated to an order, simply reply, Sorry, this seems unrelated to what we do at Restaurant Pizzeria.
38
+ """
39
+
40
+ if "openai_model" not in st.session_state:
41
+ st.session_state["openai_model"] = "gpt-3.5-turbo"
42
+
43
+ if "messages" not in st.session_state:
44
+ st.session_state.messages = []
45
+
46
+ for message in st.session_state.messages:
47
+ with st.chat_message(message["role"]):
48
+ st.markdown(message["content"])
49
+
50
+ if prompt := st.chat_input("How can I help you today?"):
51
+ st.session_state.messages.append({"role": "system", "content": grounding})
52
+ st.session_state.messages.append({"role": "user", "content": prompt})
53
+ with st.chat_message("user"):
54
+ st.markdown(prompt)
55
+
56
+ with st.chat_message("assistant"):
57
+ message_placeholder = st.empty()
58
+ full_response = ""
59
+ for response in openai.ChatCompletion.create(
60
+ model=st.session_state["openai_model"],
61
+ messages=[
62
+ {"role": m["role"], "content": m["content"]}
63
+ for m in st.session_state.messages
64
+ ],
65
+ stream=True,
66
+ ):
67
+ full_response += response.choices[0].delta.get("content", "")
68
+ message_placeholder.markdown(full_response + "▌")
69
+ message_placeholder.markdown(full_response)
70
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai==0.27.9