回退“feat: 实现KEYWORD_OR_LLM_JUDGE激活类型”

This commit is contained in:
tt-P607
2025-09-17 22:37:45 +08:00
parent 722790d830
commit bd8859ed82
15 changed files with 57 additions and 3683 deletions

View File

@@ -3,7 +3,7 @@ import time
import traceback
import math
import random
from typing import Dict, Any, Tuple, Optional
from typing import Dict, Any, Tuple
from src.chat.utils.timer_calculator import Timer
from src.common.logger import get_logger
@@ -135,16 +135,6 @@ class CycleProcessor:
action_type = "no_action"
reply_text = "" # 初始化reply_text变量避免UnboundLocalError
# 开始新的思考循环
cycle_timers, thinking_id = self.cycle_tracker.start_cycle()
logger.info(f"{self.log_prefix} 开始第{self.context.cycle_counter}次思考")
if ENABLE_S4U and self.context.chat_stream and self.context.chat_stream.user_info:
await send_typing(self.context.chat_stream.user_info.user_id)
loop_start_time = time.time()
# 使用sigmoid函数将interest_value转换为概率
# 当interest_value为0时概率接近0使用Focus模式
# 当interest_value很高时概率接近1使用Normal模式
@@ -198,7 +188,7 @@ class CycleProcessor:
# 第一步:动作修改
with Timer("动作修改", cycle_timers):
try:
await self.action_modifier.modify_actions(mode=mode)
await self.action_modifier.modify_actions()
available_actions = self.context.action_manager.get_using_actions()
except Exception as e:
logger.error(f"{self.context.log_prefix} 动作修改失败: {e}")
@@ -351,16 +341,7 @@ class CycleProcessor:
# 2. 然后并行执行所有其他动作
if other_actions:
logger.info(f"{self.log_prefix} 正在执行附加动作: {[a.get('action_type') for a 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)))
other_action_tasks = [asyncio.create_task(execute_action(action)) for action in other_actions]
results = await asyncio.gather(*other_action_tasks, return_exceptions=True)
for i, result in enumerate(results):
if isinstance(result, BaseException):
@@ -474,7 +455,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, ""
@@ -482,12 +463,3 @@ 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