diff --git a/css/main.css b/css/main.css index a08350ad..870f4192 100644 --- a/css/main.css +++ b/css/main.css @@ -980,6 +980,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { #rename-row { width: 100%; justify-content: center; + gap: 10px; } diff --git a/modules/chat.py b/modules/chat.py index 2638c794..81328385 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -1092,6 +1092,21 @@ def handle_delete_chat_confirm_click(state): ] +def handle_branch_chat_click(state): + history = state['history'] + new_unique_id = datetime.now().strftime('%Y%m%d-%H-%M-%S') + save_history(history, new_unique_id, state['character_menu'], state['mode']) + + histories = find_all_histories_with_first_prompts(state) + html = redraw_html(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu']) + + convert_to_markdown.cache_clear() + + past_chats_update = gr.update(choices=histories, value=new_unique_id) + + return [history, html, past_chats_update] + + def handle_rename_chat_click(): return [ gr.update(value="My New Chat"), diff --git a/modules/ui_chat.py b/modules/ui_chat.py index e372f5c2..b09d0081 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -24,6 +24,7 @@ def create_ui(): with gr.Row(elem_id='past-chats-row', elem_classes=['pretty_scrollbar']): with gr.Column(): with gr.Row(elem_id='past-chats-buttons'): + shared.gradio['branch_chat'] = gr.Button('Branch', elem_classes='refresh-button', interactive=not mu) shared.gradio['rename_chat'] = gr.Button('Rename', elem_classes='refresh-button', interactive=not mu) shared.gradio['delete_chat'] = gr.Button('🗑️', elem_classes='refresh-button', interactive=not mu) shared.gradio['Start new chat'] = gr.Button('New chat', elem_classes=['refresh-button', 'focus-on-chat-input']) @@ -250,6 +251,10 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( chat.handle_delete_chat_confirm_click, gradio('interface_state'), gradio('history', 'display', 'unique_id', 'delete-chat-row'), show_progress=False) + shared.gradio['branch_chat'].click( + ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( + chat.handle_branch_chat_click, gradio('interface_state'), gradio('history', 'display', 'unique_id'), show_progress=False) + shared.gradio['rename_chat'].click(chat.handle_rename_chat_click, None, gradio('rename_to', 'rename-row'), show_progress=False) shared.gradio['rename_to-cancel'].click(lambda: gr.update(visible=False), None, gradio('rename-row'), show_progress=False) shared.gradio['rename_to-confirm'].click(