fix(OpenAI Node): Allow to pass files ids as comma separated string in expressions (no-changelog) (#9240)

This commit is contained in:
Michael Kret 2024-04-29 15:02:15 +03:00 committed by GitHub
parent f84abc0586
commit 58156eeeec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -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',
},
@ -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) {

View file

@ -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',
},
@ -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(),
@ -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) {