File size: 495 Bytes
01cf98b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import re
def parse_final_answer(text, num_docs):
patterns = [
rf"【最终答案】\s*([0-3]{{{num_docs}}})",
rf"最终答案\s*[::]?\s*([0-3]{{{num_docs}}})",
rf"答案\s*[::]?\s*([0-3]{{{num_docs}}})",
]
for pattern in patterns:
matches = re.findall(pattern, text, re.DOTALL)
if matches:
return matches[-1]
matches = re.findall(rf"[0-3]{{{num_docs}}}", text)
if matches:
return matches[-1]
return None
|