From 9373ccd2cbbe1dab68548cc87f4db1af8aaa4814 Mon Sep 17 00:00:00 2001 From: guo zebin Date: Wed, 7 Jan 2026 14:58:38 +0800 Subject: [PATCH] Update fay_core.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.修复prestart标签过滤的正规表达式; 2.修复因prestart标签过滤而导致is first标记有可能掉失的问题。 --- core/fay_core.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/core/fay_core.py b/core/fay_core.py index e1c297b..cd3a79f 100644 --- a/core/fay_core.py +++ b/core/fay_core.py @@ -77,7 +77,8 @@ class FeiFei: self.sound_query = Queue() self.think_mode_users = {} # 使用字典存储每个用户的think模式状态 self.think_time_users = {} #使用字典存储每个用户的think开始时间 - self.user_conv_map = {} #存储用户对话id及句子流序号,key为(username, conversation_id) + self.user_conv_map = {} #存储用户对话id及句子流序号,key为(username, conversation_id) + self.pending_isfirst = {} # 存储因prestart被过滤而延迟的isfirst标记,key为username def __remove_emojis(self, text): """ @@ -308,7 +309,7 @@ class FeiFei: return None # 检查是否是 prestart 内容(不应该影响 thinking 状态) - is_prestart_content = text and '' in text and '' in text + is_prestart_content = self.__has_prestart(text) # 流式文本拼接存库 content_id = 0 @@ -660,7 +661,7 @@ class FeiFei: #面板播放 config_util.load_config() # 检查是否是 prestart 内容 - is_prestart = text and '' in text and '' in text + is_prestart = self.__has_prestart(text) if config_util.config["interact"]["playSound"]: # prestart 内容不应该进入播放队列,避免触发 Normal 状态 if not is_prestart: @@ -728,9 +729,17 @@ class FeiFei: if not text: return text import re - # 移除 ... 标签及其内容 - cleaned = re.sub(r'[\s\S]*?', '', text, flags=re.IGNORECASE) - return cleaned.strip() + # 移除 ... 标签及其内容(支持属性) + cleaned = re.sub(r']*>[\s\S]*?', '', text, flags=re.IGNORECASE) + return cleaned.strip() + + def __has_prestart(self, text): + """ + 判断文本中是否包含 prestart 标签(支持属性) + """ + if not text: + return False + return re.search(r']*>[\s\S]*?', text, flags=re.IGNORECASE) is not None def __send_panel_message(self, text, username, uid, content_id=None, type=None): """ @@ -746,7 +755,7 @@ class FeiFei: # 检查是否是 prestart 内容,prestart 内容不应该更新日志区消息 # 因为这会覆盖掉"思考中..."的状态显示 - is_prestart = text and '' in text and '' in text + is_prestart = self.__has_prestart(text) # gui日志区消息(prestart 内容跳过,保持"思考中..."状态) if not is_prestart: @@ -781,9 +790,16 @@ class FeiFei: cleaned_text = self.__remove_prestart_tags(text) if text else "" full_text = self.__remove_emojis(cleaned_text.replace("*", "")) if cleaned_text else "" - # 如果文本为空且不是结束标记,则不发送 - if not full_text and not is_end: - return + # 如果文本为空且不是结束标记,则不发送,但需保留 is_first + if not full_text and not is_end: + if is_first: + self.pending_isfirst[username] = True + return + + # 检查是否有延迟的 is_first 需要应用 + if self.pending_isfirst.get(username, False): + is_first = True + self.pending_isfirst[username] = False if wsa_server.get_instance().is_connected(username): content = {