优化prompt 搜索,将所有上下文一起展示

This commit is contained in:
w_xiaolizu
2023-06-08 11:51:31 +08:00
parent f2cfc44b02
commit 0a6bb18a2e
2 changed files with 21 additions and 5 deletions

View File

@ -3,6 +3,7 @@
# @Time : 2023/4/18 # @Time : 2023/4/18
# @Author : Spike # @Author : Spike
# @Descr : # @Descr :
import ast
import hashlib import hashlib
import io import io
import json import json
@ -292,7 +293,6 @@ def diff_list(txt='', percent=0.70, switch: list = None, lst: list = None, sp=15
lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value(txt)) lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value(txt))
# diff 数据根据precent系数归类数据 # diff 数据根据precent系数归类数据
str_ = time.time() str_ = time.time()
def tf_factor_calcul(i): def tf_factor_calcul(i):
found = False found = False
dict_copy = count_dict.copy() dict_copy = count_dict.copy()
@ -466,6 +466,14 @@ def copy_result(history):
return "无对话记录,复制错误!!" return "无对话记录,复制错误!!"
def str_is_list(s):
try:
list_ast = ast.literal_eval(s)
return isinstance(list_ast, list)
except (SyntaxError, ValueError):
return False
def show_prompt_result(index, data: gr.Dataset, chatbot): def show_prompt_result(index, data: gr.Dataset, chatbot):
""" """
查看Prompt的对话记录结果 查看Prompt的对话记录结果
@ -477,12 +485,20 @@ def show_prompt_result(index, data: gr.Dataset, chatbot):
返回注册函数所需的对象 返回注册函数所需的对象
""" """
click = data.samples[index] click = data.samples[index]
chatbot.append((click[1], click[2])) if str_is_list(click[2]):
list_copy = eval(click[2])
for i in range(0, len(list_copy), 2):
if i + 1 >= len(list_copy): # 如果下标越界了,单独处理最后一个元素
chatbot.append([list_copy[i]])
else:
chatbot.append([list_copy[i], list_copy[i + 1]])
else:
chatbot.append((click[1], click[2]))
return chatbot return chatbot
def thread_write_chat(chatbot): def thread_write_chat(chatbot, history):
""" """
对话记录写入数据库 对话记录写入数据库
""" """
@ -490,7 +506,7 @@ def thread_write_chat(chatbot):
chat_title = chatbot[0][1].split() chat_title = chatbot[0][1].split()
pattern = re.compile(r'^<div class="markdown-body"><p>|<\/p><\/div>$') pattern = re.compile(r'^<div class="markdown-body"><p>|<\/p><\/div>$')
i_say = pattern.sub('', chatbot[-1][0]) i_say = pattern.sub('', chatbot[-1][0])
gpt_result = pattern.sub('', chatbot[-1][1]) gpt_result = history
if private_key in chat_title: if private_key in chat_title:
SqliteHandle(f'ai_private_{chat_title[-2]}').inset_prompt({i_say: gpt_result}) SqliteHandle(f'ai_private_{chat_title[-2]}').inset_prompt({i_say: gpt_result})
else: else:

View File

@ -102,7 +102,7 @@ def update_ui(chatbot, history, msg='正常', *args): # 刷新界面
""" """
assert isinstance(chatbot, ChatBotWithCookies), "在传递chatbot的过程中不要将其丢弃。必要时可用clear将其清空然后用for+append循环重新赋值。" assert isinstance(chatbot, ChatBotWithCookies), "在传递chatbot的过程中不要将其丢弃。必要时可用clear将其清空然后用for+append循环重新赋值。"
yield chatbot.get_cookies(), chatbot, history, msg yield chatbot.get_cookies(), chatbot, history, msg
pool.submit(func_box.thread_write_chat, chatbot) pool.submit(func_box.thread_write_chat, chatbot, history)
def update_ui_lastest_msg(lastmsg, chatbot, history, delay=1): # 刷新界面 def update_ui_lastest_msg(lastmsg, chatbot, history, delay=1): # 刷新界面
""" """