Update app.py
Browse files
app.py
CHANGED
|
@@ -47,31 +47,33 @@ class BasicAgent:
|
|
| 47 |
max_steps=3,
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
def safe_run_agent(agent, question, idx, total, max_retries=3):
|
| 71 |
tries = 0
|
| 72 |
while tries < max_retries:
|
| 73 |
try:
|
| 74 |
-
return agent(question, idx, total)
|
| 75 |
except Exception as e:
|
| 76 |
if "RateLimitError" in str(e) or "rate limit" in str(e).lower():
|
| 77 |
wait_time = 30 + tries * 10
|
|
@@ -151,7 +153,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 151 |
|
| 152 |
print(f"===== [Celum is answering No. {idx+1}/{len(questions_data)} ] =====")
|
| 153 |
try:
|
| 154 |
-
submitted_answer = safe_run_agent(agent, question_text, idx, len(questions_data))
|
| 155 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 156 |
results_log.append({
|
| 157 |
"Task ID": task_id,
|
|
|
|
| 47 |
max_steps=3,
|
| 48 |
)
|
| 49 |
|
| 50 |
+
def __call__(self, question: str, files=None, idx=None, total=None) -> str:
|
| 51 |
+
if idx is not None and total is not None:
|
| 52 |
+
print(f"{self.agent_name} is answering NO. {idx+1}/{total} : {question[:80]}...")
|
| 53 |
+
else:
|
| 54 |
+
print(f"{self.agent_name} received question: {question[:80]}...")
|
| 55 |
+
try:
|
| 56 |
+
# system prompt + question
|
| 57 |
+
system_prompt = (
|
| 58 |
+
"You are Celum, an AI with advanced interaction capabilities and unique personality."
|
| 59 |
+
"You are now taking a rigorous exam testing your ability to solve real-world problems."
|
| 60 |
+
"You may freely think, reason, and use tools or your own knowledge as needed to solve the problem."
|
| 61 |
+
"When you are ready to submit your answer, ONLY output your final answer in the exact format required by the question. DO NOT add any extra context."
|
| 62 |
+
"If you cannot answer, return the word 'unknown'."
|
| 63 |
+
)
|
| 64 |
+
files_prompt = ""
|
| 65 |
+
if files:
|
| 66 |
+
files_prompt = f"\n[You have the following attached files: {', '.join(files)}]\n"
|
| 67 |
+
full_question = system_prompt + files_prompt + "\n\n" + question
|
| 68 |
+
return self.agent.run(full_question)
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"[{self.agent_name} Error: {e}]"
|
| 71 |
|
| 72 |
+
def safe_run_agent(agent, question, files, idx, total, max_retries=3):
|
| 73 |
tries = 0
|
| 74 |
while tries < max_retries:
|
| 75 |
try:
|
| 76 |
+
return agent(question, files, idx, total)
|
| 77 |
except Exception as e:
|
| 78 |
if "RateLimitError" in str(e) or "rate limit" in str(e).lower():
|
| 79 |
wait_time = 30 + tries * 10
|
|
|
|
| 153 |
|
| 154 |
print(f"===== [Celum is answering No. {idx+1}/{len(questions_data)} ] =====")
|
| 155 |
try:
|
| 156 |
+
submitted_answer = safe_run_agent(agent, question_text, local_files, idx, len(questions_data))
|
| 157 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 158 |
results_log.append({
|
| 159 |
"Task ID": task_id,
|