From e472525b0a54fbe62c8d30f67c20af895a9dbdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=8F=B6?= Date: Thu, 8 Dec 2022 15:01:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B1=8F=E8=94=BD=E8=AF=8D=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9B=9E=E5=A4=8D=E6=95=8F=E6=84=9F?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index 78adab2..845f249 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ import plugin from '../../lib/plugins/plugin.js' import { ChatGPTAPI } from 'chatgpt' import _ from 'lodash' const SESSION_TOKEN='' +const blockWords = '屏蔽词1,屏蔽词2,屏蔽词3' /** * 每个对话保留的时长。单个对话内ai是保留上下文的。超时后销毁对话,再次对话创建新的对话。 @@ -146,6 +147,14 @@ export class chatgpt extends plugin { utime: new Date(), num: previousConversation.num + 1 }), { EX: CONVERSATION_PRESERVE_TIME }) + + // 检索是否有屏蔽词 + const blockWord = blockWords.split(',').find(word => response.toLowerCase().includes(word.toLowerCase())) + if (blockWord) { + await this.reply(`返回内容存在敏感词,我不想回答你`, true) + return + } + /** 最后回复消息 */ await this.reply(`${response}`, true) } catch (e) { From ddf2714473fcd1c759d7f4153f441587aa3a8020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=8F=B6?= Date: Fri, 9 Dec 2022 14:36:35 +0800 Subject: [PATCH 2/2] Update index_no#.js --- index_no#.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index_no#.js b/index_no#.js index a6d955a..778f080 100644 --- a/index_no#.js +++ b/index_no#.js @@ -2,6 +2,7 @@ import plugin from '../../lib/plugins/plugin.js' import { ChatGPTAPI } from 'chatgpt' import _ from 'lodash' const SESSION_TOKEN = '' +const blockWords = '屏蔽词1,屏蔽词2,屏蔽词3' /** * 每个对话保留的时长。单个对话内ai是保留上下文的。超时后销毁对话,再次对话创建新的对话。 @@ -157,6 +158,14 @@ export class chatgpt extends plugin { utime: new Date(), num: previousConversation.num + 1 }), { EX: CONVERSATION_PRESERVE_TIME }) + + // 检索是否有屏蔽词 + const blockWord = blockWords.split(',').find(word => response.toLowerCase().includes(word.toLowerCase())) + if (blockWord) { + await this.reply(`返回内容存在敏感词,我不想回答你`, true) + return + } + /** 最后回复消息 */ await this.reply(`${response}`, e.isGroup) } catch (e) { @@ -164,4 +173,4 @@ export class chatgpt extends plugin { await this.reply(`与OpenAI通信异常,请稍后重试:${e}`, true, { recallMsg: e.isGroup ? 10 : 0 }) } } -} \ No newline at end of file +}