mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
refactor: remove legacy config files (#1294)
This commit is contained in:
committed by
GitHub
parent
edc7f81486
commit
c8f331675c
@@ -8,12 +8,11 @@ import enum
|
||||
import sys
|
||||
import os
|
||||
|
||||
from ..platform import manager as im_mgr
|
||||
from ..platform import botmgr as im_mgr
|
||||
from ..provider.session import sessionmgr as llm_session_mgr
|
||||
from ..provider.modelmgr import modelmgr as llm_model_mgr
|
||||
from ..provider.tools import toolmgr as llm_tool_mgr
|
||||
from ..config import manager as config_mgr
|
||||
from ..config import settings as settings_mgr
|
||||
from ..audit.center import v2 as center_mgr
|
||||
from ..command import cmdmgr
|
||||
from ..plugin import manager as plugin_mgr
|
||||
@@ -54,26 +53,24 @@ class Application:
|
||||
# TODO 移动到 pipeline 里
|
||||
tool_mgr: llm_tool_mgr.ToolManager = None
|
||||
|
||||
settings_mgr: settings_mgr.SettingsManager = None
|
||||
|
||||
# ======= 配置管理器 =======
|
||||
|
||||
command_cfg: config_mgr.ConfigManager = None
|
||||
command_cfg: config_mgr.ConfigManager = None # deprecated
|
||||
|
||||
pipeline_cfg: config_mgr.ConfigManager = None
|
||||
pipeline_cfg: config_mgr.ConfigManager = None # deprecated
|
||||
|
||||
platform_cfg: config_mgr.ConfigManager = None
|
||||
platform_cfg: config_mgr.ConfigManager = None # deprecated
|
||||
|
||||
provider_cfg: config_mgr.ConfigManager = None
|
||||
provider_cfg: config_mgr.ConfigManager = None # deprecated
|
||||
|
||||
system_cfg: config_mgr.ConfigManager = None
|
||||
system_cfg: config_mgr.ConfigManager = None # deprecated
|
||||
|
||||
instance_config: config_mgr.ConfigManager = None
|
||||
|
||||
# ======= 元数据配置管理器 =======
|
||||
|
||||
sensitive_meta: config_mgr.ConfigManager = None
|
||||
|
||||
llm_models_meta: config_mgr.ConfigManager = None
|
||||
|
||||
instance_secret_meta: config_mgr.ConfigManager = None
|
||||
|
||||
pipeline_config_meta_trigger: config_mgr.ConfigManager = None
|
||||
@@ -156,7 +153,7 @@ class Application:
|
||||
|
||||
public_ip = await ip.get_myip()
|
||||
|
||||
port = self.system_cfg.data['http-api']['port']
|
||||
port = self.instance_config.data['api']['port']
|
||||
|
||||
tips = f"""
|
||||
=======================================
|
||||
|
||||
@@ -10,12 +10,13 @@ from . import stage
|
||||
from ..utils import constants
|
||||
|
||||
# 引入启动阶段实现以便注册
|
||||
from .stages import load_config, setup_logger, build_app, migrate, show_notes
|
||||
from .stages import load_config, setup_logger, build_app, migrate, show_notes, genkeys
|
||||
|
||||
|
||||
stage_order = [
|
||||
"LoadConfigStage",
|
||||
"MigrationStage",
|
||||
"GenKeysStage",
|
||||
"SetupLoggerStage",
|
||||
"BuildAppStage",
|
||||
"ShowNotesStage"
|
||||
|
||||
@@ -7,11 +7,7 @@ import sys
|
||||
|
||||
required_files = {
|
||||
"plugins/__init__.py": "templates/__init__.py",
|
||||
"data/config/command.json": "templates/command.json",
|
||||
"data/config/pipeline.json": "templates/pipeline.json",
|
||||
"data/config/platform.json": "templates/platform.json",
|
||||
"data/config/provider.json": "templates/provider.json",
|
||||
"data/config/system.json": "templates/system.json",
|
||||
"data/config.yaml": "templates/config.yaml",
|
||||
}
|
||||
|
||||
required_paths = [
|
||||
@@ -19,7 +15,6 @@ required_paths = [
|
||||
"data",
|
||||
"data/metadata",
|
||||
"data/logs",
|
||||
"data/config",
|
||||
"data/labels",
|
||||
"plugins"
|
||||
]
|
||||
|
||||
@@ -12,7 +12,7 @@ from ...command import cmdmgr
|
||||
from ...provider.session import sessionmgr as llm_session_mgr
|
||||
from ...provider.modelmgr import modelmgr as llm_model_mgr
|
||||
from ...provider.tools import toolmgr as llm_tool_mgr
|
||||
from ...platform import manager as im_mgr
|
||||
from ...platform import botmgr as im_mgr
|
||||
from ...persistence import mgr as persistencemgr
|
||||
from ...api.http.controller import main as http_controller
|
||||
from ...api.http.service import user as user_service
|
||||
@@ -50,7 +50,7 @@ class BuildAppStage(stage.BootingStage):
|
||||
|
||||
center_v2_api = center_v2.V2CenterAPI(
|
||||
ap,
|
||||
backend_url=ap.system_cfg.data["qcg-center-url"],
|
||||
backend_url=ap.instance_config.data['telemetry']['url'],
|
||||
basic_info={
|
||||
"host_id": identifier.identifier["host_id"],
|
||||
"instance_id": identifier.identifier["instance_id"],
|
||||
@@ -58,7 +58,7 @@ class BuildAppStage(stage.BootingStage):
|
||||
"platform": platform.get_platform(),
|
||||
},
|
||||
runtime_info={
|
||||
"admin_id": "{}".format(ap.system_cfg.data["admin-sessions"]),
|
||||
"admin_id": "{}".format(ap.instance_config.data["admins"]),
|
||||
"msg_source": str([]),
|
||||
},
|
||||
)
|
||||
|
||||
20
pkg/core/stages/genkeys.py
Normal file
20
pkg/core/stages/genkeys.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
import os
|
||||
|
||||
from .. import stage, app
|
||||
|
||||
|
||||
@stage.stage_class("GenKeysStage")
|
||||
class GenKeysStage(stage.BootingStage):
|
||||
"""生成密钥阶段
|
||||
"""
|
||||
|
||||
async def run(self, ap: app.Application):
|
||||
"""启动
|
||||
"""
|
||||
|
||||
if not ap.instance_config.data['system']['jwt']['secret']:
|
||||
ap.instance_config.data['system']['jwt']['secret'] = secrets.token_hex(16)
|
||||
await ap.instance_config.dump_config()
|
||||
@@ -5,7 +5,6 @@ import os
|
||||
|
||||
from .. import stage, app
|
||||
from ..bootutils import config
|
||||
from ...config import settings as settings_mgr
|
||||
|
||||
|
||||
@stage.stage_class("LoadConfigStage")
|
||||
@@ -16,33 +15,36 @@ class LoadConfigStage(stage.BootingStage):
|
||||
async def run(self, ap: app.Application):
|
||||
"""启动
|
||||
"""
|
||||
|
||||
ap.settings_mgr = settings_mgr.SettingsManager(ap)
|
||||
await ap.settings_mgr.initialize()
|
||||
|
||||
# ======= deprecated =======
|
||||
if os.path.exists("data/config/command.json"):
|
||||
ap.command_cfg = await config.load_json_config("data/config/command.json", "templates/command.json", completion=False)
|
||||
ap.command_cfg = await config.load_json_config("data/config/command.json", "templates/legacy/command.json", completion=False)
|
||||
|
||||
if os.path.exists("data/config/pipeline.json"):
|
||||
ap.pipeline_cfg = await config.load_json_config("data/config/pipeline.json", "templates/pipeline.json", completion=False)
|
||||
ap.pipeline_cfg = await config.load_json_config("data/config/pipeline.json", "templates/legacy/pipeline.json", completion=False)
|
||||
|
||||
if os.path.exists("data/config/platform.json"):
|
||||
ap.platform_cfg = await config.load_json_config("data/config/platform.json", "templates/platform.json", completion=False)
|
||||
ap.platform_cfg = await config.load_json_config("data/config/platform.json", "templates/legacy/platform.json", completion=False)
|
||||
|
||||
if os.path.exists("data/config/provider.json"):
|
||||
ap.provider_cfg = await config.load_json_config("data/config/provider.json", "templates/provider.json", completion=False)
|
||||
ap.provider_cfg = await config.load_json_config("data/config/provider.json", "templates/legacy/provider.json", completion=False)
|
||||
|
||||
if os.path.exists("data/config/system.json"):
|
||||
ap.system_cfg = await config.load_json_config("data/config/system.json", "templates/system.json", completion=False)
|
||||
ap.system_cfg = await config.load_json_config("data/config/system.json", "templates/legacy/system.json", completion=False)
|
||||
|
||||
if os.path.exists("data/metadata/instance-secret.json"):
|
||||
ap.instance_secret_meta = await config.load_json_config("data/metadata/instance-secret.json", template_data={
|
||||
'jwt_secret': secrets.token_hex(16)
|
||||
})
|
||||
await ap.instance_secret_meta.dump_config()
|
||||
# ======= deprecated =======
|
||||
|
||||
ap.instance_config = await config.load_yaml_config("data/config.yaml", "templates/config.yaml", completion=False)
|
||||
await ap.instance_config.dump_config()
|
||||
|
||||
ap.sensitive_meta = await config.load_json_config("data/metadata/sensitive-words.json", "templates/metadata/sensitive-words.json")
|
||||
await ap.sensitive_meta.dump_config()
|
||||
|
||||
ap.instance_secret_meta = await config.load_json_config("data/metadata/instance-secret.json", template_data={
|
||||
'jwt_secret': secrets.token_hex(16)
|
||||
})
|
||||
await ap.instance_secret_meta.dump_config()
|
||||
|
||||
ap.pipeline_config_meta_trigger = await config.load_yaml_config("templates/metadata/pipeline/trigger.yaml", "templates/metadata/pipeline/trigger.yaml")
|
||||
ap.pipeline_config_meta_safety = await config.load_yaml_config("templates/metadata/pipeline/safety.yaml", "templates/metadata/pipeline/safety.yaml")
|
||||
ap.pipeline_config_meta_ai = await config.load_yaml_config("templates/metadata/pipeline/ai.yaml", "templates/metadata/pipeline/ai.yaml")
|
||||
|
||||
Reference in New Issue
Block a user