Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ litellm._turn_on_debug()
|
|
| 34 |
|
| 35 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 36 |
|
| 37 |
-
MODEL_ID = "gemini/gemini-2.5-flash" #"" "Qwen/Qwen2.5-Coder-32B-Instruct" #"groq/groq/compound-mini" #"meta-llama/llama-prompt-guard-2-22m"
|
| 38 |
|
| 39 |
MAX_STEPS = 6
|
| 40 |
MAX_TOKENS = 900
|
|
@@ -528,6 +528,18 @@ class ResearchAgentWrapper:
|
|
| 528 |
answer = self.agent.run(question)
|
| 529 |
print(f"Agent returning answer (first 50 chars): {str(answer)[:50]}...")
|
| 530 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
# Never let a non-answer leave the wrapper.
|
| 532 |
_check_is_real_answer(answer)
|
| 533 |
return str(answer).strip()
|
|
@@ -612,7 +624,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 612 |
# The /questions endpoint includes "file_name" only for tasks that have an
|
| 613 |
# attachment, so we know in advance whether a file is required.
|
| 614 |
expected_file = item.get("file_name")
|
| 615 |
-
attachment_path = download_attachment(api_url, task_id)
|
| 616 |
|
| 617 |
if expected_file and not attachment_path:
|
| 618 |
# The task needs a file but the server didn't give us one. Running the
|
|
@@ -627,6 +639,11 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 627 |
continue
|
| 628 |
|
| 629 |
agent_question = question_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
if attachment_path:
|
| 631 |
agent_question += (
|
| 632 |
f"\n\nAn attached file for this task (original name: "
|
|
|
|
| 34 |
|
| 35 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 36 |
|
| 37 |
+
MODEL_ID = "gemini/gemini-2.5-flash-lite" #"" "Qwen/Qwen2.5-Coder-32B-Instruct" #"groq/groq/compound-mini" #"meta-llama/llama-prompt-guard-2-22m"
|
| 38 |
|
| 39 |
MAX_STEPS = 6
|
| 40 |
MAX_TOKENS = 900
|
|
|
|
| 528 |
answer = self.agent.run(question)
|
| 529 |
print(f"Agent returning answer (first 50 chars): {str(answer)[:50]}...")
|
| 530 |
|
| 531 |
+
# smolagents catches LLM/provider failures at the final step and returns
|
| 532 |
+
# the error text AS the answer ("Error in generating final LLM output:
|
| 533 |
+
# litellm.RateLimitError ..."). Re-raise those as real exceptions so the
|
| 534 |
+
# backoff helper can retry rate limits or stop on daily quota exhaustion.
|
| 535 |
+
answer_text = str(answer or "")
|
| 536 |
+
lowered_answer = answer_text.lower()
|
| 537 |
+
if (
|
| 538 |
+
lowered_answer.startswith("error in generating")
|
| 539 |
+
or "litellm." in lowered_answer
|
| 540 |
+
):
|
| 541 |
+
raise RuntimeError(answer_text)
|
| 542 |
+
|
| 543 |
# Never let a non-answer leave the wrapper.
|
| 544 |
_check_is_real_answer(answer)
|
| 545 |
return str(answer).strip()
|
|
|
|
| 624 |
# The /questions endpoint includes "file_name" only for tasks that have an
|
| 625 |
# attachment, so we know in advance whether a file is required.
|
| 626 |
expected_file = item.get("file_name")
|
| 627 |
+
attachment_path = download_attachment(api_url, task_id, expected_file)
|
| 628 |
|
| 629 |
if expected_file and not attachment_path:
|
| 630 |
# The task needs a file but the server didn't give us one. Running the
|
|
|
|
| 639 |
continue
|
| 640 |
|
| 641 |
agent_question = question_text
|
| 642 |
+
agent_question += (
|
| 643 |
+
"\n\nIMPORTANT: your final answer must be ONLY the answer value "
|
| 644 |
+
"(a number, word, name or comma-separated list as the question asks), "
|
| 645 |
+
"with no explanation, no units unless requested, and no full sentences."
|
| 646 |
+
)
|
| 647 |
if attachment_path:
|
| 648 |
agent_question += (
|
| 649 |
f"\n\nAn attached file for this task (original name: "
|