UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI's Generative AI APIs.

111 lines 4.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenerateBackgroundMusic = void 0; const n8n_workflow_1 = require("n8n-workflow"); const auth_1 = require("../utils/auth"); const polling_1 = require("../utils/polling"); class GenerateBackgroundMusic { constructor() { this.description = { displayName: 'Wiro - Generate Background Music', name: 'generateBackgroundMusic', icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' }, group: ['transform'], version: 1, description: 'Generates background music using AI', defaults: { name: 'Wiro - Generate Background Music', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'wiroApi', required: true, }, ], properties: [ { displayName: 'Prompt', name: 'prompt', type: 'string', default: 'Sad and longing. The melody is slow and wistful creating a sense of melancholy and nostalgia. Simple arrangement on the piano.', required: true, description: 'Enter a style, genre, or mood to guide the music generation', }, { displayName: 'Tokens', name: 'tokens', type: 'string', default: '1024', required: true, description: 'Max number of tokens to generate', }, { displayName: 'Scale', name: 'scale', type: 'string', default: '3', required: true, description: 'Scale for classifier-free guidance', }, ], }; } async execute() { const returnData = []; const prompt = this.getNodeParameter('prompt', 0); const tokens = this.getNodeParameter('tokens', 0); const scale = this.getNodeParameter('scale', 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.request({ method: 'POST', url: 'https://api.wiro.ai/v1/Run/wiro/music_gen', headers: { ...headers, 'Content-Type': 'application/json', }, body: { prompt, tokens, scale, }, json: true, }); 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.GenerateBackgroundMusic = GenerateBackgroundMusic; //# sourceMappingURL=GenerateBackgroundMusic.node.js.map