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: add support for display options filtering in parameter options #12704

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ export const MODELS_NOT_SUPPORT_FUNCTION_CALLS = [
'tts-1-1106',
'text-embedding-ada-002',
];

export const MODELS_NOT_SUPPORT_SYSTEM_ROLE = [
'o1-mini',
'o1-mini-2024-09-12',
'o1-preview',
'o1-preview-2024-09-12',
];
48 changes: 48 additions & 0 deletions packages/editor-ui/src/components/ParameterInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
13 changes: 11 additions & 2 deletions packages/editor-ui/src/components/ParameterInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,17 @@ const editorLanguage = computed<CodeNodeEditorLanguage>(() => {

const parameterOptions = computed<INodePropertyOptions[] | undefined>(() => {
if (!hasRemoteMethod.value) {
// Options are already given
return props.parameter.options as INodePropertyOptions[];
const options = props.parameter.options as INodePropertyOptions[];
const nodeValue = ndvStore.activeNode!;
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
Expand Down