mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
[18]kimi图片支持
This commit is contained in:
@@ -134,7 +134,7 @@ GPT-3 A set of models that can understand and generate natural language
|
||||
# hook,都正常
|
||||
return False
|
||||
|
||||
def get_msg_files_content(self, message):
|
||||
def get_msg_file_content(self, message):
|
||||
# hook
|
||||
return False
|
||||
|
||||
|
||||
@@ -274,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
|
||||
else:
|
||||
# 不能用 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()
|
||||
|
||||
if not msg:
|
||||
@@ -323,19 +323,40 @@ class Channel(models.Model):
|
||||
if hasattr(channel, 'is_private') and channel.description:
|
||||
messages.append({"role": "system", "content": channel.description})
|
||||
|
||||
if message.attachment_ids:
|
||||
file_content = ai.get_msg_files_content(message)
|
||||
if file_content:
|
||||
messages.append({"role": "system", "content": file_content})
|
||||
|
||||
try:
|
||||
# 处理提示词
|
||||
sys_content = channel.description + add_sys_content
|
||||
messages.append({"role": "system", "content": 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})
|
||||
c_history = self.get_openai_context(channel.id, author_id, answer_id, openapi_context_timeout, chat_count)
|
||||
if c_history:
|
||||
messages += c_history
|
||||
messages.append({"role": "user", "content": msg})
|
||||
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})
|
||||
msg_len = sum(len(str(m)) for m in messages)
|
||||
# 接口最大接收 8430 Token
|
||||
# if msg_len * 2 > ai.max_send_char:
|
||||
@@ -359,7 +380,7 @@ class Channel(models.Model):
|
||||
else:
|
||||
self.get_ai_response(ai, messages, channel, user_id, message)
|
||||
except Exception as e:
|
||||
raise UserError(_(e))
|
||||
raise UserError(e)
|
||||
|
||||
return rdata
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
<field name="ext_ai_partner_id" widget="many2one_avatar"
|
||||
options="{'no_open': True, 'no_create': True}"/>
|
||||
<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"/>
|
||||
<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"/>
|
||||
</group>
|
||||
<group name="param_set" string="Ai Character Set">
|
||||
|
||||
Reference in New Issue
Block a user