Duke-911 commited on
Commit
42874ea
·
1 Parent(s): 0ba39a4

Remove <think> tag from submitted answers in processing logic

Browse files
Files changed (2) hide show
  1. app.py +3 -0
  2. test.ipynb +18 -20
app.py CHANGED
@@ -107,6 +107,9 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
107
  prompt += f'\nHere is the attached file you might need to answer the question: files/{item.get("file_name", "")}'
108
  r = await agent.run(prompt)
109
  submitted_answer = r.response.blocks[0].text
 
 
 
110
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
111
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
112
  print(f"Successfully processed task ID: {task_id}, Question: {question_text}, Submitted Answer: {submitted_answer}")
 
107
  prompt += f'\nHere is the attached file you might need to answer the question: files/{item.get("file_name", "")}'
108
  r = await agent.run(prompt)
109
  submitted_answer = r.response.blocks[0].text
110
+ # Remove <think> tag and its contents if present in the submitted answer
111
+ if "</think>" in submitted_answer:
112
+ submitted_answer = submitted_answer.split("</think>")[-1].strip()
113
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
114
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
115
  print(f"Successfully processed task ID: {task_id}, Question: {question_text}, Submitted Answer: {submitted_answer}")
test.ipynb CHANGED
@@ -302,33 +302,31 @@
302
  },
303
  {
304
  "cell_type": "code",
305
- "execution_count": 14,
306
  "id": "ecc8d8be",
307
  "metadata": {},
308
  "outputs": [
309
  {
310
- "name": "stdout",
311
- "output_type": "stream",
312
- "text": [
313
- "You are a general AI assistant. I will ask you a question. Report your thoughts, and return\n",
314
- "your answer.\n",
315
- "\n",
316
- "YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of\n",
317
- "numbers and/or strings.\n",
318
- "If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent\n",
319
- "sign unless specified otherwise.\n",
320
- "If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in\n",
321
- "plain text unless specified otherwise.\n",
322
- "If you are asked for a comma separated list, apply the above rules depending of whether the element to be put\n",
323
- "in the list is a number or a string.\n",
324
- "\n",
325
- "Here is the question: \n",
326
- ".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI\n"
327
- ]
328
  }
329
  ],
330
  "source": [
331
- "print(prompt)"
 
 
 
 
 
 
 
 
332
  ]
333
  }
334
  ],
 
302
  },
303
  {
304
  "cell_type": "code",
305
+ "execution_count": 15,
306
  "id": "ecc8d8be",
307
  "metadata": {},
308
  "outputs": [
309
  {
310
+ "data": {
311
+ "text/plain": [
312
+ "'132,133,134,197,245'"
313
+ ]
314
+ },
315
+ "execution_count": 15,
316
+ "metadata": {},
317
+ "output_type": "execute_result"
 
 
 
 
 
 
 
 
 
 
318
  }
319
  ],
320
  "source": [
321
+ "submitted_answer = \"\"\"<think>\n",
322
+ "Okay, let me see. The user needs the page numbers from the audio recording for their Calculus mid-term. I used the audio_to_text tool to convert the MP3 file to text. The transcription mentions pages 245, 197, 132, 133, and 134. Now I need to list these in ascending order. Let me check the numbers again.\n",
323
+ "\n",
324
+ "Pages mentioned are 132, 133, 134, 197, and 245. Wait, the user wants them in ascending order. Let me sort them: 132, 133, 134, 197, 245. That's correct. The answer should be a comma-separated list without any extra text. Just the numbers in order. I need to make sure there are no duplicates and that each page is listed once. The user also wants them in ascending order, so I'll arrange them from smallest to largest. Yep, that's right. So the final answer is 132,133,134,197,245.\n",
325
+ "</think>\n",
326
+ "\n",
327
+ "132,133,134,197,245\"\"\"\n",
328
+ "\n",
329
+ "submitted_answer.split(\"</think>\")[-1].strip()"
330
  ]
331
  }
332
  ],