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(AI Transform Node): New node #9990

Merged

Conversation

michael-radency
Copy link
Contributor

@michael-radency michael-radency commented Jul 10, 2024

Summary

This PR introduces a new "AI Transform"* node that generates code snippets based on user instructions. The AI is context-aware, understanding the workflow's nodes and their data types. Users can simply enter their instructions and click the "Generate Code" button to let the AI automatically populate the Code parameter.

image


During development, the node's "button" property was improved:

export type NodePropertyAction = {
	type: 'askAiCodeGeneration';
	handler?: string;
	target?: string;
};

export interface INodePropertyTypeOptions {
	
	buttonConfig?: {
		action?: string | NodePropertyAction;
		label?: string; 
		hasInputField?: boolean;
		inputFieldMaxLength?: number; 
	};
	...
}

This updated interface allows you to specify a label, an optional input field with its maximum input length, and an action. The action can be specified as a string or as a NodePropertyAction, which allows you to set the type of action (currently only 'askAiCodeGeneration') and optionally an action target, such as a parameter that would be affected as a result of this action. Additionally, a handler function defined in methods.actionHandler can be executed on the backend when clicked.

	methods = {
		actionHandler: {
			async generateCode(this: ILoadOptionsFunctions, payload: IDataObject | string | undefined) {
				const url = this.getNodeParameter('url', 0) as string;
				let body: IDataObject = {};
				if (payload) {
					body = typeof payload === 'string' ? jsonParse(payload) : payload;
				}
				const response = (await this.helpers.httpRequest({
					method: 'POST',
					url,
					headers: {
						'Content-Type': 'application/json',
					},
					body,
				})) as {
					data: { code: string };
				};

				return response?.data?.code;
			},
		},
	};

  • This node is currently available only on the cloud.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-1461/ai-transform-node-p0

@michael-radency michael-radency added node/new Creation of an entirely new node n8n team Authored by the n8n team labels Jul 10, 2024
michael-radency and others added 23 commits July 10, 2024 10:23
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
…transform-ai-node-click-handler-component
@@ -321,6 +327,7 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, () => {
visibleNodeTypesByInputConnectionTypeNames,
isConfigurableNode,
getResourceMapperFields,
getNodeParameterActionResult,
Copy link
Member

@elsmr elsmr Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not being used? (this endpoint in general)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not currently, but this is part of button parameter where you could use handler assigned in buttonConfig similar to loadOptions, usage example here

return true;
});

function getParentNodes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is duplicated in utils, but not used

Copy link
Contributor

@ShireenMissi ShireenMissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Copy link

cypress bot commented Aug 7, 2024



Test summary

395 0 0 0Flakiness 1


Run details

Project n8n
Status Passed
Commit 0de9d56
Started Aug 8, 2024 3:12 AM
Ended Aug 8, 2024 3:17 AM
Duration 04:56 💡
OS Linux Debian -
Browser Electron 118

View run in Cypress Cloud ➡️


Flakiness

e2e/5-ndv.cy.ts Flakiness
1 NDV > test output schema view > should display large schema

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Copy link
Contributor

github-actions bot commented Aug 7, 2024

✅ All Cypress E2E specs passed

@michael-radency michael-radency merged commit 0de9d56 into master Aug 7, 2024
30 checks passed
@michael-radency michael-radency deleted the node-1461-transform-ai-node-click-handler-component branch August 7, 2024 15:07
ShireenMissi added a commit that referenced this pull request Aug 14, 2024
@github-actions github-actions bot mentioned this pull request Aug 14, 2024
@janober
Copy link
Member

janober commented Aug 15, 2024

Got released with n8n@1.55.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team node/new Creation of an entirely new node Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants