From d8376a7465550294e1796913ec9493635b064561 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Wed, 13 Mar 2024 10:08:03 +0200 Subject: [PATCH 1/2] :zap: fix --- .../actions/assistant/create.operation.ts | 3 +- .../actions/assistant/message.operation.ts | 34 ++++++++++++++++--- .../OpenAi/actions/versionDescription.ts | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts index aa511a3ca44f8..185e0d94f917e 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts @@ -120,7 +120,8 @@ const properties: INodeProperties[] = [ }, }, { - displayName: "Add custom n8n tools when using the 'Message Assistant' operation", + displayName: + 'Add custom n8n tools when you message your assistant (rather than when creating it)', name: 'noticeTools', type: 'notice', default: '', diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts index 3623c18fd4e0c..919e694ea6e62 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts @@ -84,6 +84,19 @@ const properties: INodeProperties[] = [ description: 'Maximum amount of time a request is allowed to take in milliseconds', type: 'number', }, + { + displayName: 'Preserve Original Tools', + name: 'preserveOriginalTools', + type: 'boolean', + default: true, + description: + 'Whether to preserve the original tools of the assistant after the execution of this node, otherwise the tools will be replaced with the connected tools, if any, default is true', + displayOptions: { + show: { + '@version': [{ _cnd: { gte: 1.3 } }], + }, + }, + }, ], }, ]; @@ -123,6 +136,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise 1); + let assistantTools; if (tools.length) { const transformedConnectedTools = tools?.map(formatToOpenAIAssistantTool) ?? []; const nativeToolsParsed: OpenAIToolType = []; - const assistant = await client.beta.assistants.retrieve(assistantId); + assistantTools = (await client.beta.assistants.retrieve(assistantId)).tools; - const useCodeInterpreter = assistant.tools.some((tool) => tool.type === 'code_interpreter'); + const useCodeInterpreter = assistantTools.some((tool) => tool.type === 'code_interpreter'); if (useCodeInterpreter) { nativeToolsParsed.push({ type: 'code_interpreter', }); } - const useRetrieval = assistant.tools.some((tool) => tool.type === 'retrieval'); + const useRetrieval = assistantTools.some((tool) => tool.type === 'retrieval'); if (useRetrieval) { nativeToolsParsed.push({ type: 'retrieval', @@ -166,11 +181,22 @@ export async function execute(this: IExecuteFunctions, i: number): Promise= 1.3 && + assistantTools && + assistantTools?.length + ) { + await client.beta.assistants.update(assistantId, { + tools: assistantTools, + }); + } + return [{ json: response, pairedItem: { item: i } }]; } diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/versionDescription.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/versionDescription.ts index 778b42c26d727..080680b776604 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/versionDescription.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/versionDescription.ts @@ -68,7 +68,7 @@ export const versionDescription: INodeTypeDescription = { name: 'openAi', icon: 'file:openAi.svg', group: ['transform'], - version: [1, 1.1, 1.2], + version: [1, 1.1, 1.2, 1.3], subtitle: `={{(${prettifyOperation})($parameter.resource, $parameter.operation)}}`, description: 'Message an assistant or GPT, analyze images, generate audio, etc.', defaults: { From 4e6b87d37143e8a3a4499a339e6a6a8ddb688c77 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Wed, 13 Mar 2024 15:05:18 +0100 Subject: [PATCH 2/2] Fix linting issues Signed-off-by: Oleg Ivaniv --- .../vendors/OpenAi/actions/assistant/message.operation.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts index 919e694ea6e62..6d7e669e3923b 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts @@ -190,8 +190,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise= 1.3 && - assistantTools && - assistantTools?.length + (assistantTools ?? [])?.length ) { await client.beta.assistants.update(assistantId, { tools: assistantTools,