diff --git a/.gitignore b/.gitignore index 3a5e180c..4fb8a7df 100644 --- a/.gitignore +++ b/.gitignore @@ -153,4 +153,6 @@ media flagged request_llms/ChatGLM-6b-onnx-u8s8 .pre-commit-config.yaml -themes/common.js.min.*.js \ No newline at end of file +themes/common.js.min.*.js +test* +objdump* \ No newline at end of file diff --git a/crazy_functions/Conversation_To_File.py b/crazy_functions/Conversation_To_File.py index a077fcf4..972f4ac0 100644 --- a/crazy_functions/Conversation_To_File.py +++ b/crazy_functions/Conversation_To_File.py @@ -10,27 +10,61 @@ def write_chat_to_file(chatbot, history=None, file_name=None): """ import os import time + from themes.theme import advanced_css + if file_name is None: file_name = f_prefix + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.html' fp = os.path.join(get_log_folder(get_user(chatbot), plugin_name='chat_history'), file_name) + with open(fp, 'w', encoding='utf8') as f: - from themes.theme import advanced_css - f.write(f'
')
+ question, answer = contents[0], contents[1]
+ if question is None: question = ""
+ try: question = str(question)
+ except: question = ""
+ if answer is None: answer = ""
+ try: answer = str(answer)
+ except: answer = ""
+ CHAT_PREVIEW_BUF += qa_from.format(QUESTION=question, ANSWER=answer)
+
+ HISTORY_PREVIEW_BUF = ""
for h in history:
- f.write("\n>>>" + h)
- f.write('')
+ HISTORY_PREVIEW_BUF += history_from.format(ENTRY=h)
+ html_content = form.format(CHAT_PREVIEW=CHAT_PREVIEW_BUF, HISTORY_PREVIEW=HISTORY_PREVIEW_BUF, CSS=advanced_css)
+ f.write(html_content)
+
promote_file_to_downloadzone(fp, rename_file=file_name, chatbot=chatbot)
return '对话历史写入:' + fp
@@ -41,7 +75,7 @@ def gen_file_preview(file_name):
# 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('')
history = history.split("\n>>>")
@@ -52,21 +86,25 @@ def gen_file_preview(file_name):
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('')
- history = history.split("\n>>>")
- history = list(filter(lambda x:x!="", history))
- html = html.split('