-
Notifications
You must be signed in to change notification settings - Fork 17k
/
Copy pathversionDescription.ts
137 lines (125 loc) · 3.35 KB
/
versionDescription.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { INodeTypeDescription } from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow';
import * as assistant from './assistant';
import * as audio from './audio';
import * as file from './file';
import * as image from './image';
import * as text from './text';
const prettifyOperation = (resource: string, operation: string) => {
if (operation === 'deleteAssistant') {
return 'Delete Assistant';
}
if (operation === 'deleteFile') {
return 'Delete File';
}
if (operation === 'classify') {
return 'Classify Text';
}
if (operation === 'message' && resource === 'text') {
return 'Message Model';
}
const capitalize = (str: string) => {
const chars = str.split('');
chars[0] = chars[0].toUpperCase();
return chars.join('');
};
if (['transcribe', 'translate'].includes(operation)) {
resource = 'recording';
}
if (operation === 'list') {
resource = resource + 's';
}
return `${capitalize(operation)} ${capitalize(resource)}`;
};
const configureNodeInputs = (resource: string, operation: string, hideTools: string) => {
if (resource === 'assistant' && operation === 'message') {
return [
{ type: NodeConnectionType.Main },
{ type: NodeConnectionType.AiMemory, displayName: 'Memory', maxConnections: 1 },
{ type: NodeConnectionType.AiTool, displayName: 'Tools' },
];
}
if (resource === 'text' && operation === 'message') {
if (hideTools === 'hide') {
return [NodeConnectionType.Main];
}
return [
{ type: NodeConnectionType.Main },
{ type: NodeConnectionType.AiTool, displayName: 'Tools' },
];
}
return [NodeConnectionType.Main];
};
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
export const versionDescription: INodeTypeDescription = {
displayName: 'OpenAI',
name: 'openAi',
icon: { light: 'file:openAi.svg', dark: 'file:openAi.dark.svg' },
group: ['transform'],
version: [1, 1.1, 1.2, 1.3, 1.4],
subtitle: `={{(${prettifyOperation})($parameter.resource, $parameter.operation)}}`,
description: 'Message an assistant or GPT, analyze images, generate audio, etc.',
defaults: {
name: 'OpenAI',
},
codex: {
alias: ['LangChain', 'ChatGPT', 'DallE', 'whisper', 'audio', 'transcribe', 'tts', 'assistant'],
categories: ['AI'],
subcategories: {
AI: ['Agents', 'Miscellaneous', 'Root Nodes'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/',
},
],
},
},
inputs: `={{(${configureNodeInputs})($parameter.resource, $parameter.operation, $parameter.hideTools)}}`,
outputs: [NodeConnectionType.Main],
credentials: [
{
name: 'openAiApi',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items
options: [
{
name: 'Assistant',
value: 'assistant',
},
{
name: 'Text',
value: 'text',
},
{
name: 'Image',
value: 'image',
},
{
name: 'Audio',
value: 'audio',
},
{
name: 'File',
value: 'file',
},
],
default: 'text',
},
...assistant.description,
...audio.description,
...file.description,
...image.description,
...text.description,
],
};