mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 11:26:07 +00:00
feat: 支持拒绝回复包含敏感词的提问 (#210)
This commit is contained in:
@@ -102,6 +102,10 @@ ignore_rules = {
|
|||||||
"regexp": []
|
"regexp": []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 是否检查收到的消息中是否包含敏感词
|
||||||
|
# 若收到的消息无法通过下方指定的敏感词检查策略,则发送提示信息
|
||||||
|
income_msg_check = False
|
||||||
|
|
||||||
# 敏感词过滤开关,以同样数量的*代替敏感词回复
|
# 敏感词过滤开关,以同样数量的*代替敏感词回复
|
||||||
# 请在sensitive.json中添加敏感词
|
# 请在sensitive.json中添加敏感词
|
||||||
sensitive_word_filter = True
|
sensitive_word_filter = True
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ class ReplyFilter:
|
|||||||
self.baidu_secret_key = config.baidu_secret_key
|
self.baidu_secret_key = config.baidu_secret_key
|
||||||
self.inappropriate_message_tips = config.inappropriate_message_tips
|
self.inappropriate_message_tips = config.inappropriate_message_tips
|
||||||
|
|
||||||
|
def is_illegal(self, message: str) -> bool:
|
||||||
|
processed = self.process(message)
|
||||||
|
if processed != message:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def process(self, message: str) -> str:
|
def process(self, message: str) -> str:
|
||||||
|
|
||||||
# 本地关键词屏蔽
|
# 本地关键词屏蔽
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||||||
result.mute_time_remaining))
|
result.mute_time_remaining))
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
import config
|
||||||
|
if hasattr(config, 'income_msg_check') and config.income_msg_check:
|
||||||
|
if mgr.reply_filter.is_illegal(text_message):
|
||||||
|
return MessageChain(Plain("[bot] 你的提问中有不合适的内容, 请更换措辞~"))
|
||||||
|
|
||||||
pkg.openai.session.get_session(session_name).acquire_response_lock()
|
pkg.openai.session.get_session(session_name).acquire_response_lock()
|
||||||
|
|
||||||
text_message = text_message.strip()
|
text_message = text_message.strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user