Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OpenAI Node): Overhaul #8335

Merged
merged 69 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
a633bea
:zap: setup
michael-radency Jan 15, 2024
eaca2db
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 15, 2024
365abd0
:zap: merge fixes
michael-radency Jan 15, 2024
6b3cfe9
:zap: analyze image mime type fix
michael-radency Jan 15, 2024
29bbf0b
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 15, 2024
728a663
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 16, 2024
7cdd969
:zap: generateAudio and createModeration operations
michael-radency Jan 16, 2024
3fb5247
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 16, 2024
2e901b1
:zap: translate & transcribe operations
michael-radency Jan 16, 2024
ac43b40
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 16, 2024
b12c46f
:zap: files operations
michael-radency Jan 16, 2024
e56b740
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 16, 2024
b93429c
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 17, 2024
5a17e73
:zap: message model operation
michael-radency Jan 17, 2024
14ee38a
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 17, 2024
00852e8
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 18, 2024
39fbd38
:zap: message assistant operation
michael-radency Jan 18, 2024
196248e
:zap: message assistant additional options
michael-radency Jan 18, 2024
e2ffaa6
:zap: simplify option for message assistant operation
michael-radency Jan 18, 2024
8c6d11e
:zap: clean up
michael-radency Jan 18, 2024
5c18b39
:zap: analyzeImage fix
michael-radency Jan 18, 2024
482931a
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 20, 2024
71add3b
:zap: review update
michael-radency Jan 20, 2024
a775c3d
:zap: router optimization
michael-radency Jan 22, 2024
15a4e53
:zap: message model tools support
michael-radency Jan 22, 2024
03b6b91
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 22, 2024
06e35e4
:zap: message model tools setup for external url call
michael-radency Jan 22, 2024
061b3df
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 22, 2024
ef6f915
:zap: updated function code default
michael-radency Jan 22, 2024
1f3753d
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 22, 2024
3beca97
:zap: url fix
michael-radency Jan 23, 2024
0d4c9d5
:zap: sending parameters in path option
michael-radency Jan 23, 2024
4799537
:zap: descriptions update
michael-radency Jan 23, 2024
c8efd60
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 24, 2024
dc34b6d
:zap: new version relocated into nodes-langchain
michael-radency Jan 24, 2024
41da315
:zap: fix spam no codex data for langchain nodes when building
michael-radency Jan 24, 2024
18e60fa
:zap: integrated OpenAI Assistant into updated node
michael-radency Jan 24, 2024
cbed9d9
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 24, 2024
a2de1b1
:zap: tool code description and defaults update
michael-radency Jan 24, 2024
c6c3b77
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Jan 24, 2024
dc12046
:zap: tweaks
michael-radency Jan 25, 2024
454836c
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 5, 2024
3cd0274
:zap: review updates
michael-radency Feb 5, 2024
59d10e4
:zap: support for langchain tools in message operation
michael-radency Feb 5, 2024
e2a89fd
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 5, 2024
f8d8434
:zap: messageModel some description update
michael-radency Feb 5, 2024
5652c48
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 6, 2024
a02bb76
:zap: createAssistant operation
michael-radency Feb 6, 2024
caa973f
:zap: assistant operations
michael-radency Feb 6, 2024
b874830
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 6, 2024
ec8b417
:zap: ui fix
michael-radency Feb 6, 2024
2c07a91
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 9, 2024
536d907
:zap: review updates, refactoring
michael-radency Feb 9, 2024
6a7c479
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 9, 2024
b6253bf
:zap: message assistant promt ui update
michael-radency Feb 9, 2024
ed9caca
:zap: add chat trigger if not present on canvas when inserting openai…
michael-radency Feb 9, 2024
6a25b8c
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 9, 2024
fb8f333
:zap: added aliases
michael-radency Feb 9, 2024
d6ea6d7
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 12, 2024
f71b7c5
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 12, 2024
00bf3c5
:zap: assistant resource tests
michael-radency Feb 12, 2024
e064617
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 12, 2024
1fd2f48
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 12, 2024
c5e8c4c
:zap: audio, file, image, text tests
michael-radency Feb 12, 2024
a777275
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 13, 2024
55b18cb
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 14, 2024
0f8131b
:zap: display options update
michael-radency Feb 14, 2024
1844574
Merge branch 'master' of https://github.com/n8n-io/n8n into node-976-…
michael-radency Feb 15, 2024
8c8dddb
:zap: spelling fixes
michael-radency Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@n8n/nodes-langchain/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('jest').Config} */
module.exports = require('../../../jest.config');
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class OpenAiAssistant implements INodeType {
description: INodeTypeDescription = {
displayName: 'OpenAI Assistant',
name: 'openAiAssistant',
hidden: true,
icon: 'fa:robot',
group: ['transform'],
version: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export class ToolCode implements INodeType {
outputNames: ['Tool'],
properties: [
getConnectionHintNoticeField([NodeConnectionType.AiAgent]),
{
displayName:
'See an example of a conversational agent with custom tool written in JavaScript <a href="/templates/1963" target="_blank">here</a>.',
name: 'noticeTemplateExample',
type: 'notice',
default: '',
},
{
displayName: 'Name',
name: 'name',
Expand Down Expand Up @@ -95,11 +102,12 @@ export class ToolCode implements INodeType {
editor: 'codeNodeEditor',
editorLanguage: 'javaScript',
},
default: '',
default:
'// Example: convert the incoming query to uppercase and return it\nreturn query.toUpperCase()',
// TODO: Add proper text here later
hint: 'You can access the input the tool receives via the input property "query". The returned value should be a single string.',
description:
'JavaScript code to execute.<br><br>Tip: You can use luxon vars like <code>$today</code> for dates and <code>$jmespath</code> for querying JSON structures. <a href="https://docs.n8n.io/nodes/n8n-nodes-base.function">Learn more</a>.',
// eslint-disable-next-line n8n-nodes-base/node-param-description-missing-final-period
description: 'E.g. Converts any text to uppercase',
noDataExpression: true,
},
{
Expand All @@ -115,11 +123,12 @@ export class ToolCode implements INodeType {
editor: 'codeNodeEditor',
editorLanguage: 'python',
},
default: '',
default:
'# Example: convert the incoming query to uppercase and return it\nreturn query.upper()',
// TODO: Add proper text here later
hint: 'You can access the input the tool receives via the input property "query". The returned value should be a single string.',
description:
'Python code to execute.<br><br>Tip: You can use built-in methods and variables like <code>_today</code> for dates and <code>_jmespath</code> for querying JSON structures. <a href="https://docs.n8n.io/code/builtin/">Learn more</a>.',
// eslint-disable-next-line n8n-nodes-base/node-param-description-missing-final-period
description: 'E.g. Converts any text to uppercase',
noDataExpression: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export class ToolWorkflow implements INodeType {
outputNames: ['Tool'],
properties: [
getConnectionHintNoticeField([NodeConnectionType.AiAgent]),
{
displayName:
'See an example of a workflow to suggest meeting slots using AI <a href="/templates/1953" target="_blank">here</a>.',
name: 'noticeTemplateExample',
type: 'notice',
default: '',
},
{
displayName: 'Name',
name: 'name',
Expand Down
17 changes: 17 additions & 0 deletions packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/OpenAi.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { IExecuteFunctions, INodeType } from 'n8n-workflow';
import { router } from './actions/router';
import { versionDescription } from './actions/versionDescription';
import { listSearch, loadOptions } from './methods';

export class OpenAi implements INodeType {
description = versionDescription;

methods = {
listSearch,
loadOptions,
};

async execute(this: IExecuteFunctions) {
return await router.call(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
import type {
INodeProperties,
IExecuteFunctions,
INodeExecutionData,
IDataObject,
} from 'n8n-workflow';
import { NodeOperationError, updateDisplayOptions } from 'n8n-workflow';
import { apiRequest } from '../../transport';
import { modelRLC } from '../descriptions';

const properties: INodeProperties[] = [
modelRLC,
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'The name of the assistant. The maximum length is 256 characters.',
placeholder: 'e.g. My Assistant',
required: true,
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'The description of the assistant. The maximum length is 512 characters.',
placeholder: 'e.g. My personal assistant',
},
{
displayName: 'Instructions',
name: 'instructions',
type: 'string',
description:
'The system instructions that the assistant uses. The maximum length is 32768 characters.',
default: '',
typeOptions: {
rows: 2,
},
},
{
displayName: 'Code Interpreter',
name: 'codeInterpreter',
type: 'boolean',
default: false,
description:
'Whether to enable the code interpreter that allows the ssistants to write and run Python code in a sandboxed execution environment, find more <a href="https://platform.openai.com/docs/assistants/tools/code-interpreter" target="_blank">here</a>',
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
},
{
displayName: 'Knowledge Retrieval',
name: 'knowledgeRetrieval',
type: 'boolean',
default: false,
description:
'Whether to augments the assistant with knowledge from outside its model, such as proprietary product information or documents, find more <a href="https://platform.openai.com/docs/assistants/tools/knowledge-retrieval" target="_blank">here</a>',
},
//we want to display Files selector only when codeInterpreter true or knowledgeRetrieval true or both
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options
displayName: 'Files',
name: 'file_ids',
type: 'multiOptions',
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options
description:
'The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant',
typeOptions: {
loadOptionsMethod: 'getFiles',
},
default: [],
hint: "Add more files by using the 'Upload a File' operation",
displayOptions: {
show: {
codeInterpreter: [true],
},
hide: {
knowledgeRetrieval: [true],
},
},
},
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options
displayName: 'Files',
name: 'file_ids',
type: 'multiOptions',
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options
description:
'The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant',
typeOptions: {
loadOptionsMethod: 'getFiles',
},
default: [],
hint: "Add more files by using the 'Upload a File' operation",
displayOptions: {
show: {
knowledgeRetrieval: [true],
},
hide: {
codeInterpreter: [true],
},
},
},
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options
displayName: 'Files',
name: 'file_ids',
type: 'multiOptions',
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options
description:
'The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant',
typeOptions: {
loadOptionsMethod: 'getFiles',
},
default: [],
hint: "Add more files by using the 'Upload a File' operation",
displayOptions: {
show: {
knowledgeRetrieval: [true],
codeInterpreter: [true],
},
},
},
{
displayName: "Add custom n8n tools when using the 'Message Assistant' operation",
name: 'noticeTools',
type: 'notice',
default: '',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Fail if Assistant Already Exists',
name: 'failIfExists',
type: 'boolean',
default: false,
description:
'Whether to fail an operation if the assistant with the same name already exists',
},
],
},
];

const displayOptions = {
show: {
operation: ['create'],
resource: ['assistant'],
},
};

export const description = updateDisplayOptions(displayOptions, properties);

export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
const model = this.getNodeParameter('modelId', i, '', { extractValue: true }) as string;
const name = this.getNodeParameter('name', i) as string;
const assistantDescription = this.getNodeParameter('description', i) as string;
const instructions = this.getNodeParameter('instructions', i) as string;
const codeInterpreter = this.getNodeParameter('codeInterpreter', i) as boolean;
const knowledgeRetrieval = this.getNodeParameter('knowledgeRetrieval', i) as boolean;
const file_ids = this.getNodeParameter('file_ids', i, []) as string[];
const options = this.getNodeParameter('options', i, {});

if (options.failIfExists) {
const assistants: string[] = [];

let has_more = true;
let after: string | undefined;

do {
const response = await apiRequest.call(this, 'GET', '/assistants', {

Check warning on line 173 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe assignment of an `any` value
headers: {
'OpenAI-Beta': 'assistants=v1',
},
qs: {
limit: 100,
after,
},
});

for (const assistant of response.data || []) {

Check warning on line 183 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe member access .data on an `any` value
assistants.push(assistant.name);

Check warning on line 184 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe argument of type `any` assigned to a parameter of type `string`

Check warning on line 184 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe member access .name on an `any` value
}

has_more = response.has_more;

Check warning on line 187 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe assignment of an `any` value

Check warning on line 187 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe member access .has_more on an `any` value

if (has_more) {
after = response.last_id as string;

Check warning on line 190 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe member access .last_id on an `any` value
} else {
break;
}
} while (has_more);

if (assistants.includes(name)) {
throw new NodeOperationError(
this.getNode(),
`An assistant with the same name '${name}' already exists`,
{ itemIndex: i },
);
}
}

if (file_ids.length > 20) {
throw new NodeOperationError(
this.getNode(),
'The maximum number of files that can be attached to the assistant is 20',
{ itemIndex: i },
);
}

const body: IDataObject = {
model,
name,
description: assistantDescription,
instructions,
file_ids,
};

const tools = [];

if (codeInterpreter) {
tools.push({
type: 'code_interpreter',
});
}

if (knowledgeRetrieval) {
tools.push({
type: 'retrieval',
});
}

if (tools.length) {
body.tools = tools;
}

const response = await apiRequest.call(this, 'POST', '/assistants', {

Check warning on line 239 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe assignment of an `any` value
body,
headers: {
'OpenAI-Beta': 'assistants=v1',
},
});

return [
{
json: response,

Check warning on line 248 in packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe assignment of an `any` value
pairedItem: { item: i },
},
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { updateDisplayOptions } from 'n8n-workflow';
import { apiRequest } from '../../transport';
import { assistantRLC } from '../descriptions';

const properties: INodeProperties[] = [assistantRLC];

const displayOptions = {
show: {
operation: ['deleteAssistant'],
resource: ['assistant'],
},
};

export const description = updateDisplayOptions(displayOptions, properties);

export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
const assistantId = this.getNodeParameter('assistantId', i, '', { extractValue: true }) as string;

const response = await apiRequest.call(this, 'DELETE', `/assistants/${assistantId}`, {
headers: {
'OpenAI-Beta': 'assistants=v1',
},
});

return [
{
json: response,
pairedItem: { item: i },
},
];
}
Loading
Loading