From 8de950df2e0c41f1565947d794822303c4785717 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Mon, 27 Apr 2026 11:18:38 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=A7=81=E8=81=8A=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87=E5=92=8C=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E9=A2=91=E7=8E=87=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/utils_config.py | 29 +++++++++++++++++++++++++++-- src/config/config.py | 2 +- src/config/official_configs.py | 21 +++++++++++++++++++++ src/maisaka/runtime.py | 17 +++++++++++++++-- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/common/utils/utils_config.py b/src/common/utils/utils_config.py index 7078c0d3..565f0073 100644 --- a/src/common/utils/utils_config.py +++ b/src/common/utils/utils_config.py @@ -85,8 +85,31 @@ class ExpressionConfigUtils: class ChatConfigUtils: @staticmethod - def get_talk_value(session_id: Optional[str]) -> float: - result = global_config.chat.talk_value or 0.0 + def _resolve_is_group_chat(session_id: Optional[str]) -> Optional[bool]: + if not session_id: + return None + + try: + from src.chat.message_receive.chat_manager import chat_manager + + chat_stream = chat_manager.get_session_by_session_id(session_id) + except Exception as e: + logger.debug(f"解析聊天流类型失败: session_id={session_id} error={e}") + return None + if chat_stream is None: + return None + return bool(chat_stream.is_group_session) + + @staticmethod + def get_talk_value(session_id: Optional[str], is_group_chat: Optional[bool] = None) -> float: + if is_group_chat is None: + is_group_chat = ChatConfigUtils._resolve_is_group_chat(session_id) + + result = ( + global_config.chat.talk_value + if is_group_chat is not False + else global_config.chat.private_talk_value + ) or 0.0 if not global_config.chat.enable_talk_value_rules or not global_config.chat.talk_value_rules: return result local_time = time.localtime() @@ -121,6 +144,8 @@ class ChatConfigUtils: for rule in global_config.chat.talk_value_rules: if rule.platform or rule.item_id: continue # 只匹配全局规则 + if is_group_chat is not None and (rule.rule_type == "group") != is_group_chat: + continue parsed_range = ChatConfigUtils.parse_range(rule.time) if not parsed_range: continue # 无法解析的时间范围,跳过 diff --git a/src/config/config.py b/src/config/config.py index 0c355731..7a9a6d3a 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -56,7 +56,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.17" +CONFIG_VERSION: str = "8.9.18" MODEL_CONFIG_VERSION: str = "1.14.3" logger = get_logger("config") diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 064afdfc..00c122eb 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -179,6 +179,18 @@ class ChatConfig(ConfigBase): ) """聊天频率,越小越沉默,范围0-1""" + private_talk_value: float = Field( + default=1, + ge=0, + le=1, + json_schema_extra={ + "x-widget": "slider", + "x-icon": "message-circle", + "step": 0.1, + }, + ) + """私聊聊天频率,越小越沉默,范围0-1""" + mentioned_bot_reply: bool = Field( default=False, json_schema_extra={ @@ -218,6 +230,15 @@ class ChatConfig(ConfigBase): ) """上下文长度""" + max_private_context_size: int = Field( + default=40, + json_schema_extra={ + "x-widget": "input", + "x-icon": "layers", + }, + ) + """私聊上下文长度""" + planner_interrupt_max_consecutive_count: int = Field( default=2, ge=0, diff --git a/src/maisaka/runtime.py b/src/maisaka/runtime.py index 0828a86e..dac80958 100644 --- a/src/maisaka/runtime.py +++ b/src/maisaka/runtime.py @@ -103,7 +103,12 @@ class MaisakaHeartFlowChatting: self._recent_reply_latencies: deque[tuple[float, float]] = deque() self._wait_timeout_task: Optional[asyncio.Task[None]] = None self._max_internal_rounds = MAX_INTERNAL_ROUNDS - self._max_context_size = max(1, int(global_config.chat.max_context_size)) + configured_context_size = ( + global_config.chat.max_context_size + if self.chat_stream.is_group_session + else global_config.chat.max_private_context_size + ) + self._max_context_size = max(1, int(configured_context_size)) self._agent_state: Literal["running", "wait", "stop"] = self._STATE_STOP self._pending_wait_tool_call_id: Optional[str] = None self._force_next_timing_continue = False @@ -293,7 +298,15 @@ class MaisakaHeartFlowChatting: def _get_effective_reply_frequency(self) -> float: """返回当前会话生效的回复频率。""" - talk_value = max(0.01, float(ChatConfigUtils.get_talk_value(self.session_id))) + talk_value = max( + 0.01, + float( + ChatConfigUtils.get_talk_value( + self.session_id, + is_group_chat=self.chat_stream.is_group_session, + ) + ), + ) return max(0.01, talk_value * self._talk_frequency_adjust) async def track_reply_effect(