mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
merge gpt
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
{
|
||||
'name': 'ChatGPT4,Google Bard, AiGC Center.Ai服务中心,聚合全网Ai',
|
||||
'version': '16.23.07.29',
|
||||
'version': '16.23.08.15',
|
||||
'author': 'odooai.cn',
|
||||
'company': 'odooai.cn',
|
||||
'maintainer': 'odooai.cn',
|
||||
@@ -61,6 +61,7 @@
|
||||
'views/ai_robot_views.xml',
|
||||
'views/res_partner_ai_use_views.xml',
|
||||
'views/res_users_views.xml',
|
||||
'views/mail_channel_views.xml',
|
||||
],
|
||||
'assets': {
|
||||
'mail.assets_messaging': [
|
||||
|
||||
@@ -16,6 +16,82 @@ _logger = logging.getLogger(__name__)
|
||||
class Channel(models.Model):
|
||||
_inherit = 'mail.channel'
|
||||
|
||||
is_private = fields.Boolean(string="私有频道", default=False, help="私人频道不公开,可邀请及清退指定用户")
|
||||
# 因为 channel_member_ids 不好处理,在此增加此字段
|
||||
# 主Ai
|
||||
ai_partner_id = fields.Many2one(comodel_name="res.partner", string="专属主Ai", required=False,
|
||||
domain=[('gpt_id', '!=', None), ('is_chat_private', '=', True)],
|
||||
default=lambda self: self._app_get_m2o_default('ai_partner_id'),
|
||||
help="主Ai是主要对话对象,当没有@操作时,由主Ai回答", )
|
||||
ext_ai_partner_id = fields.Many2one(comodel_name="res.partner", string="辅助Ai",
|
||||
domain=[('gpt_id', '!=', None), ('is_chat_private', '=', True)],
|
||||
help="通过 @辅助Ai 可以让辅助Ai回答问题", )
|
||||
description = fields.Char('Ai角色设定', help="填写后,Ai将以您设定的身份与你交互,如:你是一个在航空航天领域的专家。不填则根据问题智能处理")
|
||||
set_max_tokens = fields.Selection([
|
||||
('300', '简短'),
|
||||
('600', '标准'),
|
||||
('1000', '中等'),
|
||||
('2000', '长篇'),
|
||||
('3000', '超长篇'),
|
||||
('32000', '32K'),
|
||||
], string='响应篇幅限制', default='600', help="越大返回内容越多,计费也越多")
|
||||
set_chat_count = fields.Selection([
|
||||
('none', 'Ai自动判断'),
|
||||
('1', '1标准'),
|
||||
('3', '3强关联'),
|
||||
('5', '5超强关联'),
|
||||
], string="上下文相关", default='1', help="0-5,设定后,会将最近n次对话发给Ai,有助于他更好的回答,但太大费用也高")
|
||||
set_temperature = fields.Selection([
|
||||
('2', '天马行空'),
|
||||
('1.5', '创造性'),
|
||||
('1', '标准'),
|
||||
('0.6', '理性'),
|
||||
('0.1', '保守'),
|
||||
], string="创造性", default='1', help="0-21,值越大越富有想像力,越小则越保守")
|
||||
set_top_p = fields.Selection([
|
||||
('0.9', '严谨惯性思维'),
|
||||
('0.6', '标准推理'),
|
||||
('0.4', '跳跃性'),
|
||||
('0.1', '随便'),
|
||||
], string="思维连贯性", default='0.6', help="0-1,值越大越倾向大众化的连贯思维")
|
||||
# 避免使用常用词
|
||||
set_frequency_penalty = fields.Selection([
|
||||
('2', '老学究-晦涩难懂'),
|
||||
('1.5', '学院派-较多高级词'),
|
||||
('1', '标准'),
|
||||
('0.1', '少常用词'),
|
||||
('-1', '通俗易懂'),
|
||||
('-2', '大白话'),
|
||||
], string='语言风格', default='1', help="-2~2,值越大越少使用常用词")
|
||||
set_presence_penalty = fields.Selection([
|
||||
('2', '多样强迫症'),
|
||||
('1.5', '新颖化'),
|
||||
('1', '标准'),
|
||||
('0.1', '允许常规重复'),
|
||||
('-1', '允许较多重复'),
|
||||
('-2', '更多强调重复'),
|
||||
], string='用词多样性', default='1', help="-2~2,值越大越少重复词")
|
||||
|
||||
# todo: 这里用 compute?
|
||||
max_tokens = fields.Integer('最长响应Token', default=600, help="越大返回内容越多,计费也越多")
|
||||
chat_count = fields.Integer(string="上下文数量", default=0, help="0~3,设定后,会将最近n次对话发给Ai,有助于他更好的回答")
|
||||
temperature = fields.Float(string="创造性值", default=1, help="0~2,值越大越富有想像力,越小则越保守")
|
||||
top_p = fields.Float(string="连贯性值", default=0.6, help="0~1,值越大越富有想像力,越小则越保守")
|
||||
frequency_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='是否当前用户默认微信对话频道')
|
||||
|
||||
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 '')))
|
||||
return result
|
||||
|
||||
def get_openai_context(self, channel_id, author_id, answer_id, minutes=30, chat_count=1):
|
||||
# 上下文处理,要处理群的方式,以及独聊的方式
|
||||
# azure新api 处理
|
||||
|
||||
115
app_chatgpt/views/mail_channel_views.xml
Normal file
115
app_chatgpt/views/mail_channel_views.xml
Normal file
@@ -0,0 +1,115 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<!-- 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>
|
||||
<field name="mode">extension</field>
|
||||
<field name="inherit_id" ref="mail.mail_channel_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[@name='privacy']" position="before">
|
||||
<page name="page_user" string="用户设定的角色相关,一般不要调整">
|
||||
<group>
|
||||
<group name="role_set" string="Ai常规设定">
|
||||
<field name="channel_type" readonly="1"/>
|
||||
<field name="ai_partner_id"
|
||||
options="{'no_open': True, 'no_create': True}"/>
|
||||
<field name="ext_ai_partner_id"
|
||||
options="{'no_open': True, 'no_create': True}"/>
|
||||
</group>
|
||||
<group name="param_set" string="Ai角色风格设定">
|
||||
<div class="o_td_label">
|
||||
<label for="set_max_tokens"/>
|
||||
</div>
|
||||
<field name="set_max_tokens" nolabel="1" required="1"/>
|
||||
<div class="o_td_label">
|
||||
<label for="set_chat_count"/>
|
||||
</div>
|
||||
<field name="set_chat_count" nolabel="1" required="1"/>
|
||||
<div class="o_td_label">
|
||||
<label for="set_temperature"/>
|
||||
</div>
|
||||
<field name="set_temperature" nolabel="1" required="1"/>
|
||||
<div class="o_td_label">
|
||||
<label for="set_top_p"/>
|
||||
</div>
|
||||
<field name="set_top_p" nolabel="1" required="1"/>
|
||||
<div class="o_td_label">
|
||||
<label for="set_frequency_penalty"/>
|
||||
</div>
|
||||
<field name="set_frequency_penalty" nolabel="1" required="1"/>
|
||||
<div class="o_td_label">
|
||||
<label for="set_presence_penalty"/>
|
||||
</div>
|
||||
<field name="set_presence_penalty" nolabel="1" required="1"/>
|
||||
<field name="is_private" readonly="0"/>
|
||||
<field name="create_uid" readonly="1" options="{'no_open': True, 'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='group_public_id']/.." position="after">
|
||||
<group string="Ai智能优化设定,具体参数">
|
||||
<field name="chat_count"/>
|
||||
<p class="ml16 my-n1 mb16" colspan="2">0-3,设定后,会将最近n次对话发给Ai,有助于他更好的回答</p>
|
||||
<field name="max_tokens"/>
|
||||
<p class="ml16 my-n1 mb16" colspan="2">最大响应Token,控制返回内容长度</p>
|
||||
<field name="temperature"/>
|
||||
<p class="ml16 my-n1 mb16" colspan="2">0-1,值越大越富有想像力,越小则越保守</p>
|
||||
<field name="frequency_penalty"/>
|
||||
<p class="ml16 my-n1 mb16" colspan="2">0-1,值越大越少使用常用词</p>
|
||||
<field name="presence_penalty"/>
|
||||
<p class="ml16 my-n1 mb16" colspan="2">0-1,值越大越少重复词</p>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</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"/>
|
||||
<field name="mode">extension</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//kanban//field[1]" position="before">
|
||||
<field name="is_private"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='description']" position="before">
|
||||
<em>角色:</em>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='channel_join']" position="replace">
|
||||
<button attrs="{'invisible':[('is_private','=',True), ('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>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_unfollow']" position="replace">
|
||||
<button type="object" attrs="{'invisible':['|', ('is_member','=',False), ('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"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='name']" position="after">
|
||||
<field name="channel_type"/>
|
||||
<group expand="0" string="Group By">
|
||||
<filter string="Channel Type" name="groupby_channel_type" domain="[]" context="{'group_by': 'channel_type'}"/>
|
||||
</group>
|
||||
<searchpanel>
|
||||
<field name="channel_type"/>
|
||||
<field name="is_private"/>
|
||||
</searchpanel>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user