Anne31415 commited on
Commit
97b6e08
·
1 Parent(s): 21957bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -111,35 +111,26 @@ def page1():
111
  st.session_state.chat_history.append(("User", question))
112
  process_question(question)
113
 
114
- # Modified function to process the question
115
  def process_question(question):
116
- # Add new message to the thread
117
- client.beta.threads.messages.create(
118
  thread_id=st.session_state.thread.id,
119
  role="user",
120
  content=question
121
  )
122
 
123
- # Create a new 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
- # Check if the run is completed and display the last assistant message
130
- if hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
131
- # Retrieve the list of messages
132
- st.session_state.messages = client.beta.threads.messages.list(
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: