feat:私聊单独的上下文和回复频率控制
This commit is contained in:
@@ -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 # 无法解析的时间范围,跳过
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user