Skip to content

Commit

Permalink
fix(OpenAI Node): Allow to pass files ids as comma separated string i…
Browse files Browse the repository at this point in the history
…n expressions (no-changelog) (n8n-io#9240)
  • Loading branch information
michael-radency authored Apr 29, 2024
1 parent f84abc0 commit 58156ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const properties: INodeProperties[] = [
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',
'The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant. You can use expression to pass file IDs as an array or comma-separated string.',
typeOptions: {
loadOptionsMethod: 'getFiles',
},
Expand Down Expand Up @@ -161,7 +161,10 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
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[];
let file_ids = this.getNodeParameter('file_ids', i, []) as string[] | string;
if (typeof file_ids === 'string') {
file_ids = file_ids.split(',').map((file_id) => file_id.trim());
}
const options = this.getNodeParameter('options', i, {});

if (options.failIfExists) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const properties: INodeProperties[] = [
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',
'The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant. You can use expression to pass file IDs as an array or comma-separated string.',
typeOptions: {
loadOptionsMethod: 'getFiles',
},
Expand Down Expand Up @@ -116,6 +116,10 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
const body: IDataObject = {};

if (file_ids) {
let files = file_ids;
if (typeof files === 'string') {
files = files.split(',').map((file_id) => file_id.trim());
}
if ((file_ids as IDataObject[]).length > 20) {
throw new NodeOperationError(
this.getNode(),
Expand All @@ -124,7 +128,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
);
}

body.file_ids = file_ids;
body.file_ids = files;
}

if (modelId) {
Expand Down

0 comments on commit 58156ee

Please sign in to comment.