Anne31415 commited on
Commit
5419e7e
·
1 Parent(s): f145236

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -115,22 +115,21 @@ def page1():
115
  def process_question(question):
116
  # Clear the previous run status
117
  st.session_state.run = None
118
- st.session_state.messages = []
119
 
120
-
121
  # Add message to the thread
122
  client.beta.threads.messages.create(
123
  thread_id=st.session_state.thread.id,
124
  role="user",
125
  content=question
126
  )
127
-
128
  # Create a new run to process the messages in the thread
129
  st.session_state.run = client.beta.threads.runs.create(
130
  thread_id=st.session_state.thread.id,
131
  assistant_id=st.session_state.assistant.id,
132
  )
133
-
134
  # Wait for the run to complete and then refresh the app
135
  while not hasattr(st.session_state.run, 'status') or st.session_state.run.status not in ["completed", "failed"]:
136
  time.sleep(1)
@@ -138,19 +137,18 @@ def page1():
138
  thread_id=st.session_state.thread.id,
139
  run_id=st.session_state.run.id,
140
  )
141
-
142
  if st.session_state.run.status == "completed":
143
  # Retrieve the list of messages
144
  st.session_state.messages = client.beta.threads.messages.list(
145
  thread_id=st.session_state.thread.id
146
  )
147
-
148
  # Display the latest message from the assistant
149
  last_assistant_message = next((message for message in reversed(st.session_state.messages.data) if message.role == "assistant"), None)
150
  if last_assistant_message:
151
  # Add assistant's response to chat history
152
  st.session_state.chat_history.append(("Assistant", last_assistant_message.content[0].text.value))
153
-
154
 
155
  # Example query buttons
156
  col3, col4 = st.columns(2) # Create two columns for buttons
@@ -182,6 +180,7 @@ def page1():
182
  metadata={'session_id': st.session_state.session_id}
183
  )
184
 
 
185
  # Check if the run is completed and display the last assistant message
186
  if hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
187
  # Retrieve the list of messages
 
115
  def process_question(question):
116
  # Clear the previous run status
117
  st.session_state.run = None
118
+ st.session_state.messages = []
119
 
 
120
  # Add message to the thread
121
  client.beta.threads.messages.create(
122
  thread_id=st.session_state.thread.id,
123
  role="user",
124
  content=question
125
  )
126
+
127
  # Create a new run to process the messages in the thread
128
  st.session_state.run = client.beta.threads.runs.create(
129
  thread_id=st.session_state.thread.id,
130
  assistant_id=st.session_state.assistant.id,
131
  )
132
+
133
  # Wait for the run to complete and then refresh the app
134
  while not hasattr(st.session_state.run, 'status') or st.session_state.run.status not in ["completed", "failed"]:
135
  time.sleep(1)
 
137
  thread_id=st.session_state.thread.id,
138
  run_id=st.session_state.run.id,
139
  )
140
+
141
  if st.session_state.run.status == "completed":
142
  # Retrieve the list of messages
143
  st.session_state.messages = client.beta.threads.messages.list(
144
  thread_id=st.session_state.thread.id
145
  )
146
+
147
  # Display the latest message from the assistant
148
  last_assistant_message = next((message for message in reversed(st.session_state.messages.data) if message.role == "assistant"), None)
149
  if last_assistant_message:
150
  # Add assistant's response to chat history
151
  st.session_state.chat_history.append(("Assistant", last_assistant_message.content[0].text.value))
 
152
 
153
  # Example query buttons
154
  col3, col4 = st.columns(2) # Create two columns for buttons
 
180
  metadata={'session_id': st.session_state.session_id}
181
  )
182
 
183
+
184
  # Check if the run is completed and display the last assistant message
185
  if hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
186
  # Retrieve the list of messages