Merge branch 'dev' of github.com:MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -283,25 +283,55 @@ class HeartFChatting:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self.log_prefix} 动作修改失败: {e}")
|
logger.error(f"{self.log_prefix} 动作修改失败: {e}")
|
||||||
|
|
||||||
# 如果normal,开始一个回复生成进程,先准备好回复(其实是和planer同时进行的)
|
# 检查是否在normal模式下没有可用动作(除了reply相关动作)
|
||||||
gen_task = None
|
skip_planner = False
|
||||||
reply_to_str = ""
|
|
||||||
if self.loop_mode == ChatMode.NORMAL:
|
if self.loop_mode == ChatMode.NORMAL:
|
||||||
reply_to_str = await self.build_reply_to_str(message_data)
|
# 过滤掉reply相关的动作,检查是否还有其他动作
|
||||||
gen_task = asyncio.create_task(self._generate_response(message_data, available_actions, reply_to_str, "chat.replyer.normal"))
|
non_reply_actions = {k: v for k, v in available_actions.items()
|
||||||
|
if k not in ['reply', 'no_reply', 'no_action']}
|
||||||
|
|
||||||
with Timer("规划器", cycle_timers):
|
if not non_reply_actions:
|
||||||
plan_result, target_message = await self.action_planner.plan(mode=self.loop_mode)
|
skip_planner = True
|
||||||
|
logger.info(f"{self.log_prefix} Normal模式下没有可用动作,直接回复")
|
||||||
|
|
||||||
action_result: dict = plan_result.get("action_result", {}) # type: ignore
|
# 直接设置为reply动作
|
||||||
action_type, action_data, reasoning, is_parallel = (
|
action_type = "reply"
|
||||||
action_result.get("action_type", "error"),
|
reasoning = ""
|
||||||
action_result.get("action_data", {}),
|
action_data = {"loop_start_time": loop_start_time}
|
||||||
action_result.get("reasoning", "未提供理由"),
|
is_parallel = False
|
||||||
action_result.get("is_parallel", True),
|
|
||||||
)
|
|
||||||
|
|
||||||
action_data["loop_start_time"] = loop_start_time
|
# 构建plan_result用于后续处理
|
||||||
|
plan_result = {
|
||||||
|
"action_result": {
|
||||||
|
"action_type": action_type,
|
||||||
|
"action_data": action_data,
|
||||||
|
"reasoning": reasoning,
|
||||||
|
"timestamp": time.time(),
|
||||||
|
"is_parallel": is_parallel,
|
||||||
|
},
|
||||||
|
"action_prompt": "",
|
||||||
|
}
|
||||||
|
target_message = message_data
|
||||||
|
# 如果normal,开始一个回复生成进程,先准备好回复(其实是和planer同时进行的)
|
||||||
|
gen_task = None
|
||||||
|
reply_to_str = ""
|
||||||
|
if self.loop_mode == ChatMode.NORMAL:
|
||||||
|
reply_to_str = await self.build_reply_to_str(message_data)
|
||||||
|
gen_task = asyncio.create_task(self._generate_response(message_data, available_actions, reply_to_str, "chat.replyer.normal"))
|
||||||
|
|
||||||
|
if not skip_planner:
|
||||||
|
with Timer("规划器", cycle_timers):
|
||||||
|
plan_result, target_message = await self.action_planner.plan(mode=self.loop_mode)
|
||||||
|
|
||||||
|
action_result: dict = plan_result.get("action_result", {}) # type: ignore
|
||||||
|
action_type, action_data, reasoning, is_parallel = (
|
||||||
|
action_result.get("action_type", "error"),
|
||||||
|
action_result.get("action_data", {}),
|
||||||
|
action_result.get("reasoning", "未提供理由"),
|
||||||
|
action_result.get("is_parallel", True),
|
||||||
|
)
|
||||||
|
|
||||||
|
action_data["loop_start_time"] = loop_start_time
|
||||||
|
|
||||||
|
|
||||||
if action_type == "reply":
|
if action_type == "reply":
|
||||||
@@ -358,7 +388,7 @@ class HeartFChatting:
|
|||||||
with Timer("回复发送", cycle_timers):
|
with Timer("回复发送", cycle_timers):
|
||||||
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
|
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
|
||||||
|
|
||||||
# 存储reply action信息 (focus模式)
|
# 存储reply action信息
|
||||||
person_info_manager = get_person_info_manager()
|
person_info_manager = get_person_info_manager()
|
||||||
person_id = person_info_manager.get_person_id(
|
person_id = person_info_manager.get_person_id(
|
||||||
action_message.get("chat_info_platform", ""),
|
action_message.get("chat_info_platform", ""),
|
||||||
|
|||||||
@@ -129,20 +129,6 @@ class ActionPlanner:
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"{self.log_prefix}使用中的动作 {action_name} 未在已注册动作中找到")
|
logger.warning(f"{self.log_prefix}使用中的动作 {action_name} 未在已注册动作中找到")
|
||||||
|
|
||||||
# 如果没有可用动作或只有no_reply动作,直接返回no_reply
|
|
||||||
# 因为现在reply是永远激活,所以不需要空跳判定
|
|
||||||
# if not current_available_actions:
|
|
||||||
# action = "no_reply" if mode == ChatMode.FOCUS else "no_action"
|
|
||||||
# reasoning = "没有可用的动作"
|
|
||||||
# logger.info(f"{self.log_prefix}{reasoning}")
|
|
||||||
# return {
|
|
||||||
# "action_result": {
|
|
||||||
# "action_type": action,
|
|
||||||
# "action_data": action_data,
|
|
||||||
# "reasoning": reasoning,
|
|
||||||
# },
|
|
||||||
# }, None
|
|
||||||
|
|
||||||
# --- 构建提示词 (调用修改后的 PromptBuilder 方法) ---
|
# --- 构建提示词 (调用修改后的 PromptBuilder 方法) ---
|
||||||
prompt, message_id_list = await self.build_planner_prompt(
|
prompt, message_id_list = await self.build_planner_prompt(
|
||||||
is_group_chat=is_group_chat, # <-- Pass HFC state
|
is_group_chat=is_group_chat, # <-- Pass HFC state
|
||||||
|
|||||||
@@ -21,10 +21,14 @@ class EmojiAction(BaseAction):
|
|||||||
"""表情动作 - 发送表情包"""
|
"""表情动作 - 发送表情包"""
|
||||||
|
|
||||||
# 激活设置
|
# 激活设置
|
||||||
activation_type = ActionActivationType.RANDOM
|
if global_config.emoji.emoji_activate_type == "llm":
|
||||||
|
activation_type = ActionActivationType.LLM_JUDGE
|
||||||
|
random_activation_probability = 0
|
||||||
|
else:
|
||||||
|
activation_type = ActionActivationType.RANDOM
|
||||||
|
random_activation_probability = global_config.emoji.emoji_chance
|
||||||
mode_enable = ChatMode.ALL
|
mode_enable = ChatMode.ALL
|
||||||
parallel_action = True
|
parallel_action = True
|
||||||
random_activation_probability = 0.2 # 默认值,可通过配置覆盖
|
|
||||||
|
|
||||||
# 动作基本信息
|
# 动作基本信息
|
||||||
action_name = "emoji"
|
action_name = "emoji"
|
||||||
|
|||||||
@@ -62,14 +62,6 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
|
def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
|
||||||
"""返回插件包含的组件列表"""
|
"""返回插件包含的组件列表"""
|
||||||
|
|
||||||
if global_config.emoji.emoji_activate_type == "llm":
|
|
||||||
EmojiAction.random_activation_probability = 0.0
|
|
||||||
EmojiAction.activation_type = ActionActivationType.LLM_JUDGE
|
|
||||||
|
|
||||||
elif global_config.emoji.emoji_activate_type == "random":
|
|
||||||
EmojiAction.random_activation_probability = global_config.emoji.emoji_chance
|
|
||||||
EmojiAction.activation_type = ActionActivationType.RANDOM
|
|
||||||
|
|
||||||
# --- 根据配置注册组件 ---
|
# --- 根据配置注册组件 ---
|
||||||
components = []
|
components = []
|
||||||
if self.get_config("components.enable_no_reply", True):
|
if self.get_config("components.enable_no_reply", True):
|
||||||
@@ -77,6 +69,5 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
if self.get_config("components.enable_emoji", True):
|
if self.get_config("components.enable_emoji", True):
|
||||||
components.append((EmojiAction.get_action_info(), EmojiAction))
|
components.append((EmojiAction.get_action_info(), EmojiAction))
|
||||||
|
|
||||||
# components.append((DeepReplyAction.get_action_info(), DeepReplyAction))
|
|
||||||
|
|
||||||
return components
|
return components
|
||||||
|
|||||||
Reference in New Issue
Block a user