This commit is contained in:
Windpicker-owo
2025-08-25 21:15:27 +08:00
8 changed files with 118 additions and 64 deletions

View File

@@ -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

View File

@@ -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}")

View File

@@ -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:

View File

@@ -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}"