Update app.py

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