Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,28 +31,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT -----
|
| 32 |
class RetryOpenAIModel(OpenAIModel):
|
| 33 |
def generate(self, *args, **kwargs):
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
for attempt in range(max_attempts):
|
| 37 |
try:
|
| 38 |
return super().generate(*args, **kwargs)
|
| 39 |
|
| 40 |
-
except
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
if attempt == 3:
|
| 45 |
-
raise
|
| 46 |
-
|
| 47 |
-
wait_time = min(2 ** attempt, 8)
|
| 48 |
-
|
| 49 |
-
print(
|
| 50 |
-
f"[HTTP {e.status_code}] "
|
| 51 |
-
f"Attempt {attempt + 1}/4. "
|
| 52 |
-
f"Waiting {wait_time} seconds..."
|
| 53 |
-
)
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def get_task_file(file_name):
|
| 58 |
if not file_name:
|
|
@@ -142,6 +132,23 @@ def save_cache(path, data):
|
|
| 142 |
)
|
| 143 |
|
| 144 |
temp_path.replace(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
class BasicAgent:
|
| 147 |
def __init__(self):
|
|
@@ -365,7 +372,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 365 |
|
| 366 |
results_log = []
|
| 367 |
answers_payload = []
|
| 368 |
-
|
| 369 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 370 |
for item in questions_data:
|
| 371 |
task_id = item.get("task_id")
|
|
|
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT -----
|
| 32 |
class RetryOpenAIModel(OpenAIModel):
|
| 33 |
def generate(self, *args, **kwargs):
|
| 34 |
+
def generate(self, *args, **kwargs):
|
|
|
|
|
|
|
| 35 |
try:
|
| 36 |
return super().generate(*args, **kwargs)
|
| 37 |
|
| 38 |
+
except RateLimitError as e:
|
| 39 |
+
print("[429] Rate limit exceeded. Skipping current task.")
|
| 40 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
except InternalServerError as e:
|
| 43 |
+
if e.status_code == 503:
|
| 44 |
+
print("[503] Model unavailable. Skipping current task.")
|
| 45 |
+
raise
|
| 46 |
|
| 47 |
def get_task_file(file_name):
|
| 48 |
if not file_name:
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
temp_path.replace(path)
|
| 135 |
+
|
| 136 |
+
def is_daily_quota_error(error):
|
| 137 |
+
message = str(error).lower()
|
| 138 |
+
|
| 139 |
+
if "429" not in message and "rate_limit" not in message:
|
| 140 |
+
return False
|
| 141 |
+
|
| 142 |
+
daily_keywords = [
|
| 143 |
+
"tokens per day",
|
| 144 |
+
"requests per day",
|
| 145 |
+
"per_day",
|
| 146 |
+
"daily",
|
| 147 |
+
"tpd",
|
| 148 |
+
"rpd"
|
| 149 |
+
]
|
| 150 |
+
|
| 151 |
+
return any(keyword in message for keyword in daily_keywords)
|
| 152 |
|
| 153 |
class BasicAgent:
|
| 154 |
def __init__(self):
|
|
|
|
| 372 |
|
| 373 |
results_log = []
|
| 374 |
answers_payload = []
|
| 375 |
+
daily_quota_exhausted = False
|
| 376 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 377 |
for item in questions_data:
|
| 378 |
task_id = item.get("task_id")
|