@n8n/n8n-nodes-langchain
Version:

190 lines • 6.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../../helpers/utils");
const transport_1 = require("../../transport");
const descriptions_1 = require("../descriptions");
const properties = [
(0, descriptions_1.modelRLC)('videoGenerationModelSearch'),
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
placeholder: 'e.g. Panning wide shot of a calico kitten sleeping in the sunshine',
description: 'A text description of the desired video',
default: '',
typeOptions: {
rows: 2,
},
},
{
displayName: 'Return As',
name: 'returnAs',
type: 'options',
options: [
{
name: 'Video',
value: 'video',
},
{
name: 'URL',
value: 'url',
},
],
description: 'Whether to return the video as a binary file or a URL that can be used to download the video later',
default: 'video',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Number of Videos',
name: 'sampleCount',
type: 'number',
default: 1,
description: 'How many videos to generate',
typeOptions: {
minValue: 1,
maxValue: 4,
},
},
{
displayName: 'Duration (Seconds)',
name: 'durationSeconds',
type: 'number',
default: 8,
description: 'Length of the generated video in seconds. Supported only by certain models.',
typeOptions: {
minValue: 5,
maxValue: 8,
},
},
{
displayName: 'Aspect Ratio',
name: 'aspectRatio',
type: 'options',
options: [
{
name: 'Widescreen (16:9)',
value: '16:9',
description: 'Most common aspect ratio for televisions and monitors',
},
{
name: 'Portrait (9:16)',
value: '9:16',
description: 'Popular for short-form videos like YouTube Shorts',
},
],
default: '16:9',
},
{
displayName: 'Person Generation',
name: 'personGeneration',
type: 'options',
options: [
{
name: "Don't Allow",
value: 'dont_allow',
description: 'Prevent generation of people in the video',
},
{
name: 'Allow Adult',
value: 'allow_adult',
description: 'Allow generation of adult people in the video',
},
{
name: 'Allow All',
value: 'allow_all',
description: 'Allow generation of all people in the video',
},
],
default: 'dont_allow',
},
{
displayName: 'Put Output in Field',
name: 'binaryPropertyOutput',
type: 'string',
default: 'data',
hint: 'The name of the output field to put the binary file data in',
},
],
},
];
const displayOptions = {
show: {
operation: ['generate'],
resource: ['video'],
},
};
exports.description = (0, n8n_workflow_1.updateDisplayOptions)(displayOptions, properties);
async function execute(i) {
const model = this.getNodeParameter('modelId', i, '', { extractValue: true });
const prompt = this.getNodeParameter('prompt', i, '');
const returnAs = this.getNodeParameter('returnAs', i, 'video');
const options = this.getNodeParameter('options', i, {});
const binaryPropertyOutput = this.getNodeParameter('options.binaryPropertyOutput', i, 'data');
const credentials = await this.getCredentials('googlePalmApi');
if (!model.includes('veo')) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Model ${model} is not supported for video generation. Please use a Veo model`, {
description: 'Video generation is only supported by Veo models',
});
}
const body = {
instances: [
{
prompt,
},
],
parameters: {
aspectRatio: options.aspectRatio,
personGeneration: options.personGeneration,
sampleCount: options.sampleCount ?? 1,
durationSeconds: options.durationSeconds,
},
};
let response = (await transport_1.apiRequest.call(this, 'POST', `/v1beta/${model}:predictLongRunning`, {
body,
}));
while (!response.done) {
await new Promise((resolve) => setTimeout(resolve, 5000));
response = (await transport_1.apiRequest.call(this, 'GET', `/v1beta/${response.name}`));
}
if (response.error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), response.error.message, {
description: 'Error generating video',
});
}
if (returnAs === 'video') {
const promises = response.response.generateVideoResponse.generatedSamples.map(async (sample) => {
const { fileContent, mimeType } = await utils_1.downloadFile.call(this, sample.video.uri, 'video/mp4', {
key: credentials.apiKey,
});
const fileName = (0, utils_1.getFilenameFromMimeType)(mimeType, 'video', 'mp4');
const binaryData = await this.helpers.prepareBinaryData(fileContent, fileName, mimeType);
return {
binary: { [binaryPropertyOutput]: binaryData },
json: {
...binaryData,
data: undefined,
},
pairedItem: { item: i },
};
});
return await Promise.all(promises);
}
else {
return response.response.generateVideoResponse.generatedSamples.map((sample) => ({
json: {
url: sample.video.uri,
},
pairedItem: { item: i },
}));
}
}
//# sourceMappingURL=generate.operation.js.map