MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / match_answer

Function match_answer

eval/Math/math/evaluate_math.py:93–127  ·  view source on GitHub ↗
(response)

Source from the content-addressed store, hash-verified

91 return string[left_brace_idx + 1: right_brace_idx].strip()
92
93def match_answer(response):
94 is_matched = False
95
96 ans_marker = 'the answer is: '
97 ans_idx = response.lower().rfind(ans_marker)
98 if ans_idx != -1:
99 is_matched = True
100 response = response[ans_idx + len(ans_marker):].strip()
101 if response.endswith("\n"):
102 response = response[:-2]
103
104 ans_marker = 'answer:\n'
105 ans_idx = response.lower().rfind(ans_marker)
106 if ans_idx != -1:
107 is_matched = True
108 response = response[ans_idx + len(ans_marker):].strip()
109 if response.endswith("\n"):
110 response = response[:-2]
111
112 ans_marker = 'answer: '
113 ans_idx = response.lower().rfind(ans_marker)
114 if ans_idx != -1:
115 is_matched = True
116 response = response[ans_idx + len(ans_marker):].strip()
117 if response.endswith("\n"):
118 response = response[:-2]
119
120 # Find boxed
121 ans_boxed = _last_boxed_only_string(response)
122 if ans_boxed:
123 is_matched = True
124 response = ans_boxed
125
126 # Grade
127 return is_matched, response
128
129ANS_RE = re.compile(r"#### (\-?[0-9\.\,]+)")
130INVALID_ANS = "[invalid]"

Callers 1

runFunction · 0.70

Calls 1

_last_boxed_only_stringFunction · 0.70

Tested by

no test coverage detected