UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI — 290+ AI models: video, image, audio, LLM, 3D, and more.

138 lines 6.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TrainFluxLoraPortrait = void 0; const n8n_workflow_1 = require("n8n-workflow"); const auth_1 = require("../utils/auth"); const polling_1 = require("../utils/polling"); class TrainFluxLoraPortrait { constructor() { this.description = { displayName: 'Wiro - Train Flux Lora Portrait', name: 'trainFluxLoraPortrait', icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' }, group: ['transform'], version: 1, description: 'Fast LoRA training is a technique used to fine-tune FLUX models, enabling personalized model ou', defaults: { name: 'Wiro - Train Flux Lora Portrait', }, inputs: [n8n_workflow_1.NodeConnectionTypes.Main], outputs: [n8n_workflow_1.NodeConnectionTypes.Main], usableAsTool: true, credentials: [ { name: 'wiroApi', required: true, }, ], properties: [ { displayName: 'Trained Model Name', name: 'trainModelName', type: 'string', default: '', required: true, description: 'Train-model-name-help', }, { displayName: 'Trigger Word', name: 'triggerWord', type: 'string', default: '', required: true, description: 'A short descriptor of your subject using a UNIQUE keyword and a classifier word. If training a man, your instance prompt could be "ohwx". The key here is that "ohwx" is not a word that might overlap with something in the real world "man" is a generic word to describe your subject', }, { displayName: 'Training Steps', name: 'trainingSteps', type: 'number', default: 0, required: true, description: 'How many total training steps to complete. You should train for appx 100 steps per sample image. So, if you have 40 instance/sample images, you would train for 4k steps. Recommended range 500-4000', }, { displayName: 'Learning Rate', name: 'learningRate', type: 'number', default: 0, required: true, description: 'To get good-quality images, we must find a \'sweet spot\' between the number of training steps and the learning rate. We recommend using a low learning rate and progressively increasing the number of steps until the results are satisfactory.', }, { displayName: 'Select A Folder For Training Data', name: 'selectedFolder', type: 'string', default: '', description: 'The selected folder containing the images that will be used for training. We recommend a minimum of 10 images. If you include captions, include them as one .txt file per image, e.g. my-photo.jpg should have a caption file named my-photo.txt. If you don\'t include captions, you can use autocaptioning', }, { displayName: 'ZIP URL For Training Data', name: 'selectedFolderUrl', type: 'string', default: '', description: 'When a ZIP URL is provided, it is automatically extracted and used as the training folder. A zip file containing the images that will be used for training. We recommend a minimum of 10 images. If you include captions, include them as one .txt file per image, e.g. my-photo.jpg should have a caption file named my-photo.txt. If you don\'t include captions, you can use autocaptioning', }, ], }; } async execute() { const returnData = []; const trainModelName = this.getNodeParameter('trainModelName', 0); const triggerWord = this.getNodeParameter('triggerWord', 0); const trainingSteps = this.getNodeParameter('trainingSteps', 0); const learningRate = this.getNodeParameter('learningRate', 0); const selectedFolder = this.getNodeParameter('selectedFolder', 0, ''); const selectedFolderUrl = this.getNodeParameter('selectedFolderUrl', 0, ''); const credentials = await this.getCredentials('wiroApi'); const apiKey = credentials.apiKey; const apiSecret = credentials.apiSecret; const headers = (0, auth_1.generateWiroAuthHeaders)(apiKey, apiSecret); const response = await this.helpers.httpRequest({ method: 'POST', url: 'https://api.wiro.ai/v1/Run/wiro/train-flux-lora-portrait', headers: { ...headers, 'Content-Type': 'application/json', }, body: { trainModelName, triggerWord, trainingSteps, learningRate, selectedFolder, selectedFolderUrl, }, }); if (!(response === null || response === void 0 ? void 0 : response.taskid) || !(response === null || response === void 0 ? void 0 : response.socketaccesstoken)) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Wiro API did not return a valid task ID or socket access token ' + JSON.stringify(response), }); } const taskid = response.taskid; const socketaccesstoken = response.socketaccesstoken; const result = await polling_1.pollTaskUntilComplete.call(this, socketaccesstoken, headers); const responseJSON = { taskid: taskid, url: '', status: '', }; switch (result) { case '-1': case '-2': case '-3': case '-4': responseJSON.status = 'failed'; break; default: responseJSON.status = 'completed'; responseJSON.url = result !== null && result !== void 0 ? result : ''; } returnData.push({ json: responseJSON, }); return [returnData]; } } exports.TrainFluxLoraPortrait = TrainFluxLoraPortrait; //# sourceMappingURL=TrainFluxLoraPortrait.node.js.map