Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,24 +18,24 @@ with st.sidebar:
|
|
| 18 |
if not openai_api_key:
|
| 19 |
st.info("Please add your OpenAI API key to continue.")
|
| 20 |
st.stop()
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 18 |
if not openai_api_key:
|
| 19 |
st.info("Please add your OpenAI API key to continue.")
|
| 20 |
st.stop()
|
| 21 |
+
if prompt := st.chat_input("What is up?"):
|
| 22 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 23 |
+
with st.chat_message("user"):
|
| 24 |
+
st.markdown(prompt)
|
| 25 |
+
|
| 26 |
+
with st.chat_message("assistant"):
|
| 27 |
+
message_placeholder = st.empty()
|
| 28 |
+
full_response = ""
|
| 29 |
+
for response in openai.ChatCompletion.create(
|
| 30 |
+
model=st.session_state["openai_model"],
|
| 31 |
+
messages=[
|
| 32 |
+
{"role": m["role"], "content": m["content"]}
|
| 33 |
+
for m in st.session_state.messages
|
| 34 |
+
],
|
| 35 |
+
max_tokens=8000,
|
| 36 |
+
stream=True,
|
| 37 |
+
):
|
| 38 |
+
full_response += response.choices[0].delta.get("content", "")
|
| 39 |
+
message_placeholder.markdown(full_response + "▌")
|
| 40 |
+
message_placeholder.markdown(full_response)
|
| 41 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|