Merge branch 'master' of https://github.com/MaiBot-Plus/MaiMbot-Pro-Max
This commit is contained in:
@@ -140,7 +140,7 @@ class ProactiveThinker:
|
||||
|
||||
功能说明:
|
||||
- 检查聊天流是否存在
|
||||
- 检查当前聊天是否在启用列表中(如果配置了列表)
|
||||
- 检查当前聊天是否在启用列表中(按平台和类型分别检查)
|
||||
- 根据聊天类型(群聊/私聊)和配置决定是否启用
|
||||
- 群聊需要proactive_thinking_in_group为True
|
||||
- 私聊需要proactive_thinking_in_private为True
|
||||
@@ -148,21 +148,35 @@ class ProactiveThinker:
|
||||
if not self.context.chat_stream:
|
||||
return False
|
||||
|
||||
try:
|
||||
chat_id = int(self.context.stream_id.split(':')[-1])
|
||||
except (ValueError, IndexError):
|
||||
chat_id = None
|
||||
|
||||
proactive_thinking_ids = getattr(global_config.chat, 'proactive_thinking_enable_ids', [])
|
||||
if proactive_thinking_ids and (chat_id is None or chat_id not in proactive_thinking_ids):
|
||||
return False
|
||||
|
||||
is_group_chat = self.context.chat_stream.group_info is not None
|
||||
|
||||
# 检查基础开关
|
||||
if is_group_chat and not global_config.chat.proactive_thinking_in_group:
|
||||
return False
|
||||
if not is_group_chat and not global_config.chat.proactive_thinking_in_private:
|
||||
return False
|
||||
|
||||
# 获取当前聊天的完整标识 (platform:chat_id)
|
||||
stream_parts = self.context.stream_id.split(':')
|
||||
if len(stream_parts) >= 2:
|
||||
platform = stream_parts[0]
|
||||
chat_id = stream_parts[1]
|
||||
current_chat_identifier = f"{platform}:{chat_id}"
|
||||
else:
|
||||
# 如果无法解析,则使用原始stream_id
|
||||
current_chat_identifier = self.context.stream_id
|
||||
|
||||
# 检查是否在启用列表中
|
||||
if is_group_chat:
|
||||
# 群聊检查
|
||||
enable_list = getattr(global_config.chat, 'proactive_thinking_enable_in_groups', [])
|
||||
if enable_list and current_chat_identifier not in enable_list:
|
||||
return False
|
||||
else:
|
||||
# 私聊检查
|
||||
enable_list = getattr(global_config.chat, 'proactive_thinking_enable_in_private', [])
|
||||
if enable_list and current_chat_identifier not in enable_list:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -222,9 +222,9 @@ class MessageRecv(Message):
|
||||
# 使用video analyzer分析视频
|
||||
video_analyzer = get_video_analyzer()
|
||||
result = await video_analyzer.analyze_video_from_bytes(
|
||||
video_bytes,
|
||||
video_bytes,
|
||||
filename,
|
||||
prompt="请详细分析这个视频的内容,包括场景、人物、动作、情感等"
|
||||
prompt=global_config.video_analysis.batch_analysis_prompt
|
||||
)
|
||||
|
||||
logger.info(f"视频分析结果: {result}")
|
||||
@@ -397,9 +397,9 @@ class MessageRecvS4U(MessageRecv):
|
||||
# 使用video analyzer分析视频
|
||||
video_analyzer = get_video_analyzer()
|
||||
result = await video_analyzer.analyze_video_from_bytes(
|
||||
video_bytes,
|
||||
video_bytes,
|
||||
filename,
|
||||
prompt="请详细分析这个视频的内容,包括场景、人物、动作、情感等"
|
||||
prompt=global_config.video_analysis.batch_analysis_prompt
|
||||
)
|
||||
|
||||
logger.info(f"视频分析结果: {result}")
|
||||
|
||||
@@ -1010,6 +1010,16 @@ class DefaultReplyer:
|
||||
prompt_info = results_dict["prompt_info"]
|
||||
cross_context_block = results_dict["cross_context"]
|
||||
|
||||
# 检查是否为视频分析结果,并注入引导语
|
||||
if target and ("[视频内容]" in target or "好的,我将根据您提供的" in target):
|
||||
video_prompt_injection = "\n请注意,以上内容是你刚刚观看的视频,请以第一人称分享你的观后感,而不是在分析一份报告。"
|
||||
memory_block += video_prompt_injection
|
||||
|
||||
# 检查是否为视频分析结果,并注入引导语
|
||||
if target and ("[视频内容]" in target or "好的,我将根据您提供的" in target):
|
||||
video_prompt_injection = "\n请注意,以上内容是你刚刚观看的视频,请以第一人称分享你的观后感,而不是在分析一份报告。"
|
||||
memory_block += video_prompt_injection
|
||||
|
||||
keywords_reaction_prompt = await self.build_keywords_reaction_prompt(target)
|
||||
|
||||
if extra_info:
|
||||
|
||||
@@ -169,9 +169,23 @@ class VideoAnalyzer:
|
||||
self.frame_quality = getattr(config, 'frame_quality', 85)
|
||||
self.max_image_size = getattr(config, 'max_image_size', 600)
|
||||
self.enable_frame_timing = getattr(config, 'enable_frame_timing', True)
|
||||
self.batch_analysis_prompt = getattr(config, 'batch_analysis_prompt', """请分析这个视频的内容。这些图片是从视频中按时间顺序提取的关键帧。
|
||||
|
||||
# 从personality配置中获取人格信息
|
||||
try:
|
||||
personality_config = global_config.personality
|
||||
self.personality_core = getattr(personality_config, 'personality_core', "是一个积极向上的女大学生")
|
||||
self.personality_side = getattr(personality_config, 'personality_side', "用一句话或几句话描述人格的侧面特点")
|
||||
except AttributeError:
|
||||
# 如果没有personality配置,使用默认值
|
||||
self.personality_core = "是一个积极向上的女大学生"
|
||||
self.personality_side = "用一句话或几句话描述人格的侧面特点"
|
||||
|
||||
self.batch_analysis_prompt = getattr(config, 'batch_analysis_prompt', """请以第一人称的视角来观看这一个视频,你看到的这些是从视频中按时间顺序提取的关键帧。
|
||||
|
||||
请提供详细的分析,包括:
|
||||
你的核心人设是:{personality_core}。
|
||||
你的人格细节是:{personality_side}。
|
||||
|
||||
请提供详细的视频内容描述,涵盖以下方面:
|
||||
1. 视频的整体内容和主题
|
||||
2. 主要人物、对象和场景描述
|
||||
3. 动作、情节和时间线发展
|
||||
@@ -179,7 +193,7 @@ class VideoAnalyzer:
|
||||
5. 整体氛围和情感表达
|
||||
6. 任何特殊的视觉效果或文字内容
|
||||
|
||||
请用中文回答,分析要详细准确。""")
|
||||
请用中文回答,结果要详细准确。""")
|
||||
|
||||
# 新增的线程池配置
|
||||
self.use_multiprocessing = getattr(config, 'use_multiprocessing', True)
|
||||
@@ -460,8 +474,11 @@ class VideoAnalyzer:
|
||||
if not frames:
|
||||
return "❌ 没有可分析的帧"
|
||||
|
||||
# 构建提示词
|
||||
prompt = self.batch_analysis_prompt
|
||||
# 构建提示词并格式化人格信息,要不然占位符的那个会爆炸
|
||||
prompt = self.batch_analysis_prompt.format(
|
||||
personality_core=self.personality_core,
|
||||
personality_side=self.personality_side
|
||||
)
|
||||
|
||||
if user_question:
|
||||
prompt += f"\n\n用户问题: {user_question}"
|
||||
|
||||
@@ -84,9 +84,9 @@ class ChatConfig(ValidatedConfigBase):
|
||||
The_scope_that_proactive_thinking_can_trigger: str = Field(default="all", description="主动思考可以触发的范围")
|
||||
proactive_thinking_in_private: bool = Field(default=True, description="主动思考可以在私聊里面启用")
|
||||
proactive_thinking_in_group: bool = Field(default=True, description="主动思考可以在群聊里面启用")
|
||||
proactive_thinking_enable_ids: List[int] = Field(default_factory=list, description="启用主动思考的范围,不区分群聊和私聊,为空则不限制")
|
||||
proactive_thinking_enable_in_private: List[str] = Field(default_factory=list, description="启用主动思考的私聊范围,格式:platform:user_id,为空则不限制")
|
||||
proactive_thinking_enable_in_groups: List[str] = Field(default_factory=list, description="启用主动思考的群聊范围,格式:platform:group_id,为空则不限制")
|
||||
delta_sigma: int = Field(default=120, description="采用正态分布随机时间间隔")
|
||||
enable_ids: List[int] = Field(default_factory=lambda: [123456, 234567], description="启用主动思考的范围,不区分群聊和私聊,为空则不限制")
|
||||
proactive_thinking_prompt_template: str = Field(default="""现在群里面已经隔了{time}没有人发送消息了,请你结合上下文以及群聊里面之前聊过的话题和你的人设来决定要不要主动发送消息,你可以选择:
|
||||
|
||||
1. 继续保持沉默(当{time}以前已经结束了一个话题并且你不想挑起新话题时)
|
||||
|
||||
Reference in New Issue
Block a user