mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
Merge branch '16.0' of https://github.com/guohuadeng/app-odoo into 16.0
# Conflicts: # app_chatgpt/models/mail_channel.py
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
|
||||
<field name="sequence">7</field>
|
||||
</record>
|
||||
<record id="chatgpt_robot3" model="ai.robot">
|
||||
<record id="chatgpt3_azure" model="ai.robot">
|
||||
<field name="name">ChatGPT Azure</field>
|
||||
<field name="provider">azure</field>
|
||||
<field name="endpoint">https://my.openai.azure.com</field>
|
||||
|
||||
@@ -47,31 +47,31 @@
|
||||
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="partner_chatgpt3" model="res.partner">
|
||||
<field name="name">ChatGPT Azure</field>
|
||||
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
|
||||
<record id="partner_chatgpt3_azure" model="res.partner">
|
||||
<field name="name">ChatGPT3 Azure</field>
|
||||
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt_blue.png"/>
|
||||
</record>
|
||||
|
||||
<record id="user_chatgpt3" model="res.users">
|
||||
<field name="login">chatgpt3@sunpop.cn</field>
|
||||
<field name="email">chatgpt3@sunpop.cn</field>
|
||||
<record id="user_chatgpt3_azure" model="res.users">
|
||||
<field name="login">chatgpt3_azure@odooai.cn</field>
|
||||
<field name="email">chatgpt3_azure@odooai.cn</field>
|
||||
<field name="password">chatgpt</field>
|
||||
<field name="partner_id" ref="app_chatgpt.partner_chatgpt3"/>
|
||||
<field name="gpt_id" ref="app_chatgpt.chatgpt_robot3"/>
|
||||
<field name="partner_id" ref="app_chatgpt.partner_chatgpt3_azure"/>
|
||||
<field name="gpt_id" ref="app_chatgpt.chatgpt3_azure"/>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
|
||||
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
|
||||
</record>
|
||||
<record id="partner_chatgpt4_azure" model="res.partner">
|
||||
<field name="name">ChatGPT4 Azure</field>
|
||||
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
|
||||
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt_blue.png"/>
|
||||
</record>
|
||||
|
||||
<record id="user_chatgpt4_azure" model="res.users">
|
||||
<field name="login">chatgpt4@sunpop.cn</field>
|
||||
<field name="email">chatgpt4@sunpop.cn</field>
|
||||
<field name="login">chatgpt4_azure@odooai.cn</field>
|
||||
<field name="email">chatgpt4_azure@odooai.cn</field>
|
||||
<field name="password">chatgpt</field>
|
||||
<field name="partner_id" ref="app_chatgpt.chatgpt4_azure"/>
|
||||
<field name="partner_id" ref="app_chatgpt.partner_chatgpt4_azure"/>
|
||||
<field name="gpt_id" ref="app_chatgpt.chatgpt4_azure"/>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
|
||||
|
||||
@@ -105,36 +105,37 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
def action_disconnect(self):
|
||||
requests.delete('https://chatgpt.com/v1/disconnect')
|
||||
|
||||
def get_ai(self, data, author_id=False, answer_id=False, **kwargs):
|
||||
def get_ai(self, data, author_id=False, answer_id=False, param={}):
|
||||
# 通用方法
|
||||
# author_id: 请求的 partner_id 对象
|
||||
# answer_id: 回答的 partner_id 对象
|
||||
# kwargs,dict 形式的可变参数
|
||||
self.ensure_one()
|
||||
# 前置勾子,一般返回 False,有问题返回响应内容
|
||||
res_pre = self.get_ai_pre(data, author_id, answer_id, **kwargs)
|
||||
res_pre = self.get_ai_pre(data, author_id, answer_id, param)
|
||||
if res_pre:
|
||||
return res_pre
|
||||
if hasattr(self, 'get_%s' % self.provider):
|
||||
res = getattr(self, 'get_%s' % self.provider)(data, author_id, answer_id, **kwargs)
|
||||
res = getattr(self, 'get_%s' % self.provider)(data, author_id, answer_id, param)
|
||||
else:
|
||||
res = _('No robot provider found')
|
||||
|
||||
# 后置勾子,返回处理后的内容,用于处理敏感词等
|
||||
res_post = self.get_ai_post(res, author_id, answer_id, **kwargs)
|
||||
res_post = self.get_ai_post(res, author_id, answer_id, param)
|
||||
return res_post
|
||||
|
||||
def get_ai_pre(self, data, author_id=False, answer_id=False, **kwargs):
|
||||
search = WordsSearch()
|
||||
search.SetKeywords([])
|
||||
content = data[0]['content']
|
||||
sensi = search.FindFirst(content)
|
||||
if sensi is not None:
|
||||
return _('温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。')
|
||||
def get_ai_pre(self, data, author_id=False, answer_id=False, param={}):
|
||||
if self.is_filtering:
|
||||
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):
|
||||
def get_ai_post(self, res, author_id=False, answer_id=False, param={}):
|
||||
if res and author_id and isinstance(res, openai.openai_object.OpenAIObject) or isinstance(res, list):
|
||||
usage = json.loads(json.dumps(res['usage']))
|
||||
content = json.loads(json.dumps(res['choices'][0]['message']['content']))
|
||||
@@ -212,12 +213,20 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
r_text = 'No response.'
|
||||
raise UserError(r_text)
|
||||
|
||||
def get_openai(self, data, author_id, answer_id, **kwargs):
|
||||
def get_openai(self, data, author_id, answer_id, param={}):
|
||||
self.ensure_one()
|
||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
|
||||
R_TIMEOUT = self.ai_timeout or 120
|
||||
o_url = self.endpoint or "https://api.openai.com/v1/chat/completions"
|
||||
|
||||
# 处理传参,传过来的优先于 robot 默认的
|
||||
max_tokens = param.get('max_tokens') or self.max_tokens or 600,
|
||||
temperature = param.get('temperature') or self.temperature or 0.9,
|
||||
top_p = param.get('top_p') or self.top_p or 0.6,
|
||||
frequency_penalty = param.get('frequency_penalty') or self.frequency_penalty or 0.5,
|
||||
presence_penalty = param.get('presence_penalty') or self.presence_penalty or 0.5,
|
||||
# request_timeout = param.get('request_timeout') or self.ai_timeout or 120,
|
||||
|
||||
if self.stop:
|
||||
stop = self.stop.split(',')
|
||||
else:
|
||||
@@ -231,10 +240,12 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
messages = data
|
||||
else:
|
||||
messages = [{"role": "user", "content": data}]
|
||||
# Ai角色设定
|
||||
sys_content = self.get_ai_system(kwargs.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
# Ai角色设定,如果没设定则再处理
|
||||
if messages[0].get('role') != 'system':
|
||||
sys_content = self.get_ai_system(param.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
# 暂时不变
|
||||
response = openai.ChatCompletion.create(
|
||||
model=self.ai_model,
|
||||
messages=messages,
|
||||
@@ -266,11 +277,11 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
"model": self.ai_model,
|
||||
"prompt": data,
|
||||
"temperature": 0.9,
|
||||
"max_tokens": self.max_tokens or 1000,
|
||||
"max_tokens": max_tokens,
|
||||
"top_p": 1,
|
||||
"frequency_penalty": 0.0,
|
||||
"presence_penalty": 0.6,
|
||||
"stop": ["Human:", "AI:"]
|
||||
"stop": stop
|
||||
}
|
||||
response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
|
||||
res = response.json()
|
||||
@@ -280,7 +291,7 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
|
||||
return _("Response Timeout, please speak again.")
|
||||
|
||||
def get_azure(self, data, author_id, answer_id, **kwargs):
|
||||
def get_azure(self, data, author_id, answer_id, param={}):
|
||||
self.ensure_one()
|
||||
# only for azure
|
||||
openai.api_type = self.provider
|
||||
@@ -299,10 +310,21 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
messages = data
|
||||
else:
|
||||
messages = [{"role": "user", "content": data}]
|
||||
# Ai角色设定
|
||||
sys_content = self.get_ai_system(kwargs.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
|
||||
# 处理传参,传过来的优先于 robot 默认的
|
||||
max_tokens = param.get('max_tokens') or self.max_tokens or 600,
|
||||
temperature = param.get('temperature') or self.temperature or 0.9,
|
||||
top_p = param.get('top_p') or self.top_p or 0.6,
|
||||
frequency_penalty = param.get('frequency_penalty') or self.frequency_penalty or 0.5,
|
||||
presence_penalty = param.get('presence_penalty') or self.presence_penalty or 0.5,
|
||||
# request_timeout = param.get('request_timeout') or self.ai_timeout or 120,
|
||||
|
||||
# Ai角色设定,如果没设定则再处理
|
||||
if messages[0].get('role') != 'system':
|
||||
sys_content = self.get_ai_system(param.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
# 暂时不变
|
||||
response = openai.ChatCompletion.create(
|
||||
engine=self.engine,
|
||||
messages=messages,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
回民吃猪肉
|
||||
习近平
|
||||
李强
|
||||
TMD
|
||||
毛民进党
|
||||
妹妹淫水 流
|
||||
@@ -331,7 +332,6 @@ meimei的小阴户
|
||||
毛佳静安定片
|
||||
鸟gm
|
||||
骚屄
|
||||
TeSt
|
||||
激情电影免费下载裸体美女乳房图
|
||||
日翻
|
||||
美臀嫰穴
|
||||
@@ -1637,7 +1637,6 @@ h站
|
||||
淫穢
|
||||
做爱电影
|
||||
免费淫奸女A片段试看 强*十八岁meinv护士看完保证你打飞机
|
||||
Test
|
||||
meinv 淫穴
|
||||
peng peng bang
|
||||
毛鸦片液
|
||||
@@ -8990,7 +8989,6 @@ mo擦小肥穴
|
||||
骚姐乱伦
|
||||
無套自拍
|
||||
白虎少婦
|
||||
test
|
||||
毛麻醉药
|
||||
wu jin de ren wu
|
||||
粗大的阴茎与紧窄的阴道壁之间的剧烈磨擦
|
||||
@@ -13689,7 +13687,6 @@ Tora Tora Gold Vol。14 星野みく
|
||||
肉棒里插肉洞
|
||||
亚甲二氧基甲基安非他明
|
||||
人民
|
||||
TEsT
|
||||
中国成人论坛
|
||||
几巴
|
||||
免费免注册在线淫电影
|
||||
@@ -14068,7 +14065,6 @@ tibetalk
|
||||
伱妈
|
||||
(桃太郎)ファーストアナル生中出しSpecial 佐藤江梨花 特典
|
||||
毛我妳老爸
|
||||
tEST
|
||||
激情淫穴的嫂嫂
|
||||
毛机巴
|
||||
代挂
|
||||
@@ -14184,7 +14180,6 @@ da qing di guo
|
||||
王寶森
|
||||
淫浆
|
||||
高级淫口手淫口交
|
||||
tESt
|
||||
金瓶梅免费电影院
|
||||
毛李山
|
||||
淫洞
|
||||
@@ -14204,7 +14199,6 @@ BITCH
|
||||
揚震
|
||||
www。gpchina。com
|
||||
怎样延迟射精24岁以下禁
|
||||
测试员
|
||||
18dy桃色
|
||||
xing fu hua yuan
|
||||
穴
|
||||
@@ -14391,7 +14385,6 @@ fuck生鸦片
|
||||
丝袜写真
|
||||
调理劳务系
|
||||
激情淫穴小
|
||||
测试員
|
||||
da tang hao xia
|
||||
干死 狂插 操
|
||||
我周容
|
||||
|
||||
@@ -23,13 +23,16 @@ class Channel(models.Model):
|
||||
# 处理消息: 取最新问题 + 上 chat_count=1次的交互,将之前的交互按时间顺序拼接。
|
||||
# 注意: ai 每一次回复都有 parent_id 来处理连续性
|
||||
# 私聊处理
|
||||
|
||||
# todo: 更好的处理方式
|
||||
domain = [('res_id', '=', channel_id),
|
||||
('model', '=', 'mail.channel'),
|
||||
('message_type', '!=', 'user_notification'),
|
||||
('parent_id', '!=', False),
|
||||
('author_id', '=', answer_id.id),
|
||||
('body', '!=', '<p>%s</p>' % _('Response Timeout, please speak again.')),
|
||||
('body', '!=', '温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。')]
|
||||
('body', '!=', _('温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。'))]
|
||||
|
||||
if self.channel_type in ['group', 'channel']:
|
||||
# 群聊增加时间限制,当前找所有人,不限制 author_id
|
||||
domain += [('date', '>=', afterTime)]
|
||||
@@ -51,10 +54,16 @@ class Channel(models.Model):
|
||||
})
|
||||
return context_history
|
||||
|
||||
def get_ai_config(self, ai):
|
||||
# 勾子,用于取ai 配置
|
||||
return {}
|
||||
|
||||
def get_ai_response(self, ai, messages, channel, user_id, message):
|
||||
author_id = message.create_uid.partner_id
|
||||
answer_id = user_id.partner_id
|
||||
res = ai.get_ai(messages, author_id, answer_id)
|
||||
# todo: 只有个人配置的群聊才给配置
|
||||
param = self.get_ai_config(ai)
|
||||
res = ai.get_ai(messages, author_id, answer_id, param)
|
||||
if res:
|
||||
res = res.replace('\n', '<br/>')
|
||||
channel.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
|
||||
@@ -66,7 +75,14 @@ class Channel(models.Model):
|
||||
user_id = self.env['res.users']
|
||||
author_id = msg_vals.get('author_id')
|
||||
ai = self.env['ai.robot']
|
||||
channel = self.env['mail.channel']
|
||||
channel_type = self.channel_type
|
||||
messages = []
|
||||
|
||||
# 不处理 一般notify,但处理欢迎
|
||||
if '<div class="o_mail_notification' in message.body and message.body != _('<div class="o_mail_notification">joined the channel</div>'):
|
||||
return rdata
|
||||
|
||||
if channel_type == 'chat':
|
||||
channel_partner_ids = self.channel_partner_ids
|
||||
answer_id = channel_partner_ids - message.author_id
|
||||
@@ -82,22 +98,39 @@ class Channel(models.Model):
|
||||
# partner_ids = @ ids
|
||||
partner_ids = list(msg_vals.get('partner_ids'))
|
||||
if partner_ids:
|
||||
# 常规群聊 @
|
||||
partners = self.env['res.partner'].search([('id', 'in', partner_ids)])
|
||||
# user_id = user has binded gpt robot
|
||||
# user_id = user, who has binded gpt robot
|
||||
user_id = partners.mapped('user_ids').filtered(lambda r: r.gpt_id)[:1]
|
||||
if user_id:
|
||||
gpt_policy = user_id.gpt_policy
|
||||
gpt_wl_partners = user_id.gpt_wl_partners
|
||||
is_allow = message.author_id.id in gpt_wl_partners.ids
|
||||
answer_id = user_id.partner_id
|
||||
if gpt_policy == 'all' or (gpt_policy == 'limit' and is_allow):
|
||||
ai = user_id.gpt_id
|
||||
elif message.body == _('<div class="o_mail_notification">joined the channel</div>'):
|
||||
# 欢迎的情况
|
||||
partners = self.channel_partner_ids.filtered(lambda r: r.gpt_id)[:1]
|
||||
user_id = partners.mapped('user_ids')[:1]
|
||||
elif self.member_count == 2:
|
||||
# 处理独聊频道
|
||||
if hasattr(self, 'is_private') and not self.is_private:
|
||||
# 2个人的非私有频道不处理
|
||||
pass
|
||||
else:
|
||||
partners = self.channel_partner_ids.filtered(lambda r: r.gpt_id)[:1]
|
||||
user_id = partners.mapped('user_ids')[:1]
|
||||
|
||||
if user_id:
|
||||
gpt_policy = user_id.gpt_policy
|
||||
gpt_wl_partners = user_id.gpt_wl_partners
|
||||
is_allow = message.author_id.id in gpt_wl_partners.ids
|
||||
answer_id = user_id.partner_id
|
||||
if gpt_policy == 'all' or (gpt_policy == 'limit' and is_allow):
|
||||
ai = user_id.gpt_id
|
||||
|
||||
chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt')
|
||||
msg = message.preview.replace('@%s' % answer_id.name, '').lstrip()
|
||||
|
||||
# print('prompt:', prompt)
|
||||
# print('-----')
|
||||
if message.body == _('<div class="o_mail_notification">joined the channel</div>'):
|
||||
msg = _("Please warmly welcome our new partner %s and send him the best wishes.") % message.author_id.name
|
||||
else:
|
||||
# 不能用 preview, 如果用 : 提示词则 preview信息丢失
|
||||
msg = message.description.replace('@%s' % answer_id.name, '').lstrip()
|
||||
|
||||
if not msg:
|
||||
return rdata
|
||||
# api_key = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_api_key')
|
||||
@@ -124,12 +157,14 @@ class Channel(models.Model):
|
||||
_logger.info(f'私聊:author_id:{author_id},partner_chatgpt.id:{answer_id.id}')
|
||||
channel = self.env[msg_vals.get('model')].browse(msg_vals.get('res_id'))
|
||||
elif author_id != answer_id.id and msg_vals.get('model', '') == 'mail.channel' and msg_vals.get('res_id', 0) == chatgpt_channel_id.id:
|
||||
# 公开的群聊
|
||||
# todo: 公开的群聊,当前只开1个,后续更多
|
||||
_logger.info(f'频道群聊:author_id:{author_id},partner_chatgpt.id:{answer_id.id}')
|
||||
channel = chatgpt_channel_id
|
||||
elif author_id != answer_id.id and msg_vals.get('model', '') == 'mail.channel' and self.channel_type in ['group', 'channel']:
|
||||
# 其它群聊
|
||||
channel = self
|
||||
# 高级用户自建的话题
|
||||
channel = self.env[msg_vals.get('model')].browse(msg_vals.get('res_id'))
|
||||
if hasattr(channel, 'is_private') and channel.description:
|
||||
messages.append({"role": "system", "content": channel.description})
|
||||
|
||||
try:
|
||||
messages = []
|
||||
|
||||
BIN
app_chatgpt/static/description/chatgpt_blue.png
Normal file
BIN
app_chatgpt/static/description/chatgpt_blue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
@@ -39,6 +39,7 @@
|
||||
<field name="top_p"/>
|
||||
<field name="frequency_penalty"/>
|
||||
<field name="presence_penalty"/>
|
||||
<field name="sys_content" placeholder="Role-playing and scene setting.Give the model instructions about how it should behave and any context it should reference when generating a response."/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="ai_model"/>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
{
|
||||
'name': "Sunpop Odooapp Common Func",
|
||||
'version': '16.23.03.04',
|
||||
'version': '16.23.04.15',
|
||||
'author': 'Sunpop.cn',
|
||||
'category': 'Base',
|
||||
'website': 'https://www.sunpop.cn',
|
||||
|
||||
@@ -65,6 +65,8 @@ class Base(models.AbstractModel):
|
||||
if self._context.get(fieldname) or self._context.get('default_%s' % fieldname):
|
||||
return self._context.get(fieldname) or self._context.get('default_%s' % fieldname)
|
||||
else:
|
||||
if not domain:
|
||||
domain = self._fields[fieldname].domain or []
|
||||
rec = self.env[self._fields[fieldname].comodel_name].sudo().search(domain, limit=1)
|
||||
return rec.id if rec else False
|
||||
return False
|
||||
|
||||
@@ -36,6 +36,12 @@ patch(UserMenu.prototype, "app_odoo_customize.UserMenu", {
|
||||
}
|
||||
if (session.app_show_account) {
|
||||
userMenuRegistry.add("odoo_account", odooAccountItem, {'force': true});
|
||||
} else {
|
||||
try {
|
||||
userMenuRegistry.remove("odoo_account");
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user