jjunqueras commited on
Commit
7309e15
·
verified ·
1 Parent(s): 81917a3

Update agent

Browse files
Files changed (1) hide show
  1. app.py +34 -5
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"
@@ -12,12 +14,39 @@ 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
  """
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from smolagents import CodeAgent, InferenceClientModel
8
+
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
17
+ print("Initializing smolagents CodeAgent...")
18
+
19
+ self.agent = CodeAgent(
20
+ tools=[],
21
+ model=InferenceClientModel(),
22
+ )
23
+
24
+ self.system_suffix = """
25
+ You are answering benchmark questions.
26
+ Return only the final answer.
27
+ Do not add explanations.
28
+ Do not add the words FINAL ANSWER.
29
+ If the answer is a number, return only the number.
30
+ If the answer is a short phrase, return only that short phrase.
31
+ """.strip()
32
+
33
  def __call__(self, question: str) -> str:
34
+ print(f"Agent received question (first 80 chars): {question[:80]}...")
35
+
36
+ prompt = f"{question}\n\n{self.system_suffix}"
37
+
38
+ response = self.agent.run(prompt)
39
+
40
+ if response is None:
41
+ return ""
42
+
43
+ answer = str(response).strip()
44
+
45
+ # Very light cleanup for exact-match friendliness
46
+ if answer.startswith("FINAL ANSWER:"):
47
+ answer = answer[len("FINAL ANSWER:"):].strip()
48
+
49
+ return answer
50
 
51
  def run_and_submit_all( profile: gr.OAuthProfile | None):
52
  """