diff --git a/app_chatgpt/models/ai_robot.py b/app_chatgpt/models/ai_robot.py index ee94de68..677a2ebd 100644 --- a/app_chatgpt/models/ai_robot.py +++ b/app_chatgpt/models/ai_robot.py @@ -125,7 +125,14 @@ GPT-3 A set of models that can understand and generate natural language return res_post def get_ai_pre(self, data, author_id=False, answer_id=False, **kwargs): - return False + search = WordsSearch() + search.SetKeywords([]) + content = data[0]['content'] + sensi = search.FindFirst(content) + if sensi is not None: + return _('温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。') + else: + return False def get_ai_post(self, res, author_id=False, answer_id=False, **kwargs): if res and isinstance(res, dict): diff --git a/app_chatgpt/models/lib/WordsSearch.py b/app_chatgpt/models/lib/WordsSearch.py index c7a45f84..9cf8a6a0 100644 --- a/app_chatgpt/models/lib/WordsSearch.py +++ b/app_chatgpt/models/lib/WordsSearch.py @@ -81,8 +81,8 @@ class WordsSearch(): def SetKeywords(self, keywords): keyword_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sensi_words.txt') s = open(keyword_path, 'r+', encoding='utf-8').read().split('\n') - self._keywords = s + keywords - # self._keywords = keywords + keywords += s + self._keywords = keywords self._indexs = [] for i in range(len(keywords)): self._indexs.append(i) diff --git a/app_chatgpt/models/mail_channel.py b/app_chatgpt/models/mail_channel.py index 2f7d0ed7..2cdc3fd6 100644 --- a/app_chatgpt/models/mail_channel.py +++ b/app_chatgpt/models/mail_channel.py @@ -89,7 +89,7 @@ class Channel(models.Model): ai = user_id.gpt_id chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt') - msg = message.description.replace('@%s' % answer_id.name, '').lstrip() + msg = message.preview.replace('@%s' % answer_id.name, '').lstrip() # print('prompt:', prompt) # print('-----') diff --git a/app_chatgpt/models/mail_thread.py b/app_chatgpt/models/mail_thread.py index b1bf7894..c24cbec8 100644 --- a/app_chatgpt/models/mail_thread.py +++ b/app_chatgpt/models/mail_thread.py @@ -1,20 +1,8 @@ # -*- coding: utf-8 -*- from odoo import fields, models, api, _ -from .lib.WordsSearch import WordsSearch class MailThread(models.AbstractModel): _inherit = "mail.thread" - # todo: 不是说在此屏蔽,而是当用户发出敏感词时,提示下,同时不发送到 ai - # @api.returns('mail.message', lambda value: value.id) - # def message_post(self, **kwargs): - - # self.ensure_one() - # search = WordsSearch() - # search.SetKeywords([]) - # body = kwargs.get('body', False) - # body = search.Replace(text=body) - # kwargs.update({'body': body}) - # return super(MailThread, self).message_post(**kwargs)