Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,8 @@ async def fetch_questions(session: aiohttp.ClientSession, questions_url: str) ->
|
|
45 |
except aiohttp.ClientError as e:
|
46 |
print(f"Error fetching questions: {e}")
|
47 |
return None
|
48 |
-
except
|
|
|
49 |
print(f"An unexpected error occurred fetching questions: {e}")
|
50 |
return None
|
51 |
|
@@ -68,27 +69,36 @@ async def submit_answers(session: aiohttp.ClientSession, submit_url: str,
|
|
68 |
|
69 |
async def process_question(agent, question_text: str, task_id: str, results_log: list):
|
70 |
"""Process a single question with global rate limiting."""
|
|
|
71 |
try:
|
72 |
# Retry until a token is available
|
73 |
while not token_bucket.consume(1):
|
74 |
print(f"Rate limit reached for task {task_id}. Waiting to retry...")
|
75 |
-
await asyncio.sleep(60 / RATE_LIMIT)
|
|
|
76 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
77 |
return {"task_id": task_id, "submitted_answer": submitted_answer}
|
78 |
except aiohttp.ClientResponseError as e:
|
79 |
if e.status == 429:
|
80 |
print(f"Rate limit hit for task {task_id}. Retrying after delay...")
|
81 |
-
await asyncio.sleep(60 / RATE_LIMIT)
|
82 |
while not token_bucket.consume(1):
|
83 |
await asyncio.sleep(60 / RATE_LIMIT)
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
else:
|
88 |
-
|
|
|
|
|
89 |
except Exception as e:
|
90 |
-
|
91 |
-
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer":
|
92 |
return None
|
93 |
|
94 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
45 |
except aiohttp.ClientError as e:
|
46 |
print(f"Error fetching questions: {e}")
|
47 |
return None
|
48 |
+
except
|
49 |
+
Exception as e:
|
50 |
print(f"An unexpected error occurred fetching questions: {e}")
|
51 |
return None
|
52 |
|
|
|
69 |
|
70 |
async def process_question(agent, question_text: str, task_id: str, results_log: list):
|
71 |
"""Process a single question with global rate limiting."""
|
72 |
+
submitted_answer = None
|
73 |
try:
|
74 |
# Retry until a token is available
|
75 |
while not token_bucket.consume(1):
|
76 |
print(f"Rate limit reached for task {task_id}. Waiting to retry...")
|
77 |
+
await asyncio.sleep(60 / RATE_LIMIT)
|
78 |
+
submitted_answer = await agent(question_text)
|
79 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
80 |
return {"task_id": task_id, "submitted_answer": submitted_answer}
|
81 |
except aiohttp.ClientResponseError as e:
|
82 |
if e.status == 429:
|
83 |
print(f"Rate limit hit for task {task_id}. Retrying after delay...")
|
84 |
+
await asyncio.sleep(60 / RATE_LIMIT)
|
85 |
while not token_bucket.consume(1):
|
86 |
await asyncio.sleep(60 / RATE_LIMIT)
|
87 |
+
try:
|
88 |
+
submitted_answer = await agent(question_text)
|
89 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
90 |
+
return {"task_id": task_id, "submitted_answer": submitted_answer}
|
91 |
+
except Exception as retry_e:
|
92 |
+
submitted_answer = f"AGENT ERROR: {retry_e}"
|
93 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
94 |
+
return None
|
95 |
else:
|
96 |
+
submitted_answer = f"AGENT ERROR: {e}"
|
97 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
98 |
+
return None
|
99 |
except Exception as e:
|
100 |
+
submitted_answer = f"AGENT ERROR: {e}"
|
101 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
102 |
return None
|
103 |
|
104 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|