prepare app_chatgpt 17.0

This commit is contained in:
Chill
2024-03-07 18:19:45 +08:00
parent 00bb10fd3b
commit 684b775f7c
9 changed files with 43 additions and 54 deletions

View File

@@ -10,7 +10,7 @@
{
'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心聚合全网Ai',
'version': '23.10.19',
'version': '24.03.06',
'author': 'odooai.cn',
'company': 'odooai.cn',
'maintainer': 'odooai.cn',
@@ -48,19 +48,19 @@
'app_odoo_customize',
'base_setup',
'mail',
'queue_job',
# 'queue_job',
],
'data': [
'security/ir.model.access.csv',
'security/ir_rules.xml',
'data/mail_channel_data.xml',
'data/discuss_channel_data.xml',
'data/ai_robot_data.xml',
'data/user_partner_data.xml',
'data/ir_config_parameter.xml',
'views/ai_robot_views.xml',
'views/res_partner_ai_use_views.xml',
'views/res_users_views.xml',
'views/mail_channel_views.xml',
'views/discuss_channel_views.xml',
],
'assets': {
'mail.assets_messaging': [

View File

@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="mail.channel" id="channel_chatgpt">
<record model="discuss.channel" id="channel_chatgpt">
<field name="name">ChatGPT Group Chat</field>
<field name="description">ChatGPT话题</field>
<field name="image_128" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
</record>
<record model="mail.message" id="module_install_notification">
<field name="model">mail.channel</field>
<field name="model">discuss.channel</field>
<field name="res_id" ref="app_chatgpt.channel_chatgpt"/>
<field name="message_type">email</field>
<field name="subtype_id" ref="mail.mt_comment"/>
@@ -17,14 +17,7 @@
<p>Please ask me any question.</p>]]></field>
</record>
<!-- <record model="mail.channel.member" id="channel_member_chatgtp_channel_for_admin">-->
<!-- <field name="partner_id" ref="base.partner_admin"/>-->
<!-- <field name="channel_id" ref="app_chatgpt.channel_chatgpt"/>-->
<!-- <field name="fetched_message_id" ref="app_chatgpt.module_install_notification"/>-->
<!-- <field name="seen_message_id" ref="app_chatgpt.module_install_notification"/>-->
<!-- </record>-->
<record model="mail.channel" id="app_chatgpt.channel_chatgpt">
<record model="discuss.channel" id="app_chatgpt.channel_chatgpt">
<field name="group_ids" eval="[Command.link(ref('base.group_user'))]"/>
</record>
</data>

View File

@@ -962,7 +962,7 @@ msgid "ChatGPT4 Azure"
msgstr ""
#. module: app_chatgpt
#: model:mail.channel,description:app_chatgpt.channel_chatgpt
#: model:discuss.channel,description:app_chatgpt.channel_chatgpt
msgid "ChatGPT话题"
msgstr ""

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from . import res_partner
from . import mail_channel
from . import discuss_channel
from . import res_config_settings
from . import ai_robot
from . import res_partner_ai_use

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import openai.openai_object
# import openai.openai_object
import openai
import requests, json
import openai
import base64
@@ -173,7 +174,7 @@ GPT-3 A set of models that can understand and generate natural language
def get_ai_post(self, res, author_id=False, answer_id=False, param={}):
# hook高级版要替代
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 type(res) == openai.Completion or isinstance(res, list) or isinstance(res, dict):
# 返回是个对象那么就是ai
# if isinstance(res, dict):
if self.provider == 'openai':

View File

@@ -14,7 +14,7 @@ _logger = logging.getLogger(__name__)
class Channel(models.Model):
_inherit = 'mail.channel'
_inherit = 'discuss.channel'
is_private = fields.Boolean(string="Private", default=False, help="Check to set Private, Can only use by user, not Public")
# 因为 channel_member_ids 不好处理,在此增加此字段
@@ -84,11 +84,8 @@ class Channel(models.Model):
def name_get(self):
result = []
for c in self:
if c.channel_type == 'channel' and c.is_private:
pre = '[私]'
else:
pre = ''
result.append((c.id, "%s%s" % (pre, c.name or '')))
pre = '[私]' if c.channel_type == 'channel' and c.is_private else ''
result.append((c.id, f"{pre}{c.name or ''}"))
return result
def get_openai_context(self, channel_id, author_id, answer_id, minutes=60, chat_count=0):
@@ -103,7 +100,7 @@ class Channel(models.Model):
# todo: 更好的处理方式
domain = [('res_id', '=', channel_id),
('model', '=', 'mail.channel'),
('model', '=', 'discuss.channel'),
('message_type', '!=', 'user_notification'),
('parent_id', '!=', False),
('is_ai', '=', True),
@@ -173,7 +170,7 @@ class Channel(models.Model):
user_id = self.env['res.users']
author_id = msg_vals.get('author_id')
ai = self.env['ai.robot'].sudo()
channel = self.env['mail.channel']
channel = self.env['discuss.channel']
channel_type = self.channel_type
messages = []
@@ -285,11 +282,11 @@ 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:
elif author_id != answer_id.id and msg_vals.get('model', '') == 'discuss.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']:
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'))
if hasattr(channel, 'is_private') and channel.description:
@@ -337,7 +334,7 @@ class Channel(models.Model):
# todo: 优化,每次聊天进入时就 write
user = self.env.user
msgs = self.env['mail.message'].sudo().search([
('model', '=', 'mail.channel'),
('model', '=', 'discuss.channel'),
('author_id', '=', user.partner_id.id),
], limit=3, order='id desc')
c_id = 0

View File

@@ -68,8 +68,8 @@
<field name="arch" type="xml">
<form>
<header>
<button string="Get List Model" type="object" name="get_ai_list_model" attrs="{'invisible': [('provider', '!=', 'openai')]}"/>
<button string="Get Model Info" type="object" name="get_ai_model_info" attrs="{'invisible': [('provider', '!=', 'openai')]}"/>
<button string="Get List Model" type="object" name="get_ai_list_model" invisible="provider != 'openai'"/>
<button string="Get Model Info" type="object" name="get_ai_model_info" invisible="provider != 'openai'"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
@@ -104,10 +104,8 @@
</label>
<div>
<field name="provider" class="oe_inline"/>
<a href="https://platform.openai.com/docs/introduction" title="OpenAI Document" class="o_doc_link" target="_blank"
attrs="{'invisible': [('provider', '!=', 'openai')]}"/>
<a href="https://learn.microsoft.com/zh-cn/azure/ai-services/openai/how-to/chatgpt" title="Azure AI Document" class="o_doc_link" target="_blank"
attrs="{'invisible': [('provider', '!=', 'azure')]}"/>
<a href="https://platform.openai.com/docs/introduction" title="OpenAI Document" class="o_doc_link" target="_blank" invisible="provider != 'openai'"/>
<a href="https://learn.microsoft.com/zh-cn/azure/ai-services/openai/how-to/chatgpt" title="Azure AI Document" class="o_doc_link" target="_blank" invisible="provider != 'openai'"/>
</div>
<field name="max_tokens"/>
<field name="engine"/>
@@ -118,7 +116,7 @@
</group>
<group>
<field name="is_filtering"/>
<field name="sensitive_words" attrs="{'invisible': [('is_filtering', '=', False)]}"/>
<field name="sensitive_words" invisible="not is_filtering"/>
</group>
</group>
</sheet>

View File

@@ -2,10 +2,10 @@
<odoo>
<data>
<!--list 原生处理-->
<record id="ai_mail_channel_view_tree" model="ir.ui.view">
<field name="model">mail.channel</field>
<field name="name">ai.mail.channel.tree</field>
<field name="inherit_id" ref="mail.mail_channel_view_tree"/>
<record id="ai_discuss_channel_view_tree" model="ir.ui.view">
<field name="model">discuss.channel</field>
<field name="name">ai.discuss.channel.tree</field>
<field name="inherit_id" ref="mail.discuss_channel_view_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="ai_partner_id" optional="show"/>
@@ -15,11 +15,11 @@
</field>
</record>
<!-- form,原生继承以便管理-->
<record id="ai_mail_channel_view_form" model="ir.ui.view">
<field name="name">ai.mail.channel.form</field>
<field name="model">mail.channel</field>
<record id="ai_discuss_channel_view_form" model="ir.ui.view">
<field name="name">ai.discuss.channel.form</field>
<field name="model">discuss.channel</field>
<field name="mode">extension</field>
<field name="inherit_id" ref="mail.mail_channel_view_form"/>
<field name="inherit_id" ref="mail.discuss_channel_view_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='privacy']" position="before">
<page name="page_user" string="用户设定的角色相关,一般不要调整">
@@ -80,9 +80,9 @@
</record>
<!--kanban,原生的处理-->
<record id="ai_mail_channel_view_kanban" model="ir.ui.view">
<field name="model">mail.channel</field>
<field name="inherit_id" ref="mail.mail_channel_view_kanban"/>
<record id="ai_discuss_channel_view_kanban" model="ir.ui.view">
<field name="model">discuss.channel</field>
<field name="inherit_id" ref="mail.discuss_channel_view_kanban"/>
<field name="mode">extension</field>
<field name="arch" type="xml">
<xpath expr="//kanban//field[1]" position="before">
@@ -92,23 +92,23 @@
<em>角色:</em>
</xpath>
<xpath expr="//button[@name='channel_join']" position="replace">
<button attrs="{'invisible':[('is_private','=',True), ('group_ids', '!=', [])]}"
<button invisible="is_private and group_ids"
class="btn btn-warning float-end" type="edit">
智能设定
</button>
<button type="object" attrs="{'invisible':['|', ('is_member','=',True), ('group_ids', '!=', [])]}" class="btn btn-primary float-end" name="channel_join">进入频道</button>
<button type="object" invisible="is_member or group_ids" class="btn btn-primary float-end" name="channel_join">进入频道</button>
</xpath>
<xpath expr="//button[@name='action_unfollow']" position="replace">
<button type="object" attrs="{'invisible':['|', ('is_member','=',False), ('group_ids', '!=', [])]}"
<button type="object" invisible="is_member or group_ids"
class="btn btn-secondary float-end" name="action_unfollow">暂时离开</button>
</xpath>
</field>
</record>
<!--search 原生处理-->
<record id="ai_mail_channel_view_search" model="ir.ui.view">
<field name="model">mail.channel</field>
<field name="inherit_id" ref="mail.mail_channel_view_search"/>
<record id="ai_discuss_channel_view_search" model="ir.ui.view">
<field name="model">discuss.channel</field>
<field name="inherit_id" ref="mail.discuss_channel_view_search"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="channel_type"/>

View File

@@ -25,7 +25,7 @@
<group>
<field name="gpt_id"/>
<field name="gpt_policy"/>
<field name="gpt_wl_partners" widget="many2many_tags" attrs="{'invisible': [('gpt_policy', '=', 'all')]}"/>
<field name="gpt_wl_partners" widget="many2many_tags" invisible="gpt_policy == 'all'"/>
<field name="gpt_demo_time"/>
<field name="is_chat_private"/>
</group>