Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,35 +111,26 @@ def page1():
|
|
| 111 |
st.session_state.chat_history.append(("User", question))
|
| 112 |
process_question(question)
|
| 113 |
|
| 114 |
-
|
| 115 |
def process_question(question):
|
| 116 |
-
# Add
|
| 117 |
-
client.beta.threads.messages.create(
|
| 118 |
thread_id=st.session_state.thread.id,
|
| 119 |
role="user",
|
| 120 |
content=question
|
| 121 |
)
|
| 122 |
|
| 123 |
-
#
|
| 124 |
st.session_state.run = client.beta.threads.runs.create(
|
| 125 |
thread_id=st.session_state.thread.id,
|
| 126 |
assistant_id=st.session_state.assistant.id,
|
| 127 |
)
|
| 128 |
|
| 129 |
-
#
|
| 130 |
-
if
|
| 131 |
-
#
|
| 132 |
-
st.
|
| 133 |
-
thread_id=st.session_state.thread.id
|
| 134 |
-
)
|
| 135 |
-
|
| 136 |
-
# Find the last assistant message
|
| 137 |
-
last_assistant_message = next((message for message in reversed(st.session_state.messages.data) if message.role == "assistant"), None)
|
| 138 |
-
if last_assistant_message:
|
| 139 |
-
# Add assistant's response to chat history
|
| 140 |
-
st.session_state.chat_history.append(("Assistant", last_assistant_message.content[0].text.value))
|
| 141 |
|
| 142 |
-
# [Rest of your existing code in page1 remains unchanged]
|
| 143 |
|
| 144 |
# Display chat history in Streamlit chat format
|
| 145 |
for role, message in st.session_state.chat_history:
|
|
|
|
| 111 |
st.session_state.chat_history.append(("User", question))
|
| 112 |
process_question(question)
|
| 113 |
|
| 114 |
+
# Function to process the question
|
| 115 |
def process_question(question):
|
| 116 |
+
# Add message to the thread
|
| 117 |
+
st.session_state.messages = client.beta.threads.messages.create(
|
| 118 |
thread_id=st.session_state.thread.id,
|
| 119 |
role="user",
|
| 120 |
content=question
|
| 121 |
)
|
| 122 |
|
| 123 |
+
# Do a run to process the messages in the thread
|
| 124 |
st.session_state.run = client.beta.threads.runs.create(
|
| 125 |
thread_id=st.session_state.thread.id,
|
| 126 |
assistant_id=st.session_state.assistant.id,
|
| 127 |
)
|
| 128 |
|
| 129 |
+
# Wait and rerun logic
|
| 130 |
+
if st.session_state.retry_error < 3:
|
| 131 |
+
time.sleep(1) # Wait 1 second before checking run status
|
| 132 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
|
|
|
| 134 |
|
| 135 |
# Display chat history in Streamlit chat format
|
| 136 |
for role, message in st.session_state.chat_history:
|