diff --git a/.gitignore b/.gitignore index 33e9906..beb7906 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ history ssr_conf config_private.py gpt_log +private.md diff --git a/crazy_functions/读文章写摘要.py b/crazy_functions/读文章写摘要.py index 2ce6b36..9018856 100644 --- a/crazy_functions/读文章写摘要.py +++ b/crazy_functions/读文章写摘要.py @@ -1,5 +1,5 @@ from predict import predict_no_ui -from toolbox import CatchException, report_execption +from toolbox import CatchException, report_execption, write_results_to_file fast_debug = False @@ -56,7 +56,9 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist chatbot[-1] = (i_say, gpt_say) history.append(i_say); history.append(gpt_say) yield chatbot, history, msg - + res = write_results_to_file(history) + chatbot.append(("完成了吗?", res)) + yield chatbot, history, msg diff --git a/functional_crazy.py b/functional_crazy.py index ce4b9dc..9e91970 100644 --- a/functional_crazy.py +++ b/functional_crazy.py @@ -1,5 +1,5 @@ from predict import predict_no_ui -from toolbox import CatchException, report_execption +from toolbox import CatchException, report_execption, write_results_to_file fast_debug = False @@ -110,7 +110,9 @@ def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, chatbot[-1] = (i_say, gpt_say) history.append(i_say); history.append(gpt_say) yield chatbot, history, msg - + res = write_results_to_file(history) + chatbot.append(("完成了吗?", res)) + yield chatbot, history, msg @CatchException diff --git a/toolbox.py b/toolbox.py index c28b998..8277bca 100644 --- a/toolbox.py +++ b/toolbox.py @@ -2,6 +2,20 @@ import markdown, mdtex2html from show_math import convert as convert_math from functools import wraps +def write_results_to_file(history, file_name=None): + import os, time + if file_name is None: + file_name = time.strftime("chatGPT分析报告%Y-%m-%d-%H-%M-%S", time.localtime()) + '.md' + os.makedirs('./gpt_log/', exist_ok=True) + with open(f'./gpt_log/{file_name}', 'w') as f: + f.write('# chatGPT 分析报告\n') + for i, content in enumerate(history): + if i%2==0: f.write('## ') + f.write(content) + f.write('\n\n') + res ='以上材料已经被写入', f'./gpt_log/{file_name}' + print(res) + return res def regular_txt_to_markdown(text): text = text.replace('\n', '\n\n')