From ec69c190bafc8c316a6f6e0eb0e398fc3a63f378 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 25 Jan 2023 10:52:35 -0300 Subject: [PATCH] Keep the character's greeting/example dialogue when "clear history" is clicked --- server.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index 5c694fe1..7ed64a96 100644 --- a/server.py +++ b/server.py @@ -357,13 +357,22 @@ if args.chat or args.cai_chat: else: return _history, last[0] - def clear(): - global history - history = [] - def clear_html(): return generate_chat_html([], "", "", character) + def clear_chat_log(_character, name1, name2): + global history + if _character != 'None': + load_character(_character, name1, name2) + else: + history = [] + + _history = remove_example_dialogue_from_history(history) + if args.cai_chat: + return generate_chat_html(_history, name1, name2, character) + else: + return _history + def redraw_html(name1, name2): global history _history = remove_example_dialogue_from_history(history) @@ -493,14 +502,12 @@ if args.chat or args.cai_chat: if args.cai_chat: gen_event = btn.click(cai_chatbot_wrapper, input_params, display1, show_progress=args.no_stream, api_name="textgen") gen_event2 = textbox.submit(cai_chatbot_wrapper, input_params, display1, show_progress=args.no_stream) - btn_clear.click(clear_html, [], display1, show_progress=False) else: gen_event = btn.click(chatbot_wrapper, input_params, display1, show_progress=args.no_stream, api_name="textgen") gen_event2 = textbox.submit(chatbot_wrapper, input_params, display1, show_progress=args.no_stream) - btn_clear.click(lambda x: "", display1, display1, show_progress=False) gen_event3 = btn_regenerate.click(regenerate_wrapper, input_params, display1, show_progress=args.no_stream) - btn_clear.click(clear) + btn_clear.click(clear_chat_log, [character_menu, name1, name2], display1) btn_remove_last.click(remove_last_message, [name1, name2], [display1, textbox], show_progress=False) btn.click(lambda x: "", textbox, textbox, show_progress=False) btn_regenerate.click(lambda x: "", textbox, textbox, show_progress=False)