n8n-nodes-piapi
Version:
Community n8n nodes for PiAPI - integrate generative AI capabilities (image, video, audio, 3D) into your workflows
186 lines • 6.94 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DreamMachineTextToVideo = void 0;
const GenericFunctions_1 = require("../shared/GenericFunctions");
class DreamMachineTextToVideo {
constructor() {
this.description = {
displayName: 'PiAPI Dream Machine Text to Video',
name: 'dreamMachineTextToVideo',
icon: 'file:../piapi.svg',
group: ['transform'],
version: 1,
description: 'Generate videos using PiAPI Dream Machine Text-to-Video',
defaults: {
name: 'Dream Machine Text to Video',
},
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'piAPIApi',
required: true,
},
],
properties: [
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
typeOptions: {
rows: 4,
},
default: '',
required: true,
description: 'Descriptive prompt for video generation',
},
{
displayName: 'Model Name',
name: 'modelName',
type: 'options',
options: [
{
name: 'Ray v1',
value: 'ray-v1',
},
{
name: 'Ray v2',
value: 'ray-v2',
},
],
default: 'ray-v1',
description: 'The model to use for video generation',
},
{
displayName: 'Duration',
name: 'duration',
type: 'options',
options: [
{
name: '5 seconds',
value: 5,
},
{
name: '10 seconds',
value: 10,
description: 'Only available for text-to-video',
},
],
default: 5,
description: 'Duration of the generated video in seconds',
},
{
displayName: 'Aspect Ratio',
name: 'aspectRatio',
type: 'options',
options: [
{
name: 'Portrait (9:16)',
value: '9:16',
},
{
name: 'Portrait (3:4)',
value: '3:4',
},
{
name: 'Square (1:1)',
value: '1:1',
},
{
name: 'Landscape (4:3)',
value: '4:3',
},
{
name: 'Landscape (16:9)',
value: '16:9',
},
{
name: 'Cinematic (21:9)',
value: '21:9',
},
],
default: '16:9',
description: 'Aspect ratio of the generated video',
},
{
displayName: 'Service Mode',
name: 'serviceMode',
type: 'options',
options: [
{
name: 'Default (User Workspace Setting)',
value: '',
},
{
name: 'Pay-as-you-go (PAYG)',
value: 'public',
},
{
name: 'Host-your-account (HYA)',
value: 'private',
},
],
default: '',
description: 'The service mode for processing the task',
},
{
displayName: 'Wait for Completion',
name: 'waitForCompletion',
type: 'boolean',
default: false,
description: 'Wait for task to complete and return results',
},
],
};
}
async execute() {
var _a;
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
const prompt = this.getNodeParameter('prompt', i);
const modelName = this.getNodeParameter('modelName', i);
const duration = this.getNodeParameter('duration', i);
const aspectRatio = this.getNodeParameter('aspectRatio', i);
const serviceMode = this.getNodeParameter('serviceMode', i);
const waitForCompletion = this.getNodeParameter('waitForCompletion', i, true);
const body = {
model: 'luma',
task_type: 'video_generation',
input: {
prompt,
model_name: modelName,
duration,
aspect_ratio: aspectRatio,
},
config: {
service_mode: serviceMode,
},
};
try {
const response = await GenericFunctions_1.piApiRequest.call(this, 'POST', '/api/v1/task', body);
let taskResult = response;
if (waitForCompletion && ((_a = response.data) === null || _a === void 0 ? void 0 : _a.task_id)) {
taskResult = await GenericFunctions_1.waitForTaskCompletion.call(this, response.data.task_id);
}
returnData.push({
json: taskResult,
});
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
});
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.DreamMachineTextToVideo = DreamMachineTextToVideo;
//# sourceMappingURL=DreamMachineTextToVideo.node.js.map
;