mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-25 01:09:22 +01:00
Add a rename menu for chat histories
This commit is contained in:
parent
d6814d7c15
commit
d5330406fa
@ -595,3 +595,11 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
list-style-position: outside !important;
|
list-style-position: outside !important;
|
||||||
margin-top: 6px !important;
|
margin-top: 6px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#past-chats-row {
|
||||||
|
margin-bottom: calc( -1 * var(--layout-gap) );
|
||||||
|
}
|
||||||
|
|
||||||
|
#rename-row label {
|
||||||
|
margin-top: var(--layout-gap);
|
||||||
|
}
|
||||||
|
@ -418,6 +418,21 @@ def save_history(history, unique_id, character, mode):
|
|||||||
f.write(json.dumps(history, indent=4))
|
f.write(json.dumps(history, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
def rename_history(old_id, new_id, character, mode):
|
||||||
|
if shared.args.multi_user:
|
||||||
|
return
|
||||||
|
|
||||||
|
old_p = get_history_file_path(old_id, character, mode)
|
||||||
|
new_p = get_history_file_path(new_id, character, mode)
|
||||||
|
if new_p.parent != old_p.parent:
|
||||||
|
logger.error(f"The following path is not allowed: {new_p}.")
|
||||||
|
elif new_p == old_p:
|
||||||
|
logger.info("The provided path is identical to the old one.")
|
||||||
|
else:
|
||||||
|
logger.info(f"Renaming {old_p} to {new_p}")
|
||||||
|
old_p.rename(new_p)
|
||||||
|
|
||||||
|
|
||||||
def find_all_histories(state):
|
def find_all_histories(state):
|
||||||
if shared.args.multi_user:
|
if shared.args.multi_user:
|
||||||
return ['']
|
return ['']
|
||||||
|
@ -62,12 +62,18 @@ def create_ui():
|
|||||||
shared.gradio['send-chat-to-default'] = gr.Button('Send to default')
|
shared.gradio['send-chat-to-default'] = gr.Button('Send to default')
|
||||||
shared.gradio['send-chat-to-notebook'] = gr.Button('Send to notebook')
|
shared.gradio['send-chat-to-notebook'] = gr.Button('Send to notebook')
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row(elem_id='past-chats-row'):
|
||||||
shared.gradio['unique_id'] = gr.Dropdown(label='Past chats', elem_classes=['slim-dropdown'])
|
shared.gradio['unique_id'] = gr.Dropdown(label='Past chats', elem_classes=['slim-dropdown'])
|
||||||
|
shared.gradio['rename_chat'] = gr.Button('Rename', elem_classes='refresh-button')
|
||||||
shared.gradio['delete_chat'] = gr.Button('🗑️', elem_classes='refresh-button')
|
shared.gradio['delete_chat'] = gr.Button('🗑️', elem_classes='refresh-button')
|
||||||
shared.gradio['delete_chat-cancel'] = gr.Button('Cancel', visible=False, elem_classes='refresh-button')
|
shared.gradio['delete_chat-cancel'] = gr.Button('Cancel', visible=False, elem_classes='refresh-button')
|
||||||
shared.gradio['delete_chat-confirm'] = gr.Button('Confirm', variant='stop', visible=False, elem_classes='refresh-button')
|
shared.gradio['delete_chat-confirm'] = gr.Button('Confirm', variant='stop', visible=False, elem_classes='refresh-button')
|
||||||
|
|
||||||
|
with gr.Row(elem_id='rename-row'):
|
||||||
|
shared.gradio['rename_to'] = gr.Textbox(label='Rename to:', placeholder='New name', visible=False, elem_classes=['no-background'])
|
||||||
|
shared.gradio['rename_to-cancel'] = gr.Button('Cancel', visible=False, elem_classes='refresh-button')
|
||||||
|
shared.gradio['rename_to-confirm'] = gr.Button('Confirm', visible=False, elem_classes='refresh-button')
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
shared.gradio['start_with'] = gr.Textbox(label='Start reply with', placeholder='Sure thing!', value=shared.settings['start_with'])
|
shared.gradio['start_with'] = gr.Textbox(label='Start reply with', placeholder='Sure thing!', value=shared.settings['start_with'])
|
||||||
|
|
||||||
@ -238,6 +244,18 @@ def create_event_handlers():
|
|||||||
lambda x: gr.update(choices=(histories := chat.find_all_histories(x)), value=histories[0]), gradio('interface_state'), gradio('unique_id')).then(
|
lambda x: gr.update(choices=(histories := chat.find_all_histories(x)), value=histories[0]), gradio('interface_state'), gradio('unique_id')).then(
|
||||||
lambda: [gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, gradio(clear_arr))
|
lambda: [gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, gradio(clear_arr))
|
||||||
|
|
||||||
|
shared.gradio['rename_chat'].click(
|
||||||
|
lambda x: x, gradio('unique_id'), gradio('rename_to')).then(
|
||||||
|
lambda: [gr.update(visible=True)] * 3, None, gradio('rename_to', 'rename_to-confirm', 'rename_to-cancel'), show_progress=False)
|
||||||
|
|
||||||
|
shared.gradio['rename_to-cancel'].click(
|
||||||
|
lambda: [gr.update(visible=False)] * 3, None, gradio('rename_to', 'rename_to-confirm', 'rename_to-cancel'), show_progress=False)
|
||||||
|
|
||||||
|
shared.gradio['rename_to-confirm'].click(
|
||||||
|
chat.rename_history, gradio('unique_id', 'rename_to', 'character_menu', 'mode'), None).then(
|
||||||
|
lambda: [gr.update(visible=False)] * 3, None, gradio('rename_to', 'rename_to-confirm', 'rename_to-cancel'), show_progress=False).then(
|
||||||
|
lambda x, y: gr.update(choices=chat.find_all_histories(x), value=y), gradio('interface_state', 'rename_to'), gradio('unique_id'))
|
||||||
|
|
||||||
shared.gradio['load_chat_history'].upload(
|
shared.gradio['load_chat_history'].upload(
|
||||||
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
|
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
|
||||||
chat.start_new_chat, gradio('interface_state'), gradio('history')).then(
|
chat.start_new_chat, gradio('interface_state'), gradio('history')).then(
|
||||||
|
Loading…
Reference in New Issue
Block a user