cowrycode commited on
Commit
3220cd6
·
verified ·
1 Parent(s): 8cda6ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -64,35 +64,26 @@ async def smart_agent(questions_data: List[Dict[str, Any]]) -> List[Dict[str, An
64
  llm=llm,
65
  )
66
 
67
- async def process_question(item):
 
 
68
  task_id = item.get("task_id")
69
  question_text = item.get("question")
70
- if not task_id or not question_text:
71
- print(f"Skipping invalid item: {item}")
72
- return {"task_id": task_id, "submitted_answer": "Invalid question."}
73
-
74
  try:
75
- # Retry up to 3 times if connection closes
76
- response = await llamaindex_agent.run(question_text)
77
- print(f"Answered Task {task_id}: {response[:50]}...")
78
- return {"task_id": task_id, "submitted_answer": response}
79
- # for attempt in range(3):
80
- # try:
81
- # response = await llamaindex_agent.run(question_text)
82
- # print(f"Answered Task {task_id}: {response[:50]}...")
83
- # return {"task_id": task_id, "submitted_answer": response}
84
- # except Exception as e:
85
- # if "client has been closed" in str(e) and attempt < 2:
86
- # print(f"Retrying task {task_id} (attempt {attempt + 2})...")
87
- # continue
88
- # raise e
89
  except Exception as e:
90
- print(f"Error on Task {task_id}: {e}")
91
- return {"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"}
92
 
93
- #tasks = [process_question(item) for item in questions_data]
94
- answers_payload = process_question(questions_data[0])
95
- #answers_payload = await asyncio.gather(*tasks)
 
96
 
97
  print("✅ All tasks completed.")
98
  return answers_payload
@@ -149,7 +140,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
149
 
150
  # 3. Run your Agent
151
  results_log = []
152
- answers_payload = []
153
  print(f"Running agent on {len(questions_data)} questions...")
154
  # for item in questions_data:
155
  # task_id = item.get("task_id")
 
64
  llm=llm,
65
  )
66
 
67
+ answers_payload = []
68
+
69
+ for item in questions_data:
70
  task_id = item.get("task_id")
71
  question_text = item.get("question")
72
+ if not task_id or question_text is None:
73
+ print(f"Skipping item with missing task_id or question: {item}")
74
+ continue
 
75
  try:
76
+ submitted_answer = await llamaindex_agent(question_text)
77
+ answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
78
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
 
 
 
 
 
 
 
 
 
 
79
  except Exception as e:
80
+ print(f"Error running agent on task {task_id}: {e}")
81
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
82
 
83
+ if not answers_payload:
84
+ print("Agent did not produce any answers to submit.")
85
+ return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
86
+
87
 
88
  print("✅ All tasks completed.")
89
  return answers_payload
 
140
 
141
  # 3. Run your Agent
142
  results_log = []
143
+ #answers_payload = []
144
  print(f"Running agent on {len(questions_data)} questions...")
145
  # for item in questions_data:
146
  # task_id = item.get("task_id")