Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,18 +31,29 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
print("[429] Rate limit exceeded. Skipping current task.")
|
| 40 |
-
raise
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def get_task_file(file_name):
|
| 48 |
if not file_name:
|
|
@@ -311,7 +322,10 @@ class BasicAgent:
|
|
| 311 |
return answer
|
| 312 |
|
| 313 |
except Exception as e:
|
|
|
|
|
|
|
| 314 |
print(f"Agent error: {e}")
|
|
|
|
| 315 |
raise
|
| 316 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 317 |
"""
|
|
|
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT -----
|
| 32 |
class RetryOpenAIModel(OpenAIModel):
|
| 33 |
def generate(self, *args, **kwargs):
|
| 34 |
+
try:
|
| 35 |
+
response = super().generate(*args, **kwargs)
|
| 36 |
+
|
| 37 |
+
if response is None:
|
| 38 |
+
raise ValueError("LLM returned None")
|
| 39 |
+
|
| 40 |
+
if (
|
| 41 |
+
response.content is None
|
| 42 |
+
and not response.tool_calls
|
| 43 |
+
):
|
| 44 |
+
raise ValueError(
|
| 45 |
+
"LLM returned no content and no tool calls"
|
| 46 |
+
)
|
| 47 |
|
| 48 |
+
return response
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
except RateLimitError:
|
| 51 |
+
print("[429] Rate limit reached. No retry.")
|
| 52 |
+
raise
|
| 53 |
+
|
| 54 |
+
except InternalServerError as e:
|
| 55 |
+
print(f"[HTTP {e.status_code}] Model unavailable.")
|
| 56 |
+
raise
|
| 57 |
|
| 58 |
def get_task_file(file_name):
|
| 59 |
if not file_name:
|
|
|
|
| 322 |
return answer
|
| 323 |
|
| 324 |
except Exception as e:
|
| 325 |
+
import traceback
|
| 326 |
+
|
| 327 |
print(f"Agent error: {e}")
|
| 328 |
+
traceback.print_exc()
|
| 329 |
raise
|
| 330 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 331 |
"""
|