Spaces:
Sleeping
Sleeping
samlonka
commited on
Commit
•
7d84684
1
Parent(s):
d21f567
'memory'
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
st.set_page_config(
|
3 |
page_title="SVARUPA AI",
|
4 |
layout="centered", # or "wide"
|
@@ -154,12 +155,21 @@ for message in st.session_state.messages:
|
|
154 |
with st.chat_message(message["role"]):
|
155 |
st.write(message["content"])
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
with st.
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import openai
|
3 |
st.set_page_config(
|
4 |
page_title="SVARUPA AI",
|
5 |
layout="centered", # or "wide"
|
|
|
155 |
with st.chat_message(message["role"]):
|
156 |
st.write(message["content"])
|
157 |
|
158 |
+
try:
|
159 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
160 |
+
with st.chat_message("assistant"):
|
161 |
+
with st.spinner("Thinking..."):
|
162 |
+
# Using the cached chat_engine
|
163 |
+
response = st.session_state.chat_engine.chat(prompt)
|
164 |
+
st.write(response.response)
|
165 |
+
message = {"role": "assistant", "content": response.response}
|
166 |
+
st.session_state.messages.append(message)
|
167 |
+
|
168 |
+
except openai.error.RateLimitError as e:
|
169 |
+
# Handle the RateLimitError
|
170 |
+
st.error(f"RateLimitError: {e}")
|
171 |
+
st.error("You have exceeded your API quota. Please check your plan and billing details.")
|
172 |
+
st.error("For more information, read the OpenAI documentation: https://platform.openai.com/docs/guides/error-codes/api-errors.")
|
173 |
+
except Exception as e:
|
174 |
+
# Handle other exceptions if needed
|
175 |
+
st.error(f"An unexpected error occurred: {e}")
|