From 4774dad8aba738a6a6ea1510d27e62a8f3cac0b2 Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Fri, 16 Jun 2023 12:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E8=A7=A3=E5=86=B3isay=20?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/toolbox.py b/toolbox.py index 82c4cf0..c019f09 100644 --- a/toolbox.py +++ b/toolbox.py @@ -232,8 +232,7 @@ def write_results_to_file(history, file_name=None): # remove everything that cannot be handled by utf8 f.write(content.encode('utf-8', 'ignore').decode()) f.write('\n\n') - res = '以上材料已经被写入' + os.path.abspath(f'./gpt_log/{file_name}') - print(res) + res = '以上材料已经被写入' + f'./gpt_log/{file_name}' return res @@ -258,6 +257,8 @@ def report_execption(chatbot, history, a, b): history.append(b) +import re + def text_divide_paragraph(input_str): if input_str: # 提取所有的代码块 @@ -283,11 +284,12 @@ def text_divide_paragraph(input_str): else: # 对于没有反引号的字符串,针对四个空格之前的换行符进行处理 lines = input_str.split('\n') - for idx, line in enumerate(lines[:-1]): - if not line.strip(): - continue - if not (lines[idx + 1].startswith(' ') or lines[idx + 1].startswith('\t')): - pass + if not any(line.startswith(' ') for line in lines): + for idx, line in enumerate(lines[:-1]): + if not line.strip(): + continue + if not (lines[idx + 1].startswith(' ') or lines[idx + 1].startswith('\t')): + lines[idx] += '\n' # 将一个换行符替换为两个换行符 input_str = '\n'.join(lines) return input_str @@ -539,9 +541,10 @@ def get_user_download(chatbot, link, file): for f in files: temp_ = os.path.abspath(os.path.join(root, f)) dir_file, file_name = ('/'.join(str(file_handle).split('/')[-2:]), os.path.basename(temp_)) + link_href = f'{link["local"]} / file = {temp_}' chatbot.append(['Convert the file address to a download link at:', f'[Local Message] Successful conversion\n\n ' - f'{file_name}']) + f'{func_box.html_a_blank(__href=link_href, dir_name=dir_file, file_name=file_name)}']) elif file_handle == '': pass return chatbot, ''