mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-01-09 12:09:04 +01:00
UI: add a "Search chats" input field
This commit is contained in:
parent
b8fc9010fa
commit
4b3e1b3757
@ -876,6 +876,10 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#search_chat > :nth-child(2) > :first-child {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------
|
/* ----------------------------------------------
|
||||||
Keep dropdown menus above errored components
|
Keep dropdown menus above errored components
|
||||||
---------------------------------------------- */
|
---------------------------------------------- */
|
||||||
@ -911,7 +915,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#past-chats {
|
#past-chats {
|
||||||
max-height: calc(100dvh - 90px);
|
max-height: calc(100dvh - 135px);
|
||||||
overflow-y: scroll !important;
|
overflow-y: scroll !important;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
scrollbar-width: auto;
|
scrollbar-width: auto;
|
||||||
|
@ -593,21 +593,26 @@ def find_all_histories_with_first_prompts(state):
|
|||||||
result = []
|
result = []
|
||||||
for i, path in enumerate(histories):
|
for i, path in enumerate(histories):
|
||||||
filename = path.stem
|
filename = path.stem
|
||||||
if re.match(r'^[0-9]{8}-[0-9]{2}-[0-9]{2}-[0-9]{2}$', filename):
|
file_content = ""
|
||||||
with open(path, 'r', encoding='utf-8') as f:
|
with open(path, 'r', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
file_content = f.read()
|
||||||
|
|
||||||
first_prompt = ""
|
if state['search_chat'] and state['search_chat'] not in file_content:
|
||||||
if data and 'visible' in data and len(data['visible']) > 0:
|
continue
|
||||||
if data['internal'][0][0] == '<|BEGIN-VISIBLE-CHAT|>':
|
|
||||||
if len(data['visible']) > 1:
|
data = json.loads(file_content)
|
||||||
first_prompt = html.unescape(data['visible'][1][0])
|
if re.match(r'^[0-9]{8}-[0-9]{2}-[0-9]{2}-[0-9]{2}$', filename):
|
||||||
elif i == 0:
|
first_prompt = ""
|
||||||
first_prompt = "New chat"
|
if data and 'visible' in data and len(data['visible']) > 0:
|
||||||
else:
|
if data['internal'][0][0] == '<|BEGIN-VISIBLE-CHAT|>':
|
||||||
first_prompt = html.unescape(data['visible'][0][0])
|
if len(data['visible']) > 1:
|
||||||
elif i == 0:
|
first_prompt = html.unescape(data['visible'][1][0])
|
||||||
first_prompt = "New chat"
|
elif i == 0:
|
||||||
|
first_prompt = "New chat"
|
||||||
|
else:
|
||||||
|
first_prompt = html.unescape(data['visible'][0][0])
|
||||||
|
elif i == 0:
|
||||||
|
first_prompt = "New chat"
|
||||||
else:
|
else:
|
||||||
first_prompt = filename
|
first_prompt = filename
|
||||||
|
|
||||||
@ -615,7 +620,7 @@ def find_all_histories_with_first_prompts(state):
|
|||||||
|
|
||||||
# Truncate the first prompt if it's longer than 30 characters
|
# Truncate the first prompt if it's longer than 30 characters
|
||||||
if len(first_prompt) > 30:
|
if len(first_prompt) > 30:
|
||||||
first_prompt = first_prompt[:30-3] + '...'
|
first_prompt = first_prompt[:30 - 3] + '...'
|
||||||
|
|
||||||
result.append((first_prompt, filename))
|
result.append((first_prompt, filename))
|
||||||
|
|
||||||
@ -1124,6 +1129,11 @@ def handle_rename_chat_confirm(rename_to, state):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def handle_search_chat_change(state):
|
||||||
|
histories = find_all_histories_with_first_prompts(state)
|
||||||
|
return gr.update(choices=histories)
|
||||||
|
|
||||||
|
|
||||||
def handle_upload_chat_history(load_chat_history, state):
|
def handle_upload_chat_history(load_chat_history, state):
|
||||||
history = start_new_chat(state)
|
history = start_new_chat(state)
|
||||||
history = load_history_json(load_chat_history, history)
|
history = load_history_json(load_chat_history, history)
|
||||||
|
@ -230,6 +230,7 @@ def list_interface_input_elements():
|
|||||||
'start_with',
|
'start_with',
|
||||||
'character_menu',
|
'character_menu',
|
||||||
'history',
|
'history',
|
||||||
|
'search_chat',
|
||||||
'unique_id',
|
'unique_id',
|
||||||
'name1',
|
'name1',
|
||||||
'user_bio',
|
'user_bio',
|
||||||
|
@ -29,6 +29,8 @@ def create_ui():
|
|||||||
shared.gradio['delete_chat'] = gr.Button('🗑️', 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'])
|
shared.gradio['Start new chat'] = gr.Button('New chat', elem_classes=['refresh-button', 'focus-on-chat-input'])
|
||||||
|
|
||||||
|
shared.gradio['search_chat'] = gr.Textbox(placeholder='Search chats...', max_lines=1, elem_id='search_chat')
|
||||||
|
|
||||||
with gr.Row(elem_id='delete-chat-row', visible=False) as shared.gradio['delete-chat-row']:
|
with gr.Row(elem_id='delete-chat-row', visible=False) as shared.gradio['delete-chat-row']:
|
||||||
shared.gradio['delete_chat-cancel'] = gr.Button('Cancel', elem_classes=['refresh-button', 'focus-on-chat-input'])
|
shared.gradio['delete_chat-cancel'] = gr.Button('Cancel', elem_classes=['refresh-button', 'focus-on-chat-input'])
|
||||||
shared.gradio['delete_chat-confirm'] = gr.Button('Confirm', variant='stop', elem_classes=['refresh-button', 'focus-on-chat-input'])
|
shared.gradio['delete_chat-confirm'] = gr.Button('Confirm', variant='stop', elem_classes=['refresh-button', 'focus-on-chat-input'])
|
||||||
@ -265,6 +267,10 @@ def create_event_handlers():
|
|||||||
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.handle_rename_chat_confirm, gradio('rename_to', 'interface_state'), gradio('unique_id', 'rename-row'), show_progress=False)
|
chat.handle_rename_chat_confirm, gradio('rename_to', 'interface_state'), gradio('unique_id', 'rename-row'), show_progress=False)
|
||||||
|
|
||||||
|
shared.gradio['search_chat'].change(
|
||||||
|
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
|
||||||
|
chat.handle_search_chat_change, gradio('interface_state'), gradio('unique_id'), show_progress=False)
|
||||||
|
|
||||||
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.handle_upload_chat_history, gradio('load_chat_history', 'interface_state'), gradio('history', 'display', 'unique_id'), show_progress=False).then(
|
chat.handle_upload_chat_history, gradio('load_chat_history', 'interface_state'), gradio('history', 'display', 'unique_id'), show_progress=False).then(
|
||||||
|
Loading…
Reference in New Issue
Block a user