mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
app_chatgpt优化
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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('-----')
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user