增加复用prompt功能

This commit is contained in:
w_xiaolizu
2023-06-07 10:38:34 +08:00
parent 12c4609712
commit 2bafcab043
3 changed files with 64 additions and 6 deletions

View File

@ -475,6 +475,7 @@ def show_prompt_result(index, data: gr.Dataset, chatbot):
return chatbot
def thread_write_chat(chatbot):
"""
对话记录写入数据库
@ -494,6 +495,18 @@ base_path = os.path.dirname(__file__)
prompt_path = os.path.join(base_path, 'prompt_users')
def reuse_chat(result, chatbot, history):
"""复用对话记录"""
if result is None or result == []:
pass
else:
chatbot.append(result[-1])
history += result[-1]
pattern = re.compile(r'^<div class="markdown-body"><p>|<\/p><\/div>$')
i_say = pattern.sub('', chatbot[-1][0])
return chatbot, history, i_say, gr.Tabs.update(selected='chatbot')
class YamlHandle:
def __init__(self, file=os.path.join(prompt_path, 'ai_common.yaml')):