feat: 内容函数全局开关支持

This commit is contained in:
RockChinQ
2023-07-29 16:28:18 +08:00
parent ae6994e241
commit 8c69b8a1d9
6 changed files with 48 additions and 163 deletions

View File

@@ -44,6 +44,9 @@ __plugins__ = {}
__plugins_order__ = []
"""插件顺序"""
__enable_content_functions__ = True
"""是否启用内容函数"""
__callable_functions__ = []
"""供GPT调用的函数结构"""

View File

@@ -8,7 +8,10 @@ import logging
def wrapper_dict_from_runtime_context() -> dict:
"""从变量中包装settings.json的数据字典"""
settings = {
"order": []
"order": [],
"functions": {
"enable": host.__enable_content_functions__
}
}
for plugin_name in host.__plugins_order__:
@@ -22,6 +25,11 @@ def apply_settings(settings: dict):
if "order" in settings:
host.__plugins_order__ = settings["order"]
if "functions" in settings:
if "enable" in settings["functions"]:
host.__enable_content_functions__ = settings["functions"]["enable"]
# logging.debug("set content function enable: {}".format(host.__enable_content_functions__))
def dump_settings():
"""保存settings.json数据"""
@@ -78,6 +86,17 @@ def load_settings():
settings["order"].append(plugin_name)
settings_modified = True
if "functions" not in settings:
settings["functions"] = {
"enable": host.__enable_content_functions__
}
settings_modified = True
elif "enable" not in settings["functions"]:
settings["functions"]["enable"] = host.__enable_content_functions__
settings_modified = True
logging.info("已全局{}内容函数。".format("启用" if settings["functions"]["enable"] else "禁用"))
apply_settings(settings)
if settings_modified: