This commit is contained in:
UnCLAS-Prommer
2025-07-16 10:36:52 +08:00
parent d67cffd953
commit 6c89423833
2 changed files with 13 additions and 20 deletions

View File

@@ -310,14 +310,9 @@ class HeartFChatting:
return True return True
else: else:
action_message: Dict[str, Any] = message_data or target_message # type: ignore
if message_data:
action_message = message_data
else:
action_message = target_message
# 动作执行计时 # 动作执行计时
with Timer("动作执行", cycle_timers): with Timer("动作执行", cycle_timers):
success, reply_text, command = await self._handle_action( success, reply_text, command = await self._handle_action(
action_type, reasoning, action_data, cycle_timers, thinking_id, action_message action_type, reasoning, action_data, cycle_timers, thinking_id, action_message

View File

@@ -1,7 +1,7 @@
import json import json
import time import time
import traceback import traceback
from typing import Dict, Any, Optional from typing import Dict, Any, Optional, Tuple
from rich.traceback import install from rich.traceback import install
from datetime import datetime from datetime import datetime
from json_repair import repair_json from json_repair import repair_json
@@ -81,6 +81,7 @@ class ActionPlanner:
self.last_obs_time_mark = 0.0 self.last_obs_time_mark = 0.0
def find_message_by_id(self, message_id: str, message_id_list: list) -> Optional[Dict[str, Any]]: def find_message_by_id(self, message_id: str, message_id_list: list) -> Optional[Dict[str, Any]]:
# sourcery skip: use-next
""" """
根据message_id从message_id_list中查找对应的原始消息 根据message_id从message_id_list中查找对应的原始消息
@@ -98,7 +99,7 @@ class ActionPlanner:
async def plan( async def plan(
self, mode: ChatMode = ChatMode.FOCUS self, mode: ChatMode = ChatMode.FOCUS
) -> Dict[str, Dict[str, Any] | str]: # sourcery skip: dict-comprehension ) -> Tuple[Dict[str, Dict[str, Any] | str], Optional[Dict[str, Any]]]: # sourcery skip: dict-comprehension
""" """
规划器 (Planner): 使用LLM根据上下文决定做出什么动作。 规划器 (Planner): 使用LLM根据上下文决定做出什么动作。
""" """
@@ -107,7 +108,8 @@ class ActionPlanner:
reasoning = "规划器初始化默认" reasoning = "规划器初始化默认"
action_data = {} action_data = {}
current_available_actions: Dict[str, ActionInfo] = {} current_available_actions: Dict[str, ActionInfo] = {}
target_message = None # 初始化target_message变量 target_message: Optional[Dict[str, Any]] = None # 初始化target_message变量
prompt: str = ""
try: try:
is_group_chat = True is_group_chat = True
@@ -128,10 +130,7 @@ class ActionPlanner:
# 如果没有可用动作或只有no_reply动作直接返回no_reply # 如果没有可用动作或只有no_reply动作直接返回no_reply
if not current_available_actions: if not current_available_actions:
if mode == ChatMode.FOCUS: action = "no_reply" if mode == ChatMode.FOCUS else "no_action"
action = "no_reply"
else:
action = "no_action"
reasoning = "没有可用的动作" reasoning = "没有可用的动作"
logger.info(f"{self.log_prefix}{reasoning}") logger.info(f"{self.log_prefix}{reasoning}")
return { return {
@@ -140,7 +139,7 @@ class ActionPlanner:
"action_data": action_data, "action_data": action_data,
"reasoning": reasoning, "reasoning": reasoning,
}, },
} }, None
# --- 构建提示词 (调用修改后的 PromptBuilder 方法) --- # --- 构建提示词 (调用修改后的 PromptBuilder 方法) ---
prompt, message_id_list = await self.build_planner_prompt( prompt, message_id_list = await self.build_planner_prompt(
@@ -196,8 +195,7 @@ class ActionPlanner:
# 在FOCUS模式下非no_reply动作需要target_message_id # 在FOCUS模式下非no_reply动作需要target_message_id
if mode == ChatMode.FOCUS and action != "no_reply": if mode == ChatMode.FOCUS and action != "no_reply":
target_message_id = parsed_json.get("target_message_id") if target_message_id := parsed_json.get("target_message_id"):
if target_message_id:
# 根据target_message_id查找原始消息 # 根据target_message_id查找原始消息
target_message = self.find_message_by_id(target_message_id, message_id_list) target_message = self.find_message_by_id(target_message_id, message_id_list)
else: else:
@@ -278,7 +276,7 @@ class ActionPlanner:
if mode == ChatMode.FOCUS: if mode == ChatMode.FOCUS:
by_what = "聊天内容" by_what = "聊天内容"
target_prompt = "\n \"target_message_id\":\"触发action的消息id\"" target_prompt = '\n "target_message_id":"触发action的消息id"'
no_action_block = """重要说明1 no_action_block = """重要说明1
- 'no_reply' 表示只进行不进行回复,等待合适的回复时机 - 'no_reply' 表示只进行不进行回复,等待合适的回复时机
- 当你刚刚发送了消息没有人回复时选择no_reply - 当你刚刚发送了消息没有人回复时选择no_reply