google-genai 1.53.0__py3-none-any.whl → 1.55.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/__init__.py +1 -0
- google/genai/_api_client.py +6 -6
- google/genai/_interactions/__init__.py +117 -0
- google/genai/_interactions/_base_client.py +2019 -0
- google/genai/_interactions/_client.py +511 -0
- google/genai/_interactions/_compat.py +234 -0
- google/genai/_interactions/_constants.py +29 -0
- google/genai/_interactions/_exceptions.py +122 -0
- google/genai/_interactions/_files.py +139 -0
- google/genai/_interactions/_models.py +873 -0
- google/genai/_interactions/_qs.py +165 -0
- google/genai/_interactions/_resource.py +58 -0
- google/genai/_interactions/_response.py +847 -0
- google/genai/_interactions/_streaming.py +354 -0
- google/genai/_interactions/_types.py +276 -0
- google/genai/_interactions/_utils/__init__.py +79 -0
- google/genai/_interactions/_utils/_compat.py +61 -0
- google/genai/_interactions/_utils/_datetime_parse.py +151 -0
- google/genai/_interactions/_utils/_logs.py +40 -0
- google/genai/_interactions/_utils/_proxy.py +80 -0
- google/genai/_interactions/_utils/_reflection.py +57 -0
- google/genai/_interactions/_utils/_resources_proxy.py +39 -0
- google/genai/_interactions/_utils/_streams.py +27 -0
- google/genai/_interactions/_utils/_sync.py +73 -0
- google/genai/_interactions/_utils/_transform.py +472 -0
- google/genai/_interactions/_utils/_typing.py +172 -0
- google/genai/_interactions/_utils/_utils.py +437 -0
- google/genai/_interactions/_version.py +18 -0
- google/genai/_interactions/resources/__init__.py +34 -0
- google/genai/_interactions/resources/interactions.py +1350 -0
- google/genai/_interactions/types/__init__.py +107 -0
- google/genai/_interactions/types/allowed_tools.py +33 -0
- google/genai/_interactions/types/allowed_tools_param.py +35 -0
- google/genai/_interactions/types/annotation.py +42 -0
- google/genai/_interactions/types/annotation_param.py +42 -0
- google/genai/_interactions/types/audio_content.py +38 -0
- google/genai/_interactions/types/audio_content_param.py +45 -0
- google/genai/_interactions/types/audio_mime_type.py +25 -0
- google/genai/_interactions/types/audio_mime_type_param.py +27 -0
- google/genai/_interactions/types/code_execution_call_arguments.py +33 -0
- google/genai/_interactions/types/code_execution_call_arguments_param.py +32 -0
- google/genai/_interactions/types/code_execution_call_content.py +37 -0
- google/genai/_interactions/types/code_execution_call_content_param.py +37 -0
- google/genai/_interactions/types/code_execution_result_content.py +42 -0
- google/genai/_interactions/types/code_execution_result_content_param.py +41 -0
- google/genai/_interactions/types/content_delta.py +358 -0
- google/genai/_interactions/types/content_start.py +79 -0
- google/genai/_interactions/types/content_stop.py +35 -0
- google/genai/_interactions/types/deep_research_agent_config.py +33 -0
- google/genai/_interactions/types/deep_research_agent_config_param.py +32 -0
- google/genai/_interactions/types/document_content.py +36 -0
- google/genai/_interactions/types/document_content_param.py +43 -0
- google/genai/_interactions/types/dynamic_agent_config.py +44 -0
- google/genai/_interactions/types/dynamic_agent_config_param.py +33 -0
- google/genai/_interactions/types/error_event.py +46 -0
- google/genai/_interactions/types/file_search_result_content.py +46 -0
- google/genai/_interactions/types/file_search_result_content_param.py +46 -0
- google/genai/_interactions/types/function.py +38 -0
- google/genai/_interactions/types/function_call_content.py +39 -0
- google/genai/_interactions/types/function_call_content_param.py +39 -0
- google/genai/_interactions/types/function_param.py +37 -0
- google/genai/_interactions/types/function_result_content.py +52 -0
- google/genai/_interactions/types/function_result_content_param.py +54 -0
- google/genai/_interactions/types/generation_config.py +57 -0
- google/genai/_interactions/types/generation_config_param.py +59 -0
- google/genai/_interactions/types/google_search_call_arguments.py +29 -0
- google/genai/_interactions/types/google_search_call_arguments_param.py +31 -0
- google/genai/_interactions/types/google_search_call_content.py +37 -0
- google/genai/_interactions/types/google_search_call_content_param.py +37 -0
- google/genai/_interactions/types/google_search_result.py +35 -0
- google/genai/_interactions/types/google_search_result_content.py +43 -0
- google/genai/_interactions/types/google_search_result_content_param.py +44 -0
- google/genai/_interactions/types/google_search_result_param.py +35 -0
- google/genai/_interactions/types/image_content.py +41 -0
- google/genai/_interactions/types/image_content_param.py +48 -0
- google/genai/_interactions/types/image_mime_type.py +23 -0
- google/genai/_interactions/types/image_mime_type_param.py +25 -0
- google/genai/_interactions/types/interaction.py +165 -0
- google/genai/_interactions/types/interaction_create_params.py +212 -0
- google/genai/_interactions/types/interaction_event.py +37 -0
- google/genai/_interactions/types/interaction_get_params.py +46 -0
- google/genai/_interactions/types/interaction_sse_event.py +32 -0
- google/genai/_interactions/types/interaction_status_update.py +37 -0
- google/genai/_interactions/types/mcp_server_tool_call_content.py +42 -0
- google/genai/_interactions/types/mcp_server_tool_call_content_param.py +42 -0
- google/genai/_interactions/types/mcp_server_tool_result_content.py +52 -0
- google/genai/_interactions/types/mcp_server_tool_result_content_param.py +54 -0
- google/genai/_interactions/types/model.py +36 -0
- google/genai/_interactions/types/model_param.py +38 -0
- google/genai/_interactions/types/speech_config.py +35 -0
- google/genai/_interactions/types/speech_config_param.py +35 -0
- google/genai/_interactions/types/text_content.py +37 -0
- google/genai/_interactions/types/text_content_param.py +38 -0
- google/genai/_interactions/types/thinking_level.py +22 -0
- google/genai/_interactions/types/thought_content.py +41 -0
- google/genai/_interactions/types/thought_content_param.py +47 -0
- google/genai/_interactions/types/tool.py +100 -0
- google/genai/_interactions/types/tool_choice.py +26 -0
- google/genai/_interactions/types/tool_choice_config.py +28 -0
- google/genai/_interactions/types/tool_choice_config_param.py +29 -0
- google/genai/_interactions/types/tool_choice_param.py +28 -0
- google/genai/_interactions/types/tool_choice_type.py +22 -0
- google/genai/_interactions/types/tool_param.py +97 -0
- google/genai/_interactions/types/turn.py +76 -0
- google/genai/_interactions/types/turn_param.py +73 -0
- google/genai/_interactions/types/url_context_call_arguments.py +29 -0
- google/genai/_interactions/types/url_context_call_arguments_param.py +31 -0
- google/genai/_interactions/types/url_context_call_content.py +37 -0
- google/genai/_interactions/types/url_context_call_content_param.py +37 -0
- google/genai/_interactions/types/url_context_result.py +33 -0
- google/genai/_interactions/types/url_context_result_content.py +43 -0
- google/genai/_interactions/types/url_context_result_content_param.py +44 -0
- google/genai/_interactions/types/url_context_result_param.py +32 -0
- google/genai/_interactions/types/usage.py +106 -0
- google/genai/_interactions/types/usage_param.py +106 -0
- google/genai/_interactions/types/video_content.py +41 -0
- google/genai/_interactions/types/video_content_param.py +48 -0
- google/genai/_interactions/types/video_mime_type.py +36 -0
- google/genai/_interactions/types/video_mime_type_param.py +38 -0
- google/genai/_live_converters.py +34 -3
- google/genai/_tokens_converters.py +5 -0
- google/genai/batches.py +62 -55
- google/genai/client.py +223 -0
- google/genai/errors.py +16 -1
- google/genai/file_search_stores.py +60 -60
- google/genai/files.py +56 -56
- google/genai/interactions.py +17 -0
- google/genai/live.py +4 -3
- google/genai/models.py +15 -3
- google/genai/tests/__init__.py +21 -0
- google/genai/tests/afc/__init__.py +21 -0
- google/genai/tests/afc/test_convert_if_exist_pydantic_model.py +309 -0
- google/genai/tests/afc/test_convert_number_values_for_function_call_args.py +63 -0
- google/genai/tests/afc/test_find_afc_incompatible_tool_indexes.py +240 -0
- google/genai/tests/afc/test_generate_content_stream_afc.py +530 -0
- google/genai/tests/afc/test_generate_content_stream_afc_thoughts.py +77 -0
- google/genai/tests/afc/test_get_function_map.py +176 -0
- google/genai/tests/afc/test_get_function_response_parts.py +277 -0
- google/genai/tests/afc/test_get_max_remote_calls_for_afc.py +130 -0
- google/genai/tests/afc/test_invoke_function_from_dict_args.py +241 -0
- google/genai/tests/afc/test_raise_error_for_afc_incompatible_config.py +159 -0
- google/genai/tests/afc/test_should_append_afc_history.py +53 -0
- google/genai/tests/afc/test_should_disable_afc.py +214 -0
- google/genai/tests/batches/__init__.py +17 -0
- google/genai/tests/batches/test_cancel.py +77 -0
- google/genai/tests/batches/test_create.py +78 -0
- google/genai/tests/batches/test_create_with_bigquery.py +113 -0
- google/genai/tests/batches/test_create_with_file.py +82 -0
- google/genai/tests/batches/test_create_with_gcs.py +125 -0
- google/genai/tests/batches/test_create_with_inlined_requests.py +255 -0
- google/genai/tests/batches/test_delete.py +86 -0
- google/genai/tests/batches/test_embedding.py +157 -0
- google/genai/tests/batches/test_get.py +78 -0
- google/genai/tests/batches/test_list.py +79 -0
- google/genai/tests/caches/__init__.py +17 -0
- google/genai/tests/caches/constants.py +29 -0
- google/genai/tests/caches/test_create.py +210 -0
- google/genai/tests/caches/test_create_custom_url.py +105 -0
- google/genai/tests/caches/test_delete.py +54 -0
- google/genai/tests/caches/test_delete_custom_url.py +52 -0
- google/genai/tests/caches/test_get.py +94 -0
- google/genai/tests/caches/test_get_custom_url.py +52 -0
- google/genai/tests/caches/test_list.py +68 -0
- google/genai/tests/caches/test_update.py +70 -0
- google/genai/tests/caches/test_update_custom_url.py +58 -0
- google/genai/tests/chats/__init__.py +1 -0
- google/genai/tests/chats/test_get_history.py +597 -0
- google/genai/tests/chats/test_send_message.py +844 -0
- google/genai/tests/chats/test_validate_response.py +90 -0
- google/genai/tests/client/__init__.py +17 -0
- google/genai/tests/client/test_async_stream.py +427 -0
- google/genai/tests/client/test_client_close.py +197 -0
- google/genai/tests/client/test_client_initialization.py +1687 -0
- google/genai/tests/client/test_client_requests.py +355 -0
- google/genai/tests/client/test_custom_client.py +77 -0
- google/genai/tests/client/test_http_options.py +178 -0
- google/genai/tests/client/test_replay_client_equality.py +168 -0
- google/genai/tests/client/test_retries.py +846 -0
- google/genai/tests/client/test_upload_errors.py +136 -0
- google/genai/tests/common/__init__.py +17 -0
- google/genai/tests/common/test_common.py +954 -0
- google/genai/tests/conftest.py +162 -0
- google/genai/tests/documents/__init__.py +17 -0
- google/genai/tests/documents/test_delete.py +51 -0
- google/genai/tests/documents/test_get.py +85 -0
- google/genai/tests/documents/test_list.py +72 -0
- google/genai/tests/errors/__init__.py +1 -0
- google/genai/tests/errors/test_api_error.py +417 -0
- google/genai/tests/file_search_stores/__init__.py +17 -0
- google/genai/tests/file_search_stores/test_create.py +66 -0
- google/genai/tests/file_search_stores/test_delete.py +64 -0
- google/genai/tests/file_search_stores/test_get.py +94 -0
- google/genai/tests/file_search_stores/test_import_file.py +112 -0
- google/genai/tests/file_search_stores/test_list.py +57 -0
- google/genai/tests/file_search_stores/test_upload_to_file_search_store.py +141 -0
- google/genai/tests/files/__init__.py +17 -0
- google/genai/tests/files/test_delete.py +46 -0
- google/genai/tests/files/test_download.py +85 -0
- google/genai/tests/files/test_get.py +46 -0
- google/genai/tests/files/test_list.py +72 -0
- google/genai/tests/files/test_upload.py +255 -0
- google/genai/tests/imports/test_no_optional_imports.py +28 -0
- google/genai/tests/interactions/__init__.py +0 -0
- google/genai/tests/interactions/test_integration.py +80 -0
- google/genai/tests/live/__init__.py +16 -0
- google/genai/tests/live/test_live.py +2177 -0
- google/genai/tests/live/test_live_music.py +362 -0
- google/genai/tests/live/test_live_response.py +163 -0
- google/genai/tests/live/test_send_client_content.py +147 -0
- google/genai/tests/live/test_send_realtime_input.py +268 -0
- google/genai/tests/live/test_send_tool_response.py +222 -0
- google/genai/tests/local_tokenizer/__init__.py +17 -0
- google/genai/tests/local_tokenizer/test_local_tokenizer.py +343 -0
- google/genai/tests/local_tokenizer/test_local_tokenizer_loader.py +235 -0
- google/genai/tests/mcp/__init__.py +17 -0
- google/genai/tests/mcp/test_has_mcp_tool_usage.py +89 -0
- google/genai/tests/mcp/test_mcp_to_gemini_tools.py +191 -0
- google/genai/tests/mcp/test_parse_config_for_mcp_sessions.py +201 -0
- google/genai/tests/mcp/test_parse_config_for_mcp_usage.py +130 -0
- google/genai/tests/mcp/test_set_mcp_usage_header.py +72 -0
- google/genai/tests/models/__init__.py +17 -0
- google/genai/tests/models/constants.py +8 -0
- google/genai/tests/models/test_compute_tokens.py +120 -0
- google/genai/tests/models/test_count_tokens.py +159 -0
- google/genai/tests/models/test_delete.py +107 -0
- google/genai/tests/models/test_edit_image.py +264 -0
- google/genai/tests/models/test_embed_content.py +94 -0
- google/genai/tests/models/test_function_call_streaming.py +442 -0
- google/genai/tests/models/test_generate_content.py +2502 -0
- google/genai/tests/models/test_generate_content_cached_content.py +132 -0
- google/genai/tests/models/test_generate_content_config_zero_value.py +103 -0
- google/genai/tests/models/test_generate_content_from_apikey.py +44 -0
- google/genai/tests/models/test_generate_content_http_options.py +40 -0
- google/genai/tests/models/test_generate_content_image_generation.py +143 -0
- google/genai/tests/models/test_generate_content_mcp.py +343 -0
- google/genai/tests/models/test_generate_content_media_resolution.py +97 -0
- google/genai/tests/models/test_generate_content_model.py +139 -0
- google/genai/tests/models/test_generate_content_part.py +821 -0
- google/genai/tests/models/test_generate_content_thought.py +76 -0
- google/genai/tests/models/test_generate_content_tools.py +1761 -0
- google/genai/tests/models/test_generate_images.py +191 -0
- google/genai/tests/models/test_generate_videos.py +759 -0
- google/genai/tests/models/test_get.py +104 -0
- google/genai/tests/models/test_list.py +233 -0
- google/genai/tests/models/test_recontext_image.py +189 -0
- google/genai/tests/models/test_segment_image.py +148 -0
- google/genai/tests/models/test_update.py +95 -0
- google/genai/tests/models/test_upscale_image.py +157 -0
- google/genai/tests/operations/__init__.py +17 -0
- google/genai/tests/operations/test_get.py +38 -0
- google/genai/tests/public_samples/__init__.py +17 -0
- google/genai/tests/public_samples/test_gemini_text_only.py +34 -0
- google/genai/tests/pytest_helper.py +229 -0
- google/genai/tests/shared/__init__.py +16 -0
- google/genai/tests/shared/batches/__init__.py +14 -0
- google/genai/tests/shared/batches/test_create_delete.py +57 -0
- google/genai/tests/shared/batches/test_create_get_cancel.py +56 -0
- google/genai/tests/shared/batches/test_list.py +40 -0
- google/genai/tests/shared/caches/__init__.py +14 -0
- google/genai/tests/shared/caches/test_create_get_delete.py +67 -0
- google/genai/tests/shared/caches/test_create_update_get.py +71 -0
- google/genai/tests/shared/caches/test_list.py +40 -0
- google/genai/tests/shared/chats/__init__.py +14 -0
- google/genai/tests/shared/chats/test_send_message.py +48 -0
- google/genai/tests/shared/chats/test_send_message_stream.py +50 -0
- google/genai/tests/shared/files/__init__.py +14 -0
- google/genai/tests/shared/files/test_list.py +41 -0
- google/genai/tests/shared/files/test_upload_get_delete.py +54 -0
- google/genai/tests/shared/models/__init__.py +14 -0
- google/genai/tests/shared/models/test_compute_tokens.py +41 -0
- google/genai/tests/shared/models/test_count_tokens.py +40 -0
- google/genai/tests/shared/models/test_edit_image.py +67 -0
- google/genai/tests/shared/models/test_embed.py +40 -0
- google/genai/tests/shared/models/test_generate_content.py +39 -0
- google/genai/tests/shared/models/test_generate_content_stream.py +54 -0
- google/genai/tests/shared/models/test_generate_images.py +40 -0
- google/genai/tests/shared/models/test_generate_videos.py +38 -0
- google/genai/tests/shared/models/test_list.py +37 -0
- google/genai/tests/shared/models/test_recontext_image.py +55 -0
- google/genai/tests/shared/models/test_segment_image.py +52 -0
- google/genai/tests/shared/models/test_upscale_image.py +52 -0
- google/genai/tests/shared/tunings/__init__.py +16 -0
- google/genai/tests/shared/tunings/test_create.py +46 -0
- google/genai/tests/shared/tunings/test_create_get_cancel.py +56 -0
- google/genai/tests/shared/tunings/test_list.py +39 -0
- google/genai/tests/tokens/__init__.py +16 -0
- google/genai/tests/tokens/test_create.py +154 -0
- google/genai/tests/transformers/__init__.py +17 -0
- google/genai/tests/transformers/test_blobs.py +71 -0
- google/genai/tests/transformers/test_bytes.py +15 -0
- google/genai/tests/transformers/test_duck_type.py +96 -0
- google/genai/tests/transformers/test_function_responses.py +72 -0
- google/genai/tests/transformers/test_schema.py +653 -0
- google/genai/tests/transformers/test_t_batch.py +286 -0
- google/genai/tests/transformers/test_t_content.py +160 -0
- google/genai/tests/transformers/test_t_contents.py +398 -0
- google/genai/tests/transformers/test_t_part.py +85 -0
- google/genai/tests/transformers/test_t_parts.py +87 -0
- google/genai/tests/transformers/test_t_tool.py +157 -0
- google/genai/tests/transformers/test_t_tools.py +195 -0
- google/genai/tests/tunings/__init__.py +16 -0
- google/genai/tests/tunings/test_cancel.py +39 -0
- google/genai/tests/tunings/test_end_to_end.py +106 -0
- google/genai/tests/tunings/test_get.py +67 -0
- google/genai/tests/tunings/test_list.py +75 -0
- google/genai/tests/tunings/test_tune.py +268 -0
- google/genai/tests/types/__init__.py +16 -0
- google/genai/tests/types/test_bytes_internal.py +271 -0
- google/genai/tests/types/test_bytes_type.py +152 -0
- google/genai/tests/types/test_future.py +101 -0
- google/genai/tests/types/test_optional_types.py +36 -0
- google/genai/tests/types/test_part_type.py +616 -0
- google/genai/tests/types/test_schema_from_json_schema.py +417 -0
- google/genai/tests/types/test_schema_json_schema.py +468 -0
- google/genai/tests/types/test_types.py +2903 -0
- google/genai/tunings.py +57 -57
- google/genai/types.py +229 -121
- google/genai/version.py +1 -1
- {google_genai-1.53.0.dist-info → google_genai-1.55.0.dist-info}/METADATA +4 -2
- google_genai-1.55.0.dist-info/RECORD +345 -0
- google_genai-1.53.0.dist-info/RECORD +0 -41
- {google_genai-1.53.0.dist-info → google_genai-1.55.0.dist-info}/WHEEL +0 -0
- {google_genai-1.53.0.dist-info → google_genai-1.55.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.53.0.dist-info → google_genai-1.55.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
"""Tests for generate_videos."""
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import time
|
|
21
|
+
import pytest
|
|
22
|
+
|
|
23
|
+
from ... import _replay_api_client
|
|
24
|
+
from ... import types
|
|
25
|
+
from .. import pytest_helper
|
|
26
|
+
|
|
27
|
+
VEO_MODEL_LATEST = "veo-3.1-generate-preview"
|
|
28
|
+
VEO_MODEL_2 = "veo-2.0-generate-001"
|
|
29
|
+
VEO_MODEL_2_EXP = "veo-2.0-generate-exp"
|
|
30
|
+
|
|
31
|
+
OUTPUT_GCS_URI = "gs://genai-sdk-tests/temp/videos/"
|
|
32
|
+
|
|
33
|
+
GCS_IMAGE = types.Image(
|
|
34
|
+
gcs_uri="gs://cloud-samples-data/vertex-ai/llm/prompts/landmark1.png",
|
|
35
|
+
# Required
|
|
36
|
+
mime_type="image/png",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
GCS_IMAGE2 = types.Image(
|
|
40
|
+
gcs_uri="gs://cloud-samples-data/vertex-ai/llm/prompts/landmark2.png",
|
|
41
|
+
# Required
|
|
42
|
+
mime_type="image/png",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
IMAGE_FILE_PATH = os.path.abspath(
|
|
46
|
+
os.path.join(os.path.dirname(__file__), "../data/bridge1.png")
|
|
47
|
+
)
|
|
48
|
+
LOCAL_IMAGE = types.Image.from_file(location=IMAGE_FILE_PATH)
|
|
49
|
+
|
|
50
|
+
LOCAL_IMAGE_MAN = types.Image.from_file(
|
|
51
|
+
location=os.path.abspath(
|
|
52
|
+
os.path.join(os.path.dirname(__file__), "../data/man.jpg")
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
LOCAL_IMAGE_DOG = types.Image.from_file(
|
|
57
|
+
location=os.path.abspath(
|
|
58
|
+
os.path.join(os.path.dirname(__file__), "../data/dog.jpg")
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
GCS_OUTPAINT_MASK = types.Image(
|
|
63
|
+
gcs_uri="gs://genai-sdk-tests/inputs/videos/video_outpaint_mask.png",
|
|
64
|
+
mime_type="image/png",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
GCS_REMOVE_MASK = types.Image(
|
|
68
|
+
gcs_uri="gs://genai-sdk-tests/inputs/videos/video_remove_mask.png",
|
|
69
|
+
mime_type="image/png",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
GCS_REMOVE_STATIC_MASK = types.Image(
|
|
73
|
+
gcs_uri="gs://genai-sdk-tests/inputs/videos/video_remove_static_mask.png",
|
|
74
|
+
mime_type="image/png",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
test_table: list[pytest_helper.TestTableItem] = [
|
|
79
|
+
pytest_helper.TestTableItem(
|
|
80
|
+
name="test_simple_prompt",
|
|
81
|
+
parameters=types._GenerateVideosParameters(
|
|
82
|
+
model=VEO_MODEL_LATEST,
|
|
83
|
+
prompt="Man with a dog",
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
pytest_helper.TestTableItem(
|
|
87
|
+
name="test_all_parameters_vertex",
|
|
88
|
+
parameters=types._GenerateVideosParameters(
|
|
89
|
+
model=VEO_MODEL_LATEST,
|
|
90
|
+
prompt="A neon hologram of a cat driving at top speed",
|
|
91
|
+
config=types.GenerateVideosConfig(
|
|
92
|
+
number_of_videos=1,
|
|
93
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
94
|
+
fps=30,
|
|
95
|
+
duration_seconds=6,
|
|
96
|
+
seed=1,
|
|
97
|
+
aspect_ratio="16:9",
|
|
98
|
+
resolution="720p",
|
|
99
|
+
person_generation="allow_adult",
|
|
100
|
+
# pubsub_topic="projects/<my-project>/topics/video-generation-test",
|
|
101
|
+
negative_prompt="ugly, low quality",
|
|
102
|
+
enhance_prompt=True,
|
|
103
|
+
compression_quality=types.VideoCompressionQuality.LOSSLESS,
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
exception_if_mldev=(
|
|
107
|
+
"not supported in Gemini API"
|
|
108
|
+
),
|
|
109
|
+
),
|
|
110
|
+
pytest_helper.TestTableItem(
|
|
111
|
+
name="test_from_text_source",
|
|
112
|
+
parameters=types._GenerateVideosParameters(
|
|
113
|
+
model=VEO_MODEL_LATEST,
|
|
114
|
+
source=types.GenerateVideosSource(prompt="Man with a dog"),
|
|
115
|
+
config=types.GenerateVideosConfig(
|
|
116
|
+
number_of_videos=1,
|
|
117
|
+
),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
pytest_helper.TestTableItem(
|
|
121
|
+
name="test_from_image_source",
|
|
122
|
+
parameters=types._GenerateVideosParameters(
|
|
123
|
+
model=VEO_MODEL_LATEST,
|
|
124
|
+
source=types.GenerateVideosSource(
|
|
125
|
+
image=LOCAL_IMAGE,
|
|
126
|
+
),
|
|
127
|
+
config=types.GenerateVideosConfig(
|
|
128
|
+
number_of_videos=1,
|
|
129
|
+
),
|
|
130
|
+
),
|
|
131
|
+
),
|
|
132
|
+
pytest_helper.TestTableItem(
|
|
133
|
+
name="test_from_text_and_image_source",
|
|
134
|
+
parameters=types._GenerateVideosParameters(
|
|
135
|
+
model=VEO_MODEL_LATEST,
|
|
136
|
+
source=types.GenerateVideosSource(
|
|
137
|
+
prompt="Lightning storm",
|
|
138
|
+
image=LOCAL_IMAGE,
|
|
139
|
+
),
|
|
140
|
+
config=types.GenerateVideosConfig(
|
|
141
|
+
number_of_videos=1,
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
),
|
|
145
|
+
pytest_helper.TestTableItem(
|
|
146
|
+
name="test_from_video_source",
|
|
147
|
+
parameters=types._GenerateVideosParameters(
|
|
148
|
+
model=VEO_MODEL_LATEST,
|
|
149
|
+
source=types.GenerateVideosSource(
|
|
150
|
+
video=types.Video(
|
|
151
|
+
uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4",
|
|
152
|
+
mime_type="video/mp4",
|
|
153
|
+
),
|
|
154
|
+
),
|
|
155
|
+
config=types.GenerateVideosConfig(
|
|
156
|
+
number_of_videos=1,
|
|
157
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
exception_if_mldev=(
|
|
161
|
+
"output_gcs_uri parameter is not supported in Gemini API"
|
|
162
|
+
),
|
|
163
|
+
),
|
|
164
|
+
pytest_helper.TestTableItem(
|
|
165
|
+
name="test_from_text_and_video_source",
|
|
166
|
+
parameters=types._GenerateVideosParameters(
|
|
167
|
+
model=VEO_MODEL_LATEST,
|
|
168
|
+
source=types.GenerateVideosSource(
|
|
169
|
+
prompt="Rain",
|
|
170
|
+
video=types.Video(
|
|
171
|
+
uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4",
|
|
172
|
+
mime_type="video/mp4",
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
config=types.GenerateVideosConfig(
|
|
176
|
+
number_of_videos=1,
|
|
177
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
178
|
+
),
|
|
179
|
+
),
|
|
180
|
+
exception_if_mldev=(
|
|
181
|
+
"output_gcs_uri parameter is not supported in Gemini API"
|
|
182
|
+
),
|
|
183
|
+
),
|
|
184
|
+
pytest_helper.TestTableItem(
|
|
185
|
+
name="test_video_edit_outpaint",
|
|
186
|
+
parameters=types._GenerateVideosParameters(
|
|
187
|
+
model=VEO_MODEL_2_EXP,
|
|
188
|
+
source=types.GenerateVideosSource(
|
|
189
|
+
prompt="A mountain landscape",
|
|
190
|
+
video=types.Video(
|
|
191
|
+
uri="gs://genai-sdk-tests/inputs/videos/editing_demo.mp4",
|
|
192
|
+
mime_type="video/mp4",
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
config=types.GenerateVideosConfig(
|
|
196
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
197
|
+
aspect_ratio="16:9",
|
|
198
|
+
mask=types.VideoGenerationMask(
|
|
199
|
+
image=GCS_OUTPAINT_MASK,
|
|
200
|
+
mask_mode=types.VideoGenerationMaskMode.OUTPAINT,
|
|
201
|
+
),
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
exception_if_mldev=(
|
|
205
|
+
"not supported in Gemini API"
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
pytest_helper.TestTableItem(
|
|
209
|
+
name="test_all_parameters_mldev",
|
|
210
|
+
parameters=types._GenerateVideosParameters(
|
|
211
|
+
model=VEO_MODEL_2,
|
|
212
|
+
prompt="A neon hologram of a cat driving at top speed",
|
|
213
|
+
config=types.GenerateVideosConfig(
|
|
214
|
+
number_of_videos=1,
|
|
215
|
+
duration_seconds=6,
|
|
216
|
+
aspect_ratio="16:9",
|
|
217
|
+
person_generation="allow_adult",
|
|
218
|
+
negative_prompt="ugly, low quality",
|
|
219
|
+
enhance_prompt=True,
|
|
220
|
+
),
|
|
221
|
+
),
|
|
222
|
+
),
|
|
223
|
+
pytest_helper.TestTableItem(
|
|
224
|
+
name="test_all_parameters_veo3_mldev",
|
|
225
|
+
parameters=types._GenerateVideosParameters(
|
|
226
|
+
model=VEO_MODEL_LATEST,
|
|
227
|
+
prompt="A neon hologram of a cat driving at top speed",
|
|
228
|
+
config=types.GenerateVideosConfig(
|
|
229
|
+
number_of_videos=1,
|
|
230
|
+
aspect_ratio="16:9",
|
|
231
|
+
resolution="1080p",
|
|
232
|
+
negative_prompt="ugly, low quality",
|
|
233
|
+
),
|
|
234
|
+
),
|
|
235
|
+
),
|
|
236
|
+
pytest_helper.TestTableItem(
|
|
237
|
+
name="test_reference_to_video",
|
|
238
|
+
parameters=types._GenerateVideosParameters(
|
|
239
|
+
model=VEO_MODEL_LATEST,
|
|
240
|
+
prompt="Rain",
|
|
241
|
+
config=types.GenerateVideosConfig(
|
|
242
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
243
|
+
reference_images=[
|
|
244
|
+
types.VideoGenerationReferenceImage(
|
|
245
|
+
image=GCS_IMAGE,
|
|
246
|
+
reference_type=types.VideoGenerationReferenceType.ASSET,
|
|
247
|
+
)
|
|
248
|
+
],
|
|
249
|
+
),
|
|
250
|
+
),
|
|
251
|
+
exception_if_mldev=(
|
|
252
|
+
"output_gcs_uri parameter is not supported in Gemini API"
|
|
253
|
+
),
|
|
254
|
+
),
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
pytestmark = pytest_helper.setup(
|
|
258
|
+
file=__file__,
|
|
259
|
+
globals_for_file=globals(),
|
|
260
|
+
test_method="models.generate_videos",
|
|
261
|
+
test_table=test_table,
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def test_text_to_video_poll(client):
|
|
266
|
+
operation = client.models.generate_videos(
|
|
267
|
+
model=VEO_MODEL_LATEST,
|
|
268
|
+
prompt="A neon hologram of a cat driving at top speed",
|
|
269
|
+
config=types.GenerateVideosConfig(
|
|
270
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
271
|
+
),
|
|
272
|
+
)
|
|
273
|
+
while not operation.done:
|
|
274
|
+
# Skip the sleep when in replay mode.
|
|
275
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
276
|
+
time.sleep(20)
|
|
277
|
+
operation = client.operations.get(operation=operation)
|
|
278
|
+
|
|
279
|
+
assert operation.result.generated_videos[0].video.uri
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def test_image_to_video_poll(client):
|
|
283
|
+
operation = client.models.generate_videos(
|
|
284
|
+
model=VEO_MODEL_LATEST,
|
|
285
|
+
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE,
|
|
286
|
+
config=types.GenerateVideosConfig(
|
|
287
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
288
|
+
),
|
|
289
|
+
)
|
|
290
|
+
while not operation.done:
|
|
291
|
+
# Skip the sleep when in replay mode.
|
|
292
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
293
|
+
time.sleep(20)
|
|
294
|
+
operation = client.operations.get(operation=operation)
|
|
295
|
+
|
|
296
|
+
assert operation.result.generated_videos[0].video.uri
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_text_and_image_to_video_poll(client):
|
|
300
|
+
operation = client.models.generate_videos(
|
|
301
|
+
model=VEO_MODEL_LATEST,
|
|
302
|
+
prompt="Lightning storm",
|
|
303
|
+
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE,
|
|
304
|
+
config=types.GenerateVideosConfig(
|
|
305
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
306
|
+
),
|
|
307
|
+
)
|
|
308
|
+
while not operation.done:
|
|
309
|
+
# Skip the sleep when in replay mode.
|
|
310
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
311
|
+
time.sleep(20)
|
|
312
|
+
operation = client.operations.get(operation=operation)
|
|
313
|
+
|
|
314
|
+
assert operation.result.generated_videos[0].video.uri
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def test_video_to_video_poll(client):
|
|
318
|
+
# GCS URI video input is only supported in Vertex AI.
|
|
319
|
+
if not client.vertexai:
|
|
320
|
+
return
|
|
321
|
+
|
|
322
|
+
operation = client.models.generate_videos(
|
|
323
|
+
model=VEO_MODEL_2,
|
|
324
|
+
video=types.Video(
|
|
325
|
+
uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4",
|
|
326
|
+
mime_type="video/mp4",
|
|
327
|
+
),
|
|
328
|
+
config=types.GenerateVideosConfig(
|
|
329
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
330
|
+
),
|
|
331
|
+
)
|
|
332
|
+
while not operation.done:
|
|
333
|
+
# Skip the sleep when in replay mode.
|
|
334
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
335
|
+
time.sleep(20)
|
|
336
|
+
operation = client.operations.get(operation=operation)
|
|
337
|
+
|
|
338
|
+
assert operation.result.generated_videos[0].video.uri
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def test_text_and_video_to_video_poll(client):
|
|
342
|
+
# GCS URI video input is only supported in Vertex AI.
|
|
343
|
+
if not client.vertexai:
|
|
344
|
+
return
|
|
345
|
+
|
|
346
|
+
operation = client.models.generate_videos(
|
|
347
|
+
model=VEO_MODEL_2,
|
|
348
|
+
prompt="Rain",
|
|
349
|
+
video=types.Video(
|
|
350
|
+
uri="gs://genai-sdk-tests/inputs/videos/cat_driving.mp4",
|
|
351
|
+
mime_type="video/mp4",
|
|
352
|
+
),
|
|
353
|
+
config=types.GenerateVideosConfig(
|
|
354
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
355
|
+
),
|
|
356
|
+
)
|
|
357
|
+
while not operation.done:
|
|
358
|
+
# Skip the sleep when in replay mode.
|
|
359
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
360
|
+
time.sleep(20)
|
|
361
|
+
operation = client.operations.get(operation=operation)
|
|
362
|
+
|
|
363
|
+
assert operation.result.generated_videos[0].video.uri
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def test_generated_video_extension_poll(client):
|
|
367
|
+
# Gemini API only supports video extension on generated videos.
|
|
368
|
+
if client.vertexai:
|
|
369
|
+
return
|
|
370
|
+
|
|
371
|
+
operation1 = client.models.generate_videos(
|
|
372
|
+
model=VEO_MODEL_LATEST,
|
|
373
|
+
prompt="Rain",
|
|
374
|
+
config=types.GenerateVideosConfig(
|
|
375
|
+
number_of_videos=1,
|
|
376
|
+
),
|
|
377
|
+
)
|
|
378
|
+
while not operation1.done:
|
|
379
|
+
# Skip the sleep when in replay mode.
|
|
380
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
381
|
+
time.sleep(20)
|
|
382
|
+
operation1 = client.operations.get(operation=operation1)
|
|
383
|
+
|
|
384
|
+
video1 = operation1.result.generated_videos[0].video
|
|
385
|
+
assert video1.uri
|
|
386
|
+
client.files.download(file=video1)
|
|
387
|
+
assert video1.video_bytes
|
|
388
|
+
|
|
389
|
+
operation2 = client.models.generate_videos(
|
|
390
|
+
model=VEO_MODEL_LATEST,
|
|
391
|
+
prompt="Sun",
|
|
392
|
+
video=video1,
|
|
393
|
+
config=types.GenerateVideosConfig(
|
|
394
|
+
number_of_videos=1,
|
|
395
|
+
),
|
|
396
|
+
)
|
|
397
|
+
while not operation2.done:
|
|
398
|
+
# Skip the sleep when in replay mode.
|
|
399
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
400
|
+
time.sleep(20)
|
|
401
|
+
operation2 = client.operations.get(operation=operation2)
|
|
402
|
+
|
|
403
|
+
video2 = operation2.result.generated_videos[0].video
|
|
404
|
+
assert video2.uri
|
|
405
|
+
client.files.download(file=video2)
|
|
406
|
+
assert video2.video_bytes
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def test_generated_video_extension_from_source_poll(client):
|
|
410
|
+
# Gemini API only supports video extension on generated videos.
|
|
411
|
+
if client.vertexai:
|
|
412
|
+
return
|
|
413
|
+
|
|
414
|
+
operation1 = client.models.generate_videos(
|
|
415
|
+
model=VEO_MODEL_LATEST,
|
|
416
|
+
prompt="Rain",
|
|
417
|
+
config=types.GenerateVideosConfig(
|
|
418
|
+
number_of_videos=1,
|
|
419
|
+
),
|
|
420
|
+
)
|
|
421
|
+
while not operation1.done:
|
|
422
|
+
# Skip the sleep when in replay mode.
|
|
423
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
424
|
+
time.sleep(20)
|
|
425
|
+
operation1 = client.operations.get(operation=operation1)
|
|
426
|
+
|
|
427
|
+
video1 = operation1.result.generated_videos[0].video
|
|
428
|
+
assert video1.uri
|
|
429
|
+
client.files.download(file=video1)
|
|
430
|
+
assert video1.video_bytes
|
|
431
|
+
|
|
432
|
+
operation2 = client.models.generate_videos(
|
|
433
|
+
model=VEO_MODEL_LATEST,
|
|
434
|
+
source=types.GenerateVideosSource(
|
|
435
|
+
prompt="Sun",
|
|
436
|
+
video=video1
|
|
437
|
+
),
|
|
438
|
+
config=types.GenerateVideosConfig(
|
|
439
|
+
number_of_videos=1,
|
|
440
|
+
),
|
|
441
|
+
)
|
|
442
|
+
while not operation2.done:
|
|
443
|
+
# Skip the sleep when in replay mode.
|
|
444
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
445
|
+
time.sleep(20)
|
|
446
|
+
operation2 = client.operations.get(operation=operation2)
|
|
447
|
+
|
|
448
|
+
video2 = operation2.result.generated_videos[0].video
|
|
449
|
+
assert video2.uri
|
|
450
|
+
client.files.download(file=video2)
|
|
451
|
+
assert video2.video_bytes
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def test_generated_video_extension_from_source_dict_poll(client):
|
|
455
|
+
# Gemini API only supports video extension on generated videos.
|
|
456
|
+
if client.vertexai:
|
|
457
|
+
return
|
|
458
|
+
|
|
459
|
+
operation1 = client.models.generate_videos(
|
|
460
|
+
model=VEO_MODEL_LATEST,
|
|
461
|
+
prompt="Rain",
|
|
462
|
+
config=types.GenerateVideosConfig(
|
|
463
|
+
number_of_videos=1,
|
|
464
|
+
),
|
|
465
|
+
)
|
|
466
|
+
while not operation1.done:
|
|
467
|
+
# Skip the sleep when in replay mode.
|
|
468
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
469
|
+
time.sleep(20)
|
|
470
|
+
operation1 = client.operations.get(operation=operation1)
|
|
471
|
+
|
|
472
|
+
video1 = operation1.result.generated_videos[0].video
|
|
473
|
+
assert video1.uri
|
|
474
|
+
client.files.download(file=video1)
|
|
475
|
+
assert video1.video_bytes
|
|
476
|
+
|
|
477
|
+
operation2 = client.models.generate_videos(
|
|
478
|
+
model=VEO_MODEL_LATEST,
|
|
479
|
+
source={
|
|
480
|
+
"prompt": "Sun",
|
|
481
|
+
"video": video1,
|
|
482
|
+
},
|
|
483
|
+
config=types.GenerateVideosConfig(
|
|
484
|
+
number_of_videos=1,
|
|
485
|
+
),
|
|
486
|
+
)
|
|
487
|
+
while not operation2.done:
|
|
488
|
+
# Skip the sleep when in replay mode.
|
|
489
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
490
|
+
time.sleep(20)
|
|
491
|
+
operation2 = client.operations.get(operation=operation2)
|
|
492
|
+
|
|
493
|
+
video2 = operation2.result.generated_videos[0].video
|
|
494
|
+
assert video2.uri
|
|
495
|
+
client.files.download(file=video2)
|
|
496
|
+
assert video2.video_bytes
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def test_image_to_video_frame_interpolation_poll(client):
|
|
500
|
+
operation = client.models.generate_videos(
|
|
501
|
+
model=VEO_MODEL_LATEST,
|
|
502
|
+
prompt="Rain",
|
|
503
|
+
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE_MAN,
|
|
504
|
+
config=types.GenerateVideosConfig(
|
|
505
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
506
|
+
last_frame=GCS_IMAGE2 if client.vertexai else LOCAL_IMAGE_DOG,
|
|
507
|
+
),
|
|
508
|
+
)
|
|
509
|
+
while not operation.done:
|
|
510
|
+
# Skip the sleep when in replay mode.
|
|
511
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
512
|
+
time.sleep(20)
|
|
513
|
+
operation = client.operations.get(operation=operation)
|
|
514
|
+
|
|
515
|
+
assert operation.result.generated_videos[0].video.uri
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def test_reference_images_to_video_poll(client):
|
|
519
|
+
operation = client.models.generate_videos(
|
|
520
|
+
model=VEO_MODEL_LATEST,
|
|
521
|
+
prompt="Chirping birds in a colorful forest",
|
|
522
|
+
config=types.GenerateVideosConfig(
|
|
523
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
524
|
+
reference_images=[
|
|
525
|
+
types.VideoGenerationReferenceImage(
|
|
526
|
+
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE_MAN,
|
|
527
|
+
reference_type=types.VideoGenerationReferenceType.ASSET,
|
|
528
|
+
),
|
|
529
|
+
],
|
|
530
|
+
),
|
|
531
|
+
)
|
|
532
|
+
while not operation.done:
|
|
533
|
+
# Skip the sleep when in replay mode.
|
|
534
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
535
|
+
time.sleep(20)
|
|
536
|
+
operation = client.operations.get(operation=operation)
|
|
537
|
+
|
|
538
|
+
assert operation.result.generated_videos[0].video.uri
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
def test_video_edit_outpaint_poll(client):
|
|
542
|
+
# Editing videos is only supported in Vertex AI.
|
|
543
|
+
if not client.vertexai:
|
|
544
|
+
return
|
|
545
|
+
|
|
546
|
+
operation = client.models.generate_videos(
|
|
547
|
+
model=VEO_MODEL_2_EXP,
|
|
548
|
+
source=types.GenerateVideosSource(
|
|
549
|
+
prompt="A mountain landscape",
|
|
550
|
+
video=types.Video(
|
|
551
|
+
uri="gs://genai-sdk-tests/inputs/videos/editing_demo.mp4",
|
|
552
|
+
mime_type="video/mp4",
|
|
553
|
+
),
|
|
554
|
+
),
|
|
555
|
+
config=types.GenerateVideosConfig(
|
|
556
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
557
|
+
aspect_ratio="16:9",
|
|
558
|
+
mask=types.VideoGenerationMask(
|
|
559
|
+
image=GCS_OUTPAINT_MASK,
|
|
560
|
+
mask_mode=types.VideoGenerationMaskMode.OUTPAINT,
|
|
561
|
+
),
|
|
562
|
+
),
|
|
563
|
+
)
|
|
564
|
+
while not operation.done:
|
|
565
|
+
# Skip the sleep when in replay mode.
|
|
566
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
567
|
+
time.sleep(20)
|
|
568
|
+
operation = client.operations.get(operation=operation)
|
|
569
|
+
|
|
570
|
+
assert operation.result.generated_videos[0].video.uri
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def test_video_edit_remove_poll(client):
|
|
574
|
+
# Editing videos is only supported in Vertex AI.
|
|
575
|
+
if not client.vertexai:
|
|
576
|
+
return
|
|
577
|
+
|
|
578
|
+
operation = client.models.generate_videos(
|
|
579
|
+
model=VEO_MODEL_2_EXP,
|
|
580
|
+
source=types.GenerateVideosSource(
|
|
581
|
+
prompt="A red dune buggy",
|
|
582
|
+
video=types.Video(
|
|
583
|
+
uri="gs://genai-sdk-tests/inputs/videos/editing_demo.mp4",
|
|
584
|
+
mime_type="video/mp4",
|
|
585
|
+
),
|
|
586
|
+
),
|
|
587
|
+
config=types.GenerateVideosConfig(
|
|
588
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
589
|
+
aspect_ratio="16:9",
|
|
590
|
+
mask=types.VideoGenerationMask(
|
|
591
|
+
image=GCS_REMOVE_MASK,
|
|
592
|
+
mask_mode=types.VideoGenerationMaskMode.REMOVE,
|
|
593
|
+
),
|
|
594
|
+
),
|
|
595
|
+
)
|
|
596
|
+
while not operation.done:
|
|
597
|
+
# Skip the sleep when in replay mode.
|
|
598
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
599
|
+
time.sleep(20)
|
|
600
|
+
operation = client.operations.get(operation=operation)
|
|
601
|
+
|
|
602
|
+
assert operation.result.generated_videos[0].video.uri
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def test_video_edit_remove_static_poll(client):
|
|
606
|
+
# Editing videos is only supported in Vertex AI.
|
|
607
|
+
if not client.vertexai:
|
|
608
|
+
return
|
|
609
|
+
|
|
610
|
+
operation = client.models.generate_videos(
|
|
611
|
+
model=VEO_MODEL_2_EXP,
|
|
612
|
+
source=types.GenerateVideosSource(
|
|
613
|
+
prompt="A red dune buggy",
|
|
614
|
+
video=types.Video(
|
|
615
|
+
uri="gs://genai-sdk-tests/inputs/videos/editing_demo.mp4",
|
|
616
|
+
mime_type="video/mp4",
|
|
617
|
+
),
|
|
618
|
+
),
|
|
619
|
+
config=types.GenerateVideosConfig(
|
|
620
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
621
|
+
aspect_ratio="16:9",
|
|
622
|
+
mask=types.VideoGenerationMask(
|
|
623
|
+
image=GCS_REMOVE_STATIC_MASK,
|
|
624
|
+
mask_mode=types.VideoGenerationMaskMode.REMOVE_STATIC,
|
|
625
|
+
),
|
|
626
|
+
),
|
|
627
|
+
)
|
|
628
|
+
while not operation.done:
|
|
629
|
+
# Skip the sleep when in replay mode.
|
|
630
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
631
|
+
time.sleep(20)
|
|
632
|
+
operation = client.operations.get(operation=operation)
|
|
633
|
+
|
|
634
|
+
assert operation.result.generated_videos[0].video.uri
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def test_video_edit_insert_poll(client):
|
|
638
|
+
# Editing videos is only supported in Vertex AI.
|
|
639
|
+
if not client.vertexai:
|
|
640
|
+
return
|
|
641
|
+
|
|
642
|
+
operation = client.models.generate_videos(
|
|
643
|
+
model=VEO_MODEL_2_EXP,
|
|
644
|
+
source=types.GenerateVideosSource(
|
|
645
|
+
prompt="Bike",
|
|
646
|
+
video=types.Video(
|
|
647
|
+
uri="gs://genai-sdk-tests/inputs/videos/editing_demo.mp4",
|
|
648
|
+
mime_type="video/mp4",
|
|
649
|
+
),
|
|
650
|
+
),
|
|
651
|
+
config=types.GenerateVideosConfig(
|
|
652
|
+
output_gcs_uri=OUTPUT_GCS_URI,
|
|
653
|
+
aspect_ratio="16:9",
|
|
654
|
+
mask=types.VideoGenerationMask(
|
|
655
|
+
# Insert and remove masks are the same for this input.
|
|
656
|
+
image=GCS_REMOVE_MASK,
|
|
657
|
+
mask_mode=types.VideoGenerationMaskMode.INSERT,
|
|
658
|
+
),
|
|
659
|
+
),
|
|
660
|
+
)
|
|
661
|
+
while not operation.done:
|
|
662
|
+
# Skip the sleep when in replay mode.
|
|
663
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
664
|
+
time.sleep(20)
|
|
665
|
+
operation = client.operations.get(operation=operation)
|
|
666
|
+
|
|
667
|
+
assert operation.result.generated_videos[0].video.uri
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
def test_create_operation_to_poll(client):
|
|
671
|
+
if client.vertexai:
|
|
672
|
+
# Fill in project and location for record mode
|
|
673
|
+
operation_name = "projects/<project>/locations/<location>/publishers/google/models/veo-3.1-generate-preview/operations/9d2fc0b5-5bdf-4b5f-9a41-82970515e20b"
|
|
674
|
+
else:
|
|
675
|
+
operation_name = "models/veo-3.1-generate-preview/operations/vz341u0pmdlc"
|
|
676
|
+
|
|
677
|
+
operation = types.GenerateVideosOperation(
|
|
678
|
+
name=operation_name,
|
|
679
|
+
)
|
|
680
|
+
operation = client.operations.get(operation=operation)
|
|
681
|
+
while not operation.done:
|
|
682
|
+
# Skip the sleep when in replay mode.
|
|
683
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
684
|
+
time.sleep(20)
|
|
685
|
+
operation = client.operations.get(operation=operation)
|
|
686
|
+
|
|
687
|
+
assert operation.result.generated_videos[0].video.uri
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
def test_source_and_prompt_raises(client):
|
|
691
|
+
with pytest.raises(ValueError):
|
|
692
|
+
client.models.generate_videos(
|
|
693
|
+
model=VEO_MODEL_LATEST,
|
|
694
|
+
prompt="Prompt 1",
|
|
695
|
+
source=types.GenerateVideosSource(prompt="Prompt 2"),
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
@pytest.mark.asyncio
|
|
700
|
+
async def test_text_to_video_poll_async(client):
|
|
701
|
+
operation = await client.aio.models.generate_videos(
|
|
702
|
+
model=VEO_MODEL_LATEST,
|
|
703
|
+
prompt="A neon hologram of a cat driving at top speed",
|
|
704
|
+
config=types.GenerateVideosConfig(
|
|
705
|
+
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
|
|
706
|
+
),
|
|
707
|
+
)
|
|
708
|
+
while not operation.done:
|
|
709
|
+
# Skip the sleep when in replay mode.
|
|
710
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
711
|
+
time.sleep(20)
|
|
712
|
+
operation = await client.aio.operations.get(operation=operation)
|
|
713
|
+
|
|
714
|
+
assert operation.result.generated_videos[0].video.uri
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
@pytest.mark.asyncio
|
|
718
|
+
async def test_generated_video_extension_from_source_poll_async(client):
|
|
719
|
+
# Gemini API only supports video extension on generated videos.
|
|
720
|
+
if client.vertexai:
|
|
721
|
+
return
|
|
722
|
+
|
|
723
|
+
operation1 = await client.aio.models.generate_videos(
|
|
724
|
+
model=VEO_MODEL_LATEST,
|
|
725
|
+
prompt="Rain",
|
|
726
|
+
config=types.GenerateVideosConfig(
|
|
727
|
+
number_of_videos=1,
|
|
728
|
+
),
|
|
729
|
+
)
|
|
730
|
+
while not operation1.done:
|
|
731
|
+
# Skip the sleep when in replay mode.
|
|
732
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
733
|
+
time.sleep(20)
|
|
734
|
+
operation1 = await client.aio.operations.get(operation=operation1)
|
|
735
|
+
|
|
736
|
+
video1 = operation1.result.generated_videos[0].video
|
|
737
|
+
assert video1.uri
|
|
738
|
+
assert await client.aio.files.download(file=video1)
|
|
739
|
+
|
|
740
|
+
operation2 = await client.aio.models.generate_videos(
|
|
741
|
+
model=VEO_MODEL_LATEST,
|
|
742
|
+
source=types.GenerateVideosSource(
|
|
743
|
+
prompt="Sun",
|
|
744
|
+
video=video1
|
|
745
|
+
),
|
|
746
|
+
config=types.GenerateVideosConfig(
|
|
747
|
+
number_of_videos=1,
|
|
748
|
+
),
|
|
749
|
+
)
|
|
750
|
+
while not operation2.done:
|
|
751
|
+
# Skip the sleep when in replay mode.
|
|
752
|
+
if client._api_client._mode not in ("replay", "auto"):
|
|
753
|
+
time.sleep(20)
|
|
754
|
+
operation2 = await client.aio.operations.get(operation=operation2)
|
|
755
|
+
|
|
756
|
+
video2 = operation2.result.generated_videos[0].video
|
|
757
|
+
assert video2.uri
|
|
758
|
+
assert await client.aio.files.download(file=video2)
|
|
759
|
+
|