| 53 | return tokens, attention_mask, position_ids |
| 54 | |
| 55 | def process_response(response): |
| 56 | response = response.strip() |
| 57 | response = response.replace("[[训练时间]]", "2023年") |
| 58 | punkts = [ |
| 59 | [",", ","], |
| 60 | ["!", "!"], |
| 61 | [":", ":"], |
| 62 | [";", ";"], |
| 63 | ["\?", "?"], |
| 64 | ] |
| 65 | for item in punkts: |
| 66 | response = re.sub(r"([\u4e00-\u9fff])%s" % item[0], r"\1%s" % item[1], response) |
| 67 | response = re.sub(r"%s([\u4e00-\u9fff])" % item[0], r"%s\1" % item[1], response) |
| 68 | return response |
| 69 | |
| 70 | def chat(model, tokenizer, |
| 71 | query: str, history: List[Tuple[str, str]] = None, |