mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
prepare #I6VU5L 【ai_chat】频道处理,权限以及角色设定 置顶
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'))]"/>
|
||||
|
||||
@@ -125,6 +125,7 @@ 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):
|
||||
if self.is_filtering:
|
||||
search = WordsSearch()
|
||||
search.SetKeywords([])
|
||||
content = data[0]['content']
|
||||
@@ -231,7 +232,8 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
messages = data
|
||||
else:
|
||||
messages = [{"role": "user", "content": data}]
|
||||
# Ai角色设定
|
||||
# Ai角色设定,如果没设定则再处理
|
||||
if messages[0].get('role') != 'system':
|
||||
sys_content = self.get_ai_system(kwargs.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
@@ -300,6 +302,9 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
else:
|
||||
messages = [{"role": "user", "content": data}]
|
||||
# Ai角色设定
|
||||
|
||||
# Ai角色设定,如果没设定则再处理
|
||||
if messages[0].role != 'system':
|
||||
sys_content = self.get_ai_system(kwargs.get('sys_content'))
|
||||
if sys_content:
|
||||
messages.insert(0, sys_content)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
回民吃猪肉
|
||||
习近平
|
||||
李强
|
||||
TMD
|
||||
毛民进党
|
||||
妹妹淫水 流
|
||||
@@ -331,7 +332,6 @@ meimei的小阴户
|
||||
毛佳静安定片
|
||||
鸟gm
|
||||
骚屄
|
||||
TeSt
|
||||
激情电影免费下载裸体美女乳房图
|
||||
日翻
|
||||
美臀嫰穴
|
||||
@@ -1638,7 +1638,6 @@ h站
|
||||
淫穢
|
||||
做爱电影
|
||||
免费淫奸女A片段试看 强*十八岁meinv护士看完保证你打飞机
|
||||
Test
|
||||
meinv 淫穴
|
||||
peng peng bang
|
||||
毛鸦片液
|
||||
@@ -8993,7 +8992,6 @@ mo擦小肥穴
|
||||
骚姐乱伦
|
||||
無套自拍
|
||||
白虎少婦
|
||||
test
|
||||
毛麻醉药
|
||||
wu jin de ren wu
|
||||
粗大的阴茎与紧窄的阴道壁之间的剧烈磨擦
|
||||
@@ -13692,7 +13690,6 @@ Tora Tora Gold Vol。14 星野みく
|
||||
肉棒里插肉洞
|
||||
亚甲二氧基甲基安非他明
|
||||
人民
|
||||
TEsT
|
||||
中国成人论坛
|
||||
几巴
|
||||
免费免注册在线淫电影
|
||||
@@ -14071,7 +14068,6 @@ tibetalk
|
||||
伱妈
|
||||
(桃太郎)ファーストアナル生中出しSpecial 佐藤江梨花 特典
|
||||
毛我妳老爸
|
||||
tEST
|
||||
激情淫穴的嫂嫂
|
||||
毛机巴
|
||||
代挂
|
||||
@@ -14187,7 +14183,6 @@ da qing di guo
|
||||
王寶森
|
||||
淫浆
|
||||
高级淫口手淫口交
|
||||
tESt
|
||||
金瓶梅免费电影院
|
||||
毛李山
|
||||
淫洞
|
||||
@@ -14207,7 +14202,6 @@ BITCH
|
||||
揚震
|
||||
www。gpchina。com
|
||||
怎样延迟射精24岁以下禁
|
||||
测试员
|
||||
18dy桃色
|
||||
xing fu hua yuan
|
||||
穴
|
||||
@@ -14394,7 +14388,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)]
|
||||
@@ -64,7 +67,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
|
||||
@@ -80,9 +90,23 @@ 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]
|
||||
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
|
||||
@@ -92,10 +116,12 @@ class Channel(models.Model):
|
||||
ai = user_id.gpt_id
|
||||
|
||||
chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt')
|
||||
|
||||
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:
|
||||
msg = message.preview.replace('@%s' % answer_id.name, '').lstrip()
|
||||
|
||||
# print('prompt:', prompt)
|
||||
# print('-----')
|
||||
if not msg:
|
||||
return rdata
|
||||
# api_key = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_api_key')
|
||||
@@ -116,24 +142,27 @@ class Channel(models.Model):
|
||||
# print('self.channel_type :',self.channel_type)
|
||||
if ai:
|
||||
# 非4版本,取0次。其它取3 次历史
|
||||
# todo: channel中只有2个人,1个是ai,1个不是的时候,直接用ai回话,不用处理 @
|
||||
chat_count = 0 if '4' in ai.ai_model else 3
|
||||
if author_id != answer_id.id and self.channel_type == 'chat':
|
||||
# 私聊
|
||||
_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 = [{"role": "user", "content": msg}]
|
||||
c_history = self.get_openai_context(channel.id, author_id, answer_id, openapi_context_timeout, chat_count)
|
||||
if c_history:
|
||||
messages += c_history
|
||||
messages = messages + c_history
|
||||
messages.append({"role": "user", "content": msg})
|
||||
if sync_config == 'sync':
|
||||
self.get_ai_response(ai, messages, channel, user_id, message)
|
||||
else:
|
||||
|
||||
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"/>
|
||||
|
||||
Reference in New Issue
Block a user