fix(chat): 修复空消息引用并调整动作处理逻辑

- 在 `DefaultReplyer` 中增加了对 `reply_message` 的空值检查,以避免在无回复上下文时引发错误。
- 在 `ActionPlanner` 中将 'do_nothing' 添加到非目标动作列表中,以正确处理此新增的无操作指令。
- 将 `EmojiAction` 使用的 LLM 模型从 'utils_small' 更新为 'planner',以适应模型配置的变更。
This commit is contained in:
tt-P607
2025-09-10 09:43:51 +08:00
parent e1ebf41f8d
commit d95f73d52f
3 changed files with 6 additions and 3 deletions

View File

@@ -319,7 +319,7 @@ class ActionPlanner:
action_data = {k: v for k, v in action_json.items() if k not in ["action", "reason"]} action_data = {k: v for k, v in action_json.items() if k not in ["action", "reason"]}
target_message = None target_message = None
if action not in ["no_action", "no_reply"]: if action not in ["no_action", "no_reply", "do_nothing"]:
if target_message_id := action_json.get("target_message_id"): if target_message_id := action_json.get("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)
if target_message is None: if target_message is None:
@@ -329,7 +329,7 @@ class ActionPlanner:
logger.warning(f"{self.log_prefix}动作'{action}'缺少target_message_id") logger.warning(f"{self.log_prefix}动作'{action}'缺少target_message_id")
available_action_names = [name for name, _ in current_available_actions] available_action_names = [name for name, _ in current_available_actions]
if action not in ["no_action", "no_reply", "reply"] and action not in available_action_names: if action not in ["no_action", "no_reply", "reply", "do_nothing"] and action not in available_action_names:
logger.warning( logger.warning(
f"{self.log_prefix}LLM 返回了当前不可用或无效的动作: '{action}' (可用: {available_action_names}),将强制使用 'no_action'" f"{self.log_prefix}LLM 返回了当前不可用或无效的动作: '{action}' (可用: {available_action_names}),将强制使用 'no_action'"
) )

View File

@@ -823,6 +823,9 @@ class DefaultReplyer:
sender, target = self._parse_reply_target(reply_to) sender, target = self._parse_reply_target(reply_to)
else: else:
# 获取 platform如果不存在则从 chat_stream 获取,如果还是 None 则使用默认值 # 获取 platform如果不存在则从 chat_stream 获取,如果还是 None 则使用默认值
if reply_message is None:
logger.warning("reply_message 为 None无法构建prompt")
return ""
platform = reply_message.get("chat_info_platform") platform = reply_message.get("chat_info_platform")
person_id = person_info_manager.get_person_id( person_id = person_info_manager.get_person_id(
platform, # type: ignore platform, # type: ignore

View File

@@ -132,7 +132,7 @@ class EmojiAction(BaseAction):
# 5. 调用LLM # 5. 调用LLM
models = llm_api.get_available_models() models = llm_api.get_available_models()
chat_model_config = models.get("utils_small") chat_model_config = models.get("planner")
if not chat_model_config: if not chat_model_config:
logger.error(f"{self.log_prefix} 未找到'utils_small'模型配置无法调用LLM") logger.error(f"{self.log_prefix} 未找到'utils_small'模型配置无法调用LLM")
return False, "未找到'utils_small'模型配置" return False, "未找到'utils_small'模型配置"