Files changed (1) hide show
  1. app.py +50 -4
app.py CHANGED
@@ -4,6 +4,8 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -11,13 +13,57 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
 
 
 
 
 
14
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  print("BasicAgent initialized.")
 
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -193,4 +239,4 @@ if __name__ == "__main__":
193
  print("-"*(60 + len(" App Starting ")) + "\n")
194
 
195
  print("Launching Gradio Interface for Basic Agent Evaluation...")
196
- demo.launch(debug=True, share=False)
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from smolagents import CodeAgent, InferenceClientModel, WebSearchTool
8
+
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
+ """
17
+ A real agent built with smolagents.
18
+ Uses a free Hugging Face hosted model + a web search tool + the
19
+ built-in Python code execution that CodeAgent already provides.
20
+ """
21
  def __init__(self):
22
+ print("BasicAgent initializing...")
23
+
24
+ # Free model hosted by Hugging Face Inference Providers.
25
+ # No paid API key required - just needs the Space's default HF token.
26
+ self.model = InferenceClientModel(
27
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
28
+ )
29
+
30
+ self.agent = CodeAgent(
31
+ tools=[WebSearchTool()],
32
+ model=self.model,
33
+ add_base_tools=True, # adds python interpreter + a couple of extra default tools
34
+ max_steps=8,
35
+ )
36
+
37
  print("BasicAgent initialized.")
38
+
39
  def __call__(self, question: str) -> str:
40
  print(f"Agent received question (first 50 chars): {question[:50]}...")
41
+
42
+ # Strong instruction to keep answers in the exact-match format
43
+ # the GAIA benchmark expects: no "FINAL ANSWER" prefix, no extra
44
+ # explanation, just the bare answer.
45
+ instructions = (
46
+ "You are a general AI assistant answering a benchmark question. "
47
+ "Report your thoughts, then finish with the answer. "
48
+ "Your final output must be ONLY the answer itself: "
49
+ "no explanations, no extra words, no 'FINAL ANSWER' prefix. "
50
+ "If the answer is a number, write only the number (no units unless "
51
+ "explicitly requested). If it's a string, give the minimal exact phrase "
52
+ "requested, avoiding articles and abbreviations unless asked otherwise. "
53
+ "If it's a list, give a comma separated list following the same rules.\n\n"
54
+ f"Question: {question}"
55
+ )
56
+
57
+ try:
58
+ result = self.agent.run(instructions)
59
+ answer = str(result).strip()
60
+ except Exception as e:
61
+ print(f"Agent error while answering: {e}")
62
+ answer = "I don't know."
63
+
64
+ print(f"Agent returning answer: {answer}")
65
+ return answer
66
+
67
 
68
  def run_and_submit_all( profile: gr.OAuthProfile | None):
69
  """
 
239
  print("-"*(60 + len(" App Starting ")) + "\n")
240
 
241
  print("Launching Gradio Interface for Basic Agent Evaluation...")
242
+ demo.launch(debug=True, share=False, ssr_mode=False)