Files changed (1) hide show
  1. app.py +53 -5
app.py CHANGED
@@ -12,12 +12,60 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ print("Smart Agent initialized.")
16
+
17
+ # Model
18
+ self.model = HfApiModel(
19
+ model_id="mistralai/Mistral-7B-Instruct-v0.2"
20
+ )
21
+
22
+ # Agent with web search
23
+ self.agent = ToolCallingAgent(
24
+ tools=[DuckDuckGoSearchTool()],
25
+ model=self.model,
26
+ max_steps=8,
27
+ name="gaia_agent",
28
+ description="Answers questions using web search"
29
+ )
30
+
31
+ # STRICT PROMPT (VERY IMPORTANT)
32
+ self.agent.system_prompt = """
33
+ You are a strict QA agent.
34
+
35
+ Rules:
36
+ - Return ONLY the final answer
37
+ - No explanation
38
+ - No extra words
39
+ - If number β†’ only number
40
+ - If text β†’ only exact text
41
+ """
42
+
43
  def __call__(self, question: str) -> str:
44
+ print(f"Processing: {question[:50]}...")
45
+
46
+ # πŸ”₯ Quick math boost (easy points)
47
+ if any(op in question for op in ["+", "-", "*", "/"]):
48
+ try:
49
+ return str(eval(question))
50
+ except:
51
+ pass
52
+
53
+ try:
54
+ result = self.agent.run(question)
55
+ except:
56
+ return "unknown"
57
+
58
+ # πŸ”₯ CLEAN OUTPUT (CRITICAL FOR SCORE)
59
+ clean = str(result).strip()
60
+ clean = clean.replace("Final Answer:", "")
61
+ clean = clean.replace("Answer:", "")
62
+ clean = clean.split("\n")[0].strip()
63
+
64
+ if not clean:
65
+ clean = "unknown"
66
+
67
+ print(f"Final Answer: {clean}")
68
+ return clean
69
 
70
  def run_and_submit_all( profile: gr.OAuthProfile | None):
71
  """