From 7288d3cb1595d4688437db0ccf54acbb03f7d08e Mon Sep 17 00:00:00 2001 From: chordfish <592229466@qq.com> Date: Thu, 9 Mar 2023 21:20:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=92=8C=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 2 +- pkg/openai/session.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) 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})