naman1102 commited on
Commit
7002459
·
1 Parent(s): 2757b9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -226,24 +226,46 @@ class BasicAgent:
226
  def __call__(self, question: str, task_id: str = "unknown") -> str:
227
  # Parse question to get both text and file_url
228
  try:
229
- question_data = json.loads(question)
230
- state: AgentState = {
231
- "question": question_data.get("question", ""),
232
- "current_step": "answer",
233
- "final_answer": "",
234
- "history": [],
235
- "needs_search": False,
236
- "search_query": "",
237
- "task_id": task_id,
238
- "logs": {},
239
- "file_url": question_data.get("file_url", ""),
240
- "code_blocks": question_data.get("code_blocks", [])
241
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  print(f"\nProcessing task {task_id}")
243
  print(f"Question: {state['question']}")
244
  print(f"File URL: {state['file_url']}")
 
 
 
245
  except (json.JSONDecodeError, KeyError) as e:
246
  print(f"Error parsing question data: {e}")
 
 
247
  state: AgentState = {
248
  "question": question,
249
  "current_step": "answer",
 
226
  def __call__(self, question: str, task_id: str = "unknown") -> str:
227
  # Parse question to get both text and file_url
228
  try:
229
+ # First try to parse as JSON
230
+ if isinstance(question, str) and question.strip().startswith('{'):
231
+ question_data = json.loads(question)
232
+ state: AgentState = {
233
+ "question": question_data.get("question", ""),
234
+ "current_step": "answer",
235
+ "final_answer": "",
236
+ "history": [],
237
+ "needs_search": False,
238
+ "search_query": "",
239
+ "task_id": task_id,
240
+ "logs": {},
241
+ "file_url": question_data.get("file_url", ""),
242
+ "code_blocks": question_data.get("code_blocks", [])
243
+ }
244
+ else:
245
+ # If not JSON, treat as plain text question
246
+ state: AgentState = {
247
+ "question": question,
248
+ "current_step": "answer",
249
+ "final_answer": "",
250
+ "history": [],
251
+ "needs_search": False,
252
+ "search_query": "",
253
+ "task_id": task_id,
254
+ "logs": {},
255
+ "file_url": "",
256
+ "code_blocks": []
257
+ }
258
+
259
  print(f"\nProcessing task {task_id}")
260
  print(f"Question: {state['question']}")
261
  print(f"File URL: {state['file_url']}")
262
+ if state['file_url']:
263
+ print(f"Raw question data: {question}")
264
+
265
  except (json.JSONDecodeError, KeyError) as e:
266
  print(f"Error parsing question data: {e}")
267
+ print(f"Raw question data: {question}")
268
+ # Fall back to treating as plain text
269
  state: AgentState = {
270
  "question": question,
271
  "current_step": "answer",