From 5e0dc9b9adf9303d63cb56c9c5e30faadcfbcbe4 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Thu, 7 Sep 2023 18:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPDF=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=97=B6=E9=97=B4=E6=88=B3=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functional.py | 14 ++++++++++++++ crazy_functions/CodeInterpreter.py | 26 ++++++++++++++++++++++---- crazy_functions/crazy_utils.py | 8 +++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/crazy_functional.py b/crazy_functional.py index 4c12e926d..c6578554d 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -514,6 +514,20 @@ def get_crazy_functions(): except: print('Load function plugin failed') + + # try: + # from crazy_functions.CodeInterpreter import 虚空终端CodeInterpreter + # function_plugins.update({ + # "CodeInterpreter(开发中,仅供测试)": { + # "Group": "编程|对话", + # "Color": "stop", + # "AsButton": False, + # "Function": HotReload(虚空终端CodeInterpreter) + # } + # }) + # except: + # print('Load function plugin failed') + # try: # from crazy_functions.chatglm微调工具 import 微调数据集生成 # function_plugins.update({ diff --git a/crazy_functions/CodeInterpreter.py b/crazy_functions/CodeInterpreter.py index 73e142da1..3c970f357 100644 --- a/crazy_functions/CodeInterpreter.py +++ b/crazy_functions/CodeInterpreter.py @@ -5,6 +5,7 @@ from .crazy_utils import input_clipping, try_install_deps from multiprocessing import Process, Pipe import os +import time templete = """ ```python @@ -121,6 +122,19 @@ def for_immediate_show_off_when_possible(file_type, fp, chatbot): def subprocess_worker(instance, file_path, return_dict): return_dict['result'] = instance.run(file_path) +def have_any_recent_upload_files(chatbot): + _5min = 5 * 60 + if not chatbot: return False # chatbot is None + most_recent_uploaded = chatbot._cookies.get("most_recent_uploaded", None) + if not most_recent_uploaded: return False # most_recent_uploaded is None + if time.time() - most_recent_uploaded["time"] < _5min: return True # most_recent_uploaded is new + else: return False # most_recent_uploaded is too old + +def get_recent_file_prompt_support(chatbot): + most_recent_uploaded = chatbot._cookies.get("most_recent_uploaded", None) + path = most_recent_uploaded['path'] + return path + @CatchException def 虚空终端CodeInterpreter(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): """ @@ -132,6 +146,8 @@ def 虚空终端CodeInterpreter(txt, llm_kwargs, plugin_kwargs, chatbot, history system_prompt 给gpt的静默提醒 web_port 当前软件运行的端口号 """ + raise NotImplementedError + # 清空历史,以免输入溢出 history = []; clear_file_downloadzone(chatbot) @@ -142,10 +158,12 @@ def 虚空终端CodeInterpreter(txt, llm_kwargs, plugin_kwargs, chatbot, history ]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - # 尝试导入依赖, 如果缺少依赖, 则给出安装建议 - dep_ok = yield from inspect_dependency(chatbot=chatbot, history=history) # 刷新界面 - if not dep_ok: return - + if have_any_recent_upload_files(chatbot): + file_path = get_recent_file_prompt_support(chatbot) + else: + chatbot.append(["文件检索", "没有发现任何近期上传的文件。"]) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 + # 读取文件 if ("recently_uploaded_files" in plugin_kwargs) and (plugin_kwargs["recently_uploaded_files"] == ""): plugin_kwargs.pop("recently_uploaded_files") recently_uploaded_files = plugin_kwargs.get("recently_uploaded_files", None) diff --git a/crazy_functions/crazy_utils.py b/crazy_functions/crazy_utils.py index ffe95e2be..8069703b7 100644 --- a/crazy_functions/crazy_utils.py +++ b/crazy_functions/crazy_utils.py @@ -591,11 +591,13 @@ def get_files_from_everything(txt, type): # type='.md' # 网络的远程文件 import requests from toolbox import get_conf + from toolbox import get_log_folder, gen_time_str proxies, = get_conf('proxies') r = requests.get(txt, proxies=proxies) - with open('./gpt_log/temp'+type, 'wb+') as f: f.write(r.content) - project_folder = './gpt_log/' - file_manifest = ['./gpt_log/temp'+type] + path = os.path.join(get_log_folder(plugin_name='web_download'), gen_time_str()+type) + with open(path, 'wb+') as f: f.write(r.content) + project_folder = get_log_folder(plugin_name='web_download') + file_manifest = [path] elif txt.endswith(type): # 直接给定文件 file_manifest = [txt]