mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-11 16:26:02 +00:00
refactor: 配置文件均改为json
This commit is contained in:
@@ -31,9 +31,15 @@ class Application:
|
||||
|
||||
tool_mgr: llm_tool_mgr.ToolManager = None
|
||||
|
||||
cfg_mgr: config_mgr.ConfigManager = None
|
||||
command_cfg: config_mgr.ConfigManager = None
|
||||
|
||||
tips_mgr: config_mgr.ConfigManager = None
|
||||
pipeline_cfg: config_mgr.ConfigManager = None
|
||||
|
||||
platform_cfg: config_mgr.ConfigManager = None
|
||||
|
||||
provider_cfg: config_mgr.ConfigManager = None
|
||||
|
||||
system_cfg: config_mgr.ConfigManager = None
|
||||
|
||||
ctr_mgr: center_mgr.V2CenterAPI = None
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ async def make_app() -> app.Application:
|
||||
generated_files = await files.generate_files()
|
||||
|
||||
if generated_files:
|
||||
print("以下文件不存在,已自动生成,请修改配置文件后重启:")
|
||||
print("以下文件不存在,已自动生成,请按需修改配置文件后重启:")
|
||||
for file in generated_files:
|
||||
print("-", file)
|
||||
|
||||
@@ -52,31 +52,23 @@ async def make_app() -> app.Application:
|
||||
# 生成标识符
|
||||
identifier.init()
|
||||
|
||||
cfg_mgr = await config.load_python_module_config("config.py", "config-template.py")
|
||||
cfg = cfg_mgr.data
|
||||
# ========== 加载配置文件 ==========
|
||||
|
||||
# 检查是否携带了 --override 或 -r 参数
|
||||
if "--override" in sys.argv or "-r" in sys.argv:
|
||||
use_override = True
|
||||
command_cfg = await config.load_json_config("data/config/command.json", "templates/command.json")
|
||||
pipeline_cfg = await config.load_json_config("data/config/pipeline.json", "templates/pipeline.json")
|
||||
platform_cfg = await config.load_json_config("data/config/platform.json", "templates/platform.json")
|
||||
provider_cfg = await config.load_json_config("data/config/provider.json", "templates/provider.json")
|
||||
system_cfg = await config.load_json_config("data/config/system.json", "templates/system.json")
|
||||
|
||||
if use_override:
|
||||
overrided = await config.override_config_manager(cfg_mgr)
|
||||
if overrided:
|
||||
qcg_logger.info("以下配置项已使用 override.json 覆盖:" + ",".join(overrided))
|
||||
|
||||
tips_mgr = await config.load_python_module_config(
|
||||
"tips.py", "tips-custom-template.py"
|
||||
)
|
||||
|
||||
# 检查管理员QQ号
|
||||
if cfg_mgr.data["admin_qq"] == 0:
|
||||
qcg_logger.warning("未设置管理员QQ号,将无法使用管理员命令,请在 config.py 中修改 admin_qq")
|
||||
|
||||
# 构建组建实例
|
||||
# ========== 构建应用实例 ==========
|
||||
ap = app.Application()
|
||||
ap.logger = qcg_logger
|
||||
ap.cfg_mgr = cfg_mgr
|
||||
ap.tips_mgr = tips_mgr
|
||||
|
||||
ap.command_cfg = command_cfg
|
||||
ap.pipeline_cfg = pipeline_cfg
|
||||
ap.platform_cfg = platform_cfg
|
||||
ap.provider_cfg = provider_cfg
|
||||
ap.system_cfg = system_cfg
|
||||
|
||||
proxy_mgr = proxy.ProxyManager(ap)
|
||||
await proxy_mgr.initialize()
|
||||
@@ -95,8 +87,8 @@ async def make_app() -> app.Application:
|
||||
"platform": sys.platform,
|
||||
},
|
||||
runtime_info={
|
||||
"admin_id": "{}".format(cfg["admin_qq"]),
|
||||
"msg_source": cfg["msg_source_adapter"],
|
||||
"admin_id": "{}".format(system_cfg.data["admin-sessions"]),
|
||||
"msg_source": platform_cfg.data["platform-adapter"],
|
||||
},
|
||||
)
|
||||
ap.ctr_mgr = center_v2_api
|
||||
|
||||
@@ -6,19 +6,25 @@ import sys
|
||||
|
||||
|
||||
required_files = {
|
||||
"config.py": "config-template.py",
|
||||
"banlist.py": "banlist-template.py",
|
||||
"tips.py": "tips-custom-template.py",
|
||||
"sensitive.json": "res/templates/sensitive-template.json",
|
||||
"scenario/default.json": "scenario/default-template.json",
|
||||
"cmdpriv.json": "res/templates/cmdpriv-template.json",
|
||||
"plugins/__init__.py": "templates/__init__.py",
|
||||
"plugins/plugins.json": "templates/plugin-settings.json",
|
||||
"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/sensitive-words.json": "templates/sensitive-words.json",
|
||||
"data/scenario/default.json": "templates/scenario-template.json",
|
||||
}
|
||||
|
||||
required_paths = [
|
||||
"plugins",
|
||||
"prompts",
|
||||
"temp",
|
||||
"logs"
|
||||
"data",
|
||||
"data/prompts",
|
||||
"data/scenario",
|
||||
"data/logs",
|
||||
"data/config",
|
||||
"plugins"
|
||||
]
|
||||
|
||||
async def generate_files() -> list[str]:
|
||||
|
||||
@@ -21,7 +21,7 @@ async def init_logging() -> logging.Logger:
|
||||
if "DEBUG" in os.environ and os.environ["DEBUG"] in ["true", "1"]:
|
||||
level = logging.DEBUG
|
||||
|
||||
log_file_name = "logs/qcg-%s.log" % time.strftime(
|
||||
log_file_name = "data/logs/qcg-%s.log" % time.strftime(
|
||||
"%Y-%m-%d-%H-%M-%S", time.localtime()
|
||||
)
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ from . import app, entities
|
||||
from ..pipeline import entities as pipeline_entities
|
||||
from ..plugin import events
|
||||
|
||||
DEFAULT_QUERY_CONCURRENCY = 10
|
||||
|
||||
|
||||
class Controller:
|
||||
"""总控制器
|
||||
@@ -21,7 +19,7 @@ class Controller:
|
||||
|
||||
def __init__(self, ap: app.Application):
|
||||
self.ap = ap
|
||||
self.semaphore = asyncio.Semaphore(DEFAULT_QUERY_CONCURRENCY)
|
||||
self.semaphore = asyncio.Semaphore(self.ap.system_cfg.data['pipeline-concurrency'])
|
||||
|
||||
async def consumer(self):
|
||||
"""事件处理循环
|
||||
@@ -150,9 +148,9 @@ class Controller:
|
||||
try:
|
||||
await self._execute_from_stage(0, query)
|
||||
except Exception as e:
|
||||
self.ap.logger.error(f"处理请求时出错 {query}: {e}")
|
||||
# self.ap.logger.debug(f"处理请求时出错 {query}: {e}", exc_info=True)
|
||||
traceback.print_exc()
|
||||
self.ap.logger.error(f"处理请求时出错 query_id={query.query_id}: {e}")
|
||||
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||
# traceback.print_exc()
|
||||
finally:
|
||||
self.ap.logger.debug(f"Query {query} processed")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user