feat: 启用message中的format_info功能
This commit is contained in:
@@ -5,6 +5,8 @@ from src.chat.focus_chat.info.action_info import ActionInfo
|
||||
from .base_processor import BaseProcessor
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.chat.heart_flow.observation.hfcloop_observation import HFCloopObservation
|
||||
from src.chat.heart_flow.observation.chatting_observation import ChattingObservation
|
||||
from src.chat.message_receive.chat_stream import ChatStream, chat_manager
|
||||
from typing import Dict
|
||||
from src.chat.models.utils_model import LLMRequest
|
||||
from src.config.config import global_config
|
||||
@@ -50,10 +52,12 @@ class ActionProcessor(BaseProcessor):
|
||||
|
||||
# 处理Observation对象
|
||||
if observations:
|
||||
action_info = ActionInfo()
|
||||
all_actions = None
|
||||
for obs in observations:
|
||||
if isinstance(obs, HFCloopObservation):
|
||||
# 创建动作信息
|
||||
action_info = ActionInfo()
|
||||
all_actions = obs.all_actions
|
||||
action_changes = await self.analyze_loop_actions(obs)
|
||||
if action_changes["add"] or action_changes["remove"]:
|
||||
action_info.set_action_changes(action_changes)
|
||||
@@ -64,6 +68,26 @@ class ActionProcessor(BaseProcessor):
|
||||
if action_changes["remove"]:
|
||||
reasons.append(f"移除动作{action_changes['remove']}因为检测到连续回复")
|
||||
action_info.set_reason(" | ".join(reasons))
|
||||
if isinstance(obs, ChattingObservation) and all_actions is not None:
|
||||
action_changes = {"add": [], "remove": []}
|
||||
# 检查动作的关联类型
|
||||
chat_context = chat_manager.get_stream(obs.chat_id).context
|
||||
for action_name in all_actions.keys():
|
||||
data = all_actions[action_name]
|
||||
if data.get("associated_types"):
|
||||
if not chat_context.check_types(data["associated_types"]):
|
||||
action_changes["remove"].append(action_name)
|
||||
logger.debug(f"{self.log_prefix} 动作 {action_name} 关联类型不匹配,移除该动作")
|
||||
if len(action_changes["remove"]) > 0:
|
||||
action_info.set_action_changes(action_changes)
|
||||
# 设置变更原因
|
||||
reasons = []
|
||||
if action_info.get_reason():
|
||||
reasons.append(action_info.get_reason())
|
||||
if action_changes["remove"]:
|
||||
reasons.append(f"移除动作{action_changes['remove']}因为关联类型不匹配")
|
||||
action_info.set_reason(" | ".join(reasons))
|
||||
|
||||
processed_infos.append(action_info)
|
||||
|
||||
return processed_infos
|
||||
|
||||
@@ -59,6 +59,7 @@ class ActionManager:
|
||||
action_description: str = getattr(action_class, "action_description", "")
|
||||
action_parameters: dict[str:str] = getattr(action_class, "action_parameters", {})
|
||||
action_require: list[str] = getattr(action_class, "action_require", [])
|
||||
associated_types: list[str] = getattr(action_class, "associated_types", [])
|
||||
is_default: bool = getattr(action_class, "default", False)
|
||||
|
||||
if action_name and action_description:
|
||||
@@ -67,6 +68,7 @@ class ActionManager:
|
||||
"description": action_description,
|
||||
"parameters": action_parameters,
|
||||
"require": action_require,
|
||||
"associated_types": associated_types,
|
||||
}
|
||||
|
||||
# 添加到所有已注册的动作
|
||||
|
||||
@@ -66,6 +66,8 @@ class BaseAction(ABC):
|
||||
self.action_parameters: dict = {}
|
||||
self.action_require: list[str] = []
|
||||
|
||||
self.associated_types: list[str] = []
|
||||
|
||||
self.default: bool = False
|
||||
|
||||
self.action_data = action_data
|
||||
|
||||
@@ -36,6 +36,9 @@ class ReplyAction(BaseAction):
|
||||
"避免重复或评价自己的发言,不要和自己聊天",
|
||||
"注意:回复尽量简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。不要有额外的符号,尽量简单简短",
|
||||
]
|
||||
|
||||
associated_types: list[str] = ["text", "emoji"]
|
||||
|
||||
default = True
|
||||
|
||||
def __init__(
|
||||
|
||||
@@ -38,6 +38,15 @@ class ChatMessageContext:
|
||||
"""获取最后一条消息"""
|
||||
return self.message
|
||||
|
||||
def check_types(self, types: list) -> bool:
|
||||
"""检查消息类型"""
|
||||
if not self.message.message_info.format_info.accept_format:
|
||||
return False
|
||||
for t in types:
|
||||
if t not in self.message.message_info.format_info.accept_format:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class ChatStream:
|
||||
"""聊天流对象,存储一个完整的聊天上下文"""
|
||||
|
||||
@@ -26,6 +26,7 @@ class MuteAction(PluginAction):
|
||||
"当你想回避某个话题时使用",
|
||||
]
|
||||
default = True # 不是默认动作,需要手动添加到使用集
|
||||
associated_types = ["command",'text']
|
||||
|
||||
async def process(self) -> Tuple[bool, str]:
|
||||
"""处理测试动作"""
|
||||
@@ -41,8 +42,8 @@ class MuteAction(PluginAction):
|
||||
|
||||
try:
|
||||
await self.send_message(
|
||||
type="text",
|
||||
data=f"[command]mute,{user_id},{duration}",
|
||||
type="command",
|
||||
data={"name": "GROUP_BAN", "args": {"qq_id": f"{user_id}", "duration": f"{duration}"}},
|
||||
# target = target
|
||||
)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class CheckOnlineAction(PluginAction):
|
||||
"mode参数为type时查看在线系统类型分布",
|
||||
]
|
||||
default = False # 不是默认动作,需要手动添加到使用集
|
||||
associated_types = ["text"]
|
||||
|
||||
async def process(self) -> Tuple[bool, str]:
|
||||
"""处理测试动作"""
|
||||
@@ -30,9 +31,9 @@ class CheckOnlineAction(PluginAction):
|
||||
|
||||
try:
|
||||
if mode == "type":
|
||||
await self.send_message("#online detail")
|
||||
await self.send_message("text", "#online detail")
|
||||
elif mode == "version":
|
||||
await self.send_message("#online")
|
||||
await self.send_message("text", "#online")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 执行online动作时出错: {e}")
|
||||
|
||||
Reference in New Issue
Block a user