🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -99,7 +99,6 @@ class HeartFCSender:
|
||||
message.build_reply()
|
||||
logger.debug(f"[{chat_id}] 选择回复引用消息: {message.processed_plain_text[:20]}...")
|
||||
|
||||
|
||||
await message.process()
|
||||
|
||||
if typing:
|
||||
@@ -110,7 +109,6 @@ class HeartFCSender:
|
||||
)
|
||||
await asyncio.sleep(typing_time)
|
||||
|
||||
|
||||
sent_msg = await send_message(message)
|
||||
if not sent_msg:
|
||||
return False
|
||||
|
||||
@@ -14,7 +14,7 @@ ActionInfo = Dict[str, Any]
|
||||
class ActionManager:
|
||||
"""
|
||||
动作管理器,用于管理各种类型的动作
|
||||
|
||||
|
||||
现在统一使用新插件系统,简化了原有的新旧兼容逻辑。
|
||||
"""
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ class BasePlanner(ABC):
|
||||
self.action_manager = action_manager
|
||||
|
||||
@abstractmethod
|
||||
async def plan(self, all_plan_info: List[InfoBase], running_memorys: List[Dict[str, Any]], loop_start_time: float) -> Dict[str, Any]:
|
||||
async def plan(
|
||||
self, all_plan_info: List[InfoBase], running_memorys: List[Dict[str, Any]], loop_start_time: float
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
规划下一步行动
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ class ActionModifier:
|
||||
|
||||
for action_name, action_info in actions_with_info.items():
|
||||
activation_type = action_info.get("focus_activation_type", "always")
|
||||
|
||||
|
||||
print(f"action_name: {action_name}, activation_type: {activation_type}")
|
||||
|
||||
# 现在统一是字符串格式的激活类型值
|
||||
|
||||
@@ -82,7 +82,9 @@ class ActionPlanner(BasePlanner):
|
||||
request_type="focus.planner", # 用于动作规划
|
||||
)
|
||||
|
||||
async def plan(self, all_plan_info: List[InfoBase], running_memorys: List[Dict[str, Any]], loop_start_time: float) -> Dict[str, Any]:
|
||||
async def plan(
|
||||
self, all_plan_info: List[InfoBase], running_memorys: List[Dict[str, Any]], loop_start_time: float
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
规划器 (Planner): 使用LLM根据上下文决定做出什么动作。
|
||||
|
||||
@@ -243,7 +245,7 @@ class ActionPlanner(BasePlanner):
|
||||
if selected_expressions:
|
||||
action_data["selected_expressions"] = selected_expressions
|
||||
logger.debug(f"{self.log_prefix} 传递{len(selected_expressions)}个选中的表达方式到action_data")
|
||||
|
||||
|
||||
action_data["loop_start_time"] = loop_start_time
|
||||
|
||||
# 对于reply动作不需要额外处理,因为相关字段已经在上面的循环中添加到action_data
|
||||
|
||||
@@ -71,7 +71,7 @@ def init_prompt():
|
||||
""",
|
||||
"default_generator_private_prompt",
|
||||
)
|
||||
|
||||
|
||||
Prompt(
|
||||
"""
|
||||
你可以参考你的以下的语言习惯,如果情景合适就使用,不要盲目使用,不要生硬使用,而是结合到表达中:
|
||||
@@ -156,7 +156,7 @@ class DefaultReplyer:
|
||||
|
||||
await self.heart_fc_sender.register_thinking(thinking_message)
|
||||
return None
|
||||
|
||||
|
||||
async def generate_reply_with_context(
|
||||
self,
|
||||
reply_data: Dict[str, Any],
|
||||
@@ -166,8 +166,6 @@ class DefaultReplyer:
|
||||
(已整合原 HeartFCGenerator 的功能)
|
||||
"""
|
||||
try:
|
||||
|
||||
|
||||
# 3. 构建 Prompt
|
||||
with Timer("构建Prompt", {}): # 内部计时器,可选保留
|
||||
prompt = await self.build_prompt_reply_context(
|
||||
@@ -206,13 +204,13 @@ class DefaultReplyer:
|
||||
reply_seg = ("text", str)
|
||||
reply_set.append(reply_seg)
|
||||
|
||||
return True , reply_set
|
||||
return True, reply_set
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix}回复生成意外失败: {e}")
|
||||
traceback.print_exc()
|
||||
return False, None
|
||||
|
||||
|
||||
async def rewrite_reply_with_context(
|
||||
self,
|
||||
reply_data: Dict[str, Any],
|
||||
@@ -221,8 +219,6 @@ class DefaultReplyer:
|
||||
表达器 (Expressor): 核心逻辑,负责生成回复文本。
|
||||
"""
|
||||
try:
|
||||
|
||||
|
||||
reply_to = reply_data.get("reply_to", "")
|
||||
raw_reply = reply_data.get("raw_reply", "")
|
||||
reason = reply_data.get("reason", "")
|
||||
@@ -275,24 +271,20 @@ class DefaultReplyer:
|
||||
logger.error(f"{self.log_prefix}回复生成意外失败: {e}")
|
||||
traceback.print_exc()
|
||||
return False, None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async def build_prompt_reply_context(
|
||||
self,
|
||||
reply_data=None,
|
||||
) -> str:
|
||||
chat_stream = self.chat_stream
|
||||
|
||||
|
||||
is_group_chat = bool(chat_stream.group_info)
|
||||
|
||||
|
||||
identity = reply_data.get("identity", "")
|
||||
extra_info_block = reply_data.get("extra_info_block", "")
|
||||
relation_info_block = reply_data.get("relation_info_block", "")
|
||||
reply_to = reply_data.get("reply_to", "none")
|
||||
|
||||
|
||||
sender = ""
|
||||
target = ""
|
||||
if ":" in reply_to or ":" in reply_to:
|
||||
@@ -301,7 +293,6 @@ class DefaultReplyer:
|
||||
if len(parts) == 2:
|
||||
sender = parts[0].strip()
|
||||
target = parts[1].strip()
|
||||
|
||||
|
||||
message_list_before_now = get_raw_msg_before_timestamp_with_chat(
|
||||
chat_id=chat_stream.stream_id,
|
||||
@@ -379,9 +370,7 @@ class DefaultReplyer:
|
||||
# logger.debug("开始构建 focus prompt")
|
||||
|
||||
if sender:
|
||||
reply_target_block = (
|
||||
f"现在{sender}说的:{target}。引起了你的注意,你想要在群里发言或者回复这条消息。"
|
||||
)
|
||||
reply_target_block = f"现在{sender}说的:{target}。引起了你的注意,你想要在群里发言或者回复这条消息。"
|
||||
elif target:
|
||||
reply_target_block = f"现在{target}引起了你的注意,你想要在群里发言或者回复这条消息。"
|
||||
else:
|
||||
@@ -436,9 +425,6 @@ class DefaultReplyer:
|
||||
raw_reply,
|
||||
reply_to,
|
||||
) -> str:
|
||||
|
||||
|
||||
|
||||
sender = ""
|
||||
target = ""
|
||||
if ":" in reply_to or ":" in reply_to:
|
||||
@@ -447,9 +433,9 @@ class DefaultReplyer:
|
||||
if len(parts) == 2:
|
||||
sender = parts[0].strip()
|
||||
target = parts[1].strip()
|
||||
|
||||
|
||||
chat_stream = self.chat_stream
|
||||
|
||||
|
||||
is_group_chat = bool(chat_stream.group_info)
|
||||
|
||||
message_list_before_now = get_raw_msg_before_timestamp_with_chat(
|
||||
@@ -608,23 +594,22 @@ class DefaultReplyer:
|
||||
)
|
||||
|
||||
try:
|
||||
if (bot_message.is_private_message() or
|
||||
bot_message.reply.processed_plain_text != "[System Trigger Context]" or
|
||||
mark_head):
|
||||
if (
|
||||
bot_message.is_private_message()
|
||||
or bot_message.reply.processed_plain_text != "[System Trigger Context]"
|
||||
or mark_head
|
||||
):
|
||||
set_reply = False
|
||||
else:
|
||||
set_reply = True
|
||||
|
||||
|
||||
if not mark_head:
|
||||
mark_head = True
|
||||
typing = False
|
||||
else:
|
||||
typing = True
|
||||
|
||||
|
||||
sent_msg = await self.heart_fc_sender.send_message(
|
||||
bot_message, typing=typing, set_reply=set_reply
|
||||
)
|
||||
|
||||
sent_msg = await self.heart_fc_sender.send_message(bot_message, typing=typing, set_reply=set_reply)
|
||||
|
||||
reply_message_ids.append(part_message_id) # 记录我们生成的ID
|
||||
|
||||
@@ -652,7 +637,7 @@ class DefaultReplyer:
|
||||
is_emoji: bool,
|
||||
thinking_start_time: float,
|
||||
display_message: str,
|
||||
anchor_message: MessageRecv = None
|
||||
anchor_message: MessageRecv = None,
|
||||
) -> MessageSending:
|
||||
"""构建单个发送消息"""
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from src.common.logger import get_logger
|
||||
from src.chat.heart_flow.utils_chat import get_chat_type_and_target_info
|
||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||
from src.person_info.person_info import get_person_info_manager
|
||||
|
||||
logger = get_logger("observation")
|
||||
|
||||
# 定义提示模板
|
||||
@@ -71,7 +72,7 @@ class ChattingObservation(Observation):
|
||||
self.oldest_messages = []
|
||||
self.oldest_messages_str = ""
|
||||
|
||||
self.last_observe_time = datetime.now().timestamp() -1
|
||||
self.last_observe_time = datetime.now().timestamp() - 1
|
||||
print(f"last_observe_time: {self.last_observe_time}")
|
||||
initial_messages = get_raw_msg_before_timestamp_with_chat(self.chat_id, self.last_observe_time, 10)
|
||||
self.last_observe_time = initial_messages[-1]["time"] if initial_messages else self.last_observe_time
|
||||
@@ -159,10 +160,9 @@ class ChattingObservation(Observation):
|
||||
"processed_plain_text": find_msg.get("processed_plain_text"),
|
||||
}
|
||||
find_rec_msg = MessageRecv(message_dict)
|
||||
|
||||
|
||||
find_rec_msg.update_chat_stream(get_chat_manager().get_or_create_stream(self.chat_id))
|
||||
|
||||
|
||||
|
||||
return find_rec_msg
|
||||
|
||||
async def observe(self):
|
||||
|
||||
@@ -171,7 +171,7 @@ class ChatManager:
|
||||
# 使用MD5生成唯一ID
|
||||
key = "_".join(components)
|
||||
return hashlib.md5(key.encode()).hexdigest()
|
||||
|
||||
|
||||
def get_stream_id(self, platform: str, chat_id: str, is_group: bool = True) -> str:
|
||||
"""获取聊天流ID"""
|
||||
if is_group:
|
||||
|
||||
Reference in New Issue
Block a user