Files changed (1) hide show
  1. app.py +51 -5
app.py CHANGED
@@ -10,14 +10,60 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
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
  """
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
14
+
15
+ # ----- YOUR AGENT -----
16
  class BasicAgent:
17
  def __init__(self):
18
+ print("Initializing AI Agent...")
19
+
20
+ self.model = HfApiModel(
21
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
22
+ )
23
+
24
+ self.agent = CodeAgent(
25
+ tools=[
26
+ DuckDuckGoSearchTool()
27
+ ],
28
+ model=self.model,
29
+ max_steps=15,
30
+ additional_authorized_imports=[
31
+ "math",
32
+ "statistics",
33
+ "datetime",
34
+ "json",
35
+ ]
36
+ )
37
+
38
  def __call__(self, question: str) -> str:
39
+ try:
40
+ prompt = f"""
41
+ You are an expert AI assistant.
42
+
43
+ Answer the following question.
44
+
45
+ IMPORTANT RULES:
46
+ - Return ONLY the final answer.
47
+ - Do not explain.
48
+ - Do not include 'FINAL ANSWER'.
49
+ - If it is a number, return only the number.
50
+ - If it is a name, return only the name.
51
+ - Keep the response concise.
52
+
53
+ Question:
54
+ {question}
55
+ """
56
+
57
+ answer = self.agent.run(prompt)
58
+
59
+ if answer is None:
60
+ return ""
61
+
62
+ return str(answer).strip()
63
+
64
+ except Exception as e:
65
+ print(e)
66
+ return ""
67
 
68
  def run_and_submit_all( profile: gr.OAuthProfile | None):
69
  """