🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -660,7 +660,6 @@ class HeartFChatting:
|
|||||||
}
|
}
|
||||||
|
|
||||||
with Timer("执行动作", cycle_timers):
|
with Timer("执行动作", cycle_timers):
|
||||||
|
|
||||||
action_type, action_data, reasoning = (
|
action_type, action_data, reasoning = (
|
||||||
plan_result.get("action_result", {}).get("action_type", "error"),
|
plan_result.get("action_result", {}).get("action_type", "error"),
|
||||||
plan_result.get("action_result", {}).get("action_data", {}),
|
plan_result.get("action_result", {}).get("action_data", {}),
|
||||||
|
|||||||
@@ -62,19 +62,19 @@ def init_prompt():
|
|||||||
"simple_planner_prompt_private",
|
"simple_planner_prompt_private",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Prompt(
|
# Prompt(
|
||||||
# """
|
# """
|
||||||
# 动作:{action_name}
|
# 动作:{action_name}
|
||||||
# 该动作的描述:{action_description}
|
# 该动作的描述:{action_description}
|
||||||
# 使用该动作的场景:
|
# 使用该动作的场景:
|
||||||
# {action_require}
|
# {action_require}
|
||||||
# 输出要求:
|
# 输出要求:
|
||||||
# {{
|
# {{
|
||||||
# "action": "{action_name}",{action_parameters}
|
# "action": "{action_name}",{action_parameters}
|
||||||
# }}
|
# }}
|
||||||
# """,
|
# """,
|
||||||
# "action_prompt",
|
# "action_prompt",
|
||||||
# )
|
# )
|
||||||
Prompt(
|
Prompt(
|
||||||
"""
|
"""
|
||||||
{action_require}
|
{action_require}
|
||||||
@@ -96,7 +96,6 @@ def init_prompt():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ActionPlanner(BasePlanner):
|
class ActionPlanner(BasePlanner):
|
||||||
def __init__(self, log_prefix: str, action_manager: ActionManager):
|
def __init__(self, log_prefix: str, action_manager: ActionManager):
|
||||||
super().__init__(log_prefix, action_manager)
|
super().__init__(log_prefix, action_manager)
|
||||||
@@ -170,7 +169,9 @@ class ActionPlanner(BasePlanner):
|
|||||||
# 如果获取成功,更新is_group_chat
|
# 如果获取成功,更新is_group_chat
|
||||||
if is_group_chat_updated is not None:
|
if is_group_chat_updated is not None:
|
||||||
is_group_chat = is_group_chat_updated
|
is_group_chat = is_group_chat_updated
|
||||||
logger.debug(f"{self.log_prefix}获取到聊天信息 - 群聊: {is_group_chat}, 目标信息: {chat_target_info}")
|
logger.debug(
|
||||||
|
f"{self.log_prefix}获取到聊天信息 - 群聊: {is_group_chat}, 目标信息: {chat_target_info}"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"{self.log_prefix}获取聊天目标信息失败: {e}")
|
logger.warning(f"{self.log_prefix}获取聊天目标信息失败: {e}")
|
||||||
chat_target_info = None
|
chat_target_info = None
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ class ReplyAction(BaseAction):
|
|||||||
|
|
||||||
start_time = self.action_data.get("loop_start_time", time.time())
|
start_time = self.action_data.get("loop_start_time", time.time())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
success, reply_set = await generator_api.generate_reply(
|
success, reply_set = await generator_api.generate_reply(
|
||||||
chat_stream=self.chat_stream,
|
chat_stream=self.chat_stream,
|
||||||
@@ -68,7 +66,6 @@ class ReplyAction(BaseAction):
|
|||||||
is_group=self.is_group,
|
is_group=self.is_group,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 检查从start_time以来的新消息数量
|
# 检查从start_time以来的新消息数量
|
||||||
# 获取动作触发时间或使用默认值
|
# 获取动作触发时间或使用默认值
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
@@ -89,16 +86,15 @@ class ReplyAction(BaseAction):
|
|||||||
data = reply_seg[1]
|
data = reply_seg[1]
|
||||||
if not first_replyed:
|
if not first_replyed:
|
||||||
if need_reply:
|
if need_reply:
|
||||||
await self.send_text(content=data, reply_to=self.action_data.get("reply_to", ""),typing=False)
|
await self.send_text(content=data, reply_to=self.action_data.get("reply_to", ""), typing=False)
|
||||||
first_replyed = True
|
first_replyed = True
|
||||||
else:
|
else:
|
||||||
await self.send_text(content=data,typing=False)
|
await self.send_text(content=data, typing=False)
|
||||||
first_replyed = True
|
first_replyed = True
|
||||||
else:
|
else:
|
||||||
await self.send_text(content=data,typing=True)
|
await self.send_text(content=data, typing=True)
|
||||||
reply_text += data
|
reply_text += data
|
||||||
|
|
||||||
|
|
||||||
# 存储动作记录
|
# 存储动作记录
|
||||||
await self.store_action_info(
|
await self.store_action_info(
|
||||||
action_build_into_prompt=False,
|
action_build_into_prompt=False,
|
||||||
@@ -179,17 +175,14 @@ class NoReplyAction(BaseAction):
|
|||||||
start_time=start_time - 300, # 获取开始前5分钟内的消息
|
start_time=start_time - 300, # 获取开始前5分钟内的消息
|
||||||
end_time=start_time,
|
end_time=start_time,
|
||||||
limit=5,
|
limit=5,
|
||||||
limit_mode="latest"
|
limit_mode="latest",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 构建上下文字符串
|
# 构建上下文字符串
|
||||||
context_str = ""
|
context_str = ""
|
||||||
if context_messages:
|
if context_messages:
|
||||||
context_str = message_api.build_readable_messages(
|
context_str = message_api.build_readable_messages(
|
||||||
messages=context_messages,
|
messages=context_messages, timestamp_mode="normal_no_YMD", truncate=False, show_actions=False
|
||||||
timestamp_mode="normal_no_YMD",
|
|
||||||
truncate=False,
|
|
||||||
show_actions=False
|
|
||||||
)
|
)
|
||||||
context_str = f"当时选择no_reply前的聊天上下文:\n{context_str}\n"
|
context_str = f"当时选择no_reply前的聊天上下文:\n{context_str}\n"
|
||||||
|
|
||||||
@@ -242,10 +235,7 @@ class NoReplyAction(BaseAction):
|
|||||||
if recent_messages:
|
if recent_messages:
|
||||||
# 使用message_api构建可读的消息字符串
|
# 使用message_api构建可读的消息字符串
|
||||||
messages_text = message_api.build_readable_messages(
|
messages_text = message_api.build_readable_messages(
|
||||||
messages=recent_messages,
|
messages=recent_messages, timestamp_mode="normal_no_YMD", truncate=False, show_actions=False
|
||||||
timestamp_mode="normal_no_YMD",
|
|
||||||
truncate=False,
|
|
||||||
show_actions=False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 参考simple_planner构建更完整的判断信息
|
# 参考simple_planner构建更完整的判断信息
|
||||||
@@ -288,7 +278,7 @@ class NoReplyAction(BaseAction):
|
|||||||
available_models = llm_api.get_available_models()
|
available_models = llm_api.get_available_models()
|
||||||
|
|
||||||
# 使用 utils_small 模型
|
# 使用 utils_small 模型
|
||||||
small_model = getattr(available_models, 'utils_small', None)
|
small_model = getattr(available_models, "utils_small", None)
|
||||||
|
|
||||||
if small_model:
|
if small_model:
|
||||||
# 使用小模型进行判断
|
# 使用小模型进行判断
|
||||||
@@ -296,7 +286,7 @@ class NoReplyAction(BaseAction):
|
|||||||
prompt=judge_prompt,
|
prompt=judge_prompt,
|
||||||
model_config=small_model,
|
model_config=small_model,
|
||||||
request_type="plugin.no_reply_judge",
|
request_type="plugin.no_reply_judge",
|
||||||
temperature=0.7 # 降低温度,提高判断的一致性
|
temperature=0.7, # 降低温度,提高判断的一致性
|
||||||
)
|
)
|
||||||
|
|
||||||
# 更新上次判断时间
|
# 更新上次判断时间
|
||||||
@@ -374,15 +364,15 @@ class NoReplyAction(BaseAction):
|
|||||||
tuple: (判断结果, 理由)
|
tuple: (判断结果, 理由)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
lines = response.strip().split('\n')
|
lines = response.strip().split("\n")
|
||||||
judge_result = "不需要回复" # 默认值
|
judge_result = "不需要回复" # 默认值
|
||||||
reason = "解析失败,使用默认判断"
|
reason = "解析失败,使用默认判断"
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('判断:') or line.startswith('判断:'):
|
if line.startswith("判断:") or line.startswith("判断:"):
|
||||||
# 提取判断结果
|
# 提取判断结果
|
||||||
result_part = line.split(':', 1)[-1] if ':' in line else line.split(':', 1)[-1]
|
result_part = line.split(":", 1)[-1] if ":" in line else line.split(":", 1)[-1]
|
||||||
result_part = result_part.strip()
|
result_part = result_part.strip()
|
||||||
|
|
||||||
if "需要回复" in result_part:
|
if "需要回复" in result_part:
|
||||||
@@ -390,9 +380,9 @@ class NoReplyAction(BaseAction):
|
|||||||
elif "不需要回复" in result_part:
|
elif "不需要回复" in result_part:
|
||||||
judge_result = "不需要回复"
|
judge_result = "不需要回复"
|
||||||
|
|
||||||
elif line.startswith('理由:') or line.startswith('理由:'):
|
elif line.startswith("理由:") or line.startswith("理由:"):
|
||||||
# 提取理由
|
# 提取理由
|
||||||
reason_part = line.split(':', 1)[-1] if ':' in line else line.split(':', 1)[-1]
|
reason_part = line.split(":", 1)[-1] if ":" in line else line.split(":", 1)[-1]
|
||||||
reason = reason_part.strip()
|
reason = reason_part.strip()
|
||||||
|
|
||||||
# 如果没有找到标准格式,尝试简单的关键词匹配
|
# 如果没有找到标准格式,尝试简单的关键词匹配
|
||||||
@@ -486,7 +476,6 @@ class EmojiAction(BaseAction):
|
|||||||
return False, f"表情发送失败: {str(e)}"
|
return False, f"表情发送失败: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExitFocusChatAction(BaseAction):
|
class ExitFocusChatAction(BaseAction):
|
||||||
"""退出专注聊天动作 - 从专注模式切换到普通模式"""
|
"""退出专注聊天动作 - 从专注模式切换到普通模式"""
|
||||||
|
|
||||||
@@ -588,8 +577,12 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
},
|
},
|
||||||
"no_reply": {
|
"no_reply": {
|
||||||
"max_timeout": ConfigField(type=int, default=1200, description="最大等待超时时间(秒)"),
|
"max_timeout": ConfigField(type=int, default=1200, description="最大等待超时时间(秒)"),
|
||||||
"min_judge_interval": ConfigField(type=float, default=1.0, description="LLM判断的最小间隔时间(秒),防止过于频繁"),
|
"min_judge_interval": ConfigField(
|
||||||
"auto_exit_message_count": ConfigField(type=int, default=20, description="累计消息数量达到此阈值时自动结束等待"),
|
type=float, default=1.0, description="LLM判断的最小间隔时间(秒),防止过于频繁"
|
||||||
|
),
|
||||||
|
"auto_exit_message_count": ConfigField(
|
||||||
|
type=int, default=20, description="累计消息数量达到此阈值时自动结束等待"
|
||||||
|
),
|
||||||
"random_probability": ConfigField(
|
"random_probability": ConfigField(
|
||||||
type=float, default=0.8, description="Focus模式下,随机选择不回复的概率(0.0到1.0)", example=0.8
|
type=float, default=0.8, description="Focus模式下,随机选择不回复的概率(0.0到1.0)", example=0.8
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user