diff --git a/google/genai/models.py b/google/genai/models.py index 3e34a0bf0..bd1c73853 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -21,7 +21,6 @@ import logging from typing import Any, AsyncIterator, Awaitable, Iterator, Optional, Union from urllib.parse import urlencode -import warnings from . import _api_module from . import _base_transformers as base_t @@ -2561,23 +2560,6 @@ def _GenerateVideosParameters_to_mldev( t.t_model(api_client, getv(from_object, ['model'])), ) - if getv(from_object, ['prompt']) is not None: - setv(to_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])) - - if getv(from_object, ['image']) is not None: - setv( - to_object, - ['instances[0]', 'image'], - _Image_to_mldev(getv(from_object, ['image']), to_object, root_object), - ) - - if getv(from_object, ['video']) is not None: - setv( - to_object, - ['instances[0]', 'video'], - _Video_to_mldev(getv(from_object, ['video']), to_object, root_object), - ) - if getv(from_object, ['source']) is not None: _GenerateVideosSource_to_mldev( getv(from_object, ['source']), to_object, root_object @@ -2605,23 +2587,6 @@ def _GenerateVideosParameters_to_vertex( t.t_model(api_client, getv(from_object, ['model'])), ) - if getv(from_object, ['prompt']) is not None: - setv(to_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])) - - if getv(from_object, ['image']) is not None: - setv( - to_object, - ['instances[0]', 'image'], - _Image_to_vertex(getv(from_object, ['image']), to_object, root_object), - ) - - if getv(from_object, ['video']) is not None: - setv( - to_object, - ['instances[0]', 'video'], - _Video_to_vertex(getv(from_object, ['video']), to_object, root_object), - ) - if getv(from_object, ['source']) is not None: _GenerateVideosSource_to_vertex( getv(from_object, ['source']), to_object, root_object @@ -6313,19 +6278,13 @@ def _generate_videos( self, *, model: str, - prompt: Optional[str] = None, - image: Optional[types.ImageOrDict] = None, - video: Optional[types.VideoOrDict] = None, - source: Optional[types.GenerateVideosSourceOrDict] = None, + source: types.GenerateVideosSourceOrDict, config: Optional[types.GenerateVideosConfigOrDict] = None, ) -> types.GenerateVideosOperation: """Private method for generating videos.""" parameter_model = types._GenerateVideosParameters( model=model, - prompt=prompt, - image=image, - video=video, source=source, config=config, ) @@ -7049,10 +7008,7 @@ def generate_videos( self, *, model: str, - prompt: Optional[str] = None, - image: Optional[types.ImageOrDict] = None, - video: Optional[types.VideoOrDict] = None, - source: Optional[types.GenerateVideosSourceOrDict] = None, + source: types.GenerateVideosSourceOrDict, config: Optional[types.GenerateVideosConfigOrDict] = None, ) -> types.GenerateVideosOperation: """Generates videos based on an input (text, image, or video) and configuration. @@ -7066,14 +7022,6 @@ def generate_videos( Args: model: The model to use. - prompt: The text prompt for generating the videos. Optional for image to - video and video extension use cases. This argument is deprecated, please - use source instead. - image: The input image for generating the videos. Optional if prompt is - provided. This argument is deprecated, please use source instead. - video: The input video for video extension use cases. Optional if prompt - or image is provided. This argument is deprecated, please use source - instead. source: The input source for generating the videos (prompt, image, and/or video) config: Configuration for generation. @@ -7094,34 +7042,9 @@ def generate_videos( operation.response.generated_videos[0].video.uri ``` """ - if prompt or image or video: - if source: - raise ValueError( - 'Source and prompt/image/video are mutually exclusive.' - + ' Please only use source.' - ) - if not Models._logged_generate_videos_deprecation_warning: - warnings.warn( - 'The generate_videos method with prompt/image/video arguments is' - ' deprecated and will be removed in a future major release (not' - ' before 2026-07-31). Please use the source argument instead.', - DeprecationWarning, - stacklevel=2, - ) - Models._logged_generate_videos_deprecation_warning = True # Gemini Developer API does not support video bytes. video_dct: dict[str, Any] = {} - if not self._api_client.vertexai and video: - if isinstance(video, types.Video): - video_dct = video.model_dump() - else: - video_dct = dict(video) - - if video_dct.get('uri') and video_dct.get('video_bytes'): - video = types.Video( - uri=video_dct.get('uri'), mime_type=video_dct.get('mime_type') - ) - elif not self._api_client.vertexai and source: + if not self._api_client.vertexai and source: if isinstance(source, types.GenerateVideosSource): source_dct = source.model_dump() video_dct = source_dct.get('video', {}) @@ -7141,9 +7064,6 @@ def generate_videos( ) return self._generate_videos( model=model, - prompt=prompt, - image=image, - video=video, source=source, config=config, ) @@ -8549,19 +8469,13 @@ async def _generate_videos( self, *, model: str, - prompt: Optional[str] = None, - image: Optional[types.ImageOrDict] = None, - video: Optional[types.VideoOrDict] = None, - source: Optional[types.GenerateVideosSourceOrDict] = None, + source: types.GenerateVideosSourceOrDict, config: Optional[types.GenerateVideosConfigOrDict] = None, ) -> types.GenerateVideosOperation: """Private method for generating videos asynchronously.""" parameter_model = types._GenerateVideosParameters( model=model, - prompt=prompt, - image=image, - video=video, source=source, config=config, ) @@ -9403,10 +9317,7 @@ async def generate_videos( self, *, model: str, - prompt: Optional[str] = None, - image: Optional[types.ImageOrDict] = None, - video: Optional[types.VideoOrDict] = None, - source: Optional[types.GenerateVideosSourceOrDict] = None, + source: types.GenerateVideosSourceOrDict, config: Optional[types.GenerateVideosConfigOrDict] = None, ) -> types.GenerateVideosOperation: """Generates videos based on an input (text, image, or video) and configuration. @@ -9420,14 +9331,6 @@ async def generate_videos( Args: model: The model to use. - prompt: The text prompt for generating the videos. Optional for image to - video and video extension use cases. This argument is deprecated, please - use source instead. - image: The input image for generating the videos. Optional if prompt is - provided. This argument is deprecated, please use source instead. - video: The input video for video extension use cases. Optional if prompt - or image is provided. This argument is deprecated, please use source - instead. source: The input source for generating the videos (prompt, image, and/or video) config: Configuration for generation. @@ -9448,34 +9351,9 @@ async def generate_videos( operation.result.generated_videos[0].video.uri ``` """ - if prompt or image or video: - if source: - raise ValueError( - 'Source and prompt/image/video are mutually exclusive.' - + ' Please only use source.' - ) - if not AsyncModels._logged_generate_videos_deprecation_warning: - warnings.warn( - 'The generate_videos method with prompt/image/video arguments is' - ' deprecated and will be removed in a future major release (not' - ' before 2026-07-31). Please use the source argument instead.', - DeprecationWarning, - stacklevel=2, - ) - AsyncModels._logged_generate_videos_deprecation_warning = True # Gemini Developer API does not support video bytes. video_dct: dict[str, Any] = {} - if not self._api_client.vertexai and video: - if isinstance(video, types.Video): - video_dct = video.model_dump() - else: - video_dct = dict(video) - - if video_dct.get('uri') and video_dct.get('video_bytes'): - video = types.Video( - uri=video_dct.get('uri'), mime_type=video_dct.get('mime_type') - ) - elif not self._api_client.vertexai and source: + if not self._api_client.vertexai and source: if isinstance(source, types.GenerateVideosSource): source_dct = source.model_dump() video_dct = source_dct.get('video', {}) @@ -9495,9 +9373,6 @@ async def generate_videos( ) return await self._generate_videos( model=model, - prompt=prompt, - image=image, - video=video, source=source, config=config, ) diff --git a/google/genai/tests/models/test_generate_videos.py b/google/genai/tests/models/test_generate_videos.py index aa8a9b647..4f136aceb 100644 --- a/google/genai/tests/models/test_generate_videos.py +++ b/google/genai/tests/models/test_generate_videos.py @@ -76,18 +76,13 @@ test_table: list[pytest_helper.TestTableItem] = [ - pytest_helper.TestTableItem( - name="test_simple_prompt", - parameters=types._GenerateVideosParameters( - model=VEO_MODEL_LATEST, - prompt="Man with a dog", - ), - ), pytest_helper.TestTableItem( name="test_all_parameters_vertex", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST, - prompt="A neon hologram of a cat driving at top speed", + source=types.GenerateVideosSource( + prompt="A neon hologram of a cat driving at top speed", + ), config=types.GenerateVideosConfig( number_of_videos=1, output_gcs_uri=OUTPUT_GCS_URI, @@ -206,7 +201,9 @@ name="test_all_parameters_mldev", parameters=types._GenerateVideosParameters( model=VEO_MODEL_2, - prompt="A neon hologram of a cat driving at top speed", + source=types.GenerateVideosSource( + prompt="A neon hologram of a cat driving at top speed", + ), config=types.GenerateVideosConfig( number_of_videos=1, duration_seconds=6, @@ -221,7 +218,9 @@ name="test_all_parameters_veo3_mldev", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST, - prompt="A neon hologram of a cat driving at top speed", + source=types.GenerateVideosSource( + prompt="A neon hologram of a cat driving at top speed", + ), config=types.GenerateVideosConfig( number_of_videos=1, aspect_ratio="16:9", @@ -234,7 +233,9 @@ name="test_reference_to_video", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST, - prompt="Rain", + source=types.GenerateVideosSource( + prompt="Rain", + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI, reference_images=[ @@ -253,7 +254,9 @@ name="test_with_webhook_config", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST, - prompt="Man with a dog", + source=types.GenerateVideosSource( + prompt="Man with a dog", + ), config=types.GenerateVideosConfig( number_of_videos=1, webhook_config=types.WebhookConfig( @@ -270,7 +273,9 @@ name="test_with_webhook_config_dict", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST, - prompt="Man with a dog", + source=types.GenerateVideosSource( + prompt="Man with a dog", + ), config={ "number_of_videos": 1, "webhook_config": { @@ -295,7 +300,9 @@ def test_text_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="A neon hologram of a cat driving at top speed", + source=types.GenerateVideosSource( + prompt="A neon hologram of a cat driving at top speed", + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, ), @@ -312,7 +319,9 @@ def test_text_to_video_poll(client): def test_image_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_LATEST, - image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE, + source=types.GenerateVideosSource( + image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE, + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, ), @@ -329,8 +338,10 @@ def test_image_to_video_poll(client): def test_text_and_image_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Lightning storm", - image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE, + source=types.GenerateVideosSource( + prompt="Lightning storm", + image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE, + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, resize_mode=(types.ImageResizeMode.CROP @@ -353,9 +364,11 @@ def test_video_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_2, - video=types.Video( - uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4", - mime_type="video/mp4", + source=types.GenerateVideosSource( + video=types.Video( + uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4", + mime_type="video/mp4", + ), ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI, @@ -377,10 +390,12 @@ def test_text_and_video_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_2, - prompt="Rain", - video=types.Video( - uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4", - mime_type="video/mp4", + source=types.GenerateVideosSource( + prompt="Rain", + video=types.Video( + uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4", + mime_type="video/mp4", + ), ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI, @@ -394,50 +409,6 @@ def test_text_and_video_to_video_poll(client): assert operation.result.generated_videos[0].video.uri - -def test_generated_video_extension_poll(client): - # Gemini API only supports video extension on generated videos. - if client.vertexai: - return - - operation1 = client.models.generate_videos( - model=VEO_MODEL_LATEST, - prompt="Rain", - config=types.GenerateVideosConfig( - number_of_videos=1, - ), - ) - while not operation1.done: - # Skip the sleep when in replay mode. - if client._api_client._mode not in ("replay", "auto"): - time.sleep(20) - operation1 = client.operations.get(operation=operation1) - - video1 = operation1.result.generated_videos[0].video - assert video1.uri - client.files.download(file=video1) - assert video1.video_bytes - - operation2 = client.models.generate_videos( - model=VEO_MODEL_LATEST, - prompt="Sun", - video=video1, - config=types.GenerateVideosConfig( - number_of_videos=1, - ), - ) - while not operation2.done: - # Skip the sleep when in replay mode. - if client._api_client._mode not in ("replay", "auto"): - time.sleep(20) - operation2 = client.operations.get(operation=operation2) - - video2 = operation2.result.generated_videos[0].video - assert video2.uri - client.files.download(file=video2) - assert video2.video_bytes - - def test_generated_video_extension_from_source_poll(client): # Gemini API only supports video extension on generated videos. if client.vertexai: @@ -445,7 +416,9 @@ def test_generated_video_extension_from_source_poll(client): operation1 = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Rain", + source=types.GenerateVideosSource( + prompt="Rain", + ), config=types.GenerateVideosConfig( number_of_videos=1, ), @@ -490,7 +463,9 @@ def test_generated_video_extension_from_source_dict_poll(client): operation1 = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Rain", + source=types.GenerateVideosSource( + prompt="Rain", + ), config=types.GenerateVideosConfig( number_of_videos=1, ), @@ -508,10 +483,10 @@ def test_generated_video_extension_from_source_dict_poll(client): operation2 = client.models.generate_videos( model=VEO_MODEL_LATEST, - source={ - "prompt": "Sun", - "video": video1, - }, + source=types.GenerateVideosSource( + prompt="Sun", + video=video1, + ), config=types.GenerateVideosConfig( number_of_videos=1, ), @@ -531,8 +506,10 @@ def test_generated_video_extension_from_source_dict_poll(client): def test_image_to_video_frame_interpolation_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Rain", - image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE_MAN, + source=types.GenerateVideosSource( + prompt="Rain", + image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE_MAN, + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, last_frame=GCS_IMAGE2 if client.vertexai else LOCAL_IMAGE_DOG, @@ -550,7 +527,9 @@ def test_image_to_video_frame_interpolation_poll(client): def test_reference_images_to_video_poll(client): operation = client.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Chirping birds in a colorful forest", + source=types.GenerateVideosSource( + prompt="Chirping birds in a colorful forest" + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, reference_images=[ @@ -719,20 +698,13 @@ def test_create_operation_to_poll(client): assert operation.result.generated_videos[0].video.uri -def test_source_and_prompt_raises(client): - with pytest.raises(ValueError): - client.models.generate_videos( - model=VEO_MODEL_LATEST, - prompt="Prompt 1", - source=types.GenerateVideosSource(prompt="Prompt 2"), - ) - - @pytest.mark.asyncio async def test_text_to_video_poll_async(client): operation = await client.aio.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="A neon hologram of a cat driving at top speed", + source=types.GenerateVideosSource( + prompt="A neon hologram of a cat driving at top speed", + ), config=types.GenerateVideosConfig( output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None, ), @@ -754,7 +726,9 @@ async def test_generated_video_extension_from_source_poll_async(client): operation1 = await client.aio.models.generate_videos( model=VEO_MODEL_LATEST, - prompt="Rain", + source=types.GenerateVideosSource( + prompt="Rain", + ), config=types.GenerateVideosConfig( number_of_videos=1, ), diff --git a/google/genai/tests/shared/models/test_generate_videos.py b/google/genai/tests/shared/models/test_generate_videos.py index 73c789884..c0a04e24b 100644 --- a/google/genai/tests/shared/models/test_generate_videos.py +++ b/google/genai/tests/shared/models/test_generate_videos.py @@ -27,7 +27,9 @@ name="test_simple_prompt_vertex", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST_VERTEX, - prompt="Man with a dog", + source=types.GenerateVideosSource( + prompt="Man with a dog", + ), config=types.GenerateVideosConfig( http_options=types.HttpOptions( retry_options=types.HttpRetryOptions( @@ -46,7 +48,9 @@ name="test_simple_prompt_gemini", parameters=types._GenerateVideosParameters( model=VEO_MODEL_LATEST_GEMINI, - prompt="Man with a dog", + source=types.GenerateVideosSource( + prompt="Man with a dog", + ), config=types.GenerateVideosConfig( http_options=types.HttpOptions( retry_options=types.HttpRetryOptions( diff --git a/google/genai/types.py b/google/genai/types.py index 359c00d45..dca5459fa 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -12168,21 +12168,6 @@ class _GenerateVideosParameters(_common.BaseModel): description="""ID of the model to use. For a list of models, see `Google models `_.""", ) - prompt: Optional[str] = Field( - default=None, - description="""The text prompt for generating the videos. - Optional if image or video is provided.""", - ) - image: Optional[Image] = Field( - default=None, - description="""The input image for generating the videos. - Optional if prompt is provided. Not allowed if video is provided.""", - ) - video: Optional[Video] = Field( - default=None, - description="""The input video for video extension use cases. - Optional if prompt is provided. Not allowed if image is provided.""", - ) source: Optional[GenerateVideosSource] = Field( default=None, description="""A set of source input(s) for video generation.""", @@ -12199,18 +12184,6 @@ class _GenerateVideosParametersDict(TypedDict, total=False): """ID of the model to use. For a list of models, see `Google models `_.""" - prompt: Optional[str] - """The text prompt for generating the videos. - Optional if image or video is provided.""" - - image: Optional[ImageDict] - """The input image for generating the videos. - Optional if prompt is provided. Not allowed if video is provided.""" - - video: Optional[VideoDict] - """The input video for video extension use cases. - Optional if prompt is provided. Not allowed if image is provided.""" - source: Optional[GenerateVideosSourceDict] """A set of source input(s) for video generation."""