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 |
|
@@ -69,17 +70,18 @@ async def submit_answers(session: aiohttp.ClientSession, submit_url: str,
|
|
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 |
-
#
|
73 |
-
|
74 |
-
|
|
|
75 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
76 |
-
return {"task_id"
|
77 |
-
: 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) # Wait before retry
|
82 |
-
|
|
|
83 |
submitted_answer = await agent(question_text)
|
84 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
85 |
return {"task_id": task_id, "submitted_answer": submitted_answer}
|
|
|
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 |
|
|
|
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 |
try:
|
73 |
+
# Retry until a token is available
|
74 |
+
while not token_bucket.consume(1):
|
75 |
+
print(f"Rate limit reached for task {task_id}. Waiting to retry...")
|
76 |
+
await asyncio.sleep(60 / RATE_LIMIT) # Wait before submitted_answer = await agent(question_text)
|
77 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
78 |
+
return {"task_id": task_id, "submitted_answer": submitted_answer}
|
|
|
79 |
except aiohttp.ClientResponseError as e:
|
80 |
if e.status == 429:
|
81 |
print(f"Rate limit hit for task {task_id}. Retrying after delay...")
|
82 |
await asyncio.sleep(60 / RATE_LIMIT) # Wait before retry
|
83 |
+
while not token_bucket.consume(1):
|
84 |
+
await asyncio.sleep(60 / RATE_LIMIT)
|
85 |
submitted_answer = await agent(question_text)
|
86 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
87 |
return {"task_id": task_id, "submitted_answer": submitted_answer}
|