From c9a0a3f1d8ec8dadd9a6fc8f9d9e8dc3a9e88819 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 17 Sep 2025 20:51:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(actions):=20=E5=A2=9E=E5=BC=BA=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E6=90=9C=E7=B4=A2=EF=BC=8C=E4=BB=8ELLM=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E4=B8=AD=E6=8F=90=E5=8F=96=E7=A1=AE=E5=88=87=E6=AD=8C?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了提高音乐播放的准确性,引入了一种新机制,可根据 LLM 生成的回复动态更新音乐搜索动作。 在某些场景下,Planner 生成的 `music_search` 动作可能只包含一个模糊的意图,而 LLM 在其回复文本中会明确指出要播放的具体歌曲(例如,“好的,为您播放《晴天》”)。 此变更通过以下方式解决了这个问题: - 新增 `_extract_song_name_from_reply` 辅助函数,用于从回复文本中解析书名号《》内的歌名。 - 在执行并行附加动作前,系统会尝试从主回复中提取歌名。 - 如果成功提取,该歌名将被注入 `music_search` 动作的参数中,确保执行的搜索与 LLM 的意图完全一致。 --- src/chat/chat_loop/cycle_processor.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/chat/chat_loop/cycle_processor.py b/src/chat/chat_loop/cycle_processor.py index 581de2409..ab4a087ad 100644 --- a/src/chat/chat_loop/cycle_processor.py +++ b/src/chat/chat_loop/cycle_processor.py @@ -3,7 +3,7 @@ import time import traceback import math import random -from typing import Dict, Any, Tuple +from typing import Dict, Any, Tuple, Optional from src.chat.utils.timer_calculator import Timer from src.common.logger import get_logger @@ -351,7 +351,16 @@ class CycleProcessor: # 2. 然后并行执行所有其他动作 if other_actions: logger.info(f"{self.log_prefix} 正在执行附加动作: {[a.get('action_type') for a in other_actions]}") - other_action_tasks = [asyncio.create_task(execute_action(action)) for action in other_actions] + + # 从回复文本中提取歌名 + song_name_from_reply = self._extract_song_name_from_reply(reply_text_from_reply) + + other_action_tasks = [] + for action in other_actions: + if action.get("action_type") == "music_search" and song_name_from_reply: + action["action_data"]["song_name"] = song_name_from_reply + other_action_tasks.append(asyncio.create_task(execute_action(action))) + results = await asyncio.gather(*other_action_tasks, return_exceptions=True) for i, result in enumerate(results): if isinstance(result, BaseException): @@ -465,7 +474,7 @@ class CycleProcessor: if not action_handler: logger.error(f"{self.context.log_prefix} 回退方案也失败,无法创建任何动作处理器") return False, "", "" - + # 执行动作 success, reply_text = await action_handler.handle_action() return success, reply_text, "" @@ -473,3 +482,12 @@ class CycleProcessor: logger.error(f"{self.context.log_prefix} 处理{action}时出错: {e}") traceback.print_exc() return False, "", "" + + def _extract_song_name_from_reply(self, reply_text: str) -> Optional[str]: + """从回复文本中提取歌名""" + import re + # 匹配书名号中的内容 + match = re.search(r"《(.*?)》", reply_text) + if match: + return match.group(1) + return None