QChatGPT/pkg/core/app.py

78 lines
2.0 KiB
Python
Raw Normal View History

2024-01-23 20:55:20 +08:00
from __future__ import annotations
import logging
import asyncio
2024-01-30 14:58:34 +08:00
import traceback
2024-01-23 20:55:20 +08:00
2024-01-29 21:22:27 +08:00
from ..platform import manager as im_mgr
2024-01-28 19:20:10 +08:00
from ..provider.session import sessionmgr as llm_session_mgr
from ..provider.requester import modelmgr as llm_model_mgr
from ..provider.sysprompt import sysprompt as llm_prompt_mgr
from ..provider.tools import toolmgr as llm_tool_mgr
2024-01-23 20:55:20 +08:00
from ..config import manager as config_mgr
2024-01-29 21:22:27 +08:00
# from ..utils.center import v2 as center_mgr
2024-01-28 00:16:42 +08:00
from ..command import cmdmgr
2024-01-29 21:22:27 +08:00
from ..plugin import manager as plugin_mgr
from . import pool, controller
from ..pipeline import stagemgr
2024-01-29 21:22:27 +08:00
from ..utils import version as version_mgr, proxy as proxy_mgr
2024-01-23 20:55:20 +08:00
class Application:
2024-01-29 21:22:27 +08:00
im_mgr: im_mgr.QQBotManager = None
2024-01-23 20:55:20 +08:00
2024-01-28 00:16:42 +08:00
cmd_mgr: cmdmgr.CommandManager = None
sess_mgr: llm_session_mgr.SessionManager = None
model_mgr: llm_model_mgr.ModelManager = None
prompt_mgr: llm_prompt_mgr.PromptManager = None
2024-01-27 21:50:40 +08:00
tool_mgr: llm_tool_mgr.ToolManager = None
2024-01-23 20:55:20 +08:00
cfg_mgr: config_mgr.ConfigManager = None
tips_mgr: config_mgr.ConfigManager = None
2024-01-29 21:22:27 +08:00
# ctr_mgr: center_mgr.V2CenterAPI = None
2024-01-23 20:55:20 +08:00
2024-01-29 21:22:27 +08:00
plugin_mgr: plugin_mgr.PluginManager = None
2024-01-23 20:55:20 +08:00
query_pool: pool.QueryPool = None
ctrl: controller.Controller = None
stage_mgr: stagemgr.StageManager = None
2024-01-29 21:22:27 +08:00
ver_mgr: version_mgr.VersionManager = None
proxy_mgr: proxy_mgr.ProxyManager = None
2024-01-23 20:55:20 +08:00
logger: logging.Logger = None
def __init__(self):
pass
2024-01-27 21:50:40 +08:00
async def initialize(self):
2024-01-29 21:22:27 +08:00
pass
2024-01-27 21:50:40 +08:00
async def run(self):
2024-01-29 21:22:27 +08:00
await self.plugin_mgr.load_plugins()
2024-01-29 21:41:20 +08:00
await self.plugin_mgr.initialize_plugins()
2024-01-27 21:50:40 +08:00
tasks = [
asyncio.create_task(self.im_mgr.run()),
asyncio.create_task(self.ctrl.run())
]
2024-01-30 14:58:34 +08:00
try:
await asyncio.wait(tasks)
except asyncio.CancelledError:
self.logger.info("程序退出.")
except Exception as e:
self.logger.error(f"应用运行致命异常: {e}")
self.logger.debug(f"Traceback: {traceback.format_exc()}")