diff --git a/config-template.py b/config-template.py index e519c28e..3cea74fa 100644 --- a/config-template.py +++ b/config-template.py @@ -89,7 +89,7 @@ preset_mode = "default" # 过滤AI脱离人设的消息 # 这类消息在对应情景json中设置,将其替换为自定义消息,以保持人格 -# filter_ai_warning = False +filter_ai_warning = False # 群内响应规则 # 符合此消息的群内消息即使不包含at机器人也会响应 diff --git a/pkg/openai/session.py b/pkg/openai/session.py index 2cd54baf..afd2af99 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -256,17 +256,19 @@ class Session: del (res_ans_spt[0]) res_ans = '\n\n'.join(res_ans_spt) + # 检测是否包含ai人格否定 - # logging.debug('bot_filter: {}'.format(self.bot_filter)) - # if config.filter_ai_warning and self.bot_filter: - # import re - # match = re.search(self.bot_filter['reg'], res_ans) - # logging.debug(self.bot_filter) - # logging.debug(res_ans) - # if match: - # logging.debug('回复:{}, 检测到人格否定,替换中。。'.format(res_ans)) - # res_ans = self.bot_filter['replace'] - # logging.debug('替换为: {}'.format(res_ans)) + logging.debug('bot_filter: {}'.format(self.bot_filter)) + if config.filter_ai_warning and self.bot_filter: + import re + match = re.search(self.bot_filter['reg'], res_ans) + logging.debug(self.bot_filter) + logging.debug(res_ans) + if match: + logging.debug('回复:{}, 检测到人格否定,替换中。。'.format(res_ans)) + res_ans = self.bot_filter['replace'] + logging.debug('替换为: {}'.format(res_ans)) + # 将此次对话的双方内容加入到prompt中 self.prompt.append({'role': 'user', 'content': text})