add timeout

This commit is contained in:
ivan deng
2023-04-13 01:15:22 +08:00
parent fbc2453f8f
commit d344bd6499
4 changed files with 33 additions and 4 deletions

View File

@@ -1,23 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<odoo> <odoo noupdate="1">
<record id="chatgpt_robot" model="ai.robot"> <record id="chatgpt_robot" model="ai.robot">
<field name="name">ChatGPT odoo</field> <field name="name">ChatGPT odoo</field>
<field name="provider">openai</field> <field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">1</field> <field name="sequence">1</field>
</record> </record>
<record id="chatgpt_robot1" model="ai.robot"> <record id="chatgpt_robot1" model="ai.robot">
<field name="name">ChatGPT Coding</field> <field name="name">ChatGPT Coding</field>
<field name="provider">openai</field> <field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">6</field> <field name="sequence">6</field>
</record> </record>
<record id="chatgpt_robot2" model="ai.robot"> <record id="chatgpt_robot2" model="ai.robot">
<field name="name">ChatGPT Finance</field> <field name="name">ChatGPT Finance</field>
<field name="provider">openai</field> <field name="provider">openai</field>
<field name="endpoint">https://api.openai.com/v1/chat/completions</field>
<field name="sequence">7</field> <field name="sequence">7</field>
</record> </record>
<record id="chatgpt_robot3" model="ai.robot"> <record id="chatgpt_robot3" model="ai.robot">
<field name="name">ChatGPT Azure</field> <field name="name">ChatGPT Azure</field>
<field name="provider">azure</field> <field name="provider">azure</field>
<field name="endpoint">https://my.openai.azure.com</field>
<field name="engine">gpt35</field>
<field name="sequence">8</field> <field name="sequence">8</field>
</record> </record>
<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="sequence">9</field>
</record>
</odoo> </odoo>

View File

@@ -62,5 +62,20 @@
<field name="company_ids" eval="[Command.link(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'))]"/> <field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
</record> </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/chatgpt.png"/>
</record>
<record id="user_chatgpt4_azure" model="res.users">
<field name="login">chatgpt4@sunpop.cn</field>
<field name="email">chatgpt4@sunpop.cn</field>
<field name="password">chatgpt</field>
<field name="partner_id" ref="app_chatgpt.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>
</data> </data>
</odoo> </odoo>

View File

@@ -42,6 +42,7 @@ GPT-3 A set of models that can understand and generate natural language
endpoint = fields.Char('End Point', default='https://api.openai.com/v1/chat/completions') 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.') engine = fields.Char('Engine', help='If use Azure, Please input the Model deployment name.')
api_version = fields.Char('API Version', default='2022-12-01') 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) 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.') 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') is_filtering = fields.Boolean('Filter Sensitive Words', default=False, help='Use base Filter in dir models/lib/sensi_words.txt')
@@ -77,7 +78,7 @@ GPT-3 A set of models that can understand and generate natural language
def get_ai_model_info(self): def get_ai_model_info(self):
self.ensure_one() self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"} headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = 300 R_TIMEOUT = self.ai_timeout or 120
o_url = "https://api.openai.com/v1/models/%s" % self.ai_model o_url = "https://api.openai.com/v1/models/%s" % self.ai_model
if self.endpoint: if self.endpoint:
o_url = self.endpoint.replace("/chat/completions", "") + "/models/%s" % self.ai_model o_url = self.endpoint.replace("/chat/completions", "") + "/models/%s" % self.ai_model
@@ -94,7 +95,7 @@ GPT-3 A set of models that can understand and generate natural language
def get_ai_list_model(self): def get_ai_list_model(self):
self.ensure_one() self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"} headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = 300 R_TIMEOUT = self.ai_timeout or 120
o_url = "https://api.openai.com/v1/models" o_url = "https://api.openai.com/v1/models"
if self.endpoint: if self.endpoint:
o_url = self.endpoint.replace("/chat/completions", "") + "/models" o_url = self.endpoint.replace("/chat/completions", "") + "/models"
@@ -110,7 +111,7 @@ GPT-3 A set of models that can understand and generate natural language
def get_openai(self, data, partner_name='odoo', *args): def get_openai(self, data, partner_name='odoo', *args):
self.ensure_one() self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"} headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = 300 R_TIMEOUT = self.ai_timeout or 120
o_url = self.endpoint or "https://api.openai.com/v1/chat/completions" o_url = self.endpoint or "https://api.openai.com/v1/chat/completions"
# 以下处理 open ai # 以下处理 open ai

View File

@@ -46,6 +46,7 @@
<field name="engine"/> <field name="engine"/>
<field name="endpoint"/> <field name="endpoint"/>
<field name="api_version"/> <field name="api_version"/>
<field name="ai_timeout"/>
</group> </group>
<group> <group>
<field name="is_filtering"/> <field name="is_filtering"/>