From a4105d06924f7547f00e85eb59ca2136c3b48fe9 Mon Sep 17 00:00:00 2001 From: Ronifue Date: Tue, 15 Apr 2025 16:24:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E3=80=90=E6=9B=B4?= =?UTF-8?q?=E5=A5=BD=E7=9A=84=E8=A1=A8=E6=83=85=E5=8C=85=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E3=80=91=EF=BC=88=E8=BF=AB=E7=9C=9F=EF=BC=89?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E9=A2=9C=E6=96=87=E5=AD=97=E6=B6=88?= =?UTF-8?q?=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index b4e2cb3c2..ba4781acc 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -324,11 +324,16 @@ 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}") # 提取被 () 或 [] 包裹的内容 pattern = re.compile(r"[\(\[].*?[\)\]]") - _extracted_contents = pattern.findall(text) + # _extracted_contents = pattern.findall(text) + _extracted_contents = pattern.findall(protected_text) # 在保护后的文本上查找 # 去除 () 和 [] 及其包裹的内容 - cleaned_text = pattern.sub("", text) + # cleaned_text = pattern.sub("", text) + cleaned_text = pattern.sub("", protected_text) logger.debug(f"{text}去除括号处理后的文本: {cleaned_text}") # 对清理后的文本进行进一步处理 @@ -368,6 +373,8 @@ def process_llm_response(text: str) -> List[str]: return [f"{global_config.BOT_NICKNAME}不知道哦"] # sentences.extend(extracted_contents) + # 在所有句子处理完毕后,对包含占位符的列表进行恢复 + sentences = recover_kaomoji(sentences, kaomoji_mapping) return sentences