From 3b55f706de2699e6f2b8f4c94a95fa25e07a2af3 Mon Sep 17 00:00:00 2001 From: chordfish <592229466@qq.com> Date: Thu, 9 Mar 2023 19:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=98=B2=E4=BA=BA=E6=A0=BC?= =?UTF-8?q?=E5=90=A6=E5=AE=9A=E7=9A=84=E4=B8=80=E4=B8=AABug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/openai/session.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/openai/session.py b/pkg/openai/session.py index aae1ae57..0eab952b 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -256,7 +256,19 @@ class Session: if len(res_ans_spt) > 1: 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)) + # 将此次对话的双方内容加入到prompt中 self.prompt.append({'role': 'user', 'content': text}) self.prompt.append({'role': 'assistant', 'content': res_ans})