Merge branch 'MaiM-with-u:dev' 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", ""),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from src.plugin_system.base.base_action import BaseAction
|
|||||||
from src.chat.message_receive.chat_stream import ChatStream
|
from src.chat.message_receive.chat_stream import ChatStream
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.plugin_system.core.component_registry import component_registry
|
from src.plugin_system.core.component_registry import component_registry
|
||||||
from src.plugin_system.base.component_types import ComponentType, ActionActivationType, ChatMode, ActionInfo
|
from src.plugin_system.base.component_types import ComponentType, ActionInfo
|
||||||
|
|
||||||
logger = get_logger("action_manager")
|
logger = get_logger("action_manager")
|
||||||
|
|
||||||
@@ -15,11 +15,6 @@ class ActionManager:
|
|||||||
现在统一使用新插件系统,简化了原有的新旧兼容逻辑。
|
现在统一使用新插件系统,简化了原有的新旧兼容逻辑。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 类常量
|
|
||||||
DEFAULT_RANDOM_PROBABILITY = 0.3
|
|
||||||
DEFAULT_MODE = ChatMode.ALL
|
|
||||||
DEFAULT_ACTIVATION_TYPE = ActionActivationType.ALWAYS
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""初始化动作管理器"""
|
"""初始化动作管理器"""
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class ActionModifier:
|
|||||||
continue # 总是激活,无需处理
|
continue # 总是激活,无需处理
|
||||||
|
|
||||||
elif activation_type == ActionActivationType.RANDOM:
|
elif activation_type == ActionActivationType.RANDOM:
|
||||||
probability = action_info.random_activation_probability or ActionManager.DEFAULT_RANDOM_PROBABILITY
|
probability = action_info.random_activation_probability
|
||||||
if random.random() >= probability:
|
if random.random() >= probability:
|
||||||
reason = f"RANDOM类型未触发(概率{probability})"
|
reason = f"RANDOM类型未触发(概率{probability})"
|
||||||
deactivated_actions.append((action_name, reason))
|
deactivated_actions.append((action_name, reason))
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ChatManager:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
def get_all_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
||||||
|
# sourcery skip: for-append-to-extend
|
||||||
"""获取所有聊天流
|
"""获取所有聊天流
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -57,6 +58,7 @@ class ChatManager:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_group_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
def get_group_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
||||||
|
# sourcery skip: for-append-to-extend
|
||||||
"""获取所有群聊聊天流
|
"""获取所有群聊聊天流
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -79,6 +81,7 @@ class ChatManager:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_private_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
def get_private_streams(platform: Optional[str] | SpecialTypes = "qq") -> List[ChatStream]:
|
||||||
|
# sourcery skip: for-append-to-extend
|
||||||
"""获取所有私聊聊天流
|
"""获取所有私聊聊天流
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -105,7 +108,7 @@ class ChatManager:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_group_stream_by_group_id(
|
def get_group_stream_by_group_id(
|
||||||
group_id: str, platform: Optional[str] | SpecialTypes = "qq"
|
group_id: str, platform: Optional[str] | SpecialTypes = "qq"
|
||||||
) -> Optional[ChatStream]:
|
) -> Optional[ChatStream]: # sourcery skip: remove-unnecessary-cast
|
||||||
"""根据群ID获取聊天流
|
"""根据群ID获取聊天流
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -142,7 +145,7 @@ class ChatManager:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_private_stream_by_user_id(
|
def get_private_stream_by_user_id(
|
||||||
user_id: str, platform: Optional[str] | SpecialTypes = "qq"
|
user_id: str, platform: Optional[str] | SpecialTypes = "qq"
|
||||||
) -> Optional[ChatStream]:
|
) -> Optional[ChatStream]: # sourcery skip: remove-unnecessary-cast
|
||||||
"""根据用户ID获取私聊流
|
"""根据用户ID获取私聊流
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ async def generate_reply(
|
|||||||
|
|
||||||
logger.debug("[GeneratorAPI] 开始生成回复")
|
logger.debug("[GeneratorAPI] 开始生成回复")
|
||||||
|
|
||||||
if not reply_to:
|
if not reply_to and action_data:
|
||||||
reply_to = action_data.get("reply_to", "")
|
reply_to = action_data.get("reply_to", "")
|
||||||
if not extra_info and action_data:
|
if not extra_info and action_data:
|
||||||
extra_info = action_data.get("extra_info", "")
|
extra_info = action_data.get("extra_info", "")
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ class BaseAction(ABC):
|
|||||||
keyword_case_sensitive=getattr(cls, "keyword_case_sensitive", False),
|
keyword_case_sensitive=getattr(cls, "keyword_case_sensitive", False),
|
||||||
mode_enable=getattr(cls, "mode_enable", ChatMode.ALL),
|
mode_enable=getattr(cls, "mode_enable", ChatMode.ALL),
|
||||||
parallel_action=getattr(cls, "parallel_action", True),
|
parallel_action=getattr(cls, "parallel_action", True),
|
||||||
random_activation_probability=getattr(cls, "random_activation_probability", 0.3),
|
random_activation_probability=getattr(cls, "random_activation_probability", 0.0),
|
||||||
llm_judge_prompt=getattr(cls, "llm_judge_prompt", ""),
|
llm_judge_prompt=getattr(cls, "llm_judge_prompt", ""),
|
||||||
# 使用正确的字段名
|
# 使用正确的字段名
|
||||||
action_parameters=getattr(cls, "action_parameters", {}).copy(),
|
action_parameters=getattr(cls, "action_parameters", {}).copy(),
|
||||||
|
|||||||
@@ -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