From d78add96bb2f505f4d1136d7c5287bcfcd2e12e3 Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:06:02 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BB=99keywords=5Freaction=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺便做了正则表达式预编译 --- .../chat_module/only_process/only_message_process.py | 2 +- .../chat_module/reasoning_chat/reasoning_chat.py | 2 +- .../reasoning_chat/reasoning_prompt_builder.py | 12 ++++++++++++ .../chat_module/think_flow_chat/think_flow_chat.py | 2 +- .../think_flow_chat/think_flow_prompt_builder.py | 11 +++++++++++ src/plugins/config/config.py | 8 ++++++-- template/bot_config_template.toml | 5 +++++ 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/plugins/chat_module/only_process/only_message_process.py b/src/plugins/chat_module/only_process/only_message_process.py index 6da19efe..e2e903af 100644 --- a/src/plugins/chat_module/only_process/only_message_process.py +++ b/src/plugins/chat_module/only_process/only_message_process.py @@ -28,7 +28,7 @@ class MessageProcessor: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index 683bef46..54915154 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -281,7 +281,7 @@ class ReasoningChat: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index a379fa6d..1081fb09 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -1,4 +1,5 @@ import random +import re import time from typing import Optional, Union @@ -115,6 +116,17 @@ class PromptBuilder: f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}" ) keywords_reaction_prompt += rule.get("reaction", "") + "," + for pattern in rule.get("regex", []): + result = pattern.search(message_txt) + if result: + reaction = rule.get('reaction', '') + for name, content in result.groupdict().items(): + reaction = reaction.replace(f'[{name}]', content) + logger.info( + f"匹配到以下正则表达式:{pattern},触发反应:{reaction}" + ) + keywords_reaction_prompt += reaction + "," + break # 中文高手(新加的好玩功能) prompt_ger = "" diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index f845770d..6d007f95 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -357,7 +357,7 @@ class ThinkFlowChat: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py index fc52a615..608304a2 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py @@ -86,6 +86,17 @@ class PromptBuilder: f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}" ) keywords_reaction_prompt += rule.get("reaction", "") + "," + for pattern in rule.get("regex", []): + result = pattern.search(message_txt) + if result: + reaction = rule.get('reaction', '') + for name, content in result.groupdict().items(): + reaction = reaction.replace(f'[{name}]', content) + logger.info( + f"匹配到以下正则表达式:{pattern},触发反应:{reaction}" + ) + keywords_reaction_prompt += reaction + "," + break # 中文高手(新加的好玩功能) prompt_ger = "" diff --git a/src/plugins/config/config.py b/src/plugins/config/config.py index eccb3bc0..b8bc3eff 100644 --- a/src/plugins/config/config.py +++ b/src/plugins/config/config.py @@ -1,4 +1,5 @@ import os +import re from dataclasses import dataclass, field from typing import Dict, List, Optional from dateutil import tz @@ -545,8 +546,8 @@ class BotConfig: "response_interested_rate_amplifier", config.response_interested_rate_amplifier ) config.down_frequency_rate = msg_config.get("down_frequency_rate", config.down_frequency_rate) - config.ban_msgs_regex = msg_config.get("ban_msgs_regex", config.ban_msgs_regex) - + for r in msg_config.get("ban_msgs_regex", config.ban_msgs_regex): + config.ban_msgs_regex.add(re.compile(r)) if config.INNER_VERSION in SpecifierSet(">=0.0.11"): config.max_response_length = msg_config.get("max_response_length", config.max_response_length) if config.INNER_VERSION in SpecifierSet(">=1.1.4"): @@ -587,6 +588,9 @@ class BotConfig: keywords_reaction_config = parent["keywords_reaction"] if keywords_reaction_config.get("enable", False): config.keywords_reaction_rules = keywords_reaction_config.get("rules", config.keywords_reaction_rules) + for rule in config.keywords_reaction_rules: + if rule.get("enable", False) and "regex" in rule: + rule["regex"] = [re.compile(r) for r in rule.get("regex", [])] def chinese_typo(parent: dict): chinese_typo_config = parent["chinese_typo"] diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 70cf0e0b..e4762b7d 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -149,6 +149,11 @@ enable = false # 仅作示例,不会触发 keywords = ["测试关键词回复","test",""] reaction = "回答“测试成功”" +[[keywords_reaction.rules]] # 使用正则表达式匹配句式 +enable = false # 仅作示例,不会触发 +regex = ["^(?P\\S{1,20})是这样的$"] # 将匹配到的词汇命名为n,反应中对应的[n]会被替换为匹配到的内容,若不了解正则表达式请勿编写 +reaction = "请按照以下模板造句:[n]是这样的,xx只要xx就可以,可是[n]要考虑的事情就很多了,比如什么时候xx,什么时候xx,什么时候xx。(请自由发挥替换xx部分,只需保持句式结构,同时表达一种将[n]过度重视的反讽意味)" + [chinese_typo] enable = true # 是否启用中文错别字生成器 error_rate=0.001 # 单字替换概率 From fc4063a467b12ffca58a83c1f238731e0a12106b Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:09:37 +0800 Subject: [PATCH 2/6] =?UTF-8?q?import=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat_module/only_process/only_message_process.py | 1 - src/plugins/chat_module/reasoning_chat/reasoning_chat.py | 1 - .../chat_module/reasoning_chat/reasoning_prompt_builder.py | 1 - 3 files changed, 3 deletions(-) diff --git a/src/plugins/chat_module/only_process/only_message_process.py b/src/plugins/chat_module/only_process/only_message_process.py index e2e903af..a39b7f8b 100644 --- a/src/plugins/chat_module/only_process/only_message_process.py +++ b/src/plugins/chat_module/only_process/only_message_process.py @@ -2,7 +2,6 @@ from src.common.logger import get_module_logger from src.plugins.chat.message import MessageRecv from src.plugins.storage.storage import MessageStorage from src.plugins.config.config import global_config -import re from datetime import datetime logger = get_module_logger("pfc_message_processor") diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index 54915154..194bbf4f 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -1,6 +1,5 @@ import time from random import random -import re from ...memory_system.Hippocampus import HippocampusManager from ...moods.moods import MoodManager diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 1081fb09..045045ba 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -1,5 +1,4 @@ import random -import re import time from typing import Optional, Union From 9de20854a16fc69d84c36c46aee2ab34c5689d1b Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:10:49 +0800 Subject: [PATCH 3/6] =?UTF-8?q?import=E4=BC=98=E5=8C=96+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat_module/think_flow_chat/think_flow_chat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index 6d007f95..c48f9cb7 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -1,6 +1,5 @@ import time from random import random -import re from ...memory_system.Hippocampus import HippocampusManager from ...moods.moods import MoodManager From 3653e2b4ae849cf8660e85b1b1f0bde8b6571a2c Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:06:02 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E7=BB=99keywords=5Freaction=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺便做了正则表达式预编译 --- .../chat_module/only_process/only_message_process.py | 2 +- .../chat_module/reasoning_chat/reasoning_chat.py | 2 +- .../reasoning_chat/reasoning_prompt_builder.py | 12 ++++++++++++ .../chat_module/think_flow_chat/think_flow_chat.py | 2 +- .../think_flow_chat/think_flow_prompt_builder.py | 11 +++++++++++ src/plugins/config/config.py | 8 ++++++-- template/bot_config_template.toml | 5 +++++ 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/plugins/chat_module/only_process/only_message_process.py b/src/plugins/chat_module/only_process/only_message_process.py index 6da19efe..e2e903af 100644 --- a/src/plugins/chat_module/only_process/only_message_process.py +++ b/src/plugins/chat_module/only_process/only_message_process.py @@ -28,7 +28,7 @@ class MessageProcessor: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index b9e94e4f..0bdfc7c3 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -302,7 +302,7 @@ class ReasoningChat: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index a379fa6d..1081fb09 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -1,4 +1,5 @@ import random +import re import time from typing import Optional, Union @@ -115,6 +116,17 @@ class PromptBuilder: f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}" ) keywords_reaction_prompt += rule.get("reaction", "") + "," + for pattern in rule.get("regex", []): + result = pattern.search(message_txt) + if result: + reaction = rule.get('reaction', '') + for name, content in result.groupdict().items(): + reaction = reaction.replace(f'[{name}]', content) + logger.info( + f"匹配到以下正则表达式:{pattern},触发反应:{reaction}" + ) + keywords_reaction_prompt += reaction + "," + break # 中文高手(新加的好玩功能) prompt_ger = "" diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index 51bafcbc..f9bc275a 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -388,7 +388,7 @@ class ThinkFlowChat: def _check_ban_regex(self, text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: - if re.search(pattern, text): + if pattern.search(text): logger.info( f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" ) diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py index 5d701c6a..8938e2e7 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py @@ -61,6 +61,17 @@ class PromptBuilder: f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}" ) keywords_reaction_prompt += rule.get("reaction", "") + "," + for pattern in rule.get("regex", []): + result = pattern.search(message_txt) + if result: + reaction = rule.get('reaction', '') + for name, content in result.groupdict().items(): + reaction = reaction.replace(f'[{name}]', content) + logger.info( + f"匹配到以下正则表达式:{pattern},触发反应:{reaction}" + ) + keywords_reaction_prompt += reaction + "," + break # 中文高手(新加的好玩功能) prompt_ger = "" diff --git a/src/plugins/config/config.py b/src/plugins/config/config.py index 23e27749..be334329 100644 --- a/src/plugins/config/config.py +++ b/src/plugins/config/config.py @@ -1,4 +1,5 @@ import os +import re from dataclasses import dataclass, field from typing import Dict, List, Optional from dateutil import tz @@ -545,8 +546,8 @@ class BotConfig: "response_interested_rate_amplifier", config.response_interested_rate_amplifier ) config.down_frequency_rate = msg_config.get("down_frequency_rate", config.down_frequency_rate) - config.ban_msgs_regex = msg_config.get("ban_msgs_regex", config.ban_msgs_regex) - + for r in msg_config.get("ban_msgs_regex", config.ban_msgs_regex): + config.ban_msgs_regex.add(re.compile(r)) if config.INNER_VERSION in SpecifierSet(">=0.0.11"): config.max_response_length = msg_config.get("max_response_length", config.max_response_length) if config.INNER_VERSION in SpecifierSet(">=1.1.4"): @@ -587,6 +588,9 @@ class BotConfig: keywords_reaction_config = parent["keywords_reaction"] if keywords_reaction_config.get("enable", False): config.keywords_reaction_rules = keywords_reaction_config.get("rules", config.keywords_reaction_rules) + for rule in config.keywords_reaction_rules: + if rule.get("enable", False) and "regex" in rule: + rule["regex"] = [re.compile(r) for r in rule.get("regex", [])] def chinese_typo(parent: dict): chinese_typo_config = parent["chinese_typo"] diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 84a70cd9..059a03ed 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -149,6 +149,11 @@ enable = false # 仅作示例,不会触发 keywords = ["测试关键词回复","test",""] reaction = "回答“测试成功”" +[[keywords_reaction.rules]] # 使用正则表达式匹配句式 +enable = false # 仅作示例,不会触发 +regex = ["^(?P\\S{1,20})是这样的$"] # 将匹配到的词汇命名为n,反应中对应的[n]会被替换为匹配到的内容,若不了解正则表达式请勿编写 +reaction = "请按照以下模板造句:[n]是这样的,xx只要xx就可以,可是[n]要考虑的事情就很多了,比如什么时候xx,什么时候xx,什么时候xx。(请自由发挥替换xx部分,只需保持句式结构,同时表达一种将[n]过度重视的反讽意味)" + [chinese_typo] enable = true # 是否启用中文错别字生成器 error_rate=0.001 # 单字替换概率 From d7aece01f182c4f2e0dac386e36d0fdc37c5eed5 Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:09:37 +0800 Subject: [PATCH 5/6] =?UTF-8?q?import=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Conflicts: # src/plugins/chat_module/reasoning_chat/reasoning_chat.py --- .../only_process/only_message_process.py | 1 - .../reasoning_chat/reasoning_chat.py | 22 +++++++++---------- .../reasoning_prompt_builder.py | 1 - 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/plugins/chat_module/only_process/only_message_process.py b/src/plugins/chat_module/only_process/only_message_process.py index e2e903af..a39b7f8b 100644 --- a/src/plugins/chat_module/only_process/only_message_process.py +++ b/src/plugins/chat_module/only_process/only_message_process.py @@ -2,7 +2,6 @@ from src.common.logger import get_module_logger from src.plugins.chat.message import MessageRecv from src.plugins.storage.storage import MessageStorage from src.plugins.config.config import global_config -import re from datetime import datetime logger = get_module_logger("pfc_message_processor") diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index 0bdfc7c3..85d6b72b 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -1,6 +1,6 @@ import time from random import random -import re + from typing import List from ...memory_system.Hippocampus import HippocampusManager from ...moods.moods import MoodManager @@ -59,10 +59,10 @@ class ReasoningChat: return thinking_id - async def _send_response_messages(self, - message, - chat, - response_set:List[str], + async def _send_response_messages(self, + message, + chat, + response_set:List[str], thinking_id) -> MessageSending: """发送回复消息""" container = message_manager.get_container(chat.stream_id) @@ -240,9 +240,9 @@ class ReasoningChat: thinking_id = await self._create_thinking_message(message, chat, userinfo, messageinfo) timer2 = time.time() timing_results["创建思考消息"] = timer2 - timer1 - + logger.debug(f"创建捕捉器,thinking_id:{thinking_id}") - + info_catcher = info_catcher_manager.get_info_catcher(thinking_id) info_catcher.catch_decide_to_response(message) @@ -251,7 +251,7 @@ class ReasoningChat: response_set = await self.gpt.generate_response(message,thinking_id) timer2 = time.time() timing_results["生成回复"] = timer2 - timer1 - + info_catcher.catch_after_generate_response(timing_results["生成回复"]) if not response_set: @@ -263,10 +263,10 @@ class ReasoningChat: first_bot_msg = await self._send_response_messages(message, chat, response_set, thinking_id) timer2 = time.time() timing_results["发送消息"] = timer2 - timer1 - + info_catcher.catch_after_response(timing_results["发送消息"],response_set,first_bot_msg) - - + + info_catcher.done_catch() # 处理表情包 diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 1081fb09..045045ba 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -1,5 +1,4 @@ import random -import re import time from typing import Optional, Union From 302a0c6741ecc66706d583f0cacbdf47537d344e Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:10:49 +0800 Subject: [PATCH 6/6] =?UTF-8?q?import=E4=BC=98=E5=8C=96+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think_flow_chat/think_flow_chat.py | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index f9bc275a..cf0276d9 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -1,6 +1,5 @@ import time from random import random -import re import traceback from typing import List from ...memory_system.Hippocampus import HippocampusManager @@ -61,10 +60,10 @@ class ThinkFlowChat: return thinking_id - async def _send_response_messages(self, - message, - chat, - response_set:List[str], + async def _send_response_messages(self, + message, + chat, + response_set:List[str], thinking_id) -> MessageSending: """发送回复消息""" container = message_manager.get_container(chat.stream_id) @@ -266,8 +265,8 @@ class ThinkFlowChat: if random() < reply_probability: try: do_reply = True - - + + # 创建思考消息 try: @@ -277,9 +276,9 @@ class ThinkFlowChat: timing_results["创建思考消息"] = timer2 - timer1 except Exception as e: logger.error(f"心流创建思考消息失败: {e}") - + logger.debug(f"创建捕捉器,thinking_id:{thinking_id}") - + info_catcher = info_catcher_manager.get_info_catcher(thinking_id) info_catcher.catch_decide_to_response(message) @@ -291,7 +290,7 @@ class ThinkFlowChat: timing_results["观察"] = timer2 - timer1 except Exception as e: logger.error(f"心流观察失败: {e}") - + info_catcher.catch_after_observe(timing_results["观察"]) # 思考前脑内状态 @@ -306,7 +305,7 @@ class ThinkFlowChat: timing_results["思考前脑内状态"] = timer2 - timer1 except Exception as e: logger.error(f"心流思考前脑内状态失败: {e}") - + info_catcher.catch_afer_shf_step(timing_results["思考前脑内状态"],past_mind,current_mind) # 生成回复 @@ -316,7 +315,7 @@ class ThinkFlowChat: timing_results["生成回复"] = timer2 - timer1 info_catcher.catch_after_generate_response(timing_results["生成回复"]) - + if not response_set: logger.info("回复生成失败,返回为空") return @@ -329,11 +328,11 @@ class ThinkFlowChat: timing_results["发送消息"] = timer2 - timer1 except Exception as e: logger.error(f"心流发送消息失败: {e}") - - + + info_catcher.catch_after_response(timing_results["发送消息"],response_set,first_bot_msg) - - + + info_catcher.done_catch() # 处理表情包