Sborole commited on
Commit
745281b
·
verified ·
1 Parent(s): af177ff

Update tools/FinalAnswerTool.py

Browse files
Files changed (1) hide show
  1. tools/FinalAnswerTool.py +12 -9
tools/FinalAnswerTool.py CHANGED
@@ -10,23 +10,26 @@ settings = Settings()
10
  print(settings.llm_model_id)
11
  class FinalAnswerTool(Tool):
12
  name = "final_answer"
13
- description = "Provides the exact, few comma separated words or a single final answer to the given question."
14
  inputs = {
15
  "answer": {"type": "string", "description": "The final, correctly formatted answer string."},
16
  }
17
  output_type = "string"
18
 
19
  def forward(self, answer: str) -> str:
20
- if answer is None:
21
- return "NA"
22
 
23
- answer = str(answer)
24
  match = re.search(r'boxed\{([^}]+)\}', answer)
25
  if match:
26
  answer = match.group(1)
27
- answer = re.sub(r'[\$\{\}\\]', '', answer) # Remove other LaTeX symbols
28
- answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer) # Keep letters, digits, commas
 
 
 
29
  if not answer:
30
- return "NA"
31
- final_answer = f"{str(answer)}"
32
- return final_answer
 
10
  print(settings.llm_model_id)
11
  class FinalAnswerTool(Tool):
12
  name = "final_answer"
13
+ description = "Provides the exact, few comma separated words or a single final answer to the given question."
14
  inputs = {
15
  "answer": {"type": "string", "description": "The final, correctly formatted answer string."},
16
  }
17
  output_type = "string"
18
 
19
  def forward(self, answer: str) -> str:
20
+ if not answer or str(answer).strip() == "":
21
+ return "I am unable to answer" # Fallback string for submission
22
 
23
+ answer = str(answer).strip()
24
  match = re.search(r'boxed\{([^}]+)\}', answer)
25
  if match:
26
  answer = match.group(1)
27
+ # Remove LaTeX symbols and keep letters, digits, commas
28
+ answer = re.sub(r'[\$\{\}\\]', '', answer)
29
+ answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer)
30
+ answer = " ".join(answer.split()) # Remove extra spaces
31
+
32
  if not answer:
33
+ return "I am unable to answer"
34
+
35
+ return answer