| 12 | |
| 13 | |
| 14 | def extract_answer_fn(output, mode='qa', extract_answer=False): |
| 15 | extracted_text = '' |
| 16 | pattern_info = "**Final Information" |
| 17 | if "</think>\n" in output: |
| 18 | extracted_text = output.split("</think>\n")[-1].split("<|begin_click_link|>")[0].replace(pattern_info, "").strip(':**').strip('\n').strip("```").strip() # 提取</think>后面的内容 |
| 19 | if mode == 'infogen': |
| 20 | extracted_text = '\n'.join(extracted_text.replace("\n\n", "\n").split('\n')[:5]) # 只保留前5行 |
| 21 | elif pattern_info in output: |
| 22 | extracted_text = output.split(pattern_info)[-1].split("<|begin_click_link|>")[0].strip('\n').strip(':**').strip("```").strip() # 提取**Final Information**后面的内容 |
| 23 | if mode == 'infogen': |
| 24 | extracted_text = '\n'.join(extracted_text.replace("\n\n", "\n").split('\n')[:5]) # 只保留前5行 |
| 25 | else: |
| 26 | # extracted_text = "No helpful information found." |
| 27 | extracted_text = '\n'.join(output.strip().replace("</think>\n", "").replace("\n\n", "\n").split('\n')[-5:]) # 若没提取到,只保留最后5行 |
| 28 | if mode == 'research': |
| 29 | extracted_text = extracted_text[:6000] |
| 30 | else: |
| 31 | extracted_text = extracted_text[:2500] |
| 32 | return extracted_text |
| 33 | |
| 34 | |