mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-23 00:18:20 +01:00
Improve chat preprocessing
This commit is contained in:
parent
9a7f187b5a
commit
d962e69496
10
server.py
10
server.py
@ -189,11 +189,15 @@ elif args.chat:
|
|||||||
history = []
|
history = []
|
||||||
|
|
||||||
def chatbot_wrapper(text, tokens, inference_settings, selected_model, name1, name2, context, check):
|
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'
|
question = context+'\n\n'
|
||||||
for i in range(len(history)):
|
for i in range(len(history)):
|
||||||
question += f"{name1}: {history[i][0][3:-5].strip()}\n"
|
question += f"{name1}: {history[i][0][3:-5].strip()}\n"
|
||||||
question += f"{name2}: {history[i][1][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}:"
|
question += f"{name2}:"
|
||||||
|
|
||||||
if check:
|
if check:
|
||||||
@ -205,7 +209,9 @@ elif args.chat:
|
|||||||
idx = reply.find(f"\n{name1}:")
|
idx = reply.find(f"\n{name1}:")
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
reply = reply[:idx]
|
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))
|
history.append((text, reply))
|
||||||
return history
|
return history
|
||||||
|
Loading…
Reference in New Issue
Block a user