update app_chargpt azure config

This commit is contained in:
Chill
2023-03-17 15:34:24 +08:00
parent 96864484f6
commit c6c8e47c7e
2 changed files with 14 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
import requests import requests
import openai import openai
from odoo import api, fields, models, _ from odoo import api, fields, models, _
from odoo.exceptions import UserError
class AiRobot(models.Model): class AiRobot(models.Model):
@@ -34,6 +35,9 @@ 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") openapi_api_key = fields.Char(string="API Key", help="Provide the API key here")
temperature = fields.Float(string='Temperature', default=0.9) temperature = fields.Float(string='Temperature', default=0.9)
max_length = fields.Integer('Max Length', default=100) max_length = fields.Integer('Max Length', default=100)
endpoint = fields.Char('End Point')
engine = fields.Char('Engine', default='odooapp')
api_version = fields.Char('API Version', default='2022-12-01')
sequence = fields.Integer('Sequence', help="Determine the display order", default=10) sequence = fields.Integer('Sequence', help="Determine the display order", default=10)
def action_disconnect(self): def action_disconnect(self):
@@ -41,10 +45,14 @@ GPT-3 A set of models that can understand and generate natural language
def get_openai(self, data): def get_openai(self, data):
openai.api_type = self.provider openai.api_type = self.provider
openai.api_base = "https://odooapp.openai.azure.com/" if not self.endpoint:
openai.api_version = "2022-12-01" 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 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, response = openai.Completion.create(engine=self.engine, prompt=data, temperature=self.temperature, max_tokens=self.max_length, top_p=0.5, frequency_penalty=0,
presence_penalty=0, stop=["Human:", "AI:"]) presence_penalty=0, stop=["Human:", "AI:"])
if 'choices' in response: if 'choices' in response:
res = response['choices'][0]['text'].replace(' .', '.').strip() res = response['choices'][0]['text'].replace(' .', '.').strip()

View File

@@ -39,6 +39,9 @@
<a href="https://platform.openai.com/docs/introduction" title="OpenAI Document" class="o_doc_link" target="_blank"></a> <a href="https://platform.openai.com/docs/introduction" title="OpenAI Document" class="o_doc_link" target="_blank"></a>
</div> </div>
<field name="max_length"/> <field name="max_length"/>
<field name="engine"/>
<field name="endpoint"/>
<field name="api_version"/>
</group> </group>
</group> </group>
</sheet> </sheet>