feat: 默认在启动时更新openai依赖库

This commit is contained in:
Rock Chin 2023-03-04 10:16:47 +08:00
parent f1e12563e9
commit a4d73090f8
3 changed files with 27 additions and 0 deletions

View File

@ -194,6 +194,9 @@ rate_limit_strategy = "wait"
# 若设置为空字符串,则不发送提示信息
rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃"
# 是否在启动时进行依赖库更新
upgrade_dependencies = True
# 是否上报统计信息
# 用于统计机器人的使用情况,不会收集任何用户信息
# 仅上报时间、字数使用量、绘图使用量,其他信息不会上报

19
main.py
View File

@ -43,6 +43,11 @@ def init_db():
database.initialize_database()
def ensure_openai():
import pkg.utils.pkgmgr as pkgmgr
pkgmgr.run_pip(["install", "openai", "--upgrade"])
known_exception_caught = False
log_file_name = "qchatgpt.log"
@ -333,4 +338,18 @@ if __name__ == '__main__':
#
# pkg.utils.configmgr.set_config_and_reload("quote_origin", False)
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import config
# 更新openai库到最新版本
if not hasattr(config, 'upgrade_dependencies') or config.upgrade_dependencies:
print("正在更新依赖库,请等待...")
if not hasattr(config, 'upgrade_dependencies'):
print("这个操作不是必须的,如果不想更新,请在config.py中添加upgrade_dependencies=False")
else:
print("这个操作不是必须的,如果不想更新,请在config.py中将upgrade_dependencies设置为False")
try:
ensure_openai()
except Exception as e:
print("更新openai库失败:{}, 请忽略或自行更新".format(e))
main(True)

View File

@ -8,6 +8,11 @@ def install(package):
main.reset_logging()
def run_pip(params: list):
pipmain(params)
main.reset_logging()
def install_requirements(file):
pipmain(['install', '-r', file, "--upgrade"])
main.reset_logging()