mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-04 14:17:28 +00:00
UI: add a "Search chats" input field
This commit is contained in:
parent
b8fc9010fa
commit
4b3e1b3757
4 changed files with 37 additions and 16 deletions
|
|
@ -593,21 +593,26 @@ def find_all_histories_with_first_prompts(state):
|
|||
result = []
|
||||
for i, path in enumerate(histories):
|
||||
filename = path.stem
|
||||
if re.match(r'^[0-9]{8}-[0-9]{2}-[0-9]{2}-[0-9]{2}$', filename):
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
file_content = ""
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
file_content = f.read()
|
||||
|
||||
first_prompt = ""
|
||||
if data and 'visible' in data and len(data['visible']) > 0:
|
||||
if data['internal'][0][0] == '<|BEGIN-VISIBLE-CHAT|>':
|
||||
if len(data['visible']) > 1:
|
||||
first_prompt = html.unescape(data['visible'][1][0])
|
||||
elif i == 0:
|
||||
first_prompt = "New chat"
|
||||
else:
|
||||
first_prompt = html.unescape(data['visible'][0][0])
|
||||
elif i == 0:
|
||||
first_prompt = "New chat"
|
||||
if state['search_chat'] and state['search_chat'] not in file_content:
|
||||
continue
|
||||
|
||||
data = json.loads(file_content)
|
||||
if re.match(r'^[0-9]{8}-[0-9]{2}-[0-9]{2}-[0-9]{2}$', filename):
|
||||
first_prompt = ""
|
||||
if data and 'visible' in data and len(data['visible']) > 0:
|
||||
if data['internal'][0][0] == '<|BEGIN-VISIBLE-CHAT|>':
|
||||
if len(data['visible']) > 1:
|
||||
first_prompt = html.unescape(data['visible'][1][0])
|
||||
elif i == 0:
|
||||
first_prompt = "New chat"
|
||||
else:
|
||||
first_prompt = html.unescape(data['visible'][0][0])
|
||||
elif i == 0:
|
||||
first_prompt = "New chat"
|
||||
else:
|
||||
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
|
||||
if len(first_prompt) > 30:
|
||||
first_prompt = first_prompt[:30-3] + '...'
|
||||
first_prompt = first_prompt[:30 - 3] + '...'
|
||||
|
||||
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):
|
||||
history = start_new_chat(state)
|
||||
history = load_history_json(load_chat_history, history)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue