This commit is contained in:
ivan deng
2023-04-11 20:55:04 +08:00
parent 45bfdd0bd1
commit afdbe31a80
6 changed files with 201 additions and 257 deletions

View File

@@ -1795,7 +1795,7 @@ msgstr ""
#. module: app_chatgpt
#: model:ir.model.fields,field_description:app_chatgpt.field_res_config_settings__openai_sync_config
msgid "Sync Config"
msgstr "同步配置"
msgstr "响应模式"
#. module: app_chatgpt
#: model:ir.model.fields.selection,name:app_chatgpt.selection__res_config_settings__openai_sync_config__sync

View File

@@ -57,6 +57,39 @@ GPT-3 A set of models that can understand and generate natural language
else:
return _('No robot provider found')
def get_ai_model_info(self):
self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
R_TIMEOUT = 300
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 = 300
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, partner_name='odoo', *args):
self.ensure_one()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.openapi_api_key}"}
@@ -130,20 +163,27 @@ GPT-3 A set of models that can understand and generate natural language
raise UserError(_("Please Set your AI robot's API Version first."))
openai.api_version = self.api_version
openai.api_key = self.openapi_api_key
response = openai.Completion.create(
engine=self.engine,
prompt=data,
temperature=self.temperature or 0.9,
max_tokens=self.max_length or 600,
top_p=0.5,
frequency_penalty=0,
presence_penalty=0, stop=["Human:", "AI:"])
pdata = {
"engine": self.engine,
"prompt": data,
"temperature": self.temperature or 0.9,
"max_tokens": self.max_length or 600,
"top_p": 0.5,
"frequency_penalty": 0,
"presence_penalty": 0,
"stop": ["Human:", "AI:"],
}
_logger.warning('=====================azure input data: %s' % pdata)
response = openai.Completion.create(pdata)
_logger.warning('=====================azure input data: %s' % data)
if 'choices' in response:
res = response['choices'][0]['text'].replace(' .', '.').strip()
res = self.filter_sensitive_words(res)
return res
else:
_logger.warning('=====================azure output data: %s' % response)
return _('Azure no response')
@api.onchange('provider')
def _onchange_provider(self):
@@ -156,8 +196,9 @@ GPT-3 A set of models that can understand and generate natural language
if self.is_filtering:
search = WordsSearch()
s = self.sensitive_words
if s:
search.SetKeywords(s.split('\n'))
result = search.Replace(text=data)
return result
data = search.Replace(text=data)
return data
else:
return data

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

@@ -50,15 +50,15 @@
"parent": null
},
{
"id": "gpt-3.5-turbo-0301",
"id": "text-davinci-edit-001",
"object": "model",
"created": 1677649963,
"created": 1649809179,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-ms2DpLH5OCOZpUikJ4sRQNkh",
"id": "modelperm-otmQSS0hmabtVGHI9QB3bct3",
"object": "model_permission",
"created": 1677691853,
"created": 1679934178,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -70,31 +70,7 @@
"is_blocking": false
}
],
"root": "gpt-3.5-turbo-0301",
"parent": null
},
{
"id": "text-davinci-003",
"object": "model",
"created": 1669599635,
"owned_by": "openai-internal",
"permission": [
{
"id": "modelperm-6CAfTW5IbFpnlziQKoDilahq",
"object": "model_permission",
"created": 1677793558,
"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": "text-davinci-003",
"root": "text-davinci-edit-001",
"parent": null
},
{
@@ -145,6 +121,54 @@
"root": "text-similarity-babbage-001",
"parent": null
},
{
"id": "gpt-3.5-turbo",
"object": "model",
"created": 1677610602,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-bLTRGdHW2gpCOsvg9LiXq7tX",
"object": "model_permission",
"created": 1681168143,
"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
},
{
"id": "code-davinci-edit-001",
"object": "model",
"created": 1649880484,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-Foe5Y4TvaKveYxt74oKMw8IB",
"object": "model_permission",
"created": 1679934178,
"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": "code-davinci-edit-001",
"parent": null
},
{
"id": "text-davinci-001",
"object": "model",
@@ -193,30 +217,6 @@
"root": "ada",
"parent": null
},
{
"id": "curie-instruct-beta",
"object": "model",
"created": 1649364042,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-JlSyMbxXeFm42SDjN0wTD26Y",
"object": "model_permission",
"created": 1669070162,
"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": "curie-instruct-beta",
"parent": null
},
{
"id": "babbage-code-search-text",
"object": "model",
@@ -266,15 +266,15 @@
"parent": null
},
{
"id": "gpt-3.5-turbo",
"id": "gpt-3.5-turbo-0301",
"object": "model",
"created": 1677610602,
"created": 1677649963,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-ZErASyl63fhYUeMMk7QKOHAB",
"id": "modelperm-ktA0Xuzvxbe26mhuWenoLxx4",
"object": "model_permission",
"created": 1677691854,
"created": 1681168143,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -286,31 +286,7 @@
"is_blocking": false
}
],
"root": "gpt-3.5-turbo",
"parent": null
},
{
"id": "code-davinci-002",
"object": "model",
"created": 1649880485,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-8hC5jvDSIXgYe2NPyomfyFJr",
"object": "model_permission",
"created": 1677737839,
"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": "code-davinci-002",
"root": "gpt-3.5-turbo-0301",
"parent": null
},
{
@@ -338,39 +314,15 @@
"parent": null
},
{
"id": "text-embedding-ada-002",
"id": "text-curie-001",
"object": "model",
"created": 1671217299,
"owned_by": "openai-internal",
"permission": [
{
"id": "modelperm-ThMneEHcUgdBaIucwREqRj2a",
"object": "model_permission",
"created": 1677075687,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
"allow_search_indices": true,
"allow_view": true,
"allow_fine_tuning": false,
"organization": "*",
"group": null,
"is_blocking": false
}
],
"root": "text-embedding-ada-002",
"parent": null
},
{
"id": "code-cushman-001",
"object": "model",
"created": 1656081837,
"created": 1649364043,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-M6pwNXr8UmY3mqdUEe4VFXdY",
"id": "modelperm-8InhPV3CZfN3F5QHKoJd4zRD",
"object": "model_permission",
"created": 1669066355,
"created": 1679310997,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -382,7 +334,7 @@
"is_blocking": false
}
],
"root": "code-cushman-001",
"root": "text-curie-001",
"parent": null
},
{
@@ -392,9 +344,9 @@
"owned_by": "openai-internal",
"permission": [
{
"id": "modelperm-MX888R5RhewPTR12HguE4hM2",
"id": "modelperm-JdDYm8KjLd5xnGMGVlwX1UAp",
"object": "model_permission",
"created": 1677691932,
"created": 1680896832,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -434,15 +386,15 @@
"parent": null
},
{
"id": "audio-transcribe-deprecated",
"id": "text-davinci-003",
"object": "model",
"created": 1674776185,
"created": 1669599635,
"owned_by": "openai-internal",
"permission": [
{
"id": "modelperm-IPCtO1a9wW5TDxGCIqy0iVfK",
"id": "modelperm-eX6Zax2krvLf9WtfO3NN9YJh",
"object": "model_permission",
"created": 1674776185,
"created": 1680551675,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -454,7 +406,7 @@
"is_blocking": false
}
],
"root": "audio-transcribe-deprecated",
"root": "text-davinci-003",
"parent": null
},
{
@@ -481,6 +433,30 @@
"root": "text-ada-001",
"parent": null
},
{
"id": "text-embedding-ada-002",
"object": "model",
"created": 1671217299,
"owned_by": "openai-internal",
"permission": [
{
"id": "modelperm-Dbv2FOgMdlDjO8py8vEjD5Mi",
"object": "model_permission",
"created": 1678892857,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
"allow_search_indices": true,
"allow_view": true,
"allow_fine_tuning": false,
"organization": "*",
"group": null,
"is_blocking": false
}
],
"root": "text-embedding-ada-002",
"parent": null
},
{
"id": "text-similarity-ada-001",
"object": "model",
@@ -506,15 +482,15 @@
"parent": null
},
{
"id": "text-davinci-insert-002",
"id": "curie-instruct-beta",
"object": "model",
"created": 1649880484,
"created": 1649364042,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-V5YQoSyiapAf4km5wisXkNXh",
"id": "modelperm-bsg59MlOi88CMf1MjnIKrT5a",
"object": "model_permission",
"created": 1669066354,
"created": 1680267269,
"allow_create_engine": false,
"allow_sampling": true,
"allow_logprobs": true,
@@ -526,7 +502,7 @@
"is_blocking": false
}
],
"root": "text-davinci-insert-002",
"root": "curie-instruct-beta",
"parent": null
},
{
@@ -625,54 +601,6 @@
"root": "text-search-ada-query-001",
"parent": null
},
{
"id": "text-curie-001",
"object": "model",
"created": 1649364043,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-fGAoEKBH01KNZ3zz81Sro34Q",
"object": "model_permission",
"created": 1669066352,
"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": "text-curie-001",
"parent": null
},
{
"id": "text-davinci-edit-001",
"object": "model",
"created": 1649809179,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-VzNMGrIRm3HxhEl64gkjZdEh",
"object": "model_permission",
"created": 1669066354,
"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": "text-davinci-edit-001",
"parent": null
},
{
"id": "davinci-search-document",
"object": "model",
@@ -745,30 +673,6 @@
"root": "text-search-ada-doc-001",
"parent": null
},
{
"id": "code-davinci-edit-001",
"object": "model",
"created": 1649880484,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-WwansDxcKNvZtKugNqJnsvfv",
"object": "model_permission",
"created": 1669066354,
"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": "code-davinci-edit-001",
"parent": null
},
{
"id": "davinci-instruct-beta",
"object": "model",
@@ -937,30 +841,6 @@
"root": "davinci-search-query",
"parent": null
},
{
"id": "text-davinci-insert-001",
"object": "model",
"created": 1649880484,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-3gRQMBOMoccZIURE3ZxboZWA",
"object": "model_permission",
"created": 1669066354,
"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": "text-davinci-insert-001",
"parent": null
},
{
"id": "babbage-search-document",
"object": "model",
@@ -1057,30 +937,6 @@
"root": "text-search-babbage-doc-001",
"parent": null
},
{
"id": "text-davinci-002",
"object": "model",
"created": 1649880484,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-kOLsgLs7IgI9PTPI245IRWZH",
"object": "model_permission",
"created": 1676585871,
"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": "text-davinci-002",
"parent": null
},
{
"id": "curie-search-document",
"object": "model",
@@ -1297,6 +1153,30 @@
"root": "text-similarity-davinci-001",
"parent": null
},
{
"id": "text-davinci-002",
"object": "model",
"created": 1649880484,
"owned_by": "openai",
"permission": [
{
"id": "modelperm-l4EU6QlN1HcS0so0jU16kyg8",
"object": "model_permission",
"created": 1679355287,
"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": "text-davinci-002",
"parent": null
},
{
"id": "davinci-similarity",
"object": "model",

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -22,6 +22,8 @@
<field name="arch" type="xml">
<form>
<header>
<button string="Get List Model" type="object" name="get_ai_list_model"/>
<button string="Get Model Info" type="object" name="get_ai_model_info"/>
</header>
<sheet>
<group>