Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
| 68 |
task_id = item.get("task_id")
|
| 69 |
question_text = item.get("question")
|
| 70 |
-
if not task_id or
|
| 71 |
-
print(f"Skipping
|
| 72 |
-
|
| 73 |
-
|
| 74 |
try:
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 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 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 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")
|