mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
26 lines
603 B
Python
26 lines
603 B
Python
![]() |
# flake8: noqa
|
||
|
|
||
|
import re
|
||
|
|
||
|
|
||
|
def parse_float_answer(raw_string, option=''):
|
||
|
number_pattern = re.compile(r'[-+]?\d+(\.\d+)?([eE][-+]?\d+)?')
|
||
|
|
||
|
# Search for the first match
|
||
|
match = number_pattern.search(raw_string)
|
||
|
if match:
|
||
|
# Extract the matched number and convert it to float
|
||
|
return float(match.group())
|
||
|
else:
|
||
|
# Return None if no number is found
|
||
|
return 0
|
||
|
|
||
|
|
||
|
def parse_true_false_answer(raw_string, option=''):
|
||
|
if 'yes' in raw_string.lower():
|
||
|
return True
|
||
|
elif 'no' in raw_string.lower():
|
||
|
return False
|
||
|
else:
|
||
|
return True
|