From 4e36406b742c11da643aab0174cf6648a75529c7 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 18 Jan 2025 22:35:45 +0100 Subject: [PATCH 1/5] feat(parameter-input): support display parameter on options Signed-off-by: mateonunez --- packages/editor-ui/src/components/ParameterInput.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/editor-ui/src/components/ParameterInput.vue b/packages/editor-ui/src/components/ParameterInput.vue index 7d0aa444413fc..edbad9c1afab7 100644 --- a/packages/editor-ui/src/components/ParameterInput.vue +++ b/packages/editor-ui/src/components/ParameterInput.vue @@ -413,8 +413,15 @@ const editorLanguage = computed(() => { const parameterOptions = computed(() => { if (!hasRemoteMethod.value) { - // Options are already given - return props.parameter.options as INodePropertyOptions[]; + const options = props.parameter.options as INodePropertyOptions[]; + const nodeValue = ndvStore.activeNode as INodeUi; + if (!nodeValue) { + return options; + } + + const nodeValues = nodeValue.parameters ?? {}; + const visibleOptions = options.filter((option) => nodeHelpers.displayParameter(nodeValues, option, '', nodeValue)); + return visibleOptions; } // Options get loaded from server From 2d8828e320ef7d4cb2995cb03cdc028ad13436eb Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 18 Jan 2025 22:37:40 +0100 Subject: [PATCH 2/5] chore(openai): limit system role to supported models Signed-off-by: mateonunez --- .../vendors/OpenAi/actions/text/message.operation.ts | 12 +++++++++++- .../nodes/vendors/OpenAi/helpers/constants.ts | 7 +++++++ packages/editor-ui/src/components/ParameterInput.vue | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts index 2da3163099e05..193973a436b16 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts @@ -10,7 +10,10 @@ import { jsonParse, updateDisplayOptions } from 'n8n-workflow'; import { getConnectedTools } from '@utils/helpers'; -import { MODELS_NOT_SUPPORT_FUNCTION_CALLS } from '../../helpers/constants'; +import { + MODELS_NOT_SUPPORT_FUNCTION_CALLS, + MODELS_NOT_SUPPORT_SYSTEM_ROLE, +} from '../../helpers/constants'; import type { ChatCompletion } from '../../helpers/interfaces'; import { formatToOpenAIAssistantTool } from '../../helpers/utils'; import { apiRequest } from '../../transport'; @@ -65,6 +68,11 @@ const properties: INodeProperties[] = [ value: 'system', description: "Usually used to set the model's behavior or context for the next user message", + displayOptions: { + hide: { + modelId: MODELS_NOT_SUPPORT_SYSTEM_ROLE, + }, + }, }, ], default: 'user', @@ -297,6 +305,8 @@ export async function execute(this: IExecuteFunctions, i: number): Promise(() => { } const nodeValues = nodeValue.parameters ?? {}; - const visibleOptions = options.filter((option) => nodeHelpers.displayParameter(nodeValues, option, '', nodeValue)); + const visibleOptions = options.filter((option) => + nodeHelpers.displayParameter(nodeValues, option, '', nodeValue), + ); return visibleOptions; } From edf2ac341800c34a3f2402edf05c986fecaddd16 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 18 Jan 2025 23:35:29 +0100 Subject: [PATCH 3/5] test(parameter-input): add options parameter display options Signed-off-by: mateonunez --- .../src/components/ParameterInput.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/editor-ui/src/components/ParameterInput.test.ts b/packages/editor-ui/src/components/ParameterInput.test.ts index 4ee22ec0ddf2d..3734389e2d1ee 100644 --- a/packages/editor-ui/src/components/ParameterInput.test.ts +++ b/packages/editor-ui/src/components/ParameterInput.test.ts @@ -233,4 +233,52 @@ describe('ParameterInput.vue', () => { expect(emitted('update')).toBeUndefined(); }); + + test('should handle the visibility of the options parameter based on displayOptions', async () => { + const roleParameter = { + displayName: 'Role', + name: 'role', + type: 'options', + default: 'user', + options: [ + { + name: 'User', + value: 'user', + }, + { + name: 'Assistant', + value: 'assistant', + }, + { + name: 'System', + value: 'system', + displayOptions: { + hide: { + '@version': [1], + }, + }, + }, + ], + }; + + const { container, baseElement } = renderComponent(ParameterInput, { + pinia: createTestingPinia(), + props: { + path: 'role', + parameter: roleParameter, + modelValue: 'user', + }, + }); + + const selectInput = container.querySelector('input') as HTMLInputElement; + expect(selectInput).toBeInTheDocument(); + + await userEvent.click(selectInput); + + await waitFor(() => { + expect(baseElement).toHaveTextContent('User'); + expect(baseElement).toHaveTextContent('Assistant'); + expect(baseElement).not.toHaveTextContent('System'); + }); + }); }); From 1986a6bac4cf3ab6cb3ce8d38ca0f05a42033b55 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 18 Jan 2025 23:50:20 +0100 Subject: [PATCH 4/5] chore: clean up Signed-off-by: mateonunez --- .../nodes/vendors/OpenAi/actions/text/message.operation.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts index 193973a436b16..a00c66ecc4b5e 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts @@ -305,8 +305,6 @@ export async function execute(this: IExecuteFunctions, i: number): Promise Date: Sun, 19 Jan 2025 09:32:10 +0100 Subject: [PATCH 5/5] chore(parameter-input): remove useless casting Signed-off-by: mateonunez --- packages/editor-ui/src/components/ParameterInput.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor-ui/src/components/ParameterInput.vue b/packages/editor-ui/src/components/ParameterInput.vue index 27d30901961b0..a044d1f0668f7 100644 --- a/packages/editor-ui/src/components/ParameterInput.vue +++ b/packages/editor-ui/src/components/ParameterInput.vue @@ -414,7 +414,7 @@ const editorLanguage = computed(() => { const parameterOptions = computed(() => { if (!hasRemoteMethod.value) { const options = props.parameter.options as INodePropertyOptions[]; - const nodeValue = ndvStore.activeNode as INodeUi; + const nodeValue = ndvStore.activeNode!; if (!nodeValue) { return options; }