dawid-lorek commited on
Commit
ae84e8b
·
verified ·
1 Parent(s): eab1747

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +11 -2
agent.py CHANGED
@@ -12,7 +12,16 @@ class GaiaAgent:
12
  self.api_url = "https://agents-course-unit4-scoring.hf.space"
13
 
14
  def clean(self, text):
15
- return text.strip().replace("Final Answer:", "").replace("\n", "").replace(".", "").strip()
 
 
 
 
 
 
 
 
 
16
 
17
  def fetch_file(self, task_id):
18
  try:
@@ -26,7 +35,7 @@ class GaiaAgent:
26
  res = self.client.chat.completions.create(
27
  model=model,
28
  messages=[
29
- {"role": "system", "content": "You are a precise assistant. Think step by step and return only the final answer in the correct format."},
30
  {"role": "user", "content": prompt + "\n\nFinal Answer:"}
31
  ],
32
  temperature=0.0,
 
12
  self.api_url = "https://agents-course-unit4-scoring.hf.space"
13
 
14
  def clean(self, text):
15
+ text = text.strip()
16
+ text = re.sub(r"Final Answer:\s*", "", text, flags=re.IGNORECASE)
17
+ text = re.sub(r"(?i)(the answer is|best move is|response is|it is|this is|answer:)\s*", "", text)
18
+ text = re.sub(r"\s*\(.*?\)", "", text) # remove comments in brackets
19
+ text = re.sub(r"^\W+|\W+$", "", text) # remove leading/trailing punctuation
20
+ lines = text.splitlines()
21
+ text = lines[0] if lines else text
22
+ # Handle numeric extraction if mixed in text
23
+ match = re.match(r"^.*?(\$?\d+(\.\d{1,2})?).*", text)
24
+ return match.group(1).strip() if match else text.strip()
25
 
26
  def fetch_file(self, task_id):
27
  try:
 
35
  res = self.client.chat.completions.create(
36
  model=model,
37
  messages=[
38
+ {"role": "system", "content": "You are a precise assistant. Think step by step and return only the final answer in the correct format. Avoid any explanation."},
39
  {"role": "user", "content": prompt + "\n\nFinal Answer:"}
40
  ],
41
  temperature=0.0,