base init v17, 很多只改了版号,没验证

This commit is contained in:
Ivan Office
2023-11-06 15:37:16 +08:00
parent 62ea802b13
commit 587f5ad043
96 changed files with 53379 additions and 84 deletions

View File

@@ -18,7 +18,7 @@
{ {
'name': 'odoo中文版套件之基础,中国会计基础,Chinese Enhance All in One', 'name': 'odoo中文版套件之基础,中国会计基础,Chinese Enhance All in One',
'version': '17.23.08.03', 'version': '17.23.11.06',
'author': 'odooai.cn', 'author': 'odooai.cn',
'category': 'Base', 'category': 'Base',
'website': 'https://www.odooai.cn', 'website': 'https://www.odooai.cn',
@@ -50,7 +50,7 @@
15. 销售团队改为中国 15. 销售团队改为中国
16. 精简语言的显示,如 Chinese简体中文改为 中文 16. 精简语言的显示,如 Chinese简体中文改为 中文
21. 多语言支持,多公司支持 21. 多语言支持,多公司支持
22. Odoo 16,15,14,13,12, 企业版社区版在线SaaS.sh版等全版本支持 22. Odoo 17,16,15,14,13,12, 企业版社区版在线SaaS.sh版等全版本支持
23. 代码完全开源 23. 代码完全开源
====== ======
1. Chinese address format, applicable to all Chinese customers, suppliers, partners, users, employee information etc. 1. Chinese address format, applicable to all Chinese customers, suppliers, partners, users, employee information etc.
@@ -69,7 +69,7 @@
14.Common decimal precision adjustments made. 14.Common decimal precision adjustments made.
15.Sales team changed to [China]. 15.Sales team changed to [China].
21. Multi-language Support. Multi-Company Support. 21. Multi-language Support. Multi-Company Support.
22. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition. 22. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
23. Full Open Source. 23. Full Open Source.
''', ''',
'pre_init_hook': 'pre_init_hook', 'pre_init_hook': 'pre_init_hook',

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 415 KiB

View File

@@ -75,7 +75,7 @@
</li> </li>
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>
22. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition. 22. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
</li> </li>
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>

4
app_chatgpt/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# from . import controllers
from . import models

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
# Created on 2023-02-016
# author: 欧度智能https://www.odooai.cn
# email: 300883@qq.com
# resource of odooai
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright (c) 2020-Present InTechual Solutions. (<https://intechualsolutions.com/>)
{
'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心聚合全网Ai',
'version': '17.23.10.19',
'author': 'odooai.cn',
'company': 'odooai.cn',
'maintainer': 'odooai.cn',
'category': 'Website/Website',
'website': 'https://www.odooai.cn',
'live_test_url': 'https://demo.odooapp.cn',
'license': 'LGPL-3',
'sequence': 10,
'images': ['static/description/banner.gif'],
'summary': '''
ChatGpt Odoo AI Center. Multi Ai aigc support with Ali Qwen Ai, Azure Ai, Baidu Ai,etc..
Support chatgpt 4 32k, Integration All ChatGpt Api and Azure OpenAI.
Easy Chat channel with several ChatGPT Robots and train.
''',
'description': '''
Allows the application to leverage the capabilities of the GPT language model to generate human-like responses,
providing a more natural and intuitive user experience.
Base on is_chatgpt_integration from InTechual Solutions.
1. Multi ChatGpt openAI robot Connector. Chat and train.
2. Multi Ai support including Azure Ai, Alibaba Ai, Baidu Ai, Chatgpt 4, Chatgpt 3.5 Turbo, Chatgpt 3 Davinci.
3. Bind ChatGpt Api to user. So we can chat to robot user or use ChatGpt Channel for Group Chat.
4. White and black List for ChatGpt.
5. Setup Demo Chat time for every new user.
6. Easy Start and Stop ChatGpt.
7. Evaluation the ai robot to make better response. This training.
8. Add api support Connect the Microsoft Azure OpenAI Service.
9. Can set Synchronous or Asynchronous mode for Ai response.
10.Filter Sensitive Words Setup.
11. Multi-language Support. Multi-Company Support.
12. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
13. Full Open Source.
''',
'depends': [
'base',
'app_odoo_customize',
'base_setup',
'mail',
'queue_job',
],
'data': [
'security/ir.model.access.csv',
'security/ir_rules.xml',
'data/mail_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',
],
'assets': {
'mail.assets_messaging': [
'app_chatgpt/static/src/models/*.js',
],
'mail.assets_model_data': [
'app_chatgpt/static/src/models_data/*.js',
],
'web.assets_backend': [
'app_chatgpt/static/src/components/*/*.xml',
],
},
'external_dependencies': {'python': ['openai']},
'installable': True,
'application': True,
'auto_install': False,
}

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import main

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from odoo import http
class ChatgptController(http.Controller):
@http.route(['/chatgpt_form'], type='http', auth="public", csrf=False,
website=True)
def question_submit(self):
return http.request.render('app_chatgpt.connector')

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="chatgpt_robot" model="ai.robot">
<field name="name">ChatGPT odoo</field>
<field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">1</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/openai.png"/>
</record>
<record id="chatgpt_robot1" model="ai.robot">
<field name="name">ChatGPT Coding</field>
<field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">6</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/openai.png"/>
</record>
<record id="chatgpt_robot2" model="ai.robot">
<field name="name">ChatGPT Finance</field>
<field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">7</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/openai.png"/>
</record>
<record id="chatgpt3_azure" model="ai.robot">
<field name="name">ChatGPT Azure</field>
<field name="provider">azure</field>
<field name="endpoint">https://my.openai.azure.com</field>
<field name="engine">gpt35</field>
<field name="api_version">2023-07-01-preview</field>
<field name="sequence">8</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/chatgpt35_azure.png"/>
</record>
<!-- 注意在azure中只需做1个部署即可然后指定不同模型名。 因为其同时只能部署一个endpoint-->
<record id="chatgpt4_azure" model="ai.robot">
<field name="name">ChatGPT4 Azure</field>
<field name="provider">azure</field>
<field name="endpoint">https://my.openai.azure.com</field>
<field name="engine">gpt4</field>
<field name="api_version">2023-07-01-preview</field>
<field name="sequence">9</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/chatgpt4_azure.png"/>
</record>
<record id="chatgpt4_32k_azure" model="ai.robot">
<field name="name">ChatGPT4-32k Azure</field>
<field name="provider">azure</field>
<field name="endpoint">https://my.openai.azure.com</field>
<field name="engine">gpt4-32k</field>
<field name="api_version">2023-07-01-preview</field>
<field name="sequence">10</field>
<field name="image_avatar" type="base64" file="app_chatgpt/static/description/src/chatgpt4_azure.png"/>
</record>
</odoo>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="ir.config_parameter" name="set_param" eval="('app_chatgpt.openapi_context_timeout', '300')"/>
<function model="ir.config_parameter" name="set_param" eval="('app_chatgpt.openai_sync_config', 'sync')"/>
</data>
</odoo>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="mail.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="res_id" ref="app_chatgpt.channel_chatgpt"/>
<field name="message_type">email</field>
<field name="subtype_id" ref="mail.mt_comment"/>
<field name="subject">Welcome to ChatGPT Group Chat</field>
<field name="body"><![CDATA[<p>Welcome to ChatGPT Group Chat.</p>
<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">
<field name="group_ids" eval="[Command.link(ref('base.group_user'))]"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="partner_chatgpt" model="res.partner">
<field name="name">ChatGPT odoo</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
</record>
<record id="user_chatgpt" model="res.users">
<field name="login">chatgpt@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt_robot"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
<record id="partner_chatgpt1" model="res.partner">
<field name="name">ChatGPT Coding</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
</record>
<record id="user_chatgpt1" model="res.users">
<field name="login">chatgpt1@example.com</field>
<field name="email">chatgpt1@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt1"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt_robot1"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
<record id="partner_chatgpt2" model="res.partner">
<field name="name">ChatGPT Finance</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
</record>
<record id="user_chatgpt2" model="res.users">
<field name="login">chatgpt2@example.com</field>
<field name="email">chatgpt2@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt2"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt_robot2"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
<record id="partner_chatgpt3_azure" model="res.partner">
<field name="name">ChatGPT3 Azure</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/src/chatgpt_blue.png"/>
</record>
<record id="user_chatgpt3_azure" model="res.users">
<field name="login">chatgpt3_azure@example.com</field>
<field name="email">chatgpt3_azure@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt3_azure"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt3_azure"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
<record id="partner_chatgpt4_azure" model="res.partner">
<field name="name">ChatGPT4 Azure</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/src/chatgpt4_azure.png"/>
</record>
<record id="user_chatgpt4_azure" model="res.users">
<field name="login">chatgpt4_azure@example.com</field>
<field name="email">chatgpt4_azure@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt4_azure"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt4_azure"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
<record id="partner_chatgpt4_32k_azure" model="res.partner">
<field name="name">ChatGPT4-32k Azure</field>
<field name="image_1920" type="base64" file="app_chatgpt/static/description/src/chatgpt4_32k_azure.png"/>
</record>
<record id="user_chatgpt4_32k_azure" model="res.users">
<field name="login">chatgpt4_32k_azure@example.com</field>
<field name="email">chatgpt4_32k_azure@example.com</field>
<field name="partner_id" ref="app_chatgpt.partner_chatgpt4_32k_azure"/>
<field name="gpt_id" ref="app_chatgpt.chatgpt4_32k_azure"/>
<field name="company_id" ref="base.main_company"/>
<field name="company_ids" eval="[Command.link(ref('base.main_company'))]"/>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record>
</data>
</odoo>

27879
app_chatgpt/i18n/zh_CN.po Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from . import res_partner
from . import mail_channel
from . import res_config_settings
from . import ai_robot
from . import res_partner_ai_use
from . import res_users
from . import mail_message
from . import mail_thread

View File

@@ -0,0 +1,412 @@
# -*- coding: utf-8 -*-
import openai.openai_object
import requests, json
import openai
import base64
from odoo import api, fields, models, modules, tools, _
from odoo.exceptions import UserError
import logging
_logger = logging.getLogger(__name__)
class AiRobot(models.Model):
_name = 'ai.robot'
_description = 'Ai Robot'
_order = 'sequence, name'
name = fields.Char(string='Name', translate=True, required=True)
provider = fields.Selection(string="AI Provider", selection=[('openai', 'OpenAI'), ('azure', 'Azure')],
required=True, default='openai', change_default=True)
# update ai_robot set ai_model=set_ai_model
ai_model = fields.Char(string="AI Model", required=True, default='auto', help='Customize input')
set_ai_model = fields.Selection(string="Quick Set Model", selection=[
('gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613(Default and Latest)'),
('gpt-3.5-turbo-16k-0613', 'gpt-3.5-turbo-16k-0613(Big text)'),
('gpt-4', 'Chatgpt 4'),
('gpt-4-32k', 'Chatgpt 4 32k'),
('gpt-3.5-turbo', 'Chatgpt 3.5 Turbo'),
('gpt-3.5-turbo-0301', 'Chatgpt 3.5 Turbo on 20230301'),
('text-davinci-003', 'Chatgpt 3 Davinci'),
('code-davinci-002', 'Chatgpt 2 Code Optimized'),
('text-davinci-002', 'Chatgpt 2 Davinci'),
('dall-e2', 'Dall-E Image'),
], default='gpt-3.5-turbo-0613',
help="""
GPT-4: Can understand Image, generate natural language or code.
GPT-3.5: A set of models that improve on GPT-3 and can understand as well as generate natural language or code
DALL·E: A model that can generate and edit images given a natural language prompt
Whisper: A model that can convert audio into text
Embeddings: A set of models that can convert text into a numerical form
CodexLimited: A set of models that can understand and generate code, including translating natural language to code
Moderation: A fine-tuned model that can detect whether text may be sensitive or unsafe
GPT-3 A set of models that can understand and generate natural language
""")
openapi_api_key = fields.Char(string="API Key", help="Provide the API key here")
# begin gpt 参数
# 1. stop表示聊天机器人停止生成回复的条件可以是一段文本或者一个列表当聊天机器人生成的回复中包含了这个条件就会停止继续生成回复。
# 2. temperature0-2控制回复的“新颖度”值越高聊天机器人生成的回复越不确定和随机值越低聊天机器人生成的回复会更加可预测和常规化。
# 3. top_p0-1语言连贯性与temperature有些类似也是控制回复的“新颖度”。不同的是top_p控制的是回复中概率最高的几个可能性的累计概率之和值越小生成的回复越保守值越大生成的回复越新颖。
# 4. frequency_penalty-2~2用于控制聊天机器人回复中出现频率过高的词汇的惩罚程度。聊天机器人会尝试避免在回复中使用频率较高的词汇以提高回复的多样性和新颖度。
# 5. presence_penalty-2~2与frequency_penalty相对用于控制聊天机器人回复中出现频率较低的词汇的惩罚程度。聊天机器人会尝试在回复中使用频率较低的词汇以提高回复的多样性和新颖度。
max_tokens = fields.Integer('Max Response', default=600,
help="""
Set a limit on the number of tokens per model response.
The API supports a maximum of 4000 tokens shared between the prompt
(including system message, examples, message history, and user query) and the model's response.
One token is roughly 4 characters for typical English text.
""")
temperature = fields.Float(string='Temperature', default=1,
help="""
Controls randomness. Lowering the temperature means that the model will produce
more repetitive and deterministic responses.
Increasing the temperature will result in more unexpected or creative responses.
Try adjusting temperature or Top P but not both.
""")
top_p = fields.Float('Top Probabilities', default=0.6,
help="""
Similar to temperature, this controls randomness but uses a different method.
Lowering Top P will narrow the models token selection to likelier tokens.
Increasing Top P will let the model choose from tokens with both high and low likelihood.
Try adjusting temperature or Top P but not both
""")
# 避免使用常用词
frequency_penalty = fields.Float('Frequency Penalty', default=1,
help="""
Reduce the chance of repeating a token proportionally based on how often it has appeared in the text so far.
This decreases the likelihood of repeating the exact same text in a response.
""")
# 越大模型就趋向于生成更新的话题,惩罚已经出现过的文本
presence_penalty = fields.Float('Presence penalty', default=1,
help="""
Reduce the chance of repeating any token that has appeared in the text at all so far.
This increases the likelihood of introducing new topics in a response.
""")
# 停止回复的关键词
stop = fields.Char('Stop sequences',
help="""
Use , to separate the stop key word.
Make responses stop at a desired point, such as the end of a sentence or list.
Specify up to four sequences where the model will stop generating further tokens in a response.
The returned text will not contain the stop sequence.
""")
# 角色设定
sys_content = fields.Char('System message',
help="""
Give the model instructions about how it should behave and any context it should reference when generating a response.
You can describe the assistants personality,
tell it what it should and shouldnt answer, and tell it how to format responses.
Theres no token limit for this section, but it will be included with every API call,
so it counts against the overall token limit.
""")
# end gpt 参数
endpoint = fields.Char('End Point', default='https://api.openai.com/v1/chat/completions')
engine = fields.Char('Engine', help='If use Azure, Please input the Model deployment name.')
api_version = fields.Char('API Version', default='2022-12-01')
ai_timeout = fields.Integer('Timeout(seconds)', help="Connect timeout for Ai response", default=120)
sequence = fields.Integer('Sequence', help="Determine the display order", default=10)
sensitive_words = fields.Text('Sensitive Words Plus', help='Sensitive word filtering. Separate keywords with a carriage return.')
is_filtering = fields.Boolean('Filter Sensitive Words', default=False, help='Use base Filter in dir models/lib/sensi_words.txt')
max_send_char = fields.Integer('Max Send Char', help='Max Send Prompt Length', default=8000)
image_avatar = fields.Image('Avatar')
partner_ids = fields.One2many('res.partner', 'gpt_id', string='Partner')
partner_count = fields.Integer('#Partner', compute='_compute_partner_count', store=False)
active = fields.Boolean('Active', default=True)
def _compute_partner_count(self):
for rec in self:
rec.partner_count = len(rec.partner_ids)
def action_disconnect(self):
requests.delete('https://chatgpt.com/v1/disconnect')
def get_ai_pre(self, data, author_id=False, answer_id=False, param={}):
# hook都正常
return False
def get_ai(self, data, author_id=False, answer_id=False, param={}):
# 通用方法
# author_id: 请求的 partner_id 对象
# answer_id: 回答的 partner_id 对象
# paramdict 形式的参数
# 调整输出为2个参数res_post详细内容is_ai是否ai的响应
self.ensure_one()
# 前置勾子,一般返回 False有问题返回响应内容用于处理敏感词等
res_pre = self.get_ai_pre(data, author_id, answer_id, param)
if res_pre:
# 有错误内容,则返回上级内容及 is_ai为假
return res_pre, {}, False
if not hasattr(self, 'get_%s' % self.provider):
res = _('No robot provider found')
return res, {}, False
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)
return res_post, usage, is_ai
def get_ai_origin(self, data, author_id=False, answer_id=False, param={}):
# 通用方法
# author_id: 请求的 partner_id 对象
# answer_id: 回答的 partner_id 对象
# paramdict 形式的参数
# 调整输出为2个参数res_post详细内容is_ai是否ai的响应
self.ensure_one()
# 前置勾子,一般返回 False有问题返回响应内容用于处理敏感词等
res_pre = self.get_ai_pre(data, author_id, answer_id, param)
if res_pre:
# 有错误内容,则返回上级内容及 is_ai为假
return res_pre, {}, False
if not hasattr(self, 'get_%s' % self.provider):
res = _('No robot provider found')
return res, {}, False
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)
return res
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):
# 返回是个对象那么就是ai
# if isinstance(res, dict):
if self.provider == 'openai':
# openai 格式处理
usage = res['usage']
content = res['choices'][0]['message']['content']
# _logger.warning('===========Ai响应:%s' % content)
elif self.provider == 'azure':
# azure 格式
usage = json.loads(json.dumps(res['usage']))
content = json.loads(json.dumps(res['choices'][0]['message']['content']))
else:
usage = False
content = res
data = content.replace(' .', '.').strip()
return data, usage, True
else:
# 直接返回错误语句那么就是非ai
return res, False, False
def get_ai_system(self, content=None):
# 获取基础ai角色设定, role system
sys_content = content or self.sys_content
if sys_content:
return {"role": "system", "content": sys_content}
return {}
def get_ai_model_info(self):
self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = self.ai_timeout or 120
o_url = "https://api.openai.com/v1/models/%s" % self.ai_model
if self.endpoint:
o_url = self.endpoint.replace("/chat/completions", "") + "/models/%s" % self.ai_model
response = requests.get(o_url, headers=headers, timeout=R_TIMEOUT)
response.close()
if response:
res = response.json()
r_text = json.dumps(res, indent=2)
else:
r_text = 'No response.'
raise UserError(r_text)
def get_ai_list_model(self):
self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = self.ai_timeout or 120
o_url = "https://api.openai.com/v1/models"
if self.endpoint:
o_url = self.endpoint.replace("/chat/completions", "") + "/models"
response = requests.get(o_url, headers=headers, timeout=R_TIMEOUT)
response.close()
if response:
res = response.json()
r_text = json.dumps(res, indent=2)
else:
r_text = 'No response.'
raise UserError(r_text)
def get_openai(self, data, author_id, answer_id, param={}):
self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = self.ai_timeout or 120
o_url = self.endpoint or "https://api.openai.com/v1/chat/completions"
# 处理传参,传过来的优先于 robot 默认的
max_tokens = param.get('max_tokens') if param.get('max_tokens') else self.max_tokens
temperature = param.get('temperature') if param.get('temperature') else self.temperature
top_p = param.get('top_p') if param.get('top_p') else self.top_p
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
request_timeout = param.get('request_timeout') if param.get('request_timeout') else self.ai_timeout
if self.stop:
stop = self.stop.split(',')
else:
stop = ["Human:", "AI:"]
# 以下处理 open ai
if self.ai_model in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']:
# 基本与 azure 同,要处理 api_base
openai.api_key = self.openapi_api_key
openai.api_base = o_url.replace('/chat/completions', '')
if isinstance(data, list):
messages = data
else:
messages = [{"role": "user", "content": data}]
# Ai角色设定如果没设定则再处理
if messages[0].get('role') != 'system':
sys_content = self.get_ai_system(param.get('sys_content'))
if sys_content:
messages.insert(0, sys_content)
# todo: 当前反向代理方式不通,要调整为 远程主机中接受请求post到openai再将结果返回给请求者
# response = openai.ChatCompletion.create(
# model=self.ai_model,
# messages=messages,
# # 返回的回答数量
# n=1,
# max_tokens=max_tokens,
# temperature=temperature,
# top_p=top_p,
# frequency_penalty=frequency_penalty,
# presence_penalty=presence_penalty,
# stop=stop,
# request_timeout=request_timeout,
# )
# if 'choices' in response:
# return response
# todo: 两种方式一样,要调整 v 服务器的二次处理 /root/toai.py
pdata = {
"model": self.ai_model,
"messages": messages,
"max_tokens": max_tokens,
"temperature": temperature,
"top_p": top_p,
"frequency_penalty": frequency_penalty,
"presence_penalty": presence_penalty,
"stop": stop
}
response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
try:
res = response.json()
if 'choices' in res:
return res
except Exception as e:
_logger.warning("Get Response Json failed: %s", e)
else:
_logger.warning('=====================Openai output data: %s' % response.json())
elif self.ai_model == 'dall-e2':
# todo: 处理 图像引擎,主要是返回参数到聊天中
# image_url = response['data'][0]['url']
# https://platform.openai.com/docs/guides/images/introduction
pdata = {
"prompt": data,
"n": 3,
"size": "1024x1024",
}
return '建设中'
else:
pdata = {
"model": self.ai_model,
"prompt": data,
"temperature": 1,
"max_tokens": max_tokens,
"top_p": 0.6,
"frequency_penalty": 0.1,
"presence_penalty": 0.1,
"stop": stop
}
response = openai.ChatCompletion.create(
model=self.ai_model,
messages=data
)
# response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
if 'choices' in response:
return response
else:
_logger.warning('=====================openai output data: %s' % response.json())
return _("Response Timeout, please speak again.")
def get_azure(self, data, author_id, answer_id, param={}):
self.ensure_one()
# only for azure
openai.api_type = self.provider
if not self.endpoint:
raise UserError(_("Please Set your AI robot's endpoint first."))
openai.api_base = self.endpoint
if not self.api_version:
raise UserError(_("Please Set your AI robot's API Version first."))
openai.api_version = self.api_version
openai.api_key = self.openapi_api_key
if self.stop:
stop = self.stop.split(',')
else:
stop = ["Human:", "AI:"]
if isinstance(data, list):
messages = data
else:
messages = [{"role": "user", "content": data}]
# 处理传参,传过来的优先于 robot 默认的
max_tokens = param.get('max_tokens') if param.get('max_tokens') else self.max_tokens
temperature = param.get('temperature') if param.get('temperature') else self.temperature
top_p = param.get('top_p') if param.get('top_p') else self.top_p
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
request_timeout= param.get('request_timeout') if param.get('request_timeout') else self.ai_timeout
# Ai角色设定如果没设定则再处理
if messages[0].get('role') != 'system':
sys_content = self.get_ai_system(param.get('sys_content'))
if sys_content:
messages.insert(0, sys_content)
# 暂时不变
response = openai.ChatCompletion.create(
engine=self.engine,
messages=messages,
# 返回的回答数量
n=1,
max_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty,
stop=None,
request_timeout=request_timeout,
)
if 'choices' in response:
return response
else:
_logger.warning('=====================azure output data: %s' % response.json())
return _("Response Timeout, please speak again.")
@api.onchange('provider')
def _onchange_provider(self):
if self.provider == 'openai':
self.endpoint = 'https://api.openai.com/v1/chat/completions'
elif self.provider == 'azure':
self.endpoint = 'https://odoo.openai.azure.com'
if self.provider:
# 取头像
module_path = modules.get_module_path('app_chatgpt', display_warning=False)
if module_path:
path = modules.check_resource_path(module_path, ('static/description/src/%s.png' % self.provider))
if path:
image_file = tools.file_open(path, 'rb')
self.image_avatar = base64.b64encode(image_file.read())
@api.onchange('set_ai_model')
def _onchange_set_ai_model(self):
if self.set_ai_model:
self.ai_model = self.set_ai_model
else:
self.ai_model = None

View File

@@ -0,0 +1,360 @@
# -*- coding: utf-8 -*-
import openai
import requests, json
import datetime
# from transformers import TextDavinciTokenizer, TextDavinciModel
from odoo import api, fields, models, tools, _
from odoo.exceptions import UserError
from odoo.osv import expression
from odoo.addons.app_common.models.base import get_ua_type
import logging
_logger = logging.getLogger(__name__)
class Channel(models.Model):
_inherit = 'mail.channel'
is_private = fields.Boolean(string="Private", default=False, help="Check to set Private, Can only use by user, not Public")
# 因为 channel_member_ids 不好处理,在此增加此字段
# 主Ai
ai_partner_id = fields.Many2one(comodel_name="res.partner", string="Main Ai", required=False,
domain=[('gpt_id', '!=', None), ('is_chat_private', '=', True)],
default=lambda self: self._app_get_m2o_default('ai_partner_id'),
help="Main Ai is the robot help you default.")
ext_ai_partner_id = fields.Many2one(comodel_name="res.partner", string="Secondary Ai",
domain=[('gpt_id', '!=', None), ('is_chat_private', '=', True)])
description = fields.Text('Ai Character', help="Ai would help you act as the Character set.")
set_max_tokens = fields.Selection([
('300', 'Short'),
('600', 'Standard'),
('1000', 'Medium'),
('2000', 'Long'),
('3000', 'Overlength'),
('32000', '32K'),
], string='Max Response', default='600', help="越大返回内容越多,计费也越多")
set_chat_count = fields.Selection([
('none', 'Ai Auto'),
('1', '1标准'),
('3', '3强关联'),
('5', '5超强关联'),
], string="History Count", default='1', help="0-5设定后会将最近n次对话发给Ai有助于他更好的回答但太大费用也高")
set_temperature = fields.Selection([
('2', '天马行空'),
('1.5', '创造性'),
('1', '标准'),
('0.6', '理性'),
('0.1', '保守'),
], string="Set Temperature", default='1', help="0-21值越大越富有想像力越小则越保守")
set_top_p = fields.Selection([
('0.9', '严谨惯性思维'),
('0.6', '标准推理'),
('0.4', '跳跃性'),
('0.1', '随便'),
], string="Top Probabilities", default='0.6', help="0-1值越大越倾向大众化的连贯思维")
# 避免使用常用词
set_frequency_penalty = fields.Selection([
('2', '老学究-晦涩难懂'),
('1.5', '学院派-较多高级词'),
('1', '标准'),
('0.1', '少常用词'),
('-1', '通俗易懂'),
('-2', '大白话'),
], string='Frequency Penalty', default='1', help="-2~2值越大越少使用常用词")
set_presence_penalty = fields.Selection([
('2', '多样强迫症'),
('1.5', '新颖化'),
('1', '标准'),
('0.1', '允许常规重复'),
('-1', '允许较多重复'),
('-2', '更多强调重复'),
], string='Presence penalty', 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=60, chat_count=0):
# 上下文处理,要处理群的方式,以及独聊的方式
# azure新api 处理
context_history = []
afterTime = fields.Datetime.now() - datetime.timedelta(minutes=minutes)
message_model = self.env['mail.message'].sudo()
# 处理消息: 取最新问题 + 上 chat_count=1次的交互将之前的交互按时间顺序拼接。
# 注意: ai 每一次回复都有 parent_id 来处理连续性
# 私聊处理
# todo: 更好的处理方式
domain = [('res_id', '=', channel_id),
('model', '=', 'mail.channel'),
('message_type', '!=', 'user_notification'),
('parent_id', '!=', False),
('is_ai', '=', True),
('body', '!=', '<p>%s</p>' % _('Response Timeout, please speak again.')),
('body', '!=', _('温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。'))]
if self.channel_type in ['group', 'channel']:
# 群聊增加时间限制,当前找所有人,不限制 author_id
domain = expression.AND([domain, [('date', '>=', afterTime)]])
else:
domain = expression.AND([domain, [('author_id', '=', answer_id.id)]])
if chat_count == 0:
ai_msg_list = []
else:
ai_msg_list = message_model.with_context(tz='UTC').search(domain, order="id desc", limit=chat_count)
for ai_msg in ai_msg_list:
# 判断这个 ai_msg 是不是ai发有才 insert。 判断 user_msg 是不是 user发的有才 insert
user_msg = ai_msg.parent_id.sudo()
if ai_msg.author_id.sudo().gpt_id and answer_id.sudo().gpt_id and ai_msg.author_id.sudo().gpt_id == answer_id.sudo().gpt_id:
ai_content = str(ai_msg.body).replace("<p>", "").replace("</p>", "").replace("<p>", "")
context_history.insert(0, {
'role': 'assistant',
'content': ai_content,
})
if not user_msg.author_id.gpt_id:
user_content = user_msg.description.replace("<p>", "").replace("</p>", "").replace('@%s' % answer_id.name, '').lstrip()
context_history.insert(0, {
'role': 'user',
'content': user_content,
})
return context_history
def get_ai_config(self, ai):
# 勾子用于取ai 配置
return {}
def get_ai_response(self, ai, messages, channel, user_id, message):
author_id = message.create_uid.partner_id
answer_id = user_id.partner_id
# todo: 只有个人配置的群聊才给配置
param = self.get_ai_config(ai)
res, usage, is_ai = ai.get_ai(messages, author_id, answer_id, param)
if res:
if get_ua_type() != 'wxweb':
# 处理当微信语音返回时,是直接回文本信息,不需要转换回车
res = res.replace('\n', '<br/>')
new_msg = channel.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
if usage:
if ai.provider == 'ali':
prompt_tokens = usage['input_tokens']
completion_tokens = usage['output_tokens']
total_tokens = usage['input_tokens'] + usage['output_tokens']
else:
prompt_tokens = usage['prompt_tokens']
completion_tokens = usage['completion_tokens']
total_tokens = usage['total_tokens']
new_msg.write({
'human_prompt_tokens': prompt_tokens,
'ai_completion_tokens': completion_tokens,
'cost_tokens': total_tokens,
})
def _notify_thread(self, message, msg_vals=False, **kwargs):
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
# print(f'rdata:{rdata}')
answer_id = self.env['res.partner']
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_type = self.channel_type
messages = []
# 不处理 一般notify但处理欢迎
if '<div class="o_mail_notification' in message.body and message.body != _('<div class="o_mail_notification">joined the channel</div>'):
return rdata
if 'o_odoobot_command' in message.body:
return rdata
if channel_type == 'chat':
channel_partner_ids = self.channel_partner_ids
answer_id = channel_partner_ids - message.author_id
user_id = answer_id.mapped('user_ids').sudo().filtered(lambda r: r.gpt_id)[:1]
if user_id and answer_id.gpt_id:
gpt_policy = user_id.gpt_policy
gpt_wl_partners = user_id.gpt_wl_partners
is_allow = message.author_id.id in gpt_wl_partners.ids
if gpt_policy == 'all' or (gpt_policy == 'limit' and is_allow):
ai = answer_id.sudo().gpt_id
elif channel_type in ['group', 'channel']:
# partner_ids = @ ids
partner_ids = list(msg_vals.get('partner_ids'))
if hasattr(self, 'ai_partner_id') and self.ai_partner_id:
# 当有主id时使用主id
if self.ai_partner_id.id in partner_ids:
partner_ids = [self.ai_partner_id.id]
if partner_ids:
# 常规群聊 @
partners = self.env['res.partner'].search([('id', 'in', partner_ids)])
# user_id = user, who has binded gpt robot
user_id = partners.mapped('user_ids').sudo().filtered(lambda r: r.gpt_id)[:1]
elif message.body == _('<div class="o_mail_notification">joined the channel</div>'):
# 欢迎的情况
partners = self.channel_partner_ids.sudo().filtered(lambda r: r.gpt_id)[:1]
user_id = partners.mapped('user_ids')[:1]
elif self.member_count == 2:
# 处理独聊频道
if hasattr(self, 'is_private') and not self.is_private:
# 2个人的非私有频道不处理
pass
else:
partners = self.channel_partner_ids.sudo().filtered(lambda r: r.gpt_id and r != message.author_id)[:1]
user_id = partners.mapped('user_ids')[:1]
elif not message.author_id.gpt_id:
# 没有@时默认第一个robot
# robot = self.env.ref('app_chatgpt.chatgpt_robot')
# 临时用azure
if hasattr(self, 'ai_partner_id') and self.ai_partner_id:
# 当有主id时使用主id
user_id = self.ai_partner_id.mapped('user_ids')[:1]
else:
# 使用群里的第一个robot
partners = self.channel_partner_ids.sudo().filtered(lambda r: r.gpt_id)[:1]
user_id = partners.mapped('user_ids')[:1]
if user_id:
ai = user_id.sudo().gpt_id
# 此处理不判断,将此处逻辑迁移至 get_ai_pre 非ai回复的直接内容注意设置为 is_ai=false
# gpt_policy = user_id.gpt_policy
# gpt_wl_partners = user_id.gpt_wl_partners
# is_allow = message.author_id.id in gpt_wl_partners.ids
# answer_id = user_id.partner_id
# if gpt_policy == 'all' or (gpt_policy == 'limit' and is_allow):
# ai = user_id.sudo().gpt_id
# elif user_id.gpt_id and not is_allow:
# # 暂时有限用户的Ai
# raise UserError(_('此Ai暂时未开放请联系管理员。'))
if hasattr(ai, 'is_translator') and ai.is_translator and ai.ai_model == 'translator':
return rdata
chatgpt_channel_id = self.env.ref('app_chatgpt.channel_chatgpt')
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
else:
# 不能用 preview 如果用 : 提示词则 preview信息丢失
plaintext_ct = tools.html_to_inner_content(message.body)
msg = plaintext_ct.replace('@%s' % answer_id.name, '').lstrip()
if not msg:
return rdata
if self._context.get('app_ai_sync_config') and self._context.get('app_ai_sync_config') in ['sync', 'async']:
sync_config = self._context.get('app_ai_sync_config')
else:
sync_config = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openai_sync_config')
# api_key = self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_api_key')
# ai处理不要自问自答
if ai and answer_id != message.author_id:
api_key = ai.openapi_api_key
if not api_key:
_logger.warning(_("ChatGPT Robot【%s】have not set open api key."))
return rdata
try:
openapi_context_timeout = int(self.env['ir.config_parameter'].sudo().get_param('app_chatgpt.openapi_context_timeout')) or 60
except:
openapi_context_timeout = 60
openai.api_key = api_key
# 非4版本取0次。其它取3 次历史
chat_count = 3
if '4' in ai.ai_model or '4' in ai.name:
chat_count = 1
if hasattr(self, 'chat_count'):
if self.chat_count > 0:
chat_count = 1
else:
chat_count = chat_count
if author_id != answer_id.id and self.channel_type == 'chat':
# 私聊
_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:
# 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']:
# 高级用户自建的话题
channel = self.env[msg_vals.get('model')].browse(msg_vals.get('res_id'))
if hasattr(channel, 'is_private') and channel.description:
messages.append({"role": "system", "content": channel.description})
try:
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})
msg_len = sum(len(str(m)) for m in messages)
# 接口最大接收 8430 Token
if msg_len * 2 > ai.max_send_char:
messages = []
if hasattr(channel, 'is_private') and channel.description:
messages.append({"role": "system", "content": channel.description})
messages.append({"role": "user", "content": msg})
msg_len = sum(len(str(m)) for m in messages)
if msg_len * 2 > ai.max_send_char:
new_msg = channel.with_user(user_id).message_post(body=_('您所发送的提示词已超长。'), message_type='comment',
subtype_xmlid='mail.mt_comment',
parent_id=message.id)
# if msg_len * 2 >= 8000:
# messages = [{"role": "user", "content": msg}]
if sync_config == 'sync':
self.get_ai_response(ai, messages, channel, user_id, message)
else:
self.with_delay().get_ai_response(ai, messages, channel, user_id, message)
except Exception as e:
raise UserError(_(e))
return rdata
def _message_post_after_hook(self, message, msg_vals):
if message.author_id.gpt_id:
if msg_vals['body'] not in [_('Response Timeout, please speak again.'), _('温馨提示:您发送的内容含有敏感词,请修改内容后再向我发送。'),
_('此Ai暂时未开放请联系管理员。'), _('您所发送的提示词已超长。')]:
message.is_ai = True
return super(Channel, self)._message_post_after_hook(message, msg_vals)
@api.model
def _get_my_last_cid(self):
# 获取当前用户最后一次进入的channel返回该channel的id
# todo: 优化,每次聊天进入时就 write
user = self.env.user
msgs = self.env['mail.message'].sudo().search([
('model', '=', 'mail.channel'),
('author_id', '=', user.partner_id.id),
], limit=3, order='id desc')
c_id = 0
c = self
for m in msgs:
c = self.browse(m.res_id)
if c.is_member:
c_id = c.id
break
if not c_id:
c = self.env.ref('app_chatgpt.channel_chatgpt', raise_if_not_found=False)
c_id = c.id or False
if c and not c.is_member:
c.sudo().add_members([user.partner_id.id])
return c_id
@api.onchange('ai_partner_id')
def _onchange_ai_partner_id(self):
if self.ai_partner_id and self.ai_partner_id.image_1920:
self.image_128 = self.ai_partner_id.avatar_128

View File

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class Message(models.Model):
_inherit = "mail.message"
human_prompt_tokens = fields.Integer('Human Prompt Tokens')
ai_completion_tokens = fields.Integer('AI Completion Tokens')
cost_tokens = fields.Integer('Cost Tokens')
# 是否ai回复
is_ai = fields.Boolean('Is Ai', default=False)
# 得到 ai 响应后需要特殊处理ai的
ai2model = fields.Char('Ai Response model')
ai2id = fields.Integer('Ai Response id')
def _message_add_reaction(self, content):
super(Message, self)._message_add_reaction(content)
if self.create_uid.gpt_id:
# 处理反馈
pass
def message_format(self, format_reply=True):
message_values = super(Message, self).message_format(format_reply=format_reply)
for message in message_values:
message_sudo = self.browse(message['id']).sudo().with_prefetch(self.ids)
message['human_prompt_tokens'] = message_sudo.human_prompt_tokens
message['ai_completion_tokens'] = message_sudo.ai_completion_tokens
message['cost_tokens'] = message_sudo.cost_tokens
message['is_ai'] = message_sudo.is_ai
return message_values

View File

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from odoo import fields, models, api, _
class MailThread(models.AbstractModel):
_inherit = "mail.thread"

View File

@@ -0,0 +1,21 @@
{
'id': 'chatcmpl-747IRWr2Ij3HA6NVTWp4ZTnEA2grW',
'object': 'chat.completion',
'created': 1681215715,
'model': 'gpt-3.5-turbo-0301',
'usage': {
'prompt_tokens': 17,
'completion_tokens': 38,
'total_tokens': 55
},
'choices': [
{
'message': {
'role': 'assistant',
'content': ' '
},
'finish_reason': 'stop',
'index': 0
}
]
}

View File

@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
openapi_context_timeout = fields.Integer(string="Connect Timout", help="群聊中多少分钟以内的聊天信息作为上下文继续", config_parameter="app_chatgpt.openapi_context_timeout")
openai_sync_config = fields.Selection([
('sync', 'Synchronous'),
('async', 'Asynchronous')
], string='Sync Config', default='sync', config_parameter="app_chatgpt.openai_sync_config")

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
from odoo import fields, models, api
class ResPartner(models.Model):
_inherit = "res.partner"
gpt_id = fields.Many2one('ai.robot', string='Bind to Ai', ondelete='set null')
is_chat_private = fields.Boolean('Allow Chat Private', default=False)
@api.model
def im_search(self, name, limit=20):
users = self.env['res.users'].search([
('id', '!=', self.env.user.id),
('name', 'ilike', name),
('active', '=', True),
('share', '=', False),
('is_chat_private', '=', True)
], order='gpt_id, name, id', limit=limit)
return list(users.partner_id.mail_partner_format().values())
def mail_partner_format(self, fields=None):
# 直接覆盖原生,增加 gpt_id 字段
partners_format = dict()
if not fields:
fields = {'id': True, 'name': True, 'email': True, 'active': True, 'im_status': True, 'gpt_id': 0, 'user': {}}
for partner in self:
data = {}
if 'id' in fields:
data['id'] = partner.id
if 'name' in fields:
name = partner.name
# 英文不好分,暂时不隐名
# if not partner.related_user_id.gpt_id:
# name = partner.name[0] + '*' * (len(partner.name) - 1)
data['name'] = name
if 'email' in fields:
data['email'] = partner.email
if 'active' in fields:
data['active'] = partner.active
if 'im_status' in fields:
data['im_status'] = partner.im_status
if 'gpt_id' in fields:
data['gpt_id'] = partner.gpt_id.id if partner.gpt_id else 0
if 'user' in fields:
internal_users = partner.user_ids - partner.user_ids.filtered('share')
main_user = internal_users[0] if len(internal_users) > 0 else partner.user_ids[0] if len(partner.user_ids) > 0 else self.env['res.users']
data['user'] = {
"id": main_user.id,
"isInternalUser": not main_user.share,
} if main_user else [('clear',)]
# if 'guest' in self.env.context or not self.env.user.has_group('base.group_erp_manager'):
# 完全不显示 邮箱
data.pop('email', None)
partners_format[partner] = data
return partners_format

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class ResPartnerAiUse(models.Model):
_name = "res.partner.ai.use"
_description = '消费者Ai使用情况'
name = fields.Many2one('res.partner', 'Partner')
ai_user_id = fields.Many2one('res.users', 'Ai User', domain=[('gpt_id', '!=', False)])
first_ask_time = fields.Datetime('First Ask Time')
latest_ask_time = fields.Datetime('Latest Ask Time')
service_start_date = fields.Datetime('Service Start Date')
service_end_date = fields.Datetime('Service End Date')
used_number = fields.Integer('Number of Used')
max_number = fields.Integer('Max Number of Call')
human_prompt_tokens = fields.Integer('Human Prompt Tokens')
ai_completion_tokens = fields.Integer('AI Completion Tokens')
tokens_total = fields.Integer('Total Tokens')
token_balance = fields.Integer('Token Balance')
# balance = allow - total
token_allow = fields.Integer('Token Allow')

View File

@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class ResUsers(models.Model):
_inherit = "res.users"
# 改为在 partner中设置用户处绑定
gpt_id = fields.Many2one('ai.robot', string='Bind to Ai', related='partner_id.gpt_id', inherited=True, readonly=False)
gpt_policy = fields.Selection([
('all', 'All Users'),
('limit', 'Selected Users')
], string='Allowed Conversation Mode', default='all', ondelete='set default')
gpt_wl_partners = fields.Many2many('res.partner', 'res_partner_ai_use', 'ai_user_id', 'name', string='Allowed Partners')
gpt_demo_time = fields.Integer('Default Demo Time', default=0)
is_chat_private = fields.Boolean('Allow Chat Private', default=False, related='partner_id.is_chat_private', inherited=True, readonly=False)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
{
"id": "gpt-3.5-turbo",
"object": "model",
"created": 1677610602,
"owned_by": "openai",
"permission": [
{
"object": "model_permission",
"created": 1677691854,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
"allow_search_indices": false,
"allow_view": true,
"allow_fine_tuning": false,
"organization": "*",
"group": null,
"is_blocking": false
}
],
"root": "gpt-3.5-turbo",
"parent": null
}

View File

@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_gpt_robt_user,access_gpt_robt_user,model_ai_robot,base.group_user,1,0,0,0
access_gpt_robt_manager,access_gpt_robt_manager,model_ai_robot,base.group_erp_manager,1,1,1,1
access_res_partner_ai_use_user,access_res_partner_ai_use_user,model_res_partner_ai_use,base.group_user,1,0,0,0
access_res_partner_ai_use_manager,access_res_partner_ai_use_manager,model_res_partner_ai_use,base.group_erp_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_gpt_robt_user access_gpt_robt_user model_ai_robot base.group_user 1 0 0 0
3 access_gpt_robt_manager access_gpt_robt_manager model_ai_robot base.group_erp_manager 1 1 1 1
4 access_res_partner_ai_use_user access_res_partner_ai_use_user model_res_partner_ai_use base.group_user 1 0 0 0
5 access_res_partner_ai_use_manager access_res_partner_ai_use_manager model_res_partner_ai_use base.group_erp_manager 1 1 1 1

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="res_partner_ai_use_personal_rule" model="ir.rule">
<field name="name">Personal AI Use</field>
<field ref="model_res_partner_ai_use" name="model_id"/>
<field name="domain_force">[('name','=',user.partner_id.id)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="res_partner_ai_use_see_all" model="ir.rule">
<field name="name">All AI Use</field>
<field ref="model_res_partner_ai_use" name="model_id"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('base.group_erp_manager'))]"/>
</record>
</odoo>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

View File

@@ -0,0 +1,343 @@
<section class="oe_container container">
<div class="oe_row oe_spaced" >
<div class="row">
<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 chatgpt 4 32k. 3.5 turbo, text-davinci, Integration All ChatGpt Api. </h3>
<div class="oe_row">
<h3>Lastest update: v16.23.09.27</h3>
<div class="row">
<div class="row">
Add Alibaba Qwen support(search 'app_ai_ali'), update chatgpt api
</div>
<img class="oe_demo oe_screenshot img img-fluid" src="demo02.jpg">
</div>
<h3>Lastest update: v16.23.03.16</h3>
<div class="row">
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
</div>
<div class="oe_span12 oe_spaced">
<div class="alert alert-info" style="padding:8px;font-weight: 300; font-size: 20px;">
<i class="fa fa-hand-o-right"></i><b> Key features: </b>
<ul class="list-unstyled">
<li>
<i class="fa fa-check-square-o text-primary"></i>
1. Multi ChatGpt openAI robot Connector. Chat and train.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
2. Multi Ai support including Azure Ai, Alibaba Ai, Baidu Ai, Chatgpt 4, Chatgpt 3.5 Turbo, Chatgpt 3 Davinci
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
3. Bind ChatGpt Api to user. So we can chat to robot user or use ChatGpt Channel for Group Chat.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
4. White and black List for ChatGpt.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
5. Setup Demo Chat time for every new user.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
6. Easy Start and Stop ChatGpt.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
7. Evaluation the ai robot to make better response. This training.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
8. Add api support Connect the Microsoft Azure OpenAI Service.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
9. Can set Synchronous or Asynchronous mode for Ai response.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
10.Filter Sensitive Words Setup.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
11. Multi-language Support. Multi-Company Support.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
12. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
13. Full Open Source.
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">Add more Ai support like Alibaba qwen, chatgpt 4, baidu china</h2>
<h4 class="oe_slogan"> Need to navigate to odoo app store to install addons</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo01.jpg"/>
</div>
<h4 class="oe_slogan">Please apply for the Qwen Api first from Alibaba</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo03.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">Easy to use Ai Robot with multi Provider. Easy chat, easy help</h2>
<h4 class="oe_slogan"> Open Ai for more smart. Microsoft Azure chatgpt for china user.</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demob.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">1. Multi ChatGpt openAI robot Connector. Chat and train.</h2>
<h4 class="oe_slogan"> Goto Setting--> Ai Robot to setup your robot api. </h4>
<p> Input your api key, And Select the api model you need to use.</p>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo1.jpg"/>
</div>
<p> You can set the Temperature higer for more creative answer.</p>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo2.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">2. Multi Api support, Chatgpt 3.5 Turbo, Chatgpt 3 Davinci, Chatgpt 2 Code Optimized</h2>
<h4 class="oe_slogan"> Choose the model you want to use</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo2.jpg"/>
</div>
<p> You can set the Temperature higer for more creative answer.</p>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo3.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">3. Bind ChatGpt Api to user. So we can chat to robot user or use ChatGpt Channel for Group Chat.</h2>
<h4 class="oe_slogan"> Go Settings ->users, bind chatgpt to some user.</h4>
<img src="demo4.jpg"/>
</div>
<h4 class="oe_slogan"> So you can have many user, and many chatgpt robot. This provide you an Ai pool.</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo5.jpg"/>
</div>
<h4 class="oe_slogan"> You can set the blacklist to this chatgpt robot to limit request. Also you can setup Demo time for every normal user..</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo6.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">4. White and black List for ChatGpt.</h2>
<h2 class="bg-warning text-center pt8 pb8">5. Setup Demo Chat time for every new user.</h2>
<h4 class="oe_slogan"> You can set the blacklist to this chatgpt robot to limit request. Also you can setup Demo time for every normal user..</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo6.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">6. Easy Start and Stop ChatGpt..</h2>
<h4 class="oe_slogan"> You can easy chat with the apt robot with odoo IM</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo7.jpg"/>
</div>
<h4 class="oe_slogan"> You can chat with several robot in the same time</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo8.jpg"/>
</div>
<h4 class="oe_slogan"> If you have more than 1 robot in the group. you can @ the specify robot.</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo9.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">7. Evaluation the ai robot to make better response. This training.</h2>
<h4 class="oe_slogan"> You can Evaluation chatgpt's answer. Mark as good for good answer. Mark as back for bad answer.</h4>
<p> With Evaluation, you can make your ai robot more smart.
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo71.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">8. Add api support Connect the Microsoft Azure OpenAI Service.</h2>
<h4 class="oe_slogan"> Azure openai add. It is for china and other country which no chatgpt service.</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo81.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">9. Can set Synchronous or Asynchronous mode for Ai response.</h2>
<h4 class="oe_slogan"> Synchronous(default) mode can get response then ask question again. Asynchronous mode would make you do other thing when waiting for response.</h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="demo91.jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">Multi-language Support..</h2>
<h4 class="oe_slogan"> </h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="cnreadme.jpg"/>
</div>
</div>
</section>
<!-- begin howto-->
<section class="oe_container container s_text_block o_colored_level pt16 pb16">
<h2 class="text-center bg-info text-white pt16 pb16">- How to setup and use -</h2>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h4 class="pt16">
1. Get ChatGPT Api key from openai or azure.
</h4>
<p>Api From Azure, please read </p>
<p>https://www.odooai.cn/blog/odoo-install-deploy-6/chatgpt4-china-application-chatgpt3-5-free-one-year-microsoft-azure-openai-api-registration-tutorial-odoo-aicenter-integration-28 </p>
<p>Api From Alibaba, please read </p>
<p>https://www.odooai.cn/blog/customer-success-10/odoo-ai-ali-tongyi-qianwen-281</p>
<h4 class="pt16">2. Setup your Api information from Settings -- Users --Ai Robot</h4>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup2.jpg">
</div>
</div>
<h4 class="pt16">3. Setup your Api Provider(openai) , api key, End point</h4>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup3.jpg">
</div>
<p> As openai change the api often, sometime you need to check</p>
<p> https://platform.openai.com/docs/introduction</p>
</div>
<h4 class="pt16">4.Bind your Ai Robot (GPT) to a User. We already setup a sample.</h4>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup4.jpg">
</div>
</div>
<h4 class="pt16">5. Bind your Ai User to Channel from Discuss. We already setup a sample.</h4>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup5.jpg">
</div>
</div>
<h5 class="pt16">6. You can setup the Ai system context and Character.</h5>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup6.jpg">
</div>
</div>
<h5 class="pt16">7. You can setup Lots of channel for subjects and projects..</h5>
<div class="row">
<div class="oe_demo oe_screenshot img img-fluid">
<img src="setup7.jpg">
</div>
</div>
</div>
</section>
<!-- end howto-->
<!-- begin video-->
<section class="s_text_block o_colored_level pt16 pb16">
<div class="container s_allow_columns">
<h2 class="text-center bg-info text-white pt16 pb16">- You can Buy our extra apps for website builder, seo builder or multi languages' translator. -</h2>
</div>
</section>
<section class="oe_container container s_text_block pt24 pb24 o_colored_level" data-snippet="s_text_block" data-name="文本">
<div class="s_allow_columns container">
<div data-oe-expression="//www.youtube.com/embed/ntKpCi_Lics?rel=0&amp;autoplay=1" class="media_iframe_video">
<div class="css_editable_mode_display"></div>
<div class="media_iframe_video_size"></div>
<iframe src="//www.youtube.com/embed/ntKpCi_Lics?rel=0&amp;autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
</div>
<p class="o_default_snippet_text"><br></p>
</div>
<div class="oe_row text-center">
<span>Click above Play. or go </span>
<a href="https://www.youtube.com/watch?v=ntKpCi_Lics" target="_blank" role="button" class="btn btn-link btn-lg">Youtube Video of odoo ChatGPT SEO</a>
</div>
<div class="oe_row text-center">
<p class="o_default_snippet_text">Demo Gif Animation if you can not get video</p>
<img class="oe_demo oe_screenshot img img-fluid" src="app_ai_seo.gif">
</div>
</section>
<!-- end video-->
<section class="container oe_dark">
<div class="oe_row oe_spaced text-center">
<div class="row">
<h2 class="oe_slogan">Technical Help & Support</h2>
</div>
<div class="col-md-12 pad0">
<div class="oe_mt16">
<p><h4>
For any type of technical help & support requests, Feel free to contact us</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:odoo@china.com"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-envelope"></i> odoo@china.com</a>
<p><h4>
Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:300883@qq.com"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-envelope"></i> 300883@qq.com</a>
</div>
<div class="oe_mt16">
<p><h4>
Visit our website for more support.</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="https://www.odooai.cn" target="_blank"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-web"></i>https://www.odooai.cn</a>
</div>
</div>
</div>
<div class="oe_row oe_spaced text-center">
<h2>More Powerful addons, Make your odoo very easy to use, easy customize:
<a class="btn btn-primary mb16" href="http://www.odoo.com/apps/modules/browse?author=odooai.cn">odooai.cn Odoo Addons</a>
</h2>
</div>
</section>

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="app_chatgpt.Message" t-inherit="mail.Message" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_Message_prettyBody')]//.." position="replace">
<t t-if="!messageView.composerViewInEditing">
<div class="o_Message_prettyBody" t-ref="prettyBody"/><!-- messageView.message.prettyBody is inserted here from _update() -->
<div name="bottom_operation" class="position-relative mt-8">
<div t-if="messageView.message.human_prompt_tokens &gt; 0 or messageView.message.ai_completion_tokens &gt;0"
class="o_Message_token text-muted" style="float:left;display:inline;font-size: 13px;">
<br/>
------------------
<br/>
<span title="提问/答复 消耗Token">
<t t-esc="messageView.message.human_prompt_tokens"/> / <t t-esc="messageView.message.ai_completion_tokens"/>
</span>
</div>
</div>
</t>
</xpath>
</t>
</templates>

View File

@@ -0,0 +1,48 @@
/** @odoo-module **/
import { insert } from '@mail/model/model_field_command';
import { getBundle, loadBundle } from '@web/core/assets';
import { registerPatch } from '@mail/model/model_core';
registerPatch({
name: 'EmojiRegistry',
recordMethods: {
async loadEmojiData() {
this.update({isLoading: true});
await getBundle('mail.assets_model_data').then(loadBundle);
//优化 data 文件
const {emojiCategoriesData, emojisData} = await odoo.runtimeImport("@app_chatgpt/models_data/emoji_data");
if (!this.exists()) {
return;
}
this._populateFromEmojiData(emojiCategoriesData, emojisData);
},
async _populateFromEmojiData(dataCategories, dataEmojis) {
dataCategories.map(category => {
const emojiCount = dataEmojis.reduce((acc, emoji) => emoji.category === category.name ? acc + 1 : acc, 0);
this.update({
dataCategories: insert({
name: category.name,
displayName: category.displayName,
title: category.title,
sortId: category.sortId,
emojiCount,
}),
});
});
this.models['Emoji'].insert(dataEmojis.map(emojiData => ({
codepoints: emojiData.codepoints,
shortcodes: emojiData.shortcodes,
emoticons: emojiData.emoticons,
name: emojiData.name,
keywords: emojiData.keywords,
emojiDataCategory: {name: emojiData.category},
})));
this.update({
isLoaded: true,
isLoading: false,
});
},
},
}
)

View File

@@ -0,0 +1,30 @@
/** @odoo-module **/
import { insert } from '@mail/model/model_field_command';
import { attr, many, one } from '@mail/model/model_field';
import { registerPatch } from '@mail/model/model_core';
registerPatch({
name: 'Message',
modelMethods: {
convertData(data) {
const data2 = this._super(data);
if ('human_prompt_tokens' in data) {
data2.human_prompt_tokens = data.human_prompt_tokens;
}
if ('ai_completion_tokens' in data) {
data2.ai_completion_tokens = data.ai_completion_tokens;
}
if ('is_ai' in data) {
data2.is_ai = data.is_ai;
}
return data2;
},
},
fields: {
human_prompt_tokens: attr(),
ai_completion_tokens: attr(),
is_ai: attr(),
}
})

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="ai_robot_tree_view" model="ir.ui.view">
<field name="name">ai.robot.tree</field>
<field name="model">ai.robot</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="provider" optional="hide"/>
<field name="ai_model" optional="show"/>
<field name="openapi_api_key" password="True"/>
<field name="max_tokens" optional="show"/>
<field name="temperature"/>
<field name="max_send_char"/>
</tree>
</field>
</record>
<record id="ai_robot_kanban_view" model="ir.ui.view">
<field name="name">ai.robot.kanban</field>
<field name="model">ai.robot</field>
<field name="arch" type="xml">
<kanban class="o_ai_robot_kanban">
<field name="id"/>
<field name="name"/>
<field name="provider"/>
<field name="set_ai_model"/>
<field name="ai_model"/>
<field name="partner_count"/>
<field name="image_avatar"/>
<field name="active"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_card oe_kanban_global_click">
<div class="o_kanban_image me-1">
<img t-att-src="kanban_image('ai.robot', 'image_avatar', record.id.raw_value)" alt="Robot Provider" class="o_image_64_contain"/>
</div>
<div class="oe_kanban_details">
<div class="o_kanban_record_top mb-0">
<div class="o_kanban_record_headings">
<strong class="o_kanban_record_title">
<field name="name"/>
</strong>
</div>
</div>
<div class="mt-3">
Model:
<field name="ai_model"/>
</div>
<div class="mt-1">
<strong>
<t t-esc="record.partner_count.value"/>
</strong>
Bind Partner
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
<record id="ai_robot_form_view" model="ir.ui.view">
<field name="name">ai.robot.form</field>
<field name="model">ai.robot</field>
<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')]}"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="%(base.action_res_users)d" icon="fa-users" type="action"
context="{'search_default_gpt_id': id}">
<field name="partner_count" widget="statinfo"/>
</button>
</div>
<field name="image_avatar" widget='image' class="oe_avatar"/>
<div class="oe_title">
<label for="name"/>
<h1>
<field name="name" placeholder="Robot Name" required="1"/>
</h1>
</div>
<group>
<group>
<field name="id" invisible="1"/>
<field name="openapi_api_key" password="True" required="True"/>
<field name="temperature"/>
<field name="top_p"/>
<field name="frequency_penalty"/>
<field name="presence_penalty"/>
<field name="sys_content" placeholder="Role-playing and scene setting.Give the model instructions about how it should behave and any context it should reference when generating a response."/>
<field name="max_send_char"/>
</group>
<group>
<field name="set_ai_model"/>
<field name="ai_model"/>
<label class="o_form_label" for="provider">
OpenAI Document
</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')]}"/>
</div>
<field name="max_tokens"/>
<field name="engine"/>
<field name="endpoint"/>
<field name="api_version"/>
<field name="ai_timeout"/>
<field name="sequence"/>
</group>
<group>
<field name="is_filtering"/>
<field name="sensitive_words" attrs="{'invisible': [('is_filtering', '=', False)]}"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="ai_robot_search_view" model="ir.ui.view">
<field name="name">ai.robot.search</field>
<field name="model">ai.robot</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="ai_model"/>
<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
<group expand="0" name="group_by" string="Group By">
<filter name="groupby_provider" string="Ai Provider" domain="[]" context="{'group_by' : 'provider'}"/>
</group>
</search>
</field>
</record>
<record id="action_ai_robot" model="ir.actions.act_window">
<field name="name">Ai Robot</field>
<field name="res_model">ai.robot</field>
<field name="view_mode">kanban,tree,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Let's create a Ai Robot.
</p>
</field>
</record>
<record id="model_ai_robot_action_disconnect" model="ir.actions.server">
<field name="name">Disconnect</field>
<field name="model_id" ref="app_chatgpt.model_ai_robot"/>
<field name="binding_model_id" ref="app_chatgpt.model_ai_robot"/>
<field name="binding_view_types">kanban,list,form</field>
<field name="state">code</field>
<field name="code">action = records.action_disconnect()</field>
</record>
<menuitem
id="menu_ai_robot"
name="Ai Robot"
parent="base.menu_users"
sequence="2"
action="action_ai_robot"
groups="base.group_system"/>
</odoo>

View File

@@ -0,0 +1,122 @@
<?xml version="1.0"?>
<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"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="ai_partner_id" optional="show"/>
<field name="description" optional="show"/>
<field name="set_max_tokens" optional="hide"/>
</xpath>
</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>
<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 Character Set">
<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>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<odoo>
<data>
<!--list 原生处理-->
<record id="app_view_message_tree" model="ir.ui.view">
<field name="model">mail.message</field>
<field name="name">ai.mail.message.tree</field>
<field name="inherit_id" ref="mail.view_message_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='res_id']" position="after">
<field name="ai2model" optional="hide"/>
<field name="ai2id" optional="hide"/>
</xpath>
</field>
</record>
<!-- form,原生继承以便管理-->
<record id="app_mail_message_view_form" model="ir.ui.view">
<field name="name">ai.mail.message.form</field>
<field name="model">mail.message</field>
<field name="inherit_id" ref="mail.mail_message_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='parent_id']" position="after">
<field name="ai2model" readonly="1"/>
<field name="ai2id" readonly="1"/>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="res_partner_ai_use_tree_view" model="ir.ui.view">
<field name="name">res.partner.ai.use.tree</field>
<field name="model">res.partner.ai.use</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="ai_user_id" optional="show"/>
<field name="first_ask_time" optional="show"/>
<field name="latest_ask_time" optional="show"/>
<field name="service_start_date" optional="show"/>
<field name="service_end_date" optional="show"/>
<field name="used_number" sum="Total" optional="hide"/>
<field name="max_number" sum="Total" optional="hide"/>
<field name="human_prompt_tokens" sum="Total" optional="show"/>
<field name="ai_completion_tokens" sum="Total" optional="show"/>
<field name="tokens_total" sum="Total" optional="show"/>
<field name="token_balance" sum="Total" optional="show"/>
<field name="token_allow" sum="Total" optional="show"/>
</tree>
</field>
</record>
<record id="res_partner_ai_use_form_view" model="ir.ui.view">
<field name="name">res.partner.ai.use.form</field>
<field name="model">res.partner.ai.use</field>
<field name="arch" type="xml">
<form>
<sheet>
<label for="name"/>
<h1>
<field name="name"/>
</h1>
<group>
<group>
<field name="ai_user_id"/>
<field name="first_ask_time"/>
<field name="latest_ask_time"/>
<field name="service_start_date"/>
<field name="service_end_date"/>
<field name="used_number" readonly="True"/>
<field name="max_number" readonly="True"/>
<field name="token_balance" readonly="True"/>
</group>
<group>
<field name="human_prompt_tokens" readonly="True"/>
<field name="ai_completion_tokens" readonly="True"/>
<field name="tokens_total" readonly="True"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="res_partner_ai_use_search_view" model="ir.ui.view">
<field name="name">res.partner.ai.use.search</field>
<field name="model">res.partner.ai.use</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="ai_user_id"/>
</search>
</field>
</record>
<record id="action_res_partner_ai_use" model="ir.actions.act_window">
<field name="name">Partner Ai Use</field>
<field name="res_model">res.partner.ai.use</field>
<field name="view_mode">tree,form</field>
<field name="context">{'create': 0, 'delete': 0}</field>
</record>
<record id="action_res_users_2_partner_ai_use" model="ir.actions.act_window">
<field name="name">Partner Ai Use</field>
<field name="res_model">res.partner.ai.use</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('ai_user_id', 'in', active_ids)]</field>
<field name="context">{'default_ai_user_id':active_id,}</field>
</record>
<menuitem
id="menu_res_partner_ai_use"
name="Partner Ai Use"
parent="base.menu_users"
sequence="3"
action="action_res_partner_ai_use"
groups="base.group_system"/>
</odoo>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="app_chat_res_users_tree_view" model="ir.ui.view">
<field name="name">app.chat.res.users.tree</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='login_date']" position="before">
<field name="is_chat_private" widget="boolean_toggle" optional="show"/>
</xpath>
</field>
</record>
<record id="app_chatgpt_res_users_form" model="ir.ui.view">
<field name="name">app.chatgpt.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="%(app_chatgpt.action_res_users_2_partner_ai_use)d" type="action" string="Partner Ai Use" icon="fa-comments">
</button>
</xpath>
<xpath expr="//page[@name='preferences']" position="after">
<page name="page_chatgpt" string="ChatGPT">
<group>
<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_demo_time"/>
<field name="is_chat_private"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
<!-- search-->
<record id="app_view_users_search" model="ir.ui.view">
<field name="name">app.res.users.search</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_search"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="gpt_id"/>
</xpath>
<xpath expr="//filter[@name='filter_no_share']" position="before">
<filter name="is_robot" string="Ai User" domain="[('gpt_id','!=',False)]"/>
<filter name="not_robot" string="Not Ai" domain="[('gpt_id','=',False)]"/>
<separator/>
</xpath>
</field>
</record>
</odoo>

View File

@@ -38,8 +38,8 @@
############################################################################## ##############################################################################
{ {
'name': "odooai Odooapp Common Func", 'name': "odooAi Common Util and Tools",
'version': '16.5.23.09.27', 'version': '17.23.10.30',
'author': 'odooai.cn', 'author': 'odooai.cn',
'category': 'Base', 'category': 'Base',
'website': 'https://www.odooai.cn', 'website': 'https://www.odooai.cn',
@@ -50,18 +50,25 @@
'currency': 'EUR', 'currency': 'EUR',
'images': ['static/description/banner.png'], 'images': ['static/description/banner.png'],
'summary': ''' 'summary': '''
Core for common use odooai apps. Core for common use for odooai.cn apps.
基础核心必须没有要被依赖字段及视图等实现auto_install 基础核心必须没有要被依赖字段及视图等实现auto_install
''', ''',
'description': ''' 'description': '''
Support Odoo 16, Enterprise and Community Edition
need to setup odoo.conf, add follow: need to setup odoo.conf, add follow:
server_wide_modules = web,app_common server_wide_modules = web,app_common
1. 1. Quick import data from excel with .py code
2. 2. Quick m2o default value
3. Multi-language Support. 3. Filter for useless field
4. Multi-Company Support. 4. UTC local timezone convert
5. Support Odoo 16, Enterprise and Community Edition 5. Get browser ua, user-agent
6. Image to local, image url to local, media to local attachment
7. Log cron job
8. Boost for less no use mail
9. Customize .rng file
10. Misc like get distance between two points
11. Multi-language Support. Multi-Company Support
12. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
13. Full Open Source.
========== ==========
1. 1.
2. 2.
@@ -84,6 +91,8 @@
# 'pre_init_hook': 'pre_init_hook', # 'pre_init_hook': 'pre_init_hook',
# 'post_init_hook': 'post_init_hook', # 'post_init_hook': 'post_init_hook',
# 'uninstall_hook': 'uninstall_hook', # 'uninstall_hook': 'uninstall_hook',
# 可以不需要,因为直接放 common中了
# 'external_dependencies': {'python': ['pyyaml', 'ua-parser', 'user-agents']},
'installable': True, 'installable': True,
'application': True, 'application': True,
'auto_install': True, 'auto_install': True,

View File

@@ -6,6 +6,7 @@ from odoo.http import request
import requests import requests
import base64 import base64
from io import BytesIO from io import BytesIO
import uuid
from datetime import date, datetime, time from datetime import date, datetime, time
import pytz import pytz
@@ -104,9 +105,35 @@ class Base(models.AbstractModel):
# 返回这个图片的base64编码 # 返回这个图片的base64编码
return get_image_from_url(url) return get_image_from_url(url)
@api.model
def get_image_url2attachment(self, url, mimetype_list=None):
# Todo: mimetype filter
image, file_name = get_image_url2attachment(url)
if image and file_name:
attachment = self.env['ir.attachment'].create({
'datas': image,
'name': file_name,
})
return attachment
else:
return False
@api.model
def get_image_base642attachment(self, data):
image, file_name = get_image_base642attachment(data)
if image and file_name:
attachment = self.env['ir.attachment'].create({
'datas': image,
'name': file_name,
})
return attachment
else:
return False
def get_ua_type(self): def get_ua_type(self):
return get_ua_type() return get_ua_type()
def get_image_from_url(url): def get_image_from_url(url):
if not url: if not url:
return None return None
@@ -117,6 +144,33 @@ def get_image_from_url(url):
# 返回这个图片的base64编码 # 返回这个图片的base64编码
return base64.b64encode(BytesIO(response.content).read()) return base64.b64encode(BytesIO(response.content).read())
def get_image_url2attachment(url):
if not url:
return None
try:
if url.startswith('//'):
url = 'https:%s' % url
response = requests.get(url, timeout=30)
except Exception as e:
return None, None
# 返回这个图片的base64编码
image = base64.b64encode(BytesIO(response.content).read())
file_name = url.split('/')[-1]
return image, file_name
def get_image_base642attachment(data):
if not data:
return None
try:
image_data = data.split(',')[1]
file_name = str(uuid.uuid4()) + '.png'
return image_data, file_name
except Exception as e:
return None, None
def get_ua_type(): def get_ua_type():
ua = request.httprequest.headers.get('User-Agent') ua = request.httprequest.headers.get('User-Agent')
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来 # 临时用 agent 处理,后续要前端中正确处理或者都从后台来

View File

@@ -18,6 +18,7 @@ class IrMailServer(models.Model):
email_to = message['To'] email_to = message['To']
# 忽略掉无效email避免被ban # 忽略掉无效email避免被ban
if email_to:
if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1: if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1:
pass pass
elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1: elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1:

View File

@@ -23,7 +23,7 @@ def app_relaxng(view_type):
relaxng_doc = etree.parse(frng) relaxng_doc = etree.parse(frng)
_relaxng_cache[view_type] = etree.RelaxNG(relaxng_doc) _relaxng_cache[view_type] = etree.RelaxNG(relaxng_doc)
except Exception: except Exception:
_logger.error('Failed to load RelaxNG XML schema for views validation') _logger.error('You can Ignore this. Failed to load RelaxNG XML schema for views validation')
_relaxng_cache[view_type] = None _relaxng_cache[view_type] = None
return _relaxng_cache[view_type] return _relaxng_cache[view_type]

View File

@@ -11,6 +11,14 @@ class MailMail(models.Model):
# 猴子补丁模式,改默认发邮件逻辑 # 猴子补丁模式,改默认发邮件逻辑
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None): def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
for m in self: for m in self:
if m.email_to and (m.email_to.find('example.com') != -1 or m.email_to.find('@odooai.cn') != -1 or m.email_to.find('@odooapp.cn') != -1): email_to = m.email_to
# 忽略掉无效email避免被ban
if email_to:
if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1:
pass
elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1:
_logger.error(_("=================Email to ignore: %s") % email_to)
self = self - m self = self - m
if not self:
return True
return super(MailMail, self)._send(auto_commit, raise_exception, smtp_session) return super(MailMail, self)._send(auto_commit, raise_exception, smtp_session)

View File

@@ -10,4 +10,7 @@ class ResPartner(models.Model):
def get_related_user_id(self): def get_related_user_id(self):
self.ensure_one() self.ensure_one()
user = self.env['res.users'].sudo().with_context(active_test=False).search([('partner_id', '=', self.id)], limit=1) user = self.env['res.users'].sudo().with_context(active_test=False).search([('partner_id', '=', self.id)], limit=1)
if not user and self.commercial_partner_id:
user = self.env['res.users'].sudo().with_context(active_test=False).search([('partner_id', '=', self.commercial_partner_id.id)],
limit=1)
return user return user

View File

@@ -1,10 +1,10 @@
<section class="oe_container container"> <section class="oe_container container">
<div class="oe_row oe_spaced" > <div class="oe_row oe_spaced" >
<div class="row"> <div class="row">
<h2 class="oe_slogan"> </h2> <h2 class="oe_slogan">odooAi Common Util and Tools</h2>
<h3 class="oe_slogan"> </h3> <h3 class="oe_slogan"> Network and media and base tools </h3>
<div class="oe_row"> <div class="oe_row">
<h3>Lastest update: v16.22.02.02</h3> <h3>Lastest update: v17.23.11.06</h3>
<div class="row"> <div class="row">
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png"> <img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
</div> </div>
@@ -14,19 +14,59 @@
<ul class="list-unstyled"> <ul class="list-unstyled">
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>
Put key function here. 1. Quick import data from excel with .py code
</li> </li>
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>
3. Multi-language Support. 2. Quick m2o default value
</li> </li>
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>
4. Multi-Company Support. 3. Filter for useless field
</li> </li>
<li> <li>
<i class="fa fa-check-square-o text-primary"></i> <i class="fa fa-check-square-o text-primary"></i>
5. Support Odoo 16, 15, 14, 13, 12, 11, Enterprise and Community Edition. 4. UTC local timezone convert
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
5. Get browser ua, user-agent
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
6. Image to local, image url to local, media to local attachment
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
7. Log cron job
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
8. Boost for less no use mail
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
9. Customize .rng file
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
10. Misc like get distance between two points
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
11. Multi-language Support. Multi-Company Support
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
12. Support Odoo 17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
11. Multi-language Support. Multi-Company Support
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
13. Full Open Source.
</li> </li>
</ul> </ul>
</div> </div>
@@ -40,33 +80,11 @@
<div class="oe_row oe_spaced"> <div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">Setup, please run the follow command to install the lib.</h2> <h2 class="bg-warning text-center pt8 pb8">Setup, please run the follow command to install the lib.</h2>
<h4 class="oe_slogan"> pip install pyyaml ua-parser user-agents </h4> <h4 class="oe_slogan"> pip install pyyaml ua-parser user-agents </h4>
<div class="oe_demo oe_screenshot img img-fluid"> <h4 class="oe_slogan"> After that, install the app_common </h4>
<img src=".jpg"/>
</div>
</div> </div>
</section> </section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">So Easy to navigator and search any data.</h2>
<h4 class="oe_slogan"> </h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src=".jpg"/>
</div>
</div>
</section>
<section class="oe_container container">
<div class="oe_row oe_spaced">
<h2 class="bg-warning text-center pt8 pb8">Multi-language Support..</h2>
<h4 class="oe_slogan"> </h4>
<div class="oe_demo oe_screenshot img img-fluid">
<img src="cnreadme.jpg"/>
</div>
</div>
</section>
<section class="container oe_dark"> <section class="container oe_dark">
<div class="oe_row oe_spaced text-center"> <div class="oe_row oe_spaced text-center">
<div class="row"> <div class="row">
@@ -77,9 +95,9 @@
<p><h4> <p><h4>
For any type of technical help & support requests, Feel free to contact us</h4></p> For any type of technical help & support requests, Feel free to contact us</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:guohuadeng@hotmail.com"><span class="btn btn-warning btn-lg" rel="nofollow" href="mailto:odoo@china.com"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span> style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-envelope"></i> guohuadeng@hotmail.com</a> <i class="fa fa-envelope"></i> odoo@china.com</a>
<p><h4> <p><h4>
Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p> Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"

View File

@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0"?>
<odoo> <odoo>
<!-- todo: 不知道哪进有出错了-->
<record id="app_ir_cron_view_tree" model="ir.ui.view"> <record id="app_ir_cron_view_tree" model="ir.ui.view">
<field name="name">app.ir.cron.tree</field> <field name="name">app.ir.cron.tree</field>
<field name="model">ir.cron</field> <field name="model">ir.cron</field>
<field name="mode">extension</field>
<field name="inherit_id" ref="base.ir_cron_view_tree"/> <field name="inherit_id" ref="base.ir_cron_view_tree"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='active']" position="before"> <xpath expr="//field[@name='active']" position="before">

View File

@@ -92,7 +92,7 @@
App Customize Odoo (Change Title,Language,Documentation,Quick Debug) App Customize Odoo (Change Title,Language,Documentation,Quick Debug)
============ ============
White label odoo. White label odoo.
Support odoo 16,15,14,13,12,11,10,9. Support Odoo 17,16,15,14,13,12,11,10,9.
You can config odoo, make it look like your own platform. You can config odoo, make it look like your own platform.
1. Deletes Odoo label in footer 1. Deletes Odoo label in footer
2. Replaces "Odoo" in Windows title 2. Replaces "Odoo" in Windows title

Binary file not shown.

Before

Width:  |  Height:  |  Size: 502 KiB

After

Width:  |  Height:  |  Size: 546 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

@@ -7,33 +7,31 @@
--> -->
<html> <html>
<!-- Modules Title and brief --> <!-- Modules Title and brief -->
<section class="container app">
<div class="oe_row oe_spaced" style="max-width: 95%;"> <!-- begin title-->
<div class="row"> <section class="oe_container container o_cc o_cc2">
<h2 class="oe_slogan">odoo Tweak,Ai Employee,Boost,Customize All in One. OEM,UI,Boost,Security,Data,Development Enhance</h2> <h1 class="text-center bg-warning text-white pt24 pb24">odoo 17 Tweak,Ai Employee,Boost,Customize All in One. </h1>
<h4 class="mt8"> <h3 class="text-center">Customize,UI,Boost,Security,Data,Development Enhance</h3>
You can follow this repo on github. To get the latest update of free odoo app. <h4 class="text-center pt40 text-danger">For Odoo17. Please get from the follow github. Done for 85%.</h4>
<p>https://github.com/guohuadeng/app-odoo</p> <p class="bg-primary"> https://github.com/guohuadeng/app-odoo/tree/17.0 </p>
</h4>
</div>
</div>
</section> </section>
<section class="container app"> <section class="container app">
<div class="oe_row oe_spaced" style="max-width: 95%;"> <div class="oe_row oe_spaced" style="max-width: 95%;">
<div class="row"> <div class="row">
<h2 class="oe_slogan">This is a Long Term Support Apps.Update: v16.5.23.09.13</h2> <h2 class="oe_slogan">This is a Long Term Support Apps.Update: v16.5.23.09.30</h2>
<div class="oe_demo" style=" margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;"> <div class="oe_demo" style=" margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;">
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item">1. Deletes Odoo label in footer</li> <li class="list-group-item">1. Deletes Odoo label in footer</li>
<li class="list-group-item">2. 【todo】Replaces "Odoo" in Windows title</li> <li class="list-group-item">2. Replaces "Odoo" in Windows title</li>
<li class="list-group-item">3. 【todo】Customize Documentation, Support, About links and title in usermenu</li> <li class="list-group-item">3. Customize Documentation, Support, About links and title in usermenu</li>
<li class="list-group-item">4. 【todo】Adds "Developer mode" link to the top right-hand User Menu.</li> <li class="list-group-item">4. Adds "Developer mode" link to the top right-hand User Menu.</li>
<li class="list-group-item">5. 【todo】Adds Quick Language Switcher to the top right-hand User Menu.</li> <li class="list-group-item">5. Adds Quick Language Switcher to the top right-hand User Menu.</li>
<li class="list-group-item">6. 【todo】Adds Country flags to the top right-hand User Menu.</li> <li class="list-group-item">6. Adds Country flags to the top right-hand User Menu.</li>
<li class="list-group-item">7. 【todo】Adds English and Chinese user documentation access to the top right-hand User Menu.</li> <li class="list-group-item">7. Adds English and Chinese user documentation access to the top right-hand User Menu.</li>
<li class="list-group-item">8. 【todo】Adds developer documentation access to the top right-hand User Menu.</li> <li class="list-group-item">8. Adds developer documentation access to the top right-hand User Menu.</li>
<li class="list-group-item">9. 【todo】Customize "My odoo.com account" button</li> <li class="list-group-item">9. Customize "My odoo.com account" button</li>
<li class="list-group-item">10. Standalone setting panel, easy to setup.</li> <li class="list-group-item">10. Standalone setting panel, easy to setup.</li>
<li class="list-group-item">11. Provide 236 country flags.</li> <li class="list-group-item">11. Provide 236 country flags.</li>
<li class="list-group-item">12. Multi-language Support.</li> <li class="list-group-item">12. Multi-language Support.</li>
@@ -301,8 +299,6 @@
<div class="row"> <div class="row">
<h2 class="oe_slogan">This is a Long Term Support Apps.</h2> <h2 class="oe_slogan">This is a Long Term Support Apps.</h2>
<div class="oe_demo" style=" margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;"> <div class="oe_demo" style=" margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;">
<h3>Update: v17.23.11.06</h3>
<p>Release to odoo 17. Fix project data clean.</p>
<h3>Update: v16.23.09.13</h3> <h3>Update: v16.23.09.13</h3>
<p>UI enhance. follow odoo16 setup UI.</p> <p>UI enhance. follow odoo16 setup UI.</p>
<p>46. Add Help documentation anywhere. easy get help for any odoo operation or action.</p> <p>46. Add Help documentation anywhere. easy get help for any odoo operation or action.</p>
@@ -644,9 +640,9 @@
<p><h4> <p><h4>
For any type of technical help & support requests, Feel free to contact us</h4></p> For any type of technical help & support requests, Feel free to contact us</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:guohuadeng@hotmail.com"><span class="btn btn-warning btn-lg" rel="nofollow" href="mailto:odoo@china.com"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span> style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-envelope"></i> guohuadeng@hotmail.com</a> <i class="fa fa-envelope"></i> odoo@china.com</a>
<p><h4> <p><h4>
Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p> Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"

View File

@@ -393,9 +393,9 @@
<p><h4> <p><h4>
For any type of technical help & support requests, Feel free to contact us</h4></p> For any type of technical help & support requests, Feel free to contact us</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:guohuadeng@hotmail.com"><span class="btn btn-warning btn-lg" rel="nofollow" href="mailto:odoo@china.com"><span
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span> style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
<i class="fa fa-envelope"></i> guohuadeng@hotmail.com</a> <i class="fa fa-envelope"></i> odoo@china.com</a>
<p><h4> <p><h4>
Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p> Via QQ: 300883 (App user would not get QQ or any other IM support. Only for odoo project customize.)</h4></p>
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;" <a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"