2024-02-29 19:10:30 +08:00
|
|
|
|
# QChatGPT 终端启动入口
|
|
|
|
|
# 在此层级解决依赖项检查。
|
2024-03-30 21:34:22 +08:00
|
|
|
|
# QChatGPT/main.py
|
2024-01-23 22:28:30 +08:00
|
|
|
|
|
2024-01-27 00:05:55 +08:00
|
|
|
|
asciiart = r"""
|
|
|
|
|
___ ___ _ _ ___ ___ _____
|
|
|
|
|
/ _ \ / __| |_ __ _| |_ / __| _ \_ _|
|
|
|
|
|
| (_) | (__| ' \/ _` | _| (_ | _/ | |
|
|
|
|
|
\__\_\\___|_||_\__,_|\__|\___|_| |_|
|
2024-02-08 13:37:27 +08:00
|
|
|
|
|
|
|
|
|
⭐️开源地址: https://github.com/RockChinQ/QChatGPT
|
|
|
|
|
📖文档地址: https://q.rkcn.top
|
2024-01-27 00:05:55 +08:00
|
|
|
|
"""
|
2024-01-23 22:28:30 +08:00
|
|
|
|
|
2024-02-29 19:10:30 +08:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def main_entry(loop: asyncio.AbstractEventLoop):
|
2024-01-27 00:05:55 +08:00
|
|
|
|
print(asciiart)
|
|
|
|
|
|
2024-02-29 19:10:30 +08:00
|
|
|
|
import sys
|
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
# 检查依赖
|
|
|
|
|
|
2024-02-29 19:10:30 +08:00
|
|
|
|
from pkg.core.bootutils import deps
|
|
|
|
|
|
|
|
|
|
missing_deps = await deps.check_deps()
|
|
|
|
|
|
|
|
|
|
if missing_deps:
|
|
|
|
|
print("以下依赖包未安装,将自动安装,请完成后重启程序:")
|
|
|
|
|
for dep in missing_deps:
|
|
|
|
|
print("-", dep)
|
|
|
|
|
await deps.install_deps(missing_deps)
|
|
|
|
|
print("已自动安装缺失的依赖包,请重启程序。")
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
# 检查配置文件
|
2024-03-14 16:00:22 +08:00
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
from pkg.core.bootutils import files
|
|
|
|
|
|
|
|
|
|
generated_files = await files.generate_files()
|
|
|
|
|
|
|
|
|
|
if generated_files:
|
|
|
|
|
print("以下文件不存在,已自动生成,请按需修改配置文件后重启:")
|
|
|
|
|
for file in generated_files:
|
|
|
|
|
print("-", file)
|
|
|
|
|
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2024-01-27 00:05:55 +08:00
|
|
|
|
from pkg.core import boot
|
2024-10-11 22:27:53 +08:00
|
|
|
|
await boot.main(loop)
|
2024-02-29 19:10:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-03-30 21:28:42 +08:00
|
|
|
|
import os
|
2024-10-22 18:17:09 +08:00
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
# 必须大于 3.10.1
|
|
|
|
|
if sys.version_info < (3, 10, 1):
|
|
|
|
|
print("需要 Python 3.10.1 及以上版本,当前 Python 版本为:", sys.version)
|
|
|
|
|
input("按任意键退出...")
|
|
|
|
|
exit(1)
|
2024-03-30 21:28:42 +08:00
|
|
|
|
|
2024-03-30 21:34:22 +08:00
|
|
|
|
# 检查本目录是否有main.py,且包含QChatGPT字符串
|
|
|
|
|
invalid_pwd = False
|
|
|
|
|
|
|
|
|
|
if not os.path.exists('main.py'):
|
|
|
|
|
invalid_pwd = True
|
|
|
|
|
else:
|
|
|
|
|
with open('main.py', 'r', encoding='utf-8') as f:
|
|
|
|
|
content = f.read()
|
|
|
|
|
if "QChatGPT/main.py" not in content:
|
|
|
|
|
invalid_pwd = True
|
|
|
|
|
if invalid_pwd:
|
2024-04-06 16:50:35 +08:00
|
|
|
|
print("请在QChatGPT项目根目录下以命令形式运行此程序。")
|
2024-03-30 21:34:22 +08:00
|
|
|
|
input("按任意键退出...")
|
2024-10-11 22:27:53 +08:00
|
|
|
|
exit(1)
|
2024-03-30 21:34:22 +08:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
loop = asyncio.new_event_loop()
|
2024-02-29 19:10:30 +08:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
loop.run_until_complete(main_entry(loop))
|