mirror of
https://github.com/hanzoai/open-instruct.git
synced 2026-10-30 18:26:32 +00:00
33 lines
827 B
Python
33 lines
827 B
Python
def last_boxed_only_string(string: str):
|
|
idx = string.rfind("\\boxed")
|
|
if idx < 0:
|
|
idx = string.rfind("\\fbox")
|
|
if idx < 0:
|
|
return ""
|
|
i = idx
|
|
right_brace_idx = None
|
|
num_left_braces_open = 0
|
|
while i < len(string):
|
|
if string[i] == "{":
|
|
num_left_braces_open += 1
|
|
if string[i] == "}":
|
|
num_left_braces_open -= 1
|
|
if num_left_braces_open == 0:
|
|
right_brace_idx = i
|
|
break
|
|
i += 1
|
|
if right_brace_idx == None:
|
|
retval = ""
|
|
else:
|
|
retval = string[idx:right_brace_idx + 1]
|
|
return retval
|
|
|
|
def remove_boxed(s: str):
|
|
left = "\\boxed{"
|
|
try:
|
|
assert s[:len(left)] == left
|
|
assert s[-1] == "}"
|
|
return s[len(left):-1]
|
|
except:
|
|
return ""
|