From 743d2352ed653fc5b1290460bddd65a0eb553ccd Mon Sep 17 00:00:00 2001 From: Ivan Office Date: Tue, 15 Aug 2023 18:00:54 +0800 Subject: [PATCH] merge gpt --- app_chatgpt/__manifest__.py | 3 +- app_chatgpt/models/mail_channel.py | 78 ++++++++++++++- app_chatgpt/views/mail_channel_views.xml | 115 +++++++++++++++++++++++ 3 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 app_chatgpt/views/mail_channel_views.xml diff --git a/app_chatgpt/__manifest__.py b/app_chatgpt/__manifest__.py index f6be58d9..ba7e919f 100644 --- a/app_chatgpt/__manifest__.py +++ b/app_chatgpt/__manifest__.py @@ -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': [ diff --git a/app_chatgpt/models/mail_channel.py b/app_chatgpt/models/mail_channel.py index a635ec1e..fb682390 100644 --- a/app_chatgpt/models/mail_channel.py +++ b/app_chatgpt/models/mail_channel.py @@ -15,7 +15,83 @@ _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 处理 diff --git a/app_chatgpt/views/mail_channel_views.xml b/app_chatgpt/views/mail_channel_views.xml new file mode 100644 index 00000000..f0b262d2 --- /dev/null +++ b/app_chatgpt/views/mail_channel_views.xml @@ -0,0 +1,115 @@ + + + + + + + ai.mail.channel.form + mail.channel + extension + + + + + + + + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+ + + +

0-3,设定后,会将最近n次对话发给Ai,有助于他更好的回答

+ +

最大响应Token,控制返回内容长度

+ +

0-1,值越大越富有想像力,越小则越保守

+ +

0-1,值越大越少使用常用词

+ +

0-1,值越大越少重复词

+
+
+
+
+ + + + mail.channel + + extension + + + + + + 角色: + + + + + + + + + + + + + + mail.channel + + + + + + + + + + + + + + + +
+