perf: 优化各种报错管理;

feat: 启动时检查依赖库
This commit is contained in:
Soulter
2023-04-23 08:31:22 +00:00
parent 43ac0ef87c
commit 18ffaa2b91
3 changed files with 39 additions and 23 deletions
+9 -6
View File
@@ -187,12 +187,15 @@ def initBot(cfg, prov):
input("[System-err] 请退出本程序, 然后在配置文件中填写rev_ChatGPT相关配置")
if REV_EDGEGPT in prov:
if cfg['rev_edgegpt']['enable']:
from model.provider.provider_rev_edgegpt import ProviderRevEdgeGPT
from model.command.command_rev_edgegpt import CommandRevEdgeGPT
rev_edgegpt = ProviderRevEdgeGPT()
command_rev_edgegpt = CommandRevEdgeGPT(rev_edgegpt)
chosen_provider = REV_EDGEGPT
if not os.path.exists('./cookies.json'):
input("【错误】导入Bing模型时发生错误,没有找到cookies文件或者cookies文件放置位置错误。windows启动器启动的用户请把cookies.json文件放到和启动器相同的目录下。\n如何获取请看https://github.com/Soulter/QQChannelChatGPT仓库介绍。")
else:
if cfg['rev_edgegpt']['enable']:
from model.provider.provider_rev_edgegpt import ProviderRevEdgeGPT
from model.command.command_rev_edgegpt import CommandRevEdgeGPT
rev_edgegpt = ProviderRevEdgeGPT()
command_rev_edgegpt = CommandRevEdgeGPT(rev_edgegpt)
chosen_provider = REV_EDGEGPT
if OPENAI_OFFICIAL in prov:
if cfg['openai']['key'] is not None:
from model.provider.provider_openai_official import ProviderOpenAIOfficial
+29 -17
View File
@@ -5,10 +5,15 @@ import os, sys
abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/'
def main(loop, event):
import cores.qqbot.core as qqBot
import yaml
ymlfile = open(abs_path+"configs/config.yaml", 'r', encoding='utf-8')
cfg = yaml.safe_load(ymlfile)
try:
import cores.qqbot.core as qqBot
import yaml
ymlfile = open(abs_path+"configs/config.yaml", 'r', encoding='utf-8')
cfg = yaml.safe_load(ymlfile)
except BaseException as e:
print(e)
input("yaml库未导入或者配置文件格式错误,请退出程序重试。")
exit()
if 'http_proxy' in cfg:
os.environ['HTTP_PROXY'] = cfg['http_proxy']
@@ -39,19 +44,26 @@ def check_env():
print("请使用Python3.8运行本项目")
input("按任意键退出...")
exit()
# try:
# print("检查依赖库...")
# if os.path.exists('requirements.txt'):
# os.system("pip3 install -r requirements.txt")
# elif os.path.exists('QQChannelChatGPT'+ os.sep +'requirements.txt'):
# os.system('pip3 install -r QQChannelChatGPT'+ os.sep +'requirements.txt')
# os.system("clear")
# print("安装依赖库完毕...")
# except BaseException as e:
# print("安装依赖库失败,请手动安装依赖库。")
# print(e)
# input("按任意键退出...")
# exit()
print("正在更新三方依赖库...")
mm = os.system('pip install -r QQChannelChatGPT/requirements.txt')
if mm == 0:
print("依赖库安装完毕。")
else:
while True:
res = input("依赖库可能安装失败了。\n如果是报错ValueError: check_hostname requires server_hostname,请尝试先关闭代理后重试。\n输入y回车重试\n输入c回车使用国内镜像源下载\n输入其他按键回车继续往下执行。")
if res == "y":
mm = os.system('pip install -r QQChannelChatGPT/requirements.txt')
if mm == 0:
print("依赖库安装完毕。")
break
elif res == "c":
mm = os.system('pip install -r QQChannelChatGPT/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/')
if mm == 0:
print("依赖库安装完毕。")
break
else:
break
# 检查key
with open(abs_path+"configs/config.yaml", 'r', encoding='utf-8') as ymlfile:
+1
View File
@@ -1,6 +1,7 @@
from model.provider.provider import Provider
from EdgeGPT import Chatbot, ConversationStyle
import json
import os
class ProviderRevEdgeGPT(Provider):
def __init__(self):