Files changed (1) hide show
  1. app.py +49 -5
app.py CHANGED
@@ -10,14 +10,58 @@ 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 (
14
+ CodeAgent,
15
+ DuckDuckGoSearchTool,
16
+ InferenceClientModel
17
+ )
18
+
19
  class BasicAgent:
20
+
21
  def __init__(self):
22
+
23
+ print("Initializing Smart Agent...")
24
+
25
+ search_tool = DuckDuckGoSearchTool()
26
+
27
+ model = InferenceClientModel(
28
+ model_id="meta-llama/Llama-3.1-8B-Instruct"
29
+ )
30
+
31
+ self.agent = CodeAgent(
32
+ tools=[search_tool],
33
+ model=model,
34
+ add_base_tools=True,
35
+ max_steps=5
36
+ )
37
+
38
  def __call__(self, question: str) -> str:
39
+
40
+ prompt = f"""
41
+ Answer the question.
42
+
43
+ IMPORTANT:
44
+ - Return ONLY the final answer
45
+ - No explanation
46
+ - No extra text
47
+ - No FINAL ANSWER
48
+ - Keep answer short
49
+
50
+ Question:
51
+ {question}
52
+ """
53
+
54
+ try:
55
+
56
+ response = self.agent.run(prompt)
57
+
58
+ return str(response).strip()
59
+
60
+ except Exception as e:
61
+
62
+ print(e)
63
+
64
+ return "Error"
65
 
66
  def run_and_submit_all( profile: gr.OAuthProfile | None):
67
  """