-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #707 from RockChinQ/feat/booting-stages
Feat: 分阶段启动
- Loading branch information
Showing
11 changed files
with
221 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
import typing | ||
|
||
from . import app | ||
|
||
|
||
preregistered_stages: dict[str, typing.Type[BootingStage]] = {} | ||
|
||
def stage_class( | ||
name: str | ||
): | ||
def decorator(cls: typing.Type[BootingStage]) -> typing.Type[BootingStage]: | ||
preregistered_stages[name] = cls | ||
return cls | ||
|
||
return decorator | ||
|
||
|
||
class BootingStage(abc.ABC): | ||
"""启动阶段 | ||
""" | ||
name: str = None | ||
|
||
@abc.abstractmethod | ||
async def run(self, ap: app.Application): | ||
"""启动 | ||
""" | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
|
||
from .. import stage, app | ||
from ...utils import version, proxy, announce | ||
from ...audit.center import v2 as center_v2 | ||
from ...audit import identifier | ||
from ...pipeline import pool, controller, stagemgr | ||
from ...plugin import manager as plugin_mgr | ||
from ...command import cmdmgr | ||
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 | ||
from ...platform import manager as im_mgr | ||
|
||
|
||
@stage.stage_class("BuildAppStage") | ||
class BuildAppStage(stage.BootingStage): | ||
"""构建应用阶段 | ||
""" | ||
|
||
async def run(self, ap: app.Application): | ||
"""启动 | ||
""" | ||
|
||
proxy_mgr = proxy.ProxyManager(ap) | ||
await proxy_mgr.initialize() | ||
ap.proxy_mgr = proxy_mgr | ||
|
||
ver_mgr = version.VersionManager(ap) | ||
await ver_mgr.initialize() | ||
ap.ver_mgr = ver_mgr | ||
|
||
center_v2_api = center_v2.V2CenterAPI( | ||
ap, | ||
basic_info={ | ||
"host_id": identifier.identifier["host_id"], | ||
"instance_id": identifier.identifier["instance_id"], | ||
"semantic_version": ver_mgr.get_current_version(), | ||
"platform": sys.platform, | ||
}, | ||
runtime_info={ | ||
"admin_id": "{}".format(ap.system_cfg.data["admin-sessions"]), | ||
"msg_source": str([ | ||
adapter_cfg['adapter'] if 'adapter' in adapter_cfg else 'unknown' | ||
for adapter_cfg in ap.platform_cfg.data['platform-adapters'] if adapter_cfg['enable'] | ||
]), | ||
}, | ||
) | ||
ap.ctr_mgr = center_v2_api | ||
|
||
# 发送公告 | ||
ann_mgr = announce.AnnouncementManager(ap) | ||
await ann_mgr.show_announcements() | ||
|
||
ap.query_pool = pool.QueryPool() | ||
|
||
await ap.ver_mgr.show_version_update() | ||
|
||
plugin_mgr_inst = plugin_mgr.PluginManager(ap) | ||
await plugin_mgr_inst.initialize() | ||
ap.plugin_mgr = plugin_mgr_inst | ||
|
||
cmd_mgr_inst = cmdmgr.CommandManager(ap) | ||
await cmd_mgr_inst.initialize() | ||
ap.cmd_mgr = cmd_mgr_inst | ||
|
||
llm_model_mgr_inst = llm_model_mgr.ModelManager(ap) | ||
await llm_model_mgr_inst.initialize() | ||
ap.model_mgr = llm_model_mgr_inst | ||
|
||
llm_session_mgr_inst = llm_session_mgr.SessionManager(ap) | ||
await llm_session_mgr_inst.initialize() | ||
ap.sess_mgr = llm_session_mgr_inst | ||
|
||
llm_prompt_mgr_inst = llm_prompt_mgr.PromptManager(ap) | ||
await llm_prompt_mgr_inst.initialize() | ||
ap.prompt_mgr = llm_prompt_mgr_inst | ||
|
||
llm_tool_mgr_inst = llm_tool_mgr.ToolManager(ap) | ||
await llm_tool_mgr_inst.initialize() | ||
ap.tool_mgr = llm_tool_mgr_inst | ||
|
||
im_mgr_inst = im_mgr.PlatformManager(ap=ap) | ||
await im_mgr_inst.initialize() | ||
ap.im_mgr = im_mgr_inst | ||
|
||
stage_mgr = stagemgr.StageManager(ap) | ||
await stage_mgr.initialize() | ||
ap.stage_mgr = stage_mgr | ||
|
||
ctrl = controller.Controller(ap) | ||
ap.ctrl = ctrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from .. import stage, app | ||
from ..bootutils import config | ||
|
||
|
||
@stage.stage_class("LoadConfigStage") | ||
class LoadConfigStage(stage.BootingStage): | ||
"""加载配置文件阶段 | ||
""" | ||
|
||
async def run(self, ap: app.Application): | ||
"""启动 | ||
""" | ||
ap.command_cfg = await config.load_json_config("data/config/command.json", "templates/command.json") | ||
ap.pipeline_cfg = await config.load_json_config("data/config/pipeline.json", "templates/pipeline.json") | ||
ap.platform_cfg = await config.load_json_config("data/config/platform.json", "templates/platform.json") | ||
ap.provider_cfg = await config.load_json_config("data/config/provider.json", "templates/provider.json") | ||
ap.system_cfg = await config.load_json_config("data/config/system.json", "templates/system.json") |
Oops, something went wrong.