Spaces:
Runtime error
Runtime error
added option to append message
Browse files
app.py
CHANGED
@@ -89,6 +89,8 @@ with st.sidebar:
|
|
89 |
else:
|
90 |
st.write("No cost incurred yet")
|
91 |
|
|
|
|
|
92 |
|
93 |
for message in st.session_state.messages:
|
94 |
with st.chat_message(message["role"]):
|
@@ -141,21 +143,22 @@ if prompt := st.chat_input("Type a message", key="chat_input"):
|
|
141 |
with cols[i]:
|
142 |
st.image(image)
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
89 |
else:
|
90 |
st.write("No cost incurred yet")
|
91 |
|
92 |
+
append = st.checkbox("Append to previous message", value=False)
|
93 |
+
|
94 |
|
95 |
for message in st.session_state.messages:
|
96 |
with st.chat_message(message["role"]):
|
|
|
143 |
with cols[i]:
|
144 |
st.image(image)
|
145 |
|
146 |
+
if not append:
|
147 |
+
with st.chat_message("assistant"):
|
148 |
+
messages = [
|
149 |
+
{"role": m["role"], "content": m["content"]}
|
150 |
+
for m in st.session_state.messages
|
151 |
+
]
|
152 |
+
stream = client.chat.completions.create(
|
153 |
+
model="gpt-4-vision-preview",
|
154 |
+
messages=messages,
|
155 |
+
stream=True,
|
156 |
+
seed=random_seed,
|
157 |
+
temperature=temperature,
|
158 |
+
max_tokens=max_tokens,
|
159 |
+
)
|
160 |
+
response = st.write_stream(stream)
|
161 |
+
|
162 |
+
push_message("assistant", response)
|
163 |
+
calculate_cost()
|
164 |
+
clear_uploader()
|
utils.py
CHANGED
@@ -52,9 +52,11 @@ def clear_uploader():
|
|
52 |
|
53 |
def undo():
|
54 |
if len(st.session_state.messages) > 0:
|
55 |
-
st.
|
56 |
-
st.session_state.messages.pop()
|
57 |
-
|
|
|
|
|
58 |
st.rerun()
|
59 |
|
60 |
def restart():
|
|
|
52 |
|
53 |
def undo():
|
54 |
if len(st.session_state.messages) > 0:
|
55 |
+
st.query_params.clear()
|
56 |
+
msg = st.session_state.messages.pop()
|
57 |
+
if msg["role"] == "assistant":
|
58 |
+
st.session_state.cost.pop()
|
59 |
+
time.sleep(0.1)
|
60 |
st.rerun()
|
61 |
|
62 |
def restart():
|