| 22 | return False |
| 23 | |
| 24 | def extract_answer_wizard(completion): |
| 25 | text = completion.split('The answer is: ') |
| 26 | if len(text) > 1: |
| 27 | extract_ans = text[-1].strip() |
| 28 | match = re.search(r'[\-+]?\d*[\.,/]?\d+', extract_ans) |
| 29 | if match: |
| 30 | if '/' in match.group(): |
| 31 | denominator = match.group().split('/')[1] |
| 32 | numerator = match.group().split('/')[0] |
| 33 | if is_number(denominator) == True and is_number(numerator) == True: |
| 34 | if denominator == '0': |
| 35 | return round(float(numerator.replace(',', ''))) |
| 36 | else: |
| 37 | frac = Fraction(match.group().replace(',', '')) |
| 38 | num_numerator = frac.numerator |
| 39 | num_denominator = frac.denominator |
| 40 | return round(float(num_numerator / num_denominator)) |
| 41 | else: |
| 42 | return INVALID_ANS |
| 43 | else: |
| 44 | if float(match.group().replace(',', '')) == float('inf'): |
| 45 | return INVALID_ANS |
| 46 | return round(float(match.group().replace(',', ''))) |
| 47 | else: |
| 48 | return INVALID_ANS |
| 49 | else: |
| 50 | return INVALID_ANS |
| 51 | |
| 52 | |
| 53 | def extract_answer(completion): |