mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
Merge branch '18.0' of github.com:guohuadeng/app-odoo into 18.0
This commit is contained in:
@@ -134,6 +134,10 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
# hook,都正常
|
# hook,都正常
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_msg_file_content(self, message):
|
||||||
|
# hook
|
||||||
|
return False
|
||||||
|
|
||||||
def get_ai(self, data, author_id=False, answer_id=False, param={}):
|
def get_ai(self, data, author_id=False, answer_id=False, param={}):
|
||||||
# 通用方法
|
# 通用方法
|
||||||
# author_id: 请求的 partner_id 对象
|
# author_id: 请求的 partner_id 对象
|
||||||
@@ -234,6 +238,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
|
|
||||||
def get_ai_list_model(self):
|
def get_ai_list_model(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
if self.provider == 'openai':
|
||||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
|
||||||
R_TIMEOUT = self.ai_timeout or 120
|
R_TIMEOUT = self.ai_timeout or 120
|
||||||
o_url = "https://api.openai.com/v1/models"
|
o_url = "https://api.openai.com/v1/models"
|
||||||
@@ -246,6 +251,8 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
r_text = json.dumps(res, indent=2)
|
r_text = json.dumps(res, indent=2)
|
||||||
else:
|
else:
|
||||||
r_text = 'No response.'
|
r_text = 'No response.'
|
||||||
|
else:
|
||||||
|
r_text = 'No response.'
|
||||||
raise UserError(r_text)
|
raise UserError(r_text)
|
||||||
|
|
||||||
def get_openai(self, data, author_id, answer_id, param={}):
|
def get_openai(self, data, author_id, answer_id, param={}):
|
||||||
|
|||||||
@@ -182,7 +182,6 @@ class Channel(models.Model):
|
|||||||
|
|
||||||
def _notify_thread(self, message, msg_vals=False, **kwargs):
|
def _notify_thread(self, message, msg_vals=False, **kwargs):
|
||||||
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
|
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
|
||||||
# print(f'rdata:{rdata}')
|
|
||||||
answer_id = self.env['res.partner']
|
answer_id = self.env['res.partner']
|
||||||
user_id = self.env['res.users']
|
user_id = self.env['res.users']
|
||||||
author_id = msg_vals.get('author_id')
|
author_id = msg_vals.get('author_id')
|
||||||
@@ -275,7 +274,7 @@ class Channel(models.Model):
|
|||||||
msg = _("Please warmly welcome our new partner %s and send him the best wishes.") % message.author_id.name
|
msg = _("Please warmly welcome our new partner %s and send him the best wishes.") % message.author_id.name
|
||||||
else:
|
else:
|
||||||
# 不能用 preview, 如果用 : 提示词则 preview信息丢失
|
# 不能用 preview, 如果用 : 提示词则 preview信息丢失
|
||||||
plaintext_ct = tools.html_to_inner_content(message.body)
|
plaintext_ct = tools.mail.html_to_inner_content(message.body)
|
||||||
msg = plaintext_ct.replace('@%s' % answer_id.name, '').lstrip()
|
msg = plaintext_ct.replace('@%s' % answer_id.name, '').lstrip()
|
||||||
|
|
||||||
if not msg:
|
if not msg:
|
||||||
@@ -298,6 +297,7 @@ class Channel(models.Model):
|
|||||||
if not api_key:
|
if not api_key:
|
||||||
_logger.warning(_("ChatGPT Robot【%s】have not set open api key.") % ai.name)
|
_logger.warning(_("ChatGPT Robot【%s】have not set open api key.") % ai.name)
|
||||||
return rdata
|
return rdata
|
||||||
|
|
||||||
try:
|
try:
|
||||||
openapi_context_timeout = int(self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_context_timeout')) or 60
|
openapi_context_timeout = int(self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_context_timeout')) or 60
|
||||||
except:
|
except:
|
||||||
@@ -320,20 +320,50 @@ class Channel(models.Model):
|
|||||||
elif author_id != answer_id.id and msg_vals.get('model', '') == 'discuss.channel' and self.channel_type in ['group', 'channel']:
|
elif author_id != answer_id.id and msg_vals.get('model', '') == 'discuss.channel' and self.channel_type in ['group', 'channel']:
|
||||||
# 高级用户自建的话题
|
# 高级用户自建的话题
|
||||||
channel = self.env[msg_vals.get('model')].browse(msg_vals.get('res_id'))
|
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:
|
try:
|
||||||
# 处理提示词
|
# 处理提示词
|
||||||
sys_content = channel.description + add_sys_content
|
sys_content = '%s%s' % (channel.description if channel.description else "", add_sys_content if add_sys_content else "")
|
||||||
|
if len(sys_content):
|
||||||
messages.append({"role": "system", "content": sys_content})
|
messages.append({"role": "system", "content": sys_content})
|
||||||
c_history = self.get_openai_context(channel.id, author_id, answer_id, openapi_context_timeout, chat_count)
|
c_history = self.get_openai_context(channel.id, author_id, answer_id, openapi_context_timeout, chat_count)
|
||||||
if c_history:
|
if c_history:
|
||||||
messages += c_history
|
messages += c_history
|
||||||
|
if message.attachment_ids:
|
||||||
|
attachment = message.attachment_ids[:1]
|
||||||
|
file_content = ai.get_msg_file_content(message)
|
||||||
|
if not file_content:
|
||||||
|
messages.append({"role": "user", "content": msg})
|
||||||
|
if attachment.mimetype in ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp']:
|
||||||
|
messages.append({
|
||||||
|
"role": "user",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "image_url",
|
||||||
|
"image_url": {
|
||||||
|
"url": file_content,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": msg
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
messages.append({"role": "system", "content": file_content})
|
||||||
|
messages.append({"role": "user", "content": msg})
|
||||||
|
else:
|
||||||
messages.append({"role": "user", "content": msg})
|
messages.append({"role": "user", "content": msg})
|
||||||
msg_len = sum(len(str(m)) for m in messages)
|
msg_len = sum(len(str(m)) for m in messages)
|
||||||
# 接口最大接收 8430 Token
|
# 接口最大接收 8430 Token
|
||||||
if msg_len * 2 > ai.max_send_char:
|
# if msg_len * 2 > ai.max_send_char:
|
||||||
messages = []
|
# messages = []
|
||||||
messages.append({"role": "user", "content": msg})
|
# if hasattr(channel, 'is_private') and channel.description:
|
||||||
|
# messages.append({"role": "system", "content": channel.description})
|
||||||
|
# messages.append({"role": "user", "content": msg})
|
||||||
msg_len = sum(len(str(m)) for m in messages)
|
msg_len = sum(len(str(m)) for m in messages)
|
||||||
if msg_len * 2 > ai.max_send_char:
|
if msg_len * 2 > ai.max_send_char:
|
||||||
new_msg = channel.with_user(user_id).message_post(body=_('您所发送的提示词已超长。'), message_type='comment',
|
new_msg = channel.with_user(user_id).message_post(body=_('您所发送的提示词已超长。'), message_type='comment',
|
||||||
@@ -350,7 +380,7 @@ class Channel(models.Model):
|
|||||||
else:
|
else:
|
||||||
self.get_ai_response(ai, messages, channel, user_id, message)
|
self.get_ai_response(ai, messages, channel, user_id, message)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise UserError(_(e))
|
raise UserError(e)
|
||||||
|
|
||||||
return rdata
|
return rdata
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@
|
|||||||
<field name="ext_ai_partner_id" widget="many2one_avatar"
|
<field name="ext_ai_partner_id" widget="many2one_avatar"
|
||||||
options="{'no_open': True, 'no_create': True}"/>
|
options="{'no_open': True, 'no_create': True}"/>
|
||||||
<field name="is_ai_conversation" widget="boolean_toggle"/>
|
<field name="is_ai_conversation" widget="boolean_toggle"/>
|
||||||
<field name="ai_sys_content" attrs="{'invisible':[('is_ai_conversation','!=',True)]}"
|
<field name="ai_sys_content" invisible="not is_ai_conversation"
|
||||||
widget="text" rowCount="4" colspan="2"/>
|
widget="text" rowCount="4" colspan="2"/>
|
||||||
<field name="ext_ai_sys_content" attrs="{'invisible':[('is_ai_conversation','!=',True)]}"
|
<field name="ext_ai_sys_content" invisible="not is_ai_conversation"
|
||||||
widget="text" rowCount="4" colspan="2"/>
|
widget="text" rowCount="4" colspan="2"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="param_set" string="Ai Character Set">
|
<group name="param_set" string="Ai Character Set">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="app_ai_robot_deepseek_form_view" model="ir.ui.view">
|
<!-- <record id="app_ai_robot_deepseek_form_view" model="ir.ui.view">
|
||||||
<field name="name">app.ai.robot.deepseek.form</field>
|
<field name="name">app.ai.robot.deepseek.form</field>
|
||||||
<field name="model">ai.robot</field>
|
<field name="model">ai.robot</field>
|
||||||
<field name="inherit_id" ref="app_chatgpt.ai_robot_form_view"/>
|
<field name="inherit_id" ref="app_chatgpt.ai_robot_form_view"/>
|
||||||
@@ -9,5 +9,5 @@
|
|||||||
<attribute name="attrs">{'invisible': 0}</attribute>
|
<attribute name="attrs">{'invisible': 0}</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record> -->
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user