evalscope_v0.17.0/evalscope.0.17.0/evalscope/third_party/thinkbench/tools/utils.py

14 lines
401 B
Python

import re
def extract_answer(solution_text: str):
boxed_pattern = r'\\boxed\{([^}]*)\}'
matches = re.findall(boxed_pattern, solution_text)
if matches:
last_boxed_content = matches[-1]
number_pattern = r'-?\d+'
number_matches = re.findall(number_pattern, last_boxed_content)
if number_matches:
return number_matches[-1].strip()
return None