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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user