Skip to content

Commit

Permalink
fix(OpenAI Node): Load correct models for operation (#8313)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Jan 15, 2024
1 parent c8a2fe0 commit a6a5372
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 3 deletions.
63 changes: 63 additions & 0 deletions packages/nodes-base/nodes/OpenAi/ChatDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
62 changes: 62 additions & 0 deletions packages/nodes-base/nodes/OpenAi/ImageDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/OpenAi/OpenAi.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/OpenAi/TextDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}",
},
},
{
Expand All @@ -115,7 +115,7 @@ const completeOperations: INodeProperties[] = [
property: 'model',
},
},
default: 'text-davinci-003',
default: 'gpt-3.5-turbo-instruct',
},
{
displayName: 'Prompt',
Expand Down

0 comments on commit a6a5372

Please sign in to comment.