🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-02 13:15:04 +00:00
parent 20d68a7896
commit 243d5184e6
8 changed files with 30 additions and 34 deletions

View File

@@ -23,11 +23,7 @@ class EmojiAction(BaseAction):
action_parameters: dict[str:str] = { action_parameters: dict[str:str] = {
"description": "文字描述你想要发送的表情", "description": "文字描述你想要发送的表情",
} }
action_require: list[str] = [ action_require: list[str] = ["你想要发送一个表情", "表达情绪时可以选择使用", "一般在你回复之后可以选择性使用"]
"你想要发送一个表情",
"表达情绪时可以选择使用",
"一般在你回复之后可以选择性使用"
]
associated_types: list[str] = ["emoji"] associated_types: list[str] = ["emoji"]
@@ -108,7 +104,7 @@ class EmojiAction(BaseAction):
# ) # )
# else: # else:
# anchor_message.update_chat_stream(self.chat_stream) # anchor_message.update_chat_stream(self.chat_stream)
logger.info(f"{self.log_prefix} 为了表情包创建占位符") logger.info(f"{self.log_prefix} 为了表情包创建占位符")
anchor_message = await create_empty_anchor_message( anchor_message = await create_empty_anchor_message(
self.chat_stream.platform, self.chat_stream.group_info, self.chat_stream self.chat_stream.platform, self.chat_stream.group_info, self.chat_stream

View File

@@ -58,7 +58,6 @@ def init_prompt():
""", """,
"simple_planner_prompt", "simple_planner_prompt",
) )
Prompt( Prompt(
""" """
@@ -192,7 +191,6 @@ class ActionPlanner(BasePlanner):
reasoning = f"LLM 请求失败,你的模型出现问题: {req_e}" reasoning = f"LLM 请求失败,你的模型出现问题: {req_e}"
action = "no_reply" action = "no_reply"
if llm_content: if llm_content:
try: try:
fixed_json_string = repair_json(llm_content) fixed_json_string = repair_json(llm_content)
@@ -233,9 +231,7 @@ class ActionPlanner(BasePlanner):
reasoning = extracted_reasoning reasoning = extracted_reasoning
except Exception as json_e: except Exception as json_e:
logger.warning( logger.warning(f"{self.log_prefix}解析LLM响应JSON失败 {json_e}. LLM原始输出: '{llm_content}'")
f"{self.log_prefix}解析LLM响应JSON失败 {json_e}. LLM原始输出: '{llm_content}'"
)
traceback.print_exc() traceback.print_exc()
reasoning = f"解析LLM响应JSON失败: {json_e}. 将使用默认动作 'no_reply'." reasoning = f"解析LLM响应JSON失败: {json_e}. 将使用默认动作 'no_reply'."
action = "no_reply" action = "no_reply"
@@ -353,7 +349,7 @@ class ActionPlanner(BasePlanner):
# moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。" # moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。"
moderation_prompt_block = "" moderation_prompt_block = ""
# 获取当前时间 # 获取当前时间
time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"

View File

@@ -75,7 +75,7 @@ def init_prompt():
不要浮夸,不要夸张修辞,只输出一条回复就好。 不要浮夸,不要夸张修辞,只输出一条回复就好。
现在,你说: 现在,你说:
""", """,
"default_replyer_private_prompt", "default_replyer_private_prompt",
) )
@@ -181,7 +181,7 @@ class DefaultReplyer:
return False, None return False, None
# --- 回复器 (Replier) 的定义 --- # # --- 回复器 (Replier) 的定义 --- #
async def deal_emoji( async def deal_emoji(
self, self,
anchor_message: MessageRecv, anchor_message: MessageRecv,
@@ -192,10 +192,9 @@ class DefaultReplyer:
""" """
表情动作处理类 表情动作处理类
""" """
await self._create_thinking_message(anchor_message, thinking_id) await self._create_thinking_message(anchor_message, thinking_id)
try: try:
has_sent_something = False has_sent_something = False
sent_msg_list = [] sent_msg_list = []
@@ -208,8 +207,7 @@ class DefaultReplyer:
reply.append(("emoji", emoji_base64)) reply.append(("emoji", emoji_base64))
else: else:
logger.warning(f"{self.log_prefix} 没有找到合适表情") logger.warning(f"{self.log_prefix} 没有找到合适表情")
if reply: if reply:
with Timer("发送表情", cycle_timers): with Timer("发送表情", cycle_timers):
sent_msg_list = await self.send_response_messages( sent_msg_list = await self.send_response_messages(
@@ -230,8 +228,6 @@ class DefaultReplyer:
logger.error(f"回复失败: {e}") logger.error(f"回复失败: {e}")
traceback.print_exc() traceback.print_exc()
return False, None return False, None
async def reply( async def reply(
self, self,
@@ -293,7 +289,7 @@ class DefaultReplyer:
# TODO: API-Adapter修改标记 # TODO: API-Adapter修改标记
# logger.info(f"{self.log_prefix}[Replier-{thinking_id}]\nPrompt:\n{prompt}\n") # logger.info(f"{self.log_prefix}[Replier-{thinking_id}]\nPrompt:\n{prompt}\n")
content, (reasoning_content, model_name) = await self.express_model.generate_response_async(prompt) content, (reasoning_content, model_name) = await self.express_model.generate_response_async(prompt)
logger.debug(f"prompt: {prompt}") logger.debug(f"prompt: {prompt}")
logger.info(f"最终回复: {content}") logger.info(f"最终回复: {content}")
@@ -384,8 +380,8 @@ class DefaultReplyer:
style_habbits_str = "\n".join(style_habbits) style_habbits_str = "\n".join(style_habbits)
grammar_habbits_str = "\n".join(grammar_habbits) grammar_habbits_str = "\n".join(grammar_habbits)
# 关键词检测与反应 # 关键词检测与反应
keywords_reaction_prompt = "" keywords_reaction_prompt = ""
try: try:
# 处理关键词规则 # 处理关键词规则
@@ -393,7 +389,7 @@ class DefaultReplyer:
if any(keyword in target_message for keyword in rule.keywords): if any(keyword in target_message for keyword in rule.keywords):
logger.info(f"检测到关键词规则:{rule.keywords},触发反应:{rule.reaction}") logger.info(f"检测到关键词规则:{rule.keywords},触发反应:{rule.reaction}")
keywords_reaction_prompt += f"{rule.reaction}" keywords_reaction_prompt += f"{rule.reaction}"
# 处理正则表达式规则 # 处理正则表达式规则
for rule in global_config.keyword_reaction.regex_rules: for rule in global_config.keyword_reaction.regex_rules:
for pattern_str in rule.regex: for pattern_str in rule.regex:
@@ -411,7 +407,7 @@ class DefaultReplyer:
continue continue
except Exception as e: except Exception as e:
logger.error(f"关键词检测与反应时发生异常: {str(e)}", exc_info=True) logger.error(f"关键词检测与反应时发生异常: {str(e)}", exc_info=True)
time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
# logger.debug("开始构建 focus prompt") # logger.debug("开始构建 focus prompt")

View File

@@ -510,11 +510,15 @@ class MemoryManager:
# 如果有摘要信息,添加到提示中 # 如果有摘要信息,添加到提示中
if summary1: if summary1:
prompt += f"记忆1主题{summary1['brief']}\n" prompt += f"记忆1主题{summary1['brief']}\n"
prompt += "记忆1关键要点\n" + "\n".join([f"- {point}" for point in summary1.get("key_points", [])]) + "\n\n" prompt += (
"记忆1关键要点\n" + "\n".join([f"- {point}" for point in summary1.get("key_points", [])]) + "\n\n"
)
if summary2: if summary2:
prompt += f"记忆2主题{summary2['brief']}\n" prompt += f"记忆2主题{summary2['brief']}\n"
prompt += "记忆2关键要点\n" + "\n".join([f"- {point}" for point in summary2.get("key_points", [])]) + "\n\n" prompt += (
"记忆2关键要点\n" + "\n".join([f"- {point}" for point in summary2.get("key_points", [])]) + "\n\n"
)
# 添加记忆原始内容 # 添加记忆原始内容
prompt += f""" prompt += f"""

View File

@@ -636,4 +636,4 @@ def translate_timestamp_to_human_readable(timestamp: float, mode: str = "normal"
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + ":\n" return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + ":\n"
else: # mode = "lite" or unknown else: # mode = "lite" or unknown
# 只返回时分秒格式,喵~ # 只返回时分秒格式,喵~
return time.strftime("%H:%M:%S", time.localtime(timestamp)) return time.strftime("%H:%M:%S", time.localtime(timestamp))

View File

@@ -184,9 +184,7 @@ class ImageManager:
return f"[图片:{cached_description}]" return f"[图片:{cached_description}]"
# 调用AI获取描述 # 调用AI获取描述
prompt = ( prompt = "请用中文描述这张图片的内容。如果有文字请把文字都描述出来请留意其主题直观感受以及是否有擦边色情内容。最多100个字。"
"请用中文描述这张图片的内容。如果有文字请把文字都描述出来请留意其主题直观感受以及是否有擦边色情内容。最多100个字。"
)
description, _ = await self._llm.generate_response_for_image(prompt, image_base64, image_format) description, _ = await self._llm.generate_response_for_image(prompt, image_base64, image_format)
if description is None: if description is None:

View File

@@ -90,7 +90,9 @@ class TelemetryHeartBeatTask(AsyncTask):
else: else:
logger.error("无效的服务端响应") logger.error("无效的服务端响应")
else: else:
logger.error(f"请求UUID失败不过你还是可以正常使用麦麦状态码: {response.status_code}, 响应内容: {response.text}") logger.error(
f"请求UUID失败不过你还是可以正常使用麦麦状态码: {response.status_code}, 响应内容: {response.text}"
)
# 请求失败,重试次数+1 # 请求失败,重试次数+1
try_count += 1 try_count += 1

View File

@@ -79,7 +79,11 @@ class ConfigBase:
if field_origin_type is list: if field_origin_type is list:
# 如果列表元素类型是ConfigBase的子类则对每个元素调用from_dict # 如果列表元素类型是ConfigBase的子类则对每个元素调用from_dict
if field_type_args and isinstance(field_type_args[0], type) and issubclass(field_type_args[0], ConfigBase): if (
field_type_args
and isinstance(field_type_args[0], type)
and issubclass(field_type_args[0], ConfigBase)
):
return [field_type_args[0].from_dict(item) for item in value] return [field_type_args[0].from_dict(item) for item in value]
return [cls._convert_field(item, field_type_args[0]) for item in value] return [cls._convert_field(item, field_type_args[0]) for item in value]
elif field_origin_type is set: elif field_origin_type is set: