feat:表达方式可简化
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
from src.config.legacy_migration import try_migrate_legacy_bot_config_dict
|
||||
|
||||
|
||||
def test_legacy_empty_qq_account_is_migrated_to_zero():
|
||||
payload = {"bot": {"qq_account": ""}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "bot.qq_account_empty" in result.reason
|
||||
assert result.data["bot"]["qq_account"] == 0
|
||||
|
||||
|
||||
def test_legacy_learning_list_with_numeric_fourth_column_is_migrated():
|
||||
payload = {
|
||||
"expression": {
|
||||
"learning_list": [
|
||||
["qq:123456:group", "enable", "disable", "0.5"],
|
||||
["", "disable", "enable", "0.1"],
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "expression.learning_list" in result.reason
|
||||
assert result.data["expression"]["learning_list"] == [
|
||||
{
|
||||
"platform": "qq",
|
||||
"item_id": "123456",
|
||||
"rule_type": "group",
|
||||
"use_expression": True,
|
||||
"enable_learning": False,
|
||||
"enable_jargon_learning": False,
|
||||
},
|
||||
{
|
||||
"platform": "",
|
||||
"item_id": "",
|
||||
"rule_type": "group",
|
||||
"use_expression": False,
|
||||
"enable_learning": True,
|
||||
"enable_jargon_learning": False,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_legacy_learning_list_with_string_bool_fourth_column_is_migrated():
|
||||
payload = {"expression": {"learning_list": [["qq::group", "enable", "enable", "true"]]}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "expression.learning_list" in result.reason
|
||||
assert result.data["expression"]["learning_list"] == [
|
||||
{
|
||||
"platform": "qq",
|
||||
"item_id": "",
|
||||
"rule_type": "group",
|
||||
"use_expression": True,
|
||||
"enable_learning": True,
|
||||
"enable_jargon_learning": True,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_legacy_expression_groups_empty_string_is_migrated():
|
||||
payload = {"expression": {"expression_groups": ""}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "expression.expression_groups" in result.reason
|
||||
assert result.data["expression"]["expression_groups"] == []
|
||||
|
||||
|
||||
def test_legacy_expression_groups_global_marker_is_migrated():
|
||||
payload = {"expression": {"expression_groups": [["*"]]}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "expression.expression_groups" in result.reason
|
||||
assert result.data["expression"]["expression_groups"] == [
|
||||
{
|
||||
"expression_groups": [
|
||||
{
|
||||
"platform": "*",
|
||||
"item_id": "*",
|
||||
"rule_type": "group",
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_empty_keyword_rules_are_dropped():
|
||||
payload = {
|
||||
"keyword_reaction": {
|
||||
"keyword_rules": [
|
||||
{"keywords": [], "reaction": ""},
|
||||
{"keywords": ["test"], "reaction": "ok"},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "keyword_reaction.keyword_rules_empty" in result.reason
|
||||
assert result.data["keyword_reaction"]["keyword_rules"] == [{"keywords": ["test"], "reaction": "ok"}]
|
||||
|
||||
|
||||
def test_visual_multimodal_planner_is_migrated_to_planner_mode():
|
||||
payload = {"visual": {"multimodal_planner": True}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "visual.multimodal_planner_moved_to_visual.planner_mode" in result.reason
|
||||
assert result.data["visual"]["planner_mode"] == "multimodal"
|
||||
assert "multimodal_planner" not in result.data["visual"]
|
||||
|
||||
|
||||
def test_chat_multimodal_planner_is_migrated_to_visual_planner_mode():
|
||||
payload = {"chat": {"multimodal_planner": True}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "chat.multimodal_planner_moved_to_visual.planner_mode" in result.reason
|
||||
assert result.data["visual"]["planner_mode"] == "multimodal"
|
||||
assert "multimodal_planner" not in result.data["chat"]
|
||||
|
||||
|
||||
def test_visual_multimodal_replyer_is_migrated_to_replyer_mode():
|
||||
payload = {"visual": {"multimodal_replyer": True}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "visual.multimodal_replyer_moved_to_visual.replyer_mode" in result.reason
|
||||
assert result.data["visual"]["replyer_mode"] == "multimodal"
|
||||
assert "multimodal_replyer" not in result.data["visual"]
|
||||
|
||||
|
||||
def test_chat_replyer_generator_type_is_migrated_to_replyer_mode():
|
||||
payload = {"chat": {"replyer_generator_type": "legacy"}}
|
||||
|
||||
result = try_migrate_legacy_bot_config_dict(payload)
|
||||
|
||||
assert result.migrated is True
|
||||
assert "chat.replyer_generator_type_moved_to_visual.replyer_mode" in result.reason
|
||||
assert result.data["visual"]["replyer_mode"] == "text"
|
||||
assert "replyer_generator_type" not in result.data["chat"]
|
||||
@@ -41,13 +41,6 @@ class MaisakaExpressionSelector:
|
||||
logger.error(f"检查表达方式使用开关失败: {exc}")
|
||||
return False
|
||||
|
||||
def _can_use_advanced_chosen(self, session_id: str) -> bool:
|
||||
try:
|
||||
return ExpressionConfigUtils.get_expression_advanced_chosen_for_chat(session_id)
|
||||
except Exception as exc:
|
||||
logger.error(f"检查表达方式二次选择开关失败: {exc}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _is_global_expression_group_marker(platform: str, item_id: str) -> bool:
|
||||
return platform == "*" and item_id == "*"
|
||||
@@ -287,7 +280,7 @@ class MaisakaExpressionSelector:
|
||||
logger.info(f"表达方式选择已跳过:本地候选不足,session_id={session_id}")
|
||||
return MaisakaExpressionSelectionResult()
|
||||
|
||||
if not self._can_use_advanced_chosen(session_id):
|
||||
if not global_config.expression.advanced_chosen:
|
||||
return self._build_direct_selection_result(
|
||||
session_id=session_id,
|
||||
candidates=candidates,
|
||||
|
||||
@@ -35,14 +35,6 @@ class TempMethodsExpression:
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_expression_advanced_chosen_for_chat(chat_stream_id: Optional[str] = None) -> bool:
|
||||
"""根据聊天流 ID 获取表达方式是否启用二次选择。"""
|
||||
config_item = TempMethodsExpression._find_expression_config_item(chat_stream_id)
|
||||
if config_item is None:
|
||||
return False
|
||||
return config_item.advanced_chosen
|
||||
|
||||
@staticmethod
|
||||
def get_expression_config_for_chat(chat_stream_id: Optional[str] = None) -> tuple[bool, bool, bool]:
|
||||
"""
|
||||
|
||||
@@ -35,14 +35,6 @@ class ExpressionConfigUtils:
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_expression_advanced_chosen_for_chat(session_id: Optional[str] = None) -> bool:
|
||||
"""根据聊天会话 ID 获取表达方式是否启用二次选择。"""
|
||||
config_item = ExpressionConfigUtils._find_expression_config_item(session_id)
|
||||
if config_item is None:
|
||||
return False
|
||||
return config_item.advanced_chosen
|
||||
|
||||
@staticmethod
|
||||
def get_expression_config_for_chat(session_id: Optional[str] = None) -> tuple[bool, bool, bool]:
|
||||
# sourcery skip: use-next
|
||||
|
||||
@@ -55,7 +55,7 @@ BOT_CONFIG_PATH: Path = (CONFIG_DIR / "bot_config.toml").resolve().absolute()
|
||||
MODEL_CONFIG_PATH: Path = (CONFIG_DIR / "model_config.toml").resolve().absolute()
|
||||
LEGACY_ENV_PATH: Path = (PROJECT_ROOT / ".env").resolve().absolute()
|
||||
MMC_VERSION: str = "1.0.0"
|
||||
CONFIG_VERSION: str = "8.9.5"
|
||||
CONFIG_VERSION: str = "8.9.6"
|
||||
MODEL_CONFIG_VERSION: str = "1.14.1"
|
||||
|
||||
logger = get_logger("config")
|
||||
|
||||
@@ -676,16 +676,6 @@ class LearningItem(ConfigBase):
|
||||
)
|
||||
"""是否启用jargon学习"""
|
||||
|
||||
advanced_chosen: bool = Field(
|
||||
default=False,
|
||||
json_schema_extra={
|
||||
"x-widget": "switch",
|
||||
"x-icon": "sparkles",
|
||||
},
|
||||
)
|
||||
"""是否启用基于子代理的二次表达方式选择"""
|
||||
|
||||
|
||||
class ExpressionGroup(ConfigBase):
|
||||
"""表达互通组配置类,若列表为空代表全局共享"""
|
||||
|
||||
@@ -714,7 +704,6 @@ class ExpressionConfig(ConfigBase):
|
||||
use_expression=True,
|
||||
enable_learning=True,
|
||||
enable_jargon_learning=True,
|
||||
advanced_chosen=False,
|
||||
)
|
||||
],
|
||||
json_schema_extra={
|
||||
@@ -724,6 +713,15 @@ class ExpressionConfig(ConfigBase):
|
||||
)
|
||||
"""_wrap_表达学习配置列表,支持按聊天流配置"""
|
||||
|
||||
advanced_chosen: bool = Field(
|
||||
default=False,
|
||||
json_schema_extra={
|
||||
"x-widget": "switch",
|
||||
"x-icon": "sparkles",
|
||||
},
|
||||
)
|
||||
"""是否启用基于子代理的二次表达方式选择"""
|
||||
|
||||
expression_groups: list[ExpressionGroup] = Field(
|
||||
default_factory=list,
|
||||
json_schema_extra={
|
||||
|
||||
Reference in New Issue
Block a user