Skip to content

Commit

Permalink
修复PDF下载路径时间戳的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Sep 7, 2023
1 parent 4c6f3aa commit 5e0dc9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
14 changes: 14 additions & 0 deletions crazy_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
26 changes: 22 additions & 4 deletions crazy_functions/CodeInterpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .crazy_utils import input_clipping, try_install_deps
from multiprocessing import Process, Pipe
import os
import time

templete = """
```python
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)

Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions crazy_functions/crazy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5e0dc9b

Please sign in to comment.