mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-15 19:22:24 +08:00
perf: 调整main.py中的引入顺序
This commit is contained in:
parent
c96833fcf0
commit
45295b52db
|
@ -47,7 +47,7 @@ git clone https://github.com/RockChinQ/QChatGPT
|
|||
2. 安装依赖
|
||||
|
||||
```bash
|
||||
pip install pymysql yiri-mirai openai colorlog
|
||||
pip install pymysql yiri-mirai openai colorlog func_timeout
|
||||
```
|
||||
|
||||
3. 运行一次主程序,生成配置文件
|
||||
|
|
40
main.py
40
main.py
|
@ -7,7 +7,6 @@ import time
|
|||
import logging
|
||||
import colorlog
|
||||
|
||||
|
||||
log_colors_config = {
|
||||
'DEBUG': 'green', # cyan white
|
||||
'INFO': 'white',
|
||||
|
@ -16,6 +15,7 @@ log_colors_config = {
|
|||
'CRITICAL': 'bold_red',
|
||||
}
|
||||
|
||||
|
||||
def init_db():
|
||||
import config
|
||||
import pkg.database.manager
|
||||
|
@ -46,6 +46,11 @@ def main():
|
|||
))
|
||||
logging.getLogger().addHandler(sh)
|
||||
|
||||
import pkg.openai.manager
|
||||
import pkg.database.manager
|
||||
import pkg.openai.session
|
||||
import pkg.qqbot.manager
|
||||
|
||||
# 主启动流程
|
||||
openai_interact = pkg.openai.manager.OpenAIInteract(config.openai_config['api_key'], config.completion_api_params)
|
||||
|
||||
|
@ -61,25 +66,6 @@ def main():
|
|||
qq_bot_thread = threading.Thread(target=qqbot.bot.run, args=(), daemon=True)
|
||||
qq_bot_thread.start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 检查是否有config.py,如果没有就把config-template.py复制一份,并退出程序
|
||||
if not os.path.exists('config.py'):
|
||||
shutil.copy('config-template.py', 'config.py')
|
||||
print('请先在config.py中填写配置')
|
||||
sys.exit(0)
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'init_db':
|
||||
init_db()
|
||||
sys.exit(0)
|
||||
|
||||
import pkg.openai.manager
|
||||
import pkg.database.manager
|
||||
import pkg.openai.session
|
||||
import pkg.qqbot.manager
|
||||
|
||||
main()
|
||||
|
||||
logging.info('程序启动完成')
|
||||
|
||||
while True:
|
||||
|
@ -95,3 +81,17 @@ if __name__ == '__main__':
|
|||
raise e
|
||||
print("程序退出")
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 检查是否有config.py,如果没有就把config-template.py复制一份,并退出程序
|
||||
if not os.path.exists('config.py'):
|
||||
shutil.copy('config-template.py', 'config.py')
|
||||
print('请先在config.py中填写配置')
|
||||
sys.exit(0)
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'init_db':
|
||||
init_db()
|
||||
sys.exit(0)
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user