fix(Google Gemini Node): Don't pass hardcoded value for durationSeconds when generating a video (#17793)

Co-authored-by: Shireen Missi <shireen@n8n.io>
This commit is contained in:
RomanDavydchuk
2025-07-31 17:20:08 +03:00
committed by GitHub
parent 1d31e6a0c4
commit 460e3b1dfd
2 changed files with 69 additions and 4 deletions

View File

@@ -1,9 +1,8 @@
import * as helpers from '@utils/helpers';
import { mockDeep } from 'jest-mock-extended';
import type { IExecuteFunctions, IBinaryData, INode } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import * as helpers from '@utils/helpers';
import * as audio from './actions/audio';
import * as file from './actions/file';
import * as image from './actions/image';
@@ -1008,6 +1007,72 @@ describe('GoogleGemini Node', () => {
});
});
it('should not pass durationSeconds if not provided', async () => {
executeFunctionsMock.getNodeParameter.mockImplementation((parameter: string) => {
switch (parameter) {
case 'modelId':
return 'models/veo-3.0-generate-002';
case 'prompt':
return 'Panning wide shot of a calico kitten sleeping in the sunshine';
case 'options':
return {
aspectRatio: '16:9',
personGeneration: 'dont_allow',
sampleCount: 1,
};
case 'returnAs':
return 'url';
default:
return undefined;
}
});
executeFunctionsMock.getCredentials.mockResolvedValue({ apiKey: 'test-api-key' });
apiRequestMock.mockResolvedValue({
name: 'operations/123',
done: true,
response: {
generateVideoResponse: {
generatedSamples: [
{
video: {
uri: 'https://example.com/video.mp4',
},
},
],
},
},
});
const result = await video.generate.execute.call(executeFunctionsMock, 0);
expect(result).toEqual([
{
json: {
url: 'https://example.com/video.mp4',
},
pairedItem: { item: 0 },
},
]);
expect(apiRequestMock).toHaveBeenCalledWith(
'POST',
'/v1beta/models/veo-3.0-generate-002:predictLongRunning',
{
body: {
instances: [
{
prompt: 'Panning wide shot of a calico kitten sleeping in the sunshine',
},
],
parameters: {
aspectRatio: '16:9',
personGeneration: 'dont_allow',
sampleCount: 1,
},
},
},
);
});
it('should handle errors from video generation', async () => {
executeFunctionsMock.getNodeParameter.mockImplementation((parameter: string) => {
switch (parameter) {

View File

@@ -60,7 +60,7 @@ const properties: INodeProperties[] = [
name: 'durationSeconds',
type: 'number',
default: 8,
description: 'Length of the generated video in seconds',
description: 'Length of the generated video in seconds. Supported only by certain models.',
typeOptions: {
minValue: 5,
maxValue: 8,
@@ -159,7 +159,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
aspectRatio: options.aspectRatio,
personGeneration: options.personGeneration,
sampleCount: options.sampleCount ?? 1,
durationSeconds: options.durationSeconds ?? 8,
durationSeconds: options.durationSeconds,
},
};
let response = (await apiRequest.call(this, 'POST', `/v1beta/${model}:predictLongRunning`, {