(text: str, replace_quote: bool)
| 143 | |
| 144 | |
| 145 | def postprocess_text(text: str, replace_quote: bool) -> str: |
| 146 | text = text.replace(r"\(", "$") |
| 147 | text = text.replace(r"\)", "$") |
| 148 | text = text.replace(r"\[", "$$") |
| 149 | text = text.replace(r"\]", "$$") |
| 150 | text = text.replace("<|assistant|>", "") |
| 151 | text = text.replace("<|observation|>", "") |
| 152 | text = text.replace("<|system|>", "") |
| 153 | text = text.replace("<|user|>", "") |
| 154 | text = text.replace("<|endoftext|>", "") |
| 155 | |
| 156 | # Replace quotes |
| 157 | if replace_quote: |
| 158 | for match in QUOTE_REGEX.finditer(text): |
| 159 | quote_id = match.group(1) |
| 160 | quote = quotes.get(quote_id, Quote("未找到引用内容", "")) |
| 161 | text = text.replace(match.group(0), f" (来源:[{quote.title}]({quote.url})) ") |
| 162 | |
| 163 | return text.strip() |
no test coverage detected