This commit is contained in:
tcmofashi
2025-04-18 13:28:26 +08:00
24 changed files with 3656 additions and 236 deletions

View File

@@ -8,6 +8,8 @@ from ..chat_module.only_process.only_message_process import MessageProcessor
from src.common.logger import get_module_logger, CHAT_STYLE_CONFIG, LogConfig
from ..chat_module.think_flow_chat.think_flow_chat import ThinkFlowChat
from ..chat_module.reasoning_chat.reasoning_chat import ReasoningChat
from ..chat_module.heartFC_chat.heartFC_chat import HeartFC_Chat
from ..chat_module.heartFC_chat.heartFC_processor import HeartFC_Processor
from ..utils.prompt_builder import Prompt, global_prompt_manager
import traceback
@@ -30,6 +32,8 @@ class ChatBot:
self.mood_manager.start_mood_update() # 启动情绪更新
self.think_flow_chat = ThinkFlowChat()
self.reasoning_chat = ReasoningChat()
self.heartFC_chat = HeartFC_Chat()
self.heartFC_processor = HeartFC_Processor(self.heartFC_chat)
self.only_process_chat = MessageProcessor()
# 创建初始化PFC管理器的任务会在_ensure_started时执行
@@ -117,7 +121,10 @@ class ChatBot:
if groupinfo.group_id in global_config.talk_allowed_groups:
# logger.debug(f"开始群聊模式{str(message_data)[:50]}...")
if global_config.response_mode == "heart_flow":
await self.think_flow_chat.process_message(message_data)
# logger.info(f"启动最新最好的思维流FC模式{str(message_data)[:50]}...")
await self.heartFC_processor.process_message(message_data)
elif global_config.response_mode == "reasoning":
# logger.debug(f"开始推理模式{str(message_data)[:50]}...")
await self.reasoning_chat.process_message(message_data)

View File

@@ -190,6 +190,20 @@ class ChatManager:
stream_id = self._generate_stream_id(platform, user_info, group_info)
return self.streams.get(stream_id)
def get_stream_name(self, stream_id: str) -> Optional[str]:
"""根据 stream_id 获取聊天流名称"""
stream = self.get_stream(stream_id)
if not stream:
return None
if stream.group_info and stream.group_info.group_name:
return stream.group_info.group_name
elif stream.user_info and stream.user_info.user_nickname:
return f"{stream.user_info.user_nickname}的私聊"
else:
# 如果没有群名或用户昵称,返回 None 或其他默认值
return None
@staticmethod
async def _save_stream(stream: ChatStream):
"""保存聊天流到数据库"""

View File

@@ -340,7 +340,7 @@ def random_remove_punctuation(text: str) -> str:
def process_llm_response(text: str) -> List[str]:
# 先保护颜文字
protected_text, kaomoji_mapping = protect_kaomoji(text)
logger.debug(f"保护颜文字后的文本: {protected_text}")
logger.trace(f"保护颜文字后的文本: {protected_text}")
# 提取被 () 或 [] 包裹的内容
pattern = re.compile(r"[\(\[\].*?[\)\]\]")
# _extracted_contents = pattern.findall(text)
@@ -717,30 +717,12 @@ def parse_text_timestamps(text: str, mode: str = "normal") -> str:
# normal模式: 直接转换所有时间戳
if mode == "normal":
result_text = text
# 将时间戳转换为可读格式并记录相同格式的时间戳
timestamp_readable_map = {}
readable_time_used = set()
for match in matches:
timestamp = float(match.group(1))
readable_time = translate_timestamp_to_human_readable(timestamp, "normal")
timestamp_readable_map[match.group(0)] = (timestamp, readable_time)
# 按时间戳排序
sorted_timestamps = sorted(timestamp_readable_map.items(), key=lambda x: x[1][0])
# 执行替换,相同格式的只保留最早的
for ts_str, (_, readable) in sorted_timestamps:
pattern_instance = re.escape(ts_str)
if readable in readable_time_used:
# 如果这个可读时间已经使用过,替换为空字符串
result_text = re.sub(pattern_instance, "", result_text, count=1)
else:
# 否则替换为可读时间并记录
result_text = re.sub(pattern_instance, readable, result_text, count=1)
readable_time_used.add(readable)
# 由于替换会改变文本长度,需要使用正则替换而非直接替换
pattern_instance = re.escape(match.group(0))
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
return result_text
else:
# lite模式: 按5秒间隔划分并选择性转换
@@ -799,30 +781,15 @@ def parse_text_timestamps(text: str, mode: str = "normal") -> str:
pattern_instance = re.escape(match.group(0))
result_text = re.sub(pattern_instance, "", result_text, count=1)
# 按照时间戳升序排序
to_convert.sort(key=lambda x: x[0])
# 将时间戳转换为可读时间并记录哪些可读时间已经使用过
converted_timestamps = []
readable_time_used = set()
# 按照时间戳原始顺序排序,避免替换时位置错误
to_convert.sort(key=lambda x: x[1].start())
# 执行替换
# 由于替换会改变文本长度,从后向前替换
to_convert.reverse()
for ts, match in to_convert:
readable_time = translate_timestamp_to_human_readable(ts, "relative")
converted_timestamps.append((ts, match, readable_time))
# 按照时间戳原始顺序排序,避免替换时位置错误
converted_timestamps.sort(key=lambda x: x[1].start())
# 从后向前替换,避免位置改变
converted_timestamps.reverse()
for match, readable_time in converted_timestamps:
pattern_instance = re.escape(match.group(0))
if readable_time in readable_time_used:
# 如果相同格式的时间已存在,替换为空字符串
result_text = re.sub(pattern_instance, "", result_text, count=1)
else:
# 否则替换为可读时间并记录
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
readable_time_used.add(readable_time)
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
return result_text

View File

@@ -112,7 +112,7 @@ class ImageManager:
# 查询缓存的描述
cached_description = self._get_description_from_db(image_hash, "emoji")
if cached_description:
logger.debug(f"缓存表情包描述: {cached_description}")
# logger.debug(f"缓存表情包描述: {cached_description}")
return f"[表情包:{cached_description}]"
# 调用AI获取描述