shgao commited on
Commit
495ce2c
·
1 Parent(s): 797b02f
Files changed (2) hide show
  1. app.py +0 -0
  2. utils.py +14 -12
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
utils.py CHANGED
@@ -178,15 +178,6 @@ def append_to_sheet(user_data=None, custom_row_dict=None, custom_sheet_name=None
178
  # Read headers from the first row of the sheet
179
  headers = sheet.row_values(1) if sheet.row_count > 0 else []
180
 
181
- # --- Check for new headers in custom_row_dict and add them if needed ---
182
- if custom_row_dict is not None:
183
- new_headers = [key for key in custom_row_dict.keys() if key not in headers]
184
- if new_headers:
185
- # Add new headers to the existing header row
186
- headers.extend(new_headers)
187
- # Update the first row in the sheet with the new headers
188
- sheet.update('1:1', [headers])
189
-
190
  # --- Build row aligned to headers ---
191
  if custom_row_dict is not None:
192
  # Ensure all values are aligned to headers, fill missing with ""
@@ -256,8 +247,7 @@ def format_chat(response, tool_database_labels):
256
 
257
  # Clear after rendering
258
  last_tool_calls = []
259
- # Post-process: replace [FinalAnswer] with "\n***Answer:**\n" in the last message's content if present
260
- # Insert "**Rasoning:**\n" at the beginning of the first assistant message if [FinalAnswer] is in the last assistant message
261
  if chat_history:
262
  last_msg = chat_history[-1]
263
  if isinstance(last_msg.content, str) and "[FinalAnswer]" in last_msg.content:
@@ -270,4 +260,16 @@ def format_chat(response, tool_database_labels):
270
  last_msg = chat_history[-1]
271
  if isinstance(last_msg.content, str) and "[FinalAnswer]" in last_msg.content:
272
  last_msg.content = last_msg.content.replace("[FinalAnswer]", "\n**Answer:**\n")
273
- return chat_history
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  # Read headers from the first row of the sheet
179
  headers = sheet.row_values(1) if sheet.row_count > 0 else []
180
 
 
 
 
 
 
 
 
 
 
181
  # --- Build row aligned to headers ---
182
  if custom_row_dict is not None:
183
  # Ensure all values are aligned to headers, fill missing with ""
 
247
 
248
  # Clear after rendering
249
  last_tool_calls = []
250
+
 
251
  if chat_history:
252
  last_msg = chat_history[-1]
253
  if isinstance(last_msg.content, str) and "[FinalAnswer]" in last_msg.content:
 
260
  last_msg = chat_history[-1]
261
  if isinstance(last_msg.content, str) and "[FinalAnswer]" in last_msg.content:
262
  last_msg.content = last_msg.content.replace("[FinalAnswer]", "\n**Answer:**\n")
263
+
264
+
265
+ final_answer_messages = [gr.ChatMessage(role="assistant", content=chat_history[-1].content.split("\n**Answer:**\n")[-1].strip())]
266
+ assistant_count = sum(1 for msg in chat_history if msg.role == "assistant")
267
+ if assistant_count == 1:
268
+ # If only one assistant message, show "No reasoning conducted."
269
+ reasoning_messages = [gr.ChatMessage(role="assistant", content="No reasoning was conducted.")]
270
+ else:
271
+ # Include ALL messages in reasoning_messages, including the last one
272
+ reasoning_messages = chat_history.copy()
273
+
274
+
275
+ return final_answer_messages, reasoning_messages, chat_history