AlexDGenu commited on
Commit
bd08449
·
1 Parent(s): 8e83fd8

Enhance SYSTEM_PROMPT in SmolAgent for clarity and accuracy, update model ID, and simplify response handling.

Browse files
Files changed (1) hide show
  1. app.py +15 -30
app.py CHANGED
@@ -10,20 +10,21 @@ from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
  SYSTEM_PROMPT = """
13
- You are an expert assistant answering questions for evaluation where answers are checked using exact string match.
14
 
15
- Rules:
16
  - Return ONLY the final answer on a single line.
17
- - Do NOT include reasoning or extra text.
18
- - If the answer is a number, return the plain number with no commas, no currency symbols, and no units unless explicitly required.
19
- - If the answer is a string, use lowercase, no articles, no abbreviations, and digits written in plain text unless specified.
20
- - If the answer is a comma-separated list, follow the above rules for each element, with no spaces after commas.
21
  - Do NOT write "Answer:" or "FINAL ANSWER:" before your response.
 
 
 
22
  - If unsure, guess concisely.
23
 
24
- Always strictly follow these instructions to ensure exact match.
25
  """
26
 
 
27
  # --- Smol Agent Definition ---
28
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
29
  class SmolAgent:
@@ -37,7 +38,7 @@ class SmolAgent:
37
 
38
  # 3. Initialize the SmolLM model
39
  model = InferenceClientModel(
40
- model_id="HuggingFaceTB/SmolLM-360M-Instruct",
41
  token=hf_token,
42
  )
43
 
@@ -50,30 +51,14 @@ class SmolAgent:
50
  print("SmolAgent initialized")
51
 
52
  def __call__(self, question: str) -> str:
53
- print(f"Agent received question (first 50 chars): {question[:50]}...")
54
  try:
55
- # The system prompt is already set, just pass the question.
56
- full_response = self._agent.run(question)
57
- print(f"Agent full response: {full_response}")
58
-
59
- # Parse the response to extract the final answer
60
- if "FINAL ANSWER:" in full_response:
61
- # Split and get the part after "FINAL ANSWER:"
62
- final_answer_part = full_response.split("FINAL ANSWER:")[1]
63
- # Remove brackets if they exist and strip whitespace
64
- final_answer = final_answer_part.strip()
65
- if final_answer.startswith('[') and final_answer.endswith(']'):
66
- final_answer = final_answer[1:-1]
67
-
68
- print(f"Agent returning parsed answer: {final_answer}")
69
- return final_answer
70
- else:
71
- print("Warning: 'FINAL ANSWER:' not found in response. Returning full response.")
72
- return full_response
73
-
74
  except Exception as e:
75
- print(f"Error running agent: {e}")
76
- return f"AGENT ERROR: {e}"
77
 
78
 
79
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
  SYSTEM_PROMPT = """
13
+ You are a helpful assistant answering evaluation questions that will be scored using exact string match.
14
 
15
+ Instructions:
16
  - Return ONLY the final answer on a single line.
17
+ - Do NOT include explanations or reasoning.
 
 
 
18
  - Do NOT write "Answer:" or "FINAL ANSWER:" before your response.
19
+ - If the answer is a number, return the plain number with no commas, currency symbols, or units unless explicitly required.
20
+ - If the answer is a string, use lowercase, no articles, no abbreviations, and digits in plain text unless specified otherwise.
21
+ - If the answer is a comma-separated list, follow the above rules for each element with no spaces after commas.
22
  - If unsure, guess concisely.
23
 
24
+ Always strictly follow these instructions to maximize exact match accuracy.
25
  """
26
 
27
+
28
  # --- Smol Agent Definition ---
29
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
30
  class SmolAgent:
 
38
 
39
  # 3. Initialize the SmolLM model
40
  model = InferenceClientModel(
41
+ model_id="HuggingFaceTB/SmolLM-1.7B-Instruct",
42
  token=hf_token,
43
  )
44
 
 
51
  print("SmolAgent initialized")
52
 
53
  def __call__(self, question: str) -> str:
54
+ print(f"\n🪐 Running on question:\n{question}\n")
55
  try:
56
+ answer = self._agent.run(prompt)
57
+ print(f"Agent returning answer: {answer}")
58
+ return str(answer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  except Exception as e:
60
+ print(f"Agent error: {e}")
61
+ return f"Agent error: {e}"
62
 
63
 
64
  def run_and_submit_all( profile: gr.OAuthProfile | None):