From 92f3c078b5928c9e72b9def13d2020af85f0d3ba Mon Sep 17 00:00:00 2001 From: binary-husky <505030475@qq.com> Date: Sat, 29 Apr 2023 02:04:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A9=E4=BF=9D=E5=AD=98=E7=9A=84html?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=96=87=E4=BB=B6=E8=83=BD=E5=A4=9F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BB=A3=E7=A0=81=E9=AB=98=E4=BA=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/对话历史存档.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crazy_functions/对话历史存档.py b/crazy_functions/对话历史存档.py index e78a0ca..bc75875 100644 --- a/crazy_functions/对话历史存档.py +++ b/crazy_functions/对话历史存档.py @@ -1,5 +1,6 @@ from toolbox import CatchException, update_ui from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive +import re def write_chat_to_file(chatbot, history=None, file_name=None): """ @@ -11,6 +12,8 @@ def write_chat_to_file(chatbot, history=None, file_name=None): file_name = 'chatGPT对话历史' + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.html' os.makedirs('./gpt_log/', exist_ok=True) with open(f'./gpt_log/{file_name}', 'w', encoding='utf8') as f: + from theme import advanced_css + f.write(f'
')
+ history = history.strip('
')
+ history = history.split("\n>>>")
+ return list(filter(lambda x:x!="", history))[0][:100]
+ except:
+ return ""
+
def read_file_to_chat(chatbot, history, file_name):
with open(file_name, 'r', encoding='utf8') as f:
file_content = f.read()
+ # pattern to match the text between and
+ pattern = re.compile(r'.*?', flags=re.DOTALL)
+ file_content = re.sub(pattern, '', file_content)
html, history = file_content.split('')
history = history.strip('
')
@@ -87,7 +107,7 @@ def 载入对话历史存档(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
if not success:
if txt == "": txt = '空空如也的输入栏'
import glob
- local_history = "