fix(OpenAI Node): Load correct models for operation (#8313)

This commit is contained in:
Michael Kret 2024-01-15 15:13:38 +02:00 committed by GitHub
parent c8a2fe05d2
commit a6a5372b5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 3 deletions

View file

@ -42,6 +42,69 @@ const completeOperations: INodeProperties[] = [
show: {
operation: ['complete'],
resource: ['chat'],
'@version': [1],
},
},
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '/v1/models',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'data',
},
},
{
type: 'filter',
properties: {
pass: "={{ $responseItem.id.startsWith('gpt-') && !$responseItem.id.startsWith('gpt-4-vision') }}",
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.id}}',
value: '={{$responseItem.id}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
},
routing: {
send: {
type: 'body',
property: 'model',
},
},
default: 'gpt-3.5-turbo',
},
{
displayName: 'Model',
name: 'chatModel',
type: 'options',
description:
'The model which will generate the completion. <a href="https://beta.openai.com/docs/models/overview">Learn more</a>.',
displayOptions: {
show: {
operation: ['complete'],
resource: ['chat'],
},
hide: {
'@version': [1],
},
},
typeOptions: {

View file

@ -114,6 +114,68 @@ const createOperations: INodeProperties[] = [
show: {
resource: ['image'],
operation: ['create'],
'@version': [1],
},
},
routing: {
send: {
type: 'body',
property: 'model',
},
},
},
{
displayName: 'Model',
name: 'imageModel',
type: 'options',
default: 'dall-e-2',
description: 'The model to use for image generation',
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '/v1/models',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'data',
},
},
{
type: 'filter',
properties: {
pass: "={{ $responseItem.id.startsWith('dall-') }}",
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.id}}',
value: '={{$responseItem.id}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
},
displayOptions: {
show: {
resource: ['image'],
operation: ['create'],
},
hide: {
'@version': [1],
},
},
routing: {

View file

@ -9,7 +9,7 @@ export class OpenAi implements INodeType {
name: 'openAi',
icon: 'file:openAi.svg',
group: ['transform'],
version: 1,
version: [1, 1.1],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Open AI',
defaults: {

View file

@ -88,7 +88,7 @@ const completeOperations: INodeProperties[] = [
{
type: 'filter',
properties: {
pass: "={{ !$responseItem.id.startsWith('audio-') && !$responseItem.id.startsWith('gpt-') && !$responseItem.id.startsWith('dall-') && !$responseItem.id.startsWith('tts-') && !$responseItem.id.startsWith('whisper-') && !['cushman:2020-05-03', 'davinci-if:3.0.0', 'davinci-instruct-beta:2.0.0', 'if'].includes($responseItem.id) && !$responseItem.id.includes('-edit-') && !$responseItem.id.endsWith(':001') }}",
pass: "={{ !$responseItem.id.startsWith('audio-') && ($responseItem.id === 'gpt-3.5-turbo-instruct' || !$responseItem.id.startsWith('gpt-') ) && !$responseItem.id.startsWith('dall-') && !$responseItem.id.startsWith('tts-') && !$responseItem.id.startsWith('whisper-') && !['cushman:2020-05-03', 'davinci-if:3.0.0', 'davinci-instruct-beta:2.0.0', 'if'].includes($responseItem.id) && !$responseItem.id.includes('-edit-') && !$responseItem.id.endsWith(':001') }}",
},
},
{
@ -115,7 +115,7 @@ const completeOperations: INodeProperties[] = [
property: 'model',
},
},
default: 'text-davinci-003',
default: 'gpt-3.5-turbo-instruct',
},
{
displayName: 'Prompt',