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

This commit is contained in:
github-actions[bot]
2025-06-14 07:03:25 +00:00
parent e15a9b29ff
commit 538c3ae3f2
9 changed files with 77 additions and 75 deletions

View File

@@ -11,7 +11,7 @@ from src.common.logger import get_logger
import math import math
import re import re
import traceback import traceback
from typing import Optional, Tuple, Dict, Any from typing import Optional, Tuple
from maim_message import UserInfo from maim_message import UserInfo
from src.person_info.relationship_manager import get_relationship_manager from src.person_info.relationship_manager import get_relationship_manager

View File

@@ -51,7 +51,6 @@ class ChatBot:
async def _process_commands_with_new_system(self, message: MessageRecv): async def _process_commands_with_new_system(self, message: MessageRecv):
"""使用新插件系统处理命令""" """使用新插件系统处理命令"""
try: try:
text = message.processed_plain_text text = message.processed_plain_text
# 使用新的组件注册中心查找命令 # 使用新的组件注册中心查找命令

View File

@@ -182,7 +182,9 @@ class NormalChat:
interested_rate=interest_value * self.willing_amplifier, interested_rate=interest_value * self.willing_amplifier,
) )
except Exception as e: except Exception as e:
logger.error(f"[{self.stream_name}] 处理兴趣消息{msg_id}时出错: {e}\n{traceback.format_exc()}") logger.error(
f"[{self.stream_name}] 处理兴趣消息{msg_id}时出错: {e}\n{traceback.format_exc()}"
)
finally: finally:
self.interest_dict.pop(msg_id, None) self.interest_dict.pop(msg_id, None)

View File

@@ -329,7 +329,9 @@ class NormalChatActionModifier:
should_switch = recent_reply_count > reply_threshold should_switch = recent_reply_count > reply_threshold
if should_switch: if should_switch:
logger.debug(f"{self.log_prefix} 检测到1分钟内回复数量({recent_reply_count})大于{reply_threshold}满足切换到focus模式条件") logger.debug(
f"{self.log_prefix} 检测到1分钟内回复数量({recent_reply_count})大于{reply_threshold}满足切换到focus模式条件"
)
return should_switch return should_switch

View File

@@ -191,7 +191,7 @@ def _build_readable_messages_internal(
nonlocal current_pic_counter nonlocal current_pic_counter
# 匹配 [picid:xxxxx] 格式 # 匹配 [picid:xxxxx] 格式
pic_pattern = r'\[picid:([^\]]+)\]' pic_pattern = r"\[picid:([^\]]+)\]"
def replace_pic_id(match): def replace_pic_id(match):
nonlocal current_pic_counter nonlocal current_pic_counter
@@ -445,7 +445,12 @@ def _build_readable_messages_internal(
formatted_string = "".join(output_lines).strip() formatted_string = "".join(output_lines).strip()
# 返回格式化后的字符串、消息详情列表、图片映射字典和更新后的计数器 # 返回格式化后的字符串、消息详情列表、图片映射字典和更新后的计数器
return formatted_string, [(t, n, c) for t, n, c, is_action in message_details if not is_action], pic_id_mapping, current_pic_counter return (
formatted_string,
[(t, n, c) for t, n, c, is_action in message_details if not is_action],
pic_id_mapping,
current_pic_counter,
)
def build_pic_mapping_info(pic_id_mapping: Dict[str, str]) -> str: def build_pic_mapping_info(pic_id_mapping: Dict[str, str]) -> str:
@@ -461,8 +466,6 @@ def build_pic_mapping_info(pic_id_mapping: Dict[str, str]) -> str:
if not pic_id_mapping: if not pic_id_mapping:
return "" return ""
mapping_lines = [] mapping_lines = []
# 按图片编号排序 # 按图片编号排序
@@ -475,7 +478,7 @@ def build_pic_mapping_info(pic_id_mapping: Dict[str, str]) -> str:
image = Images.get_or_none(Images.image_id == pic_id) image = Images.get_or_none(Images.image_id == pic_id)
if image and image.description: if image and image.description:
description = image.description description = image.description
except Exception as e: except Exception:
# 如果查询失败,保持默认描述 # 如果查询失败,保持默认描述
pass pass
@@ -593,12 +596,16 @@ def build_readable_messages(
# 分别格式化,但使用共享的图片映射 # 分别格式化,但使用共享的图片映射
formatted_before, _, pic_id_mapping, pic_counter = _build_readable_messages_internal( formatted_before, _, pic_id_mapping, pic_counter = _build_readable_messages_internal(
messages_before_mark, replace_bot_name, merge_messages, timestamp_mode, truncate, messages_before_mark,
pic_id_mapping, pic_counter replace_bot_name,
merge_messages,
timestamp_mode,
truncate,
pic_id_mapping,
pic_counter,
) )
formatted_after, _, pic_id_mapping, _ = _build_readable_messages_internal( formatted_after, _, pic_id_mapping, _ = _build_readable_messages_internal(
messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, False, messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, False, pic_id_mapping, pic_counter
pic_id_mapping, pic_counter
) )
read_mark_line = "\n--- 以上消息是你已经看过---\n--- 请关注以下未读的新消息---\n" read_mark_line = "\n--- 以上消息是你已经看过---\n--- 请关注以下未读的新消息---\n"
@@ -646,7 +653,7 @@ async def build_anonymous_messages(messages: List[Dict[str, Any]]) -> str:
nonlocal pic_counter nonlocal pic_counter
# 匹配 [picid:xxxxx] 格式 # 匹配 [picid:xxxxx] 格式
pic_pattern = r'\[picid:([^\]]+)\]' pic_pattern = r"\[picid:([^\]]+)\]"
def replace_pic_id(match): def replace_pic_id(match):
nonlocal pic_counter nonlocal pic_counter

View File

@@ -411,7 +411,7 @@ class ImageManager:
base64=image_base64, base64=image_base64,
type="image", type="image",
timestamp=current_timestamp, timestamp=current_timestamp,
vlm_processed=False vlm_processed=False,
) )
# 启动异步VLM处理 # 启动异步VLM处理
@@ -453,11 +453,7 @@ class ImageManager:
prompt = """请用中文描述这张图片的内容。如果有文字请把文字描述概括出来请留意其主题直观感受输出为一段平文本最多50字""" prompt = """请用中文描述这张图片的内容。如果有文字请把文字描述概括出来请留意其主题直观感受输出为一段平文本最多50字"""
# 获取VLM描述 # 获取VLM描述
description, _ = await self._llm.generate_response_for_image( description, _ = await self._llm.generate_response_for_image(prompt, image_base64, image_format)
prompt,
image_base64,
image_format
)
if description is None: if description is None:
logger.warning("VLM未能生成图片描述") logger.warning("VLM未能生成图片描述")

View File

@@ -32,11 +32,7 @@ class PluginManager:
def _ensure_plugin_directories(self): def _ensure_plugin_directories(self):
"""确保所有插件目录存在,如果不存在则创建""" """确保所有插件目录存在,如果不存在则创建"""
default_directories = [ default_directories = ["src/plugins/built_in", "src/plugins/examples", "plugins"]
"src/plugins/built_in",
"src/plugins/examples",
"plugins"
]
for directory in default_directories: for directory in default_directories:
if not os.path.exists(directory): if not os.path.exists(directory):

View File

@@ -267,7 +267,7 @@ class ChangeToFocusChatAction(BaseAction):
"聊天上下文中自己的回复条数较多超过3-4条", "聊天上下文中自己的回复条数较多超过3-4条",
"对话进行得非常热烈活跃", "对话进行得非常热烈活跃",
"用户表现出深入交流的意图", "用户表现出深入交流的意图",
"话题需要更专注和深入的讨论" "话题需要更专注和深入的讨论",
] ]
async def execute(self) -> Tuple[bool, str]: async def execute(self) -> Tuple[bool, str]: