mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
chatgpt增加azure支持
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
{
|
||||
'name': 'Latest ChatGPT AI Center. GPT 3.5 Turbo, Dall-E Image.Multi Robot Support. Chat and Training',
|
||||
'version': '16.23.03.05',
|
||||
'version': '16.23.03.16',
|
||||
'author': 'Sunpop.cn',
|
||||
'company': 'Sunpop.cn',
|
||||
'maintainer': 'Sunpop.cn',
|
||||
@@ -21,7 +21,7 @@
|
||||
'license': 'AGPL-3',
|
||||
'images': ['static/description/banner.gif'],
|
||||
'summary': '''
|
||||
ChatGpt Odoo AI Center. Multi Odoo ChatGPT Robot. Support chatgpt 3.5 turbo, text-davinci, DALL·E, Integration All ChatGpt Api.
|
||||
ChatGpt Odoo AI Center. Multi Odoo ChatGPT Robot. Support chatgpt 3.5 turbo, text-davinci, DALL·E, Integration All ChatGpt Api and Azure OpenAI Service.
|
||||
Easy Chat channel with several ChatGPT Robots and train.
|
||||
Whitelist and blacklist for Users or IP.
|
||||
''',
|
||||
@@ -36,6 +36,7 @@
|
||||
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. Connect the Azure OpenAI Service.
|
||||
11. Multi-language Support. Multi-Company Support.
|
||||
12. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
|
||||
13. Full Open Source.
|
||||
|
||||
@@ -2,14 +2,22 @@
|
||||
<odoo>
|
||||
<record id="chatgpt_robot" model="ai.robot">
|
||||
<field name="name">ChatGPT odoo</field>
|
||||
<field name="provider">openai</field>
|
||||
<field name="sequence">1</field>
|
||||
</record>
|
||||
<record id="chatgpt_robot1" model="ai.robot">
|
||||
<field name="name">ChatGPT Coding</field>
|
||||
<field name="provider">openai</field>
|
||||
<field name="sequence">6</field>
|
||||
</record>
|
||||
<record id="chatgpt_robot2" model="ai.robot">
|
||||
<field name="name">ChatGPT Finance</field>
|
||||
<field name="provider">openai</field>
|
||||
<field name="sequence">7</field>
|
||||
</record>
|
||||
<record id="chatgpt_robot3" model="ai.robot">
|
||||
<field name="name">ChatGPT Azure</field>
|
||||
<field name="provider">azure</field>
|
||||
<field name="sequence">8</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -46,5 +46,21 @@
|
||||
<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" model="res.partner">
|
||||
<field name="name">ChatGPT Azure</field>
|
||||
<field name="image_1920" type="base64" file="app_chatgpt/static/description/chatgpt.png"/>
|
||||
</record>
|
||||
|
||||
<record id="user_chatgpt3" model="res.users">
|
||||
<field name="login">chatgpt3@sunpop.cn</field>
|
||||
<field name="email">chatgpt3@sunpop.cn</field>
|
||||
<field name="password">chatgpt</field>
|
||||
<field name="partner_id" ref="app_chatgpt.partner_chatgpt3"/>
|
||||
<field name="gpt_id" ref="app_chatgpt.chatgpt_robot3"/>
|
||||
<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>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import requests
|
||||
import openai
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
@@ -10,7 +11,7 @@ class AiRobot(models.Model):
|
||||
_order = 'sequence, name'
|
||||
|
||||
name = fields.Char(string='Name', translate=True)
|
||||
provider = fields.Selection(string="AI Provider", selection=[('openai', 'OpenAI')], required=True, default='openai')
|
||||
provider = fields.Selection(string="AI Provider", selection=[('openai', 'OpenAI'), ('azure', 'Azure')], required=True, default='openai')
|
||||
ai_model = fields.Selection(string="AI Model", selection=[
|
||||
('gpt-4', 'Chatgpt 4'),
|
||||
('gpt-3.5-turbo', 'Chatgpt 3.5 Turbo'),
|
||||
@@ -31,10 +32,19 @@ 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")
|
||||
temperature = fields.Float(string='Temperature', default=0.9)
|
||||
|
||||
|
||||
max_length = fields.Integer('Max Length', default=100)
|
||||
sequence = fields.Integer('Sequence', help="Determine the display order", default=10)
|
||||
|
||||
def action_disconnect(self):
|
||||
requests.delete('https://chatgpt.com/v1/disconnect')
|
||||
|
||||
def get_openai(self, data):
|
||||
openai.api_type = self.provider
|
||||
openai.api_base = "https://odooapp.openai.azure.com/"
|
||||
openai.api_version = "2022-12-01"
|
||||
openai.api_key = self.openapi_api_key
|
||||
response = openai.Completion.create(engine='odooapp', prompt=data, temperature=self.temperature, max_tokens=self.max_length, top_p=0.5, frequency_penalty=0,
|
||||
presence_penalty=0, stop=["Human:", "AI:"])
|
||||
if 'choices' in response:
|
||||
res = response['choices'][0]['text'].replace(' .', '.').strip()
|
||||
return res
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import openai
|
||||
import requests,json
|
||||
import datetime
|
||||
@@ -15,7 +14,7 @@ class Channel(models.Model):
|
||||
_inherit = 'mail.channel'
|
||||
|
||||
@api.model
|
||||
def get_openai(self, api_key, ai_model, data, user="Odoo"):
|
||||
def get_openai(self, gpt_id, provider, api_key, ai_model, data, user="Odoo"):
|
||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}
|
||||
R_TIMEOUT = 5
|
||||
|
||||
@@ -41,12 +40,16 @@ class Channel(models.Model):
|
||||
"user": user,
|
||||
"stop": ["Human:", "AI:"]
|
||||
}
|
||||
response = requests.post("https://api.openai.com/v1/chat/completions", data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
|
||||
res = response.json()
|
||||
if 'choices' in res:
|
||||
# for rec in res:
|
||||
# res = rec['message']['content']
|
||||
res = '\n'.join([x['message']['content'] for x in res['choices']])
|
||||
if provider == 'openai':
|
||||
response = requests.post("https://api.openai.com/v1/chat/completions", data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
|
||||
res = response.json()
|
||||
if 'choices' in res:
|
||||
# for rec in res:
|
||||
# res = rec['message']['content']
|
||||
res = '\n'.join([x['message']['content'] for x in res['choices']])
|
||||
return res
|
||||
elif provider == 'azure':
|
||||
res = gpt_id.get_openai(data)
|
||||
return res
|
||||
else:
|
||||
pdata = {
|
||||
@@ -60,10 +63,14 @@ class Channel(models.Model):
|
||||
"user": user,
|
||||
"stop": ["Human:", "AI:"]
|
||||
}
|
||||
response = requests.post("https://api.openai.com/v1/completions", data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
|
||||
res = response.json()
|
||||
if 'choices' in res:
|
||||
res = '\n'.join([x['text'] for x in res['choices']])
|
||||
if provider == 'openai':
|
||||
response = requests.post("https://api.openai.com/v1/completions", data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
|
||||
res = response.json()
|
||||
if 'choices' in res:
|
||||
res = '\n'.join([x['text'] for x in res['choices']])
|
||||
return res
|
||||
elif provider == 'azure':
|
||||
res = gpt_id.get_openai(data)
|
||||
return res
|
||||
# 获取模型信息
|
||||
# list_model = requests.get("https://api.openai.com/v1/models", headers=headers)
|
||||
@@ -178,6 +185,7 @@ class Channel(models.Model):
|
||||
# print(msg_vals.get('record_name', ''))
|
||||
# print('self.channel_type :',self.channel_type)
|
||||
if gpt_id:
|
||||
provider = gpt_id.provider
|
||||
ai_model = gpt_id.ai_model or 'text-davinci-003'
|
||||
# print('chatgpt_name:', chatgpt_name)
|
||||
# if author_id != to_partner_id.id and (chatgpt_name in msg_vals.get('record_name', '') or 'ChatGPT' in msg_vals.get('record_name', '') ) and self.channel_type == 'chat':
|
||||
@@ -189,7 +197,7 @@ class Channel(models.Model):
|
||||
prompt = self.get_openai_context(channel.id, to_partner_id.id, prompt, openapi_context_timeout)
|
||||
print(prompt)
|
||||
# res = self.get_chatgpt_answer(prompt,partner_name)
|
||||
res = self.get_openai(api_key, ai_model, prompt, partner_name)
|
||||
res = self.get_openai(gpt_id, provider, api_key, ai_model, prompt, partner_name)
|
||||
res = res.replace('\n', '<br/>')
|
||||
# print('res:',res)
|
||||
# print('channel:',channel)
|
||||
@@ -211,7 +219,7 @@ class Channel(models.Model):
|
||||
prompt = self.get_openai_context(chatgpt_channel_id.id, to_partner_id.id, prompt, openapi_context_timeout)
|
||||
# print(prompt)
|
||||
# res = self.get_chatgpt_answer(prompt, partner_name)
|
||||
res = self.get_openai(api_key, ai_model, prompt, partner_name)
|
||||
res = self.get_openai(gpt_id, provider, api_key, ai_model, prompt, partner_name)
|
||||
res = res.replace('\n', '<br/>')
|
||||
chatgpt_channel_id.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment',parent_id=message.id)
|
||||
except Exception as e:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<h2 class="oe_slogan"> Latest ChatGPT AI Center. GPT 3.5, Dall-E Image.Multi Robot Support. Chat and Training </h2>
|
||||
<h3 class="oe_slogan"> Support chatgpt 3.5 turbo, text-davinci, DALL·E(Working Now.), Integration All ChatGpt Api </h3>
|
||||
<div class="oe_row">
|
||||
<h3>Lastest update: v16.23.03.05</h3>
|
||||
<h3>Lastest update: v16.23.03.16</h3>
|
||||
<div class="oe_span12">
|
||||
<img class="oe_demo oe_screenshot" style="max-height: 100%;" src="banner.gif">
|
||||
</div>
|
||||
@@ -40,6 +40,10 @@
|
||||
<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. Connect the Azure OpenAI Service.
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<i class="fa fa-check-square-o text-primary"></i>
|
||||
@@ -191,7 +195,7 @@
|
||||
</div>
|
||||
<div class="oe_row oe_spaced text-center">
|
||||
<h1>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=Sunpop.cn">Supop.cn Odoo Addons</a>
|
||||
<a class="btn btn-primary mb16" href="http://www.odoo.com/apps/modules/browse?author=Sunpop.cn">Sunpop.cn Odoo Addons</a>
|
||||
</h1>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<field name="provider" optional="hide"/>
|
||||
<field name="ai_model" optional="show"/>
|
||||
<field name="openapi_api_key" password="True"/>
|
||||
<field name="max_length" optional="show"/>
|
||||
<field name="temperature"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -37,6 +38,7 @@
|
||||
<field name="provider"/>
|
||||
<a href="https://platform.openai.com/docs/introduction" title="OpenAI Document" class="o_doc_link" target="_blank"></a>
|
||||
</div>
|
||||
<field name="max_length"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
|
||||
Reference in New Issue
Block a user