在能量值上面动了点手脚,现在你可以在config里面重新配置群聊里面的聊天模式了
This commit is contained in:
@@ -118,6 +118,18 @@ class HeartFChatting:
|
||||
|
||||
self.energy_value = 5
|
||||
|
||||
# 根据配置初始化聊天模式和能量值
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
if is_group_chat and global_config.chat.group_chat_mode != "auto":
|
||||
if global_config.chat.group_chat_mode == "focus":
|
||||
self.loop_mode = ChatMode.FOCUS
|
||||
self.energy_value = 35
|
||||
logger.info(f"{self.log_prefix} 群聊强制专注模式已启用,能量值设置为35")
|
||||
elif global_config.chat.group_chat_mode == "normal":
|
||||
self.loop_mode = ChatMode.NORMAL
|
||||
self.energy_value = 15
|
||||
logger.info(f"{self.log_prefix} 群聊强制普通模式已启用,能量值设置为15")
|
||||
|
||||
self.focus_energy = 1
|
||||
self.no_reply_consecutive = 0
|
||||
|
||||
@@ -207,6 +219,20 @@ class HeartFChatting:
|
||||
async def _energy_loop(self):
|
||||
while self.running:
|
||||
await asyncio.sleep(10)
|
||||
|
||||
# 检查是否为群聊且配置了强制模式
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
if is_group_chat and global_config.chat.group_chat_mode != "auto":
|
||||
# 强制模式下固定能量值和聊天模式
|
||||
if global_config.chat.group_chat_mode == "focus":
|
||||
self.loop_mode = ChatMode.FOCUS
|
||||
self.energy_value = 35 # 强制设置为35
|
||||
elif global_config.chat.group_chat_mode == "normal":
|
||||
self.loop_mode = ChatMode.NORMAL
|
||||
self.energy_value = 15 # 强制设置为15
|
||||
continue # 跳过正常的能量值衰减逻辑
|
||||
|
||||
# 原有的自动模式逻辑
|
||||
if self.loop_mode == ChatMode.NORMAL:
|
||||
self.energy_value -= 0.3
|
||||
self.energy_value = max(self.energy_value, 0.3)
|
||||
@@ -323,26 +349,38 @@ class HeartFChatting:
|
||||
|
||||
if self.last_action == "no_reply":
|
||||
if not await self._execute_no_reply(recent_messages_dict):
|
||||
self.energy_value -= 0.3 / global_config.chat.focus_value
|
||||
self._log_energy_change("能量值减少")
|
||||
# 在强制模式下,能量值不会随时间减少
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
if not (is_group_chat and global_config.chat.group_chat_mode != "auto"):
|
||||
self.energy_value -= 0.3 / global_config.chat.focus_value
|
||||
self._log_energy_change("能量值减少")
|
||||
await asyncio.sleep(0.5)
|
||||
return True
|
||||
|
||||
self.last_read_time = time.time()
|
||||
|
||||
if await self._observe():
|
||||
self.energy_value += 1 / global_config.chat.focus_value
|
||||
self._log_energy_change("能量值增加")
|
||||
# 在强制模式下,能量值不会因观察而增加
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
if not (is_group_chat and global_config.chat.group_chat_mode != "auto"):
|
||||
self.energy_value += 1 / global_config.chat.focus_value
|
||||
self._log_energy_change("能量值增加")
|
||||
|
||||
# 检查是否应该退出专注模式
|
||||
# 如果开启了强制私聊专注模式且当前为私聊,则不允许退出专注状态
|
||||
is_private_chat = self.chat_stream.group_info is None
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
|
||||
if global_config.chat.force_focus_private and is_private_chat:
|
||||
# 强制私聊专注模式下,保持专注状态,但重置能量值防止过低
|
||||
if self.energy_value <= 1:
|
||||
self.energy_value = 5 # 重置为较低但足够的能量值
|
||||
return True
|
||||
|
||||
# 群聊强制专注模式下,不允许退出专注状态
|
||||
if is_group_chat and global_config.chat.group_chat_mode == "focus":
|
||||
return True
|
||||
|
||||
if self.energy_value <= 1:
|
||||
self.energy_value = 1
|
||||
self.loop_mode = ChatMode.NORMAL
|
||||
@@ -352,12 +390,18 @@ class HeartFChatting:
|
||||
elif self.loop_mode == ChatMode.NORMAL:
|
||||
# 检查是否应该强制进入专注模式(私聊且开启强制专注)
|
||||
is_private_chat = self.chat_stream.group_info is None
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
|
||||
if global_config.chat.force_focus_private and is_private_chat:
|
||||
self.loop_mode = ChatMode.FOCUS
|
||||
self.energy_value = 10 # 设置初始能量值
|
||||
return True
|
||||
|
||||
if global_config.chat.focus_value != 0:
|
||||
# 群聊强制普通模式下,不允许进入专注状态
|
||||
if is_group_chat and global_config.chat.group_chat_mode == "normal":
|
||||
# 在强制普通模式下,即使满足条件也不进入专注模式
|
||||
pass
|
||||
elif global_config.chat.focus_value != 0:
|
||||
if new_message_count > 3 / pow(global_config.chat.focus_value, 0.5):
|
||||
self.loop_mode = ChatMode.FOCUS
|
||||
self.energy_value = (
|
||||
@@ -374,7 +418,13 @@ class HeartFChatting:
|
||||
self.last_read_time = earliest_messages_data.get("time")
|
||||
|
||||
if_think = await self.normal_response(earliest_messages_data)
|
||||
if if_think:
|
||||
|
||||
# 在强制模式下,能量值变化逻辑需要特殊处理
|
||||
is_group_chat = self.chat_stream.group_info is not None
|
||||
if is_group_chat and global_config.chat.group_chat_mode != "auto":
|
||||
# 强制模式下不改变能量值
|
||||
pass
|
||||
elif if_think:
|
||||
factor = max(global_config.chat.focus_value, 0.1)
|
||||
self.energy_value *= 1.1 * factor
|
||||
self._log_energy_change("进行了思考,能量值按倍数增加")
|
||||
|
||||
@@ -182,6 +182,9 @@ class ChatConfig(ConfigBase):
|
||||
force_focus_private: bool = False
|
||||
"""是否强制私聊进入专注模式,开启后私聊将始终保持专注状态"""
|
||||
|
||||
group_chat_mode: Literal["auto", "normal", "focus"] = "auto"
|
||||
"""群聊聊天模式设置:auto-自动切换,normal-强制普通模式,focus-强制专注模式"""
|
||||
|
||||
def get_current_talk_frequency(self, chat_stream_id: Optional[str] = None) -> float:
|
||||
"""
|
||||
根据当前时间和聊天流获取对应的 talk_frequency
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "6.2.8"
|
||||
version = "6.2.9"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||
#如果你想要修改配置文件,请递增version的值
|
||||
@@ -97,6 +97,9 @@ talk_frequency = 1 # 麦麦活跃度,越高,麦麦回复越频繁
|
||||
# 强制私聊专注模式
|
||||
force_focus_private = false # 是否强制私聊进入专注模式,开启后私聊将始终保持专注状态
|
||||
|
||||
# 群聊聊天模式设置
|
||||
group_chat_mode = "auto" # 群聊聊天模式:auto-自动切换,normal-强制普通模式,focus-强制专注模式
|
||||
|
||||
max_context_size = 25 # 上下文长度
|
||||
thinking_timeout = 40 # 麦麦一次回复最长思考规划时间,超过这个时间的思考会放弃(往往是api反应太慢)
|
||||
replyer_random_probability = 0.5 # 首要replyer模型被选择的概率
|
||||
|
||||
Reference in New Issue
Block a user