From d962e69496f593059f2739976b8154b2be4604d8 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:50:34 -0300 Subject: [PATCH] Improve chat preprocessing --- server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 5e14459..77feecb 100644 --- a/server.py +++ b/server.py @@ -189,11 +189,15 @@ elif args.chat: history = [] def chatbot_wrapper(text, tokens, inference_settings, selected_model, name1, name2, context, check): + text = text.replace('\n', '\n\n') + text = re.sub(r"\n{3,}", "\n\n", text) + text = text.strip() + question = context+'\n\n' for i in range(len(history)): question += f"{name1}: {history[i][0][3:-5].strip()}\n" question += f"{name2}: {history[i][1][3:-5].strip()}\n" - question += f"{name1}: {text.strip()}\n" + question += f"{name1}: {text}\n" question += f"{name2}:" if check: @@ -205,7 +209,9 @@ elif args.chat: idx = reply.find(f"\n{name1}:") if idx != -1: reply = reply[:idx] - reply = reply.replace('\n', '\n\n').strip() + reply = reply.replace('\n', '\n\n') + reply = re.sub(r"\n{3,}", "\n\n", reply) + reply = reply.strip() history.append((text, reply)) return history