mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
[16] kimi图文支持
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心,聚合全网Ai',
|
'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心,聚合全网Ai',
|
||||||
'version': '16.0.25.02.10',
|
'version': '16.0.25.02.11',
|
||||||
'author': 'odooai.cn',
|
'author': 'odooai.cn',
|
||||||
'company': 'odooai.cn',
|
'company': 'odooai.cn',
|
||||||
'maintainer': 'odooai.cn',
|
'maintainer': 'odooai.cn',
|
||||||
|
|||||||
@@ -133,13 +133,17 @@ 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 对象
|
||||||
# answer_id: 回答的 partner_id 对象
|
# answer_id: 回答的 partner_id 对象
|
||||||
# param,dict 形式的参数
|
# param,dict 形式的参数
|
||||||
# 调整输出为2个参数:res_post详细内容,is_ai是否ai的响应
|
# 调整输出为2个参数:res_post详细内容,is_ai是否ai的响应
|
||||||
|
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
# 前置勾子,一般返回 False,有问题返回响应内容,用于处理敏感词等
|
# 前置勾子,一般返回 False,有问题返回响应内容,用于处理敏感词等
|
||||||
res_pre = self.get_ai_pre(data, author_id, answer_id, param)
|
res_pre = self.get_ai_pre(data, author_id, answer_id, param)
|
||||||
@@ -149,7 +153,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
if not hasattr(self, 'get_%s' % self.provider):
|
if not hasattr(self, 'get_%s' % self.provider):
|
||||||
res = _('No robot provider found')
|
res = _('No robot provider found')
|
||||||
return res, {}, False
|
return res, {}, False
|
||||||
|
|
||||||
res = getattr(self, 'get_%s' % self.provider)(data, author_id, answer_id, param)
|
res = getattr(self, 'get_%s' % self.provider)(data, author_id, answer_id, param)
|
||||||
# 后置勾子,返回处理后的内容
|
# 后置勾子,返回处理后的内容
|
||||||
res_post, usage, is_ai = self.get_ai_post(res, author_id, answer_id, param)
|
res_post, usage, is_ai = self.get_ai_post(res, author_id, answer_id, param)
|
||||||
@@ -176,7 +180,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
# 后置勾子,返回处理后的内容
|
# 后置勾子,返回处理后的内容
|
||||||
res_post, usage, is_ai = self.get_ai_post(res, author_id, answer_id, param)
|
res_post, usage, is_ai = self.get_ai_post(res, author_id, answer_id, param)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_ai_post(self, res, author_id=False, answer_id=False, param=None):
|
def get_ai_post(self, res, author_id=False, answer_id=False, param=None):
|
||||||
# hook,高级版要替代
|
# hook,高级版要替代
|
||||||
if param is None:
|
if param is None:
|
||||||
@@ -202,7 +206,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error('==========app_chatgpt get_ai_post Error: %s' % e)
|
_logger.error('==========app_chatgpt get_ai_post Error: %s' % e)
|
||||||
return res, False, False
|
return res, False, False
|
||||||
|
|
||||||
# if res and author_id and isinstance(res, openai.openai_object.OpenAIObject) or isinstance(res, list) or isinstance(res, dict):
|
# if res and author_id and isinstance(res, openai.openai_object.OpenAIObject) or isinstance(res, list) or isinstance(res, dict):
|
||||||
# # 返回是个对象,那么就是ai
|
# # 返回是个对象,那么就是ai
|
||||||
# # if isinstance(res, dict):
|
# # if isinstance(res, dict):
|
||||||
@@ -223,14 +227,14 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
# else:
|
# else:
|
||||||
# # 直接返回错误语句,那么就是非ai
|
# # 直接返回错误语句,那么就是非ai
|
||||||
# return res, False, False
|
# return res, False, False
|
||||||
|
|
||||||
def get_ai_system(self, content=None):
|
def get_ai_system(self, content=None):
|
||||||
# 获取基础ai角色设定, role system
|
# 获取基础ai角色设定, role system
|
||||||
sys_content = content or self.sys_content
|
sys_content = content or self.sys_content
|
||||||
if sys_content:
|
if sys_content:
|
||||||
return {"role": "system", "content": sys_content}
|
return {"role": "system", "content": sys_content}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_ai_model_info(self):
|
def get_ai_model_info(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
|
||||||
@@ -238,7 +242,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
o_url = "https://api.openai.com/v1/models/%s" % self.ai_model
|
o_url = "https://api.openai.com/v1/models/%s" % self.ai_model
|
||||||
if self.endpoint:
|
if self.endpoint:
|
||||||
o_url = self.endpoint.replace("/chat/completions", "") + "/models/%s" % self.ai_model
|
o_url = self.endpoint.replace("/chat/completions", "") + "/models/%s" % self.ai_model
|
||||||
|
|
||||||
response = requests.get(o_url, headers=headers, timeout=R_TIMEOUT)
|
response = requests.get(o_url, headers=headers, timeout=R_TIMEOUT)
|
||||||
response.close()
|
response.close()
|
||||||
if response:
|
if response:
|
||||||
@@ -280,7 +284,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
frequency_penalty = param.get('frequency_penalty') if param.get('frequency_penalty') else self.frequency_penalty
|
frequency_penalty = param.get('frequency_penalty') if param.get('frequency_penalty') else self.frequency_penalty
|
||||||
presence_penalty = param.get('presence_penalty') if param.get('presence_penalty') else self.presence_penalty
|
presence_penalty = param.get('presence_penalty') if param.get('presence_penalty') else self.presence_penalty
|
||||||
request_timeout = param.get('request_timeout') if param.get('request_timeout') else self.ai_timeout
|
request_timeout = param.get('request_timeout') if param.get('request_timeout') else self.ai_timeout
|
||||||
|
|
||||||
if self.stop:
|
if self.stop:
|
||||||
stop = self.stop.split(',')
|
stop = self.stop.split(',')
|
||||||
else:
|
else:
|
||||||
@@ -320,7 +324,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
_logger.warning('=====================openai output data: %s' % response.json())
|
_logger.warning('=====================openai output data: %s' % response.json())
|
||||||
|
|
||||||
return _("Response Timeout, please speak again.")
|
return _("Response Timeout, please speak again.")
|
||||||
# if self.ai_model in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']:
|
# if self.ai_model in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']:
|
||||||
# # 基本与 azure 同,要处理 api_base
|
# # 基本与 azure 同,要处理 api_base
|
||||||
@@ -401,7 +405,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
# return response
|
# return response
|
||||||
# else:
|
# else:
|
||||||
# _logger.warning('=====================openai output data: %s' % response.json())
|
# _logger.warning('=====================openai output data: %s' % response.json())
|
||||||
|
|
||||||
# return _("Response Timeout, please speak again.")
|
# return _("Response Timeout, please speak again.")
|
||||||
|
|
||||||
def get_azure(self, data, author_id, answer_id, param={}):
|
def get_azure(self, data, author_id, answer_id, param={}):
|
||||||
@@ -409,10 +413,10 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
# only for azure
|
# only for azure
|
||||||
if not self.endpoint:
|
if not self.endpoint:
|
||||||
raise UserError(_("Please Set your AI robot's endpoint first."))
|
raise UserError(_("Please Set your AI robot's endpoint first."))
|
||||||
|
|
||||||
if not self.api_version:
|
if not self.api_version:
|
||||||
raise UserError(_("Please Set your AI robot's API Version first."))
|
raise UserError(_("Please Set your AI robot's API Version first."))
|
||||||
|
|
||||||
if self.stop:
|
if self.stop:
|
||||||
stop = self.stop.split(',')
|
stop = self.stop.split(',')
|
||||||
else:
|
else:
|
||||||
@@ -436,7 +440,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
if sys_content:
|
if sys_content:
|
||||||
messages.insert(0, sys_content)
|
messages.insert(0, sys_content)
|
||||||
# 暂时不变
|
# 暂时不变
|
||||||
|
|
||||||
client = AzureOpenAI(
|
client = AzureOpenAI(
|
||||||
api_version=self.api_version,
|
api_version=self.api_version,
|
||||||
azure_endpoint=self.endpoint,
|
azure_endpoint=self.endpoint,
|
||||||
@@ -468,7 +472,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
self.endpoint = 'https://api.openai.com/v1/chat/completions'
|
self.endpoint = 'https://api.openai.com/v1/chat/completions'
|
||||||
elif self.provider == 'azure':
|
elif self.provider == 'azure':
|
||||||
self.endpoint = 'https://odoo.openai.azure.com'
|
self.endpoint = 'https://odoo.openai.azure.com'
|
||||||
|
|
||||||
if self.provider:
|
if self.provider:
|
||||||
# 取头像
|
# 取头像
|
||||||
module_path = modules.get_module_path('app_chatgpt', display_warning=False)
|
module_path = modules.get_module_path('app_chatgpt', display_warning=False)
|
||||||
@@ -477,7 +481,7 @@ GPT-3 A set of models that can understand and generate natural language
|
|||||||
if path:
|
if path:
|
||||||
image_file = tools.file_open(path, 'rb')
|
image_file = tools.file_open(path, 'rb')
|
||||||
self.image_avatar = base64.b64encode(image_file.read())
|
self.image_avatar = base64.b64encode(image_file.read())
|
||||||
|
|
||||||
@api.onchange('set_ai_model')
|
@api.onchange('set_ai_model')
|
||||||
def _onchange_set_ai_model(self):
|
def _onchange_set_ai_model(self):
|
||||||
if self.set_ai_model:
|
if self.set_ai_model:
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Channel(models.Model):
|
|||||||
presence_penalty = fields.Float('避免重复词值', default=1, help="-2~2,值越大越少重复词")
|
presence_penalty = fields.Float('避免重复词值', default=1, help="-2~2,值越大越少重复词")
|
||||||
|
|
||||||
is_current_channel = fields.Boolean('是否当前用户默认频道', compute='_compute_is_current_channel', help='是否当前用户默认微信对话频道')
|
is_current_channel = fields.Boolean('是否当前用户默认频道', compute='_compute_is_current_channel', help='是否当前用户默认微信对话频道')
|
||||||
|
|
||||||
# begin 处理Ai对话
|
# begin 处理Ai对话
|
||||||
is_ai_conversation = fields.Boolean('Ai Conversation', default=False,
|
is_ai_conversation = fields.Boolean('Ai Conversation', default=False,
|
||||||
help='Set active to make conversation between 2+ Ai Employee. You Just say first word, then Ai robots Auto Chat.')
|
help='Set active to make conversation between 2+ Ai Employee. You Just say first word, then Ai robots Auto Chat.')
|
||||||
@@ -263,11 +263,11 @@ class Channel(models.Model):
|
|||||||
# # 暂时有限用户的Ai
|
# # 暂时有限用户的Ai
|
||||||
# raise UserError(_('此Ai暂时未开放,请联系管理员。'))
|
# raise UserError(_('此Ai暂时未开放,请联系管理员。'))
|
||||||
# end: 找ai,增加 ai二人转功能
|
# end: 找ai,增加 ai二人转功能
|
||||||
|
|
||||||
if hasattr(ai, 'is_translator') and ai.is_translator and ai.ai_model == 'translator':
|
if hasattr(ai, 'is_translator') and ai.is_translator and ai.ai_model == 'translator':
|
||||||
return rdata
|
return rdata
|
||||||
chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt')
|
chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt')
|
||||||
|
|
||||||
if message.body == _('<div class="o_mail_notification">joined the channel</div>'):
|
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
|
msg = _("Please warmly welcome our new partner %s and send him the best wishes.") % message.author_id.name
|
||||||
else:
|
else:
|
||||||
@@ -282,12 +282,12 @@ class Channel(models.Model):
|
|||||||
sync_config = self._context.get('app_ai_sync_config')
|
sync_config = self._context.get('app_ai_sync_config')
|
||||||
else:
|
else:
|
||||||
sync_config = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openai_sync_config')
|
sync_config = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openai_sync_config')
|
||||||
|
|
||||||
if self._context.get('app_ai_chat_padding_time'):
|
if self._context.get('app_ai_chat_padding_time'):
|
||||||
padding_time = int(self._context.get('app_ai_chat_padding_time'))
|
padding_time = int(self._context.get('app_ai_chat_padding_time'))
|
||||||
else:
|
else:
|
||||||
padding_time = int(self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.ai_chat_padding_time'))
|
padding_time = int(self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.ai_chat_padding_time'))
|
||||||
|
|
||||||
# api_key = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_api_key')
|
# api_key = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_api_key')
|
||||||
# ai处理,不要自问自答
|
# ai处理,不要自问自答
|
||||||
if ai and answer_id != message.author_id:
|
if ai and answer_id != message.author_id:
|
||||||
@@ -305,7 +305,7 @@ class Channel(models.Model):
|
|||||||
chat_count = 1
|
chat_count = 1
|
||||||
else:
|
else:
|
||||||
chat_count = self.chat_count or 3
|
chat_count = self.chat_count or 3
|
||||||
|
|
||||||
if author_id != answer_id.id and self.channel_type == 'chat':
|
if author_id != answer_id.id and self.channel_type == 'chat':
|
||||||
# 私聊
|
# 私聊
|
||||||
_logger.info(f'私聊:author_id:{author_id},partner_chatgpt.id:{answer_id.id}')
|
_logger.info(f'私聊:author_id:{author_id},partner_chatgpt.id:{answer_id.id}')
|
||||||
@@ -317,25 +317,51 @@ class Channel(models.Model):
|
|||||||
elif author_id != answer_id.id and msg_vals.get('model', '') == 'mail.channel' and self.channel_type in ['group', 'channel']:
|
elif author_id != answer_id.id and msg_vals.get('model', '') == 'mail.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'))
|
||||||
|
|
||||||
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 "")
|
||||||
messages.append({"role": "system", "content": sys_content})
|
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)
|
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
|
||||||
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)
|
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})
|
# 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',
|
||||||
subtype_xmlid='mail.mt_comment',
|
# subtype_xmlid='mail.mt_comment',
|
||||||
parent_id=message.id)
|
# parent_id=message.id)
|
||||||
|
|
||||||
# if msg_len * 2 >= 8000:
|
# if msg_len * 2 >= 8000:
|
||||||
# messages = [{"role": "user", "content": msg}]
|
# messages = [{"role": "user", "content": msg}]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<h2 class="oe_slogan"> Latest ChatGPT AI Center. GPT 3.5, Ali Ai, Baidu Ai, Multi Robot Support. Chat and Training </h2>
|
<h2 class="oe_slogan"> Latest ChatGPT AI Center. GPT 3.5, Ali Ai, Baidu Ai, Multi Robot Support. Chat and Training </h2>
|
||||||
<h3 class="oe_slogan"> Support GPT-4o, chatgpt 4 32k. 3.5 turbo, text-davinci, Integration All ChatGpt Api. </h3>
|
<h3 class="oe_slogan"> Support GPT-4o, chatgpt 4 32k. 3.5 turbo, text-davinci, Integration All ChatGpt Api. </h3>
|
||||||
<div class="oe_row">
|
<div class="oe_row">
|
||||||
<h3>Latest update: v16.0.25.02.10</h3>
|
<h3>Latest update: v16.0.25.02.11</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
Add Alibaba Qwen support(search 'app_ai_ali'), update chatgpt api
|
Add Alibaba Qwen support(search 'app_ai_ali'), update chatgpt api
|
||||||
|
|||||||
Reference in New Issue
Block a user