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,821 @@
|
|
|
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_content_part."""
|
|
18
|
+
|
|
19
|
+
import base64
|
|
20
|
+
import os
|
|
21
|
+
|
|
22
|
+
from pydantic import ValidationError
|
|
23
|
+
import pytest
|
|
24
|
+
|
|
25
|
+
from ... import _transformers as t
|
|
26
|
+
from ... import errors
|
|
27
|
+
from ... import types
|
|
28
|
+
from .. import pytest_helper
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
IMAGE_PNG_FILE_PATH = os.path.abspath(
|
|
32
|
+
os.path.join(os.path.dirname(__file__), '../data/google.png')
|
|
33
|
+
)
|
|
34
|
+
IMAGE_JPEG_FILE_PATH = os.path.abspath(
|
|
35
|
+
os.path.join(os.path.dirname(__file__), '../data/google.jpg')
|
|
36
|
+
)
|
|
37
|
+
APPLICATION_PDF_FILE_PATH = os.path.abspath(
|
|
38
|
+
os.path.join(os.path.dirname(__file__), '../data/story.pdf')
|
|
39
|
+
)
|
|
40
|
+
VIDEO_MP4_FILE_PATH = os.path.abspath(
|
|
41
|
+
os.path.join(os.path.dirname(__file__), '../data/animal.mp4')
|
|
42
|
+
)
|
|
43
|
+
AUDIO_MP3_FILE_PATH = os.path.abspath(
|
|
44
|
+
os.path.join(os.path.dirname(__file__), '../data/pixel.m4a')
|
|
45
|
+
)
|
|
46
|
+
with open(IMAGE_PNG_FILE_PATH, 'rb') as image_file:
|
|
47
|
+
image_bytes = image_file.read()
|
|
48
|
+
image_string = base64.b64encode(image_bytes).decode('utf-8')
|
|
49
|
+
with open(APPLICATION_PDF_FILE_PATH, 'rb') as pdf_file:
|
|
50
|
+
pdf_bytes = pdf_file.read()
|
|
51
|
+
with open(VIDEO_MP4_FILE_PATH, 'rb') as video_file:
|
|
52
|
+
video_bytes = video_file.read()
|
|
53
|
+
with open(AUDIO_MP3_FILE_PATH, 'rb') as audio_file:
|
|
54
|
+
audio_bytes = audio_file.read()
|
|
55
|
+
|
|
56
|
+
test_table: list[pytest_helper.TestTableItem] = [
|
|
57
|
+
pytest_helper.TestTableItem(
|
|
58
|
+
name='test_image_uri',
|
|
59
|
+
parameters=types._GenerateContentParameters(
|
|
60
|
+
model='gemini-2.5-flash',
|
|
61
|
+
contents=[
|
|
62
|
+
t.t_content('What is this image about?'),
|
|
63
|
+
t.t_content(
|
|
64
|
+
{
|
|
65
|
+
'role': 'user',
|
|
66
|
+
'parts': [
|
|
67
|
+
types.PartDict({
|
|
68
|
+
'file_data': {
|
|
69
|
+
'file_uri': (
|
|
70
|
+
'gs://generativeai-downloads/images/scones.jpg'
|
|
71
|
+
),
|
|
72
|
+
'mime_type': 'image/jpeg',
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
),
|
|
78
|
+
],
|
|
79
|
+
),
|
|
80
|
+
exception_if_mldev='400',
|
|
81
|
+
),
|
|
82
|
+
pytest_helper.TestTableItem(
|
|
83
|
+
name='test_external_file_uri',
|
|
84
|
+
parameters=types._GenerateContentParameters(
|
|
85
|
+
model='gemini-2.5-flash',
|
|
86
|
+
contents=[
|
|
87
|
+
t.t_content('What is this image about?'),
|
|
88
|
+
t.t_content(
|
|
89
|
+
{
|
|
90
|
+
'role': 'user',
|
|
91
|
+
'parts': [
|
|
92
|
+
types.PartDict({
|
|
93
|
+
'file_data': {
|
|
94
|
+
'file_uri': (
|
|
95
|
+
'https://storage.googleapis.com/cloud-samples-data/generative-ai/image/scones.jpg'
|
|
96
|
+
),
|
|
97
|
+
'mime_type': 'image/jpeg',
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
),
|
|
103
|
+
],
|
|
104
|
+
),
|
|
105
|
+
exception_if_mldev='400',
|
|
106
|
+
),
|
|
107
|
+
pytest_helper.TestTableItem(
|
|
108
|
+
name='test_image_png_file_uri',
|
|
109
|
+
skip_in_api_mode=(
|
|
110
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
111
|
+
),
|
|
112
|
+
parameters=types._GenerateContentParameters(
|
|
113
|
+
model='gemini-2.5-flash',
|
|
114
|
+
contents=[
|
|
115
|
+
t.t_content('What is this image about?'),
|
|
116
|
+
t.t_content(
|
|
117
|
+
{
|
|
118
|
+
'role': 'user',
|
|
119
|
+
'parts': [
|
|
120
|
+
types.PartDict({
|
|
121
|
+
'file_data': {
|
|
122
|
+
'file_uri': (
|
|
123
|
+
'https://generativelanguage.googleapis.com/v1beta/files/864z7ft4m14h'
|
|
124
|
+
),
|
|
125
|
+
'mime_type': 'image/png',
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
),
|
|
131
|
+
],
|
|
132
|
+
),
|
|
133
|
+
exception_if_vertex='403',
|
|
134
|
+
),
|
|
135
|
+
pytest_helper.TestTableItem(
|
|
136
|
+
name='test_image_jpg_file_uri',
|
|
137
|
+
skip_in_api_mode=(
|
|
138
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
139
|
+
),
|
|
140
|
+
parameters=types._GenerateContentParameters(
|
|
141
|
+
model='gemini-2.5-flash',
|
|
142
|
+
contents=[
|
|
143
|
+
t.t_content('What is this image about?'),
|
|
144
|
+
t.t_content(
|
|
145
|
+
{
|
|
146
|
+
'role': 'user',
|
|
147
|
+
'parts': [
|
|
148
|
+
types.PartDict({
|
|
149
|
+
'file_data': {
|
|
150
|
+
'file_uri': (
|
|
151
|
+
'https://generativelanguage.googleapis.com/v1beta/files/22xab9a8jp0v'
|
|
152
|
+
),
|
|
153
|
+
'mime_type': 'image/jpeg',
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
),
|
|
159
|
+
],
|
|
160
|
+
),
|
|
161
|
+
exception_if_vertex='403',
|
|
162
|
+
),
|
|
163
|
+
pytest_helper.TestTableItem(
|
|
164
|
+
name='test_image_inline_part_media_resolution',
|
|
165
|
+
parameters=types._GenerateContentParameters(
|
|
166
|
+
model='gemini-2.5-flash',
|
|
167
|
+
contents=[
|
|
168
|
+
t.t_content('What is this image about?'),
|
|
169
|
+
t.t_content(
|
|
170
|
+
{
|
|
171
|
+
'role': 'user',
|
|
172
|
+
'parts': [
|
|
173
|
+
types.Part(
|
|
174
|
+
inline_data=types.Blob(
|
|
175
|
+
data=image_string, mime_type='image/png'
|
|
176
|
+
),
|
|
177
|
+
media_resolution={'level': 'MEDIA_RESOLUTION_LOW'}
|
|
178
|
+
)
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
),
|
|
182
|
+
],
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
pytest_helper.TestTableItem(
|
|
186
|
+
name='test_application_pdf_file_uri',
|
|
187
|
+
skip_in_api_mode=(
|
|
188
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
189
|
+
),
|
|
190
|
+
parameters=types._GenerateContentParameters(
|
|
191
|
+
model='gemini-2.5-flash',
|
|
192
|
+
contents=[
|
|
193
|
+
t.t_content(
|
|
194
|
+
'Summarize the pdf in concise and professional tone.'
|
|
195
|
+
),
|
|
196
|
+
t.t_content(
|
|
197
|
+
{
|
|
198
|
+
'role': 'user',
|
|
199
|
+
'parts': [
|
|
200
|
+
types.PartDict({
|
|
201
|
+
'file_data': {
|
|
202
|
+
'file_uri': (
|
|
203
|
+
'https://generativelanguage.googleapis.com/v1beta/files/9tnpjy0re13a'
|
|
204
|
+
),
|
|
205
|
+
'mime_type': 'application/pdf',
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
),
|
|
211
|
+
],
|
|
212
|
+
),
|
|
213
|
+
exception_if_vertex='403',
|
|
214
|
+
),
|
|
215
|
+
pytest_helper.TestTableItem(
|
|
216
|
+
name='test_video_mp4_file_uri',
|
|
217
|
+
skip_in_api_mode=(
|
|
218
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
219
|
+
),
|
|
220
|
+
parameters=types._GenerateContentParameters(
|
|
221
|
+
model='gemini-2.5-flash',
|
|
222
|
+
contents=[
|
|
223
|
+
t.t_content(
|
|
224
|
+
"""
|
|
225
|
+
summarize the video in concise and professional tone.
|
|
226
|
+
the summary should include all important information said in the video.
|
|
227
|
+
""",
|
|
228
|
+
),
|
|
229
|
+
t.t_content(
|
|
230
|
+
{
|
|
231
|
+
'role': 'user',
|
|
232
|
+
'parts': [
|
|
233
|
+
types.PartDict({
|
|
234
|
+
'file_data': {
|
|
235
|
+
'file_uri': (
|
|
236
|
+
'https://generativelanguage.googleapis.com/v1beta/files/i2ojhd8z99uk'
|
|
237
|
+
),
|
|
238
|
+
'mime_type': 'video/mp4',
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
),
|
|
244
|
+
],
|
|
245
|
+
),
|
|
246
|
+
exception_if_vertex='403',
|
|
247
|
+
),
|
|
248
|
+
pytest_helper.TestTableItem(
|
|
249
|
+
name='test_audio_m4a_file_uri',
|
|
250
|
+
skip_in_api_mode=(
|
|
251
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
252
|
+
),
|
|
253
|
+
parameters=types._GenerateContentParameters(
|
|
254
|
+
model='gemini-2.5-flash',
|
|
255
|
+
contents=[
|
|
256
|
+
t.t_content(
|
|
257
|
+
"""
|
|
258
|
+
Provide a summary for the audio in the beginning of the transcript.
|
|
259
|
+
Provide concise chapter titles with timestamps.
|
|
260
|
+
Do not make up any information that is not part of the audio.
|
|
261
|
+
""",
|
|
262
|
+
),
|
|
263
|
+
t.t_content(
|
|
264
|
+
{
|
|
265
|
+
'role': 'user',
|
|
266
|
+
'parts': [
|
|
267
|
+
types.PartDict({
|
|
268
|
+
'file_data': {
|
|
269
|
+
'file_uri': (
|
|
270
|
+
'https://generativelanguage.googleapis.com/v1beta/files/0o9iyit198g1'
|
|
271
|
+
),
|
|
272
|
+
'mime_type': 'audio/mp4',
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
),
|
|
278
|
+
],
|
|
279
|
+
),
|
|
280
|
+
exception_if_vertex='403',
|
|
281
|
+
),
|
|
282
|
+
pytest_helper.TestTableItem(
|
|
283
|
+
name='test_mldev_video_offset_and_fps',
|
|
284
|
+
skip_in_api_mode=(
|
|
285
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
286
|
+
),
|
|
287
|
+
parameters=types._GenerateContentParameters(
|
|
288
|
+
model='gemini-2.5-flash',
|
|
289
|
+
contents=[
|
|
290
|
+
types.Content(
|
|
291
|
+
role='user',
|
|
292
|
+
parts=[
|
|
293
|
+
types.Part(text='summarize this video'),
|
|
294
|
+
types.Part(
|
|
295
|
+
file_data=types.FileData(
|
|
296
|
+
file_uri='https://generativelanguage.googleapis.com/v1beta/files/fq9r5ftyqrho',
|
|
297
|
+
mime_type= 'video/mp4',
|
|
298
|
+
),
|
|
299
|
+
video_metadata=types.VideoMetadata(
|
|
300
|
+
start_offset='0s',
|
|
301
|
+
end_offset= '5s',
|
|
302
|
+
fps= 3,
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
]
|
|
306
|
+
),
|
|
307
|
+
],
|
|
308
|
+
),
|
|
309
|
+
exception_if_vertex='403',
|
|
310
|
+
),
|
|
311
|
+
pytest_helper.TestTableItem(
|
|
312
|
+
name='test_video_gcs_file_uri',
|
|
313
|
+
skip_in_api_mode=(
|
|
314
|
+
'Name of the file is hardcoded, only supporting replay mode.'
|
|
315
|
+
),
|
|
316
|
+
parameters=types._GenerateContentParameters(
|
|
317
|
+
model='gemini-2.5-flash',
|
|
318
|
+
contents=[
|
|
319
|
+
t.t_content('what is the video about?'),
|
|
320
|
+
t.t_content(
|
|
321
|
+
{
|
|
322
|
+
'role': 'user',
|
|
323
|
+
'parts': [
|
|
324
|
+
types.PartDict({
|
|
325
|
+
'file_data': {
|
|
326
|
+
'file_uri': (
|
|
327
|
+
'gs://generativeai-downloads/videos/Big_Buck_Bunny.mp4'
|
|
328
|
+
),
|
|
329
|
+
'mime_type': 'video/mp4',
|
|
330
|
+
},
|
|
331
|
+
'video_metadata': {
|
|
332
|
+
'start_offset': '0s',
|
|
333
|
+
'end_offset': '10s',
|
|
334
|
+
'fps': 3,
|
|
335
|
+
},
|
|
336
|
+
})
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
),
|
|
340
|
+
],
|
|
341
|
+
),
|
|
342
|
+
exception_if_mldev='400',
|
|
343
|
+
),
|
|
344
|
+
pytest_helper.TestTableItem(
|
|
345
|
+
name='test_image_base64',
|
|
346
|
+
parameters=types._GenerateContentParameters(
|
|
347
|
+
model='gemini-2.5-flash',
|
|
348
|
+
contents=[
|
|
349
|
+
t.t_content('What is this image about?'),
|
|
350
|
+
t.t_content(
|
|
351
|
+
{
|
|
352
|
+
'role': 'user',
|
|
353
|
+
'parts': [
|
|
354
|
+
types.Part(
|
|
355
|
+
inline_data=types.Blob(
|
|
356
|
+
data=image_string, mime_type='image/png'
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
),
|
|
362
|
+
],
|
|
363
|
+
),
|
|
364
|
+
),
|
|
365
|
+
pytest_helper.TestTableItem(
|
|
366
|
+
name='test_union_none_part',
|
|
367
|
+
parameters=types._GenerateContentParameters(
|
|
368
|
+
model='gemini-2.5-flash',
|
|
369
|
+
contents=[],
|
|
370
|
+
),
|
|
371
|
+
exception_if_mldev='contents',
|
|
372
|
+
exception_if_vertex='contents',
|
|
373
|
+
has_union=True,
|
|
374
|
+
),
|
|
375
|
+
pytest_helper.TestTableItem(
|
|
376
|
+
name='test_dict_content',
|
|
377
|
+
parameters=types._GenerateContentParameters(
|
|
378
|
+
model='gemini-2.5-flash',
|
|
379
|
+
contents=t.t_contents(
|
|
380
|
+
types.ContentDict(
|
|
381
|
+
{'role': 'user', 'parts': [{'text': 'what is your name?'}]}
|
|
382
|
+
),
|
|
383
|
+
),
|
|
384
|
+
),
|
|
385
|
+
),
|
|
386
|
+
pytest_helper.TestTableItem(
|
|
387
|
+
name='test_union_part_list',
|
|
388
|
+
parameters=types._GenerateContentParameters(
|
|
389
|
+
model='gemini-2.5-flash',
|
|
390
|
+
contents=['What is your name?'],
|
|
391
|
+
),
|
|
392
|
+
has_union=True,
|
|
393
|
+
),
|
|
394
|
+
]
|
|
395
|
+
pytestmark = pytest_helper.setup(
|
|
396
|
+
file=__file__,
|
|
397
|
+
globals_for_file=globals(),
|
|
398
|
+
test_method='models.generate_content',
|
|
399
|
+
test_table=test_table,
|
|
400
|
+
)
|
|
401
|
+
pytest_plugins = ('pytest_asyncio',)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def test_empty_part(client):
|
|
405
|
+
client.models.generate_content(
|
|
406
|
+
model='gemini-2.5-flash',
|
|
407
|
+
contents=t.t_contents(['']),
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def test_none_list_part(client):
|
|
412
|
+
# pydantic will raise ValidationError
|
|
413
|
+
with pytest.raises(ValidationError):
|
|
414
|
+
client.models.generate_content(
|
|
415
|
+
model='gemini-2.5-flash',
|
|
416
|
+
contents=[None],
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def test_image_file(client):
|
|
421
|
+
client.models.generate_content(
|
|
422
|
+
model='gemini-2.5-flash',
|
|
423
|
+
contents=[
|
|
424
|
+
'What is this image about?',
|
|
425
|
+
{'inline_data': {'data': image_bytes, 'mimeType': 'image/png'}},
|
|
426
|
+
],
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def test_image_jpeg(client, image_jpeg):
|
|
431
|
+
client.models.generate_content(
|
|
432
|
+
model='gemini-2.5-flash',
|
|
433
|
+
contents=['What is this image about?', image_jpeg],
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def test_from_uri(client):
|
|
438
|
+
# gs://generativeai-downloads/images/scones.jpg isn't supported in MLDev
|
|
439
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
440
|
+
client.models.generate_content(
|
|
441
|
+
model='gemini-2.5-flash',
|
|
442
|
+
contents=[
|
|
443
|
+
'What is this image about?',
|
|
444
|
+
types.Part.from_uri(
|
|
445
|
+
file_uri='gs://generativeai-downloads/images/scones.jpg',
|
|
446
|
+
mime_type='image/jpeg',
|
|
447
|
+
),
|
|
448
|
+
],
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def test_user_content_text(client):
|
|
453
|
+
response = client.models.generate_content(
|
|
454
|
+
model='gemini-2.5-flash',
|
|
455
|
+
contents=types.UserContent(parts='why is the sky blue?'),
|
|
456
|
+
)
|
|
457
|
+
assert response.text
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def test_user_content_part(client):
|
|
461
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
462
|
+
response = client.models.generate_content(
|
|
463
|
+
model='gemini-2.5-flash',
|
|
464
|
+
contents=types.UserContent(
|
|
465
|
+
parts=[
|
|
466
|
+
'what is this image about?',
|
|
467
|
+
types.Part.from_uri(
|
|
468
|
+
file_uri='gs://generativeai-downloads/images/scones.jpg',
|
|
469
|
+
mime_type='image/jpeg',
|
|
470
|
+
),
|
|
471
|
+
]
|
|
472
|
+
),
|
|
473
|
+
)
|
|
474
|
+
assert response.text
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
def test_model_content_text(client):
|
|
478
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
479
|
+
response = client.models.generate_content(
|
|
480
|
+
model='gemini-2.5-flash',
|
|
481
|
+
contents=[
|
|
482
|
+
types.UserContent(
|
|
483
|
+
parts=[
|
|
484
|
+
'what is this image about?',
|
|
485
|
+
types.Part.from_uri(
|
|
486
|
+
file_uri=(
|
|
487
|
+
'gs://generativeai-downloads/images/scones.jpg'
|
|
488
|
+
),
|
|
489
|
+
mime_type='image/jpeg',
|
|
490
|
+
),
|
|
491
|
+
]
|
|
492
|
+
),
|
|
493
|
+
types.ModelContent(
|
|
494
|
+
parts=(
|
|
495
|
+
'The image is about a cozy breakfast or brunch with'
|
|
496
|
+
' blueberry scones, coffee, and fresh flowers.'
|
|
497
|
+
)
|
|
498
|
+
),
|
|
499
|
+
types.UserContent(
|
|
500
|
+
parts='Is this a good environment for a family gathering?'
|
|
501
|
+
),
|
|
502
|
+
],
|
|
503
|
+
)
|
|
504
|
+
assert response.text
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def test_from_file_input(client):
|
|
508
|
+
with pytest_helper.exception_if_vertex(client, ValueError):
|
|
509
|
+
file = client.files.upload(file='tests/data/story.txt')
|
|
510
|
+
client.models.generate_content(
|
|
511
|
+
model='gemini-2.5-flash',
|
|
512
|
+
contents=file,
|
|
513
|
+
)
|
|
514
|
+
client.models.generate_content(
|
|
515
|
+
model='gemini-2.5-flash',
|
|
516
|
+
contents=[
|
|
517
|
+
'Summarize this file',
|
|
518
|
+
file,
|
|
519
|
+
],
|
|
520
|
+
)
|
|
521
|
+
client.models.generate_content(
|
|
522
|
+
model='gemini-2.5-flash',
|
|
523
|
+
contents=[['Summarize this file', file]],
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def test_from_file_dict_input(client):
|
|
528
|
+
with pytest_helper.exception_if_vertex(client, ValueError):
|
|
529
|
+
file = client.files.upload(file='tests/data/story.txt')
|
|
530
|
+
file_dict = file.model_dump()
|
|
531
|
+
client.models.generate_content(
|
|
532
|
+
model='gemini-2.5-flash',
|
|
533
|
+
contents=file_dict,
|
|
534
|
+
)
|
|
535
|
+
client.models.generate_content(
|
|
536
|
+
model='gemini-2.5-flash',
|
|
537
|
+
contents=[
|
|
538
|
+
'Summarize this file',
|
|
539
|
+
file_dict,
|
|
540
|
+
],
|
|
541
|
+
)
|
|
542
|
+
client.models.generate_content(
|
|
543
|
+
model='gemini-2.5-flash',
|
|
544
|
+
contents=[['Summarize this file', file_dict]],
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def test_from_uploaded_file_uri(client):
|
|
549
|
+
with pytest_helper.exception_if_vertex(client, ValueError):
|
|
550
|
+
file = client.files.upload(file='tests/data/story.txt')
|
|
551
|
+
file_part = types.Part.from_uri(file_uri=file.uri, mime_type='text/plain')
|
|
552
|
+
client.models.generate_content(
|
|
553
|
+
model='gemini-2.5-flash',
|
|
554
|
+
contents=file_part,
|
|
555
|
+
)
|
|
556
|
+
client.models.generate_content(
|
|
557
|
+
model='gemini-2.5-flash',
|
|
558
|
+
contents=[
|
|
559
|
+
'Summarize this file',
|
|
560
|
+
file_part,
|
|
561
|
+
],
|
|
562
|
+
)
|
|
563
|
+
client.models.generate_content(
|
|
564
|
+
model='gemini-2.5-flash',
|
|
565
|
+
contents=[['Summarize this file', file_part]],
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def test_from_uri_inferred_mime_type(client):
|
|
570
|
+
# gs://generativeai-downloads/images/scones.jpg isn't supported in MLDev
|
|
571
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
572
|
+
client.models.generate_content(
|
|
573
|
+
model='gemini-2.5-flash',
|
|
574
|
+
contents=[
|
|
575
|
+
'What is this image about?',
|
|
576
|
+
types.Part.from_uri(
|
|
577
|
+
file_uri='gs://generativeai-downloads/images/scones.jpg'
|
|
578
|
+
),
|
|
579
|
+
],
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def test_from_uri_invalid_inferred_mime_type(client):
|
|
584
|
+
# Throws ValueError if mime_type cannot be inferred.
|
|
585
|
+
with pytest.raises(ValueError):
|
|
586
|
+
client.models.generate_content(
|
|
587
|
+
model='gemini-2.5-flash',
|
|
588
|
+
contents=[
|
|
589
|
+
'What is this image about?',
|
|
590
|
+
types.Part.from_uri(
|
|
591
|
+
file_uri='uri/without/mime/type'
|
|
592
|
+
),
|
|
593
|
+
],
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def test_audio_uri(client):
|
|
598
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
599
|
+
client.models.generate_content(
|
|
600
|
+
model='gemini-2.5-flash',
|
|
601
|
+
contents=[
|
|
602
|
+
"""
|
|
603
|
+
Provide a summary for the audio in the beginning of the transcript.
|
|
604
|
+
Provide concise chapter titles with timestamps.
|
|
605
|
+
Do not make up any information that is not part of the audio.
|
|
606
|
+
""",
|
|
607
|
+
types.Part.from_uri(
|
|
608
|
+
file_uri='gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
|
|
609
|
+
mime_type='audio/mpeg',
|
|
610
|
+
),
|
|
611
|
+
],
|
|
612
|
+
config={
|
|
613
|
+
'system_instruction': (
|
|
614
|
+
'You are a helpful assistant for audio transcription.'
|
|
615
|
+
)
|
|
616
|
+
},
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def test_pdf_uri(client):
|
|
621
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
622
|
+
client.models.generate_content(
|
|
623
|
+
model='gemini-2.5-flash',
|
|
624
|
+
contents=[
|
|
625
|
+
'summarize the pdf in concise and professional tone',
|
|
626
|
+
types.Part.from_uri(
|
|
627
|
+
file_uri='gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
|
|
628
|
+
mime_type='application/pdf',
|
|
629
|
+
),
|
|
630
|
+
],
|
|
631
|
+
config={
|
|
632
|
+
'system_instruction': (
|
|
633
|
+
'You are a helpful assistant for academic literature review.'
|
|
634
|
+
)
|
|
635
|
+
},
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
def test_video_uri(client):
|
|
640
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
641
|
+
client.models.generate_content(
|
|
642
|
+
model='gemini-2.5-flash',
|
|
643
|
+
contents=[
|
|
644
|
+
"""
|
|
645
|
+
summarize the video in concise and professional tone.
|
|
646
|
+
the summary should include all important information said in the video.
|
|
647
|
+
""",
|
|
648
|
+
types.Part.from_uri(
|
|
649
|
+
file_uri='gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
|
|
650
|
+
mime_type='video/mp4',
|
|
651
|
+
),
|
|
652
|
+
],
|
|
653
|
+
config={
|
|
654
|
+
'system_instruction': (
|
|
655
|
+
'you are a helpful assistant for market research.'
|
|
656
|
+
)
|
|
657
|
+
},
|
|
658
|
+
)
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def test_video_audio_uri(client):
|
|
662
|
+
with pytest_helper.exception_if_mldev(client, errors.ClientError):
|
|
663
|
+
client.models.generate_content(
|
|
664
|
+
model='gemini-2.5-flash',
|
|
665
|
+
contents=[
|
|
666
|
+
"""
|
|
667
|
+
Is the audio related to the video?
|
|
668
|
+
If so, how?
|
|
669
|
+
What are the common themes?
|
|
670
|
+
What are the different emphases?
|
|
671
|
+
""",
|
|
672
|
+
types.Part.from_uri(
|
|
673
|
+
file_uri='gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
|
|
674
|
+
mime_type='video/mp4',
|
|
675
|
+
),
|
|
676
|
+
types.Part.from_uri(
|
|
677
|
+
file_uri='gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
|
|
678
|
+
mime_type='audio/mpeg',
|
|
679
|
+
),
|
|
680
|
+
],
|
|
681
|
+
config={
|
|
682
|
+
'system_instruction': (
|
|
683
|
+
'you are a helpful assistant for people with visual and hearing'
|
|
684
|
+
' disabilities.'
|
|
685
|
+
)
|
|
686
|
+
},
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
def test_file(client):
|
|
691
|
+
with pytest_helper.exception_if_vertex(client, errors.ClientError):
|
|
692
|
+
file = types.File(
|
|
693
|
+
uri='https://generativelanguage.googleapis.com/v1beta/files/8q6j6weg80ey',
|
|
694
|
+
mime_type='text/plain',
|
|
695
|
+
)
|
|
696
|
+
client.models.generate_content(
|
|
697
|
+
model='gemini-2.5-flash',
|
|
698
|
+
contents=[
|
|
699
|
+
'Summarize this file',
|
|
700
|
+
file,
|
|
701
|
+
],
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def test_file_error(client):
|
|
706
|
+
# missing mime_type
|
|
707
|
+
with pytest.raises(ValueError):
|
|
708
|
+
file = types.File(
|
|
709
|
+
uri='https://generativelanguage.googleapis.com/v1beta/files/8q6j6weg80ey',
|
|
710
|
+
)
|
|
711
|
+
client.models.generate_content(
|
|
712
|
+
model='gemini-2.5-flash',
|
|
713
|
+
contents=[
|
|
714
|
+
'Summarize this file',
|
|
715
|
+
file,
|
|
716
|
+
],
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def test_from_text(client):
|
|
721
|
+
client.models.generate_content(
|
|
722
|
+
model='gemini-2.5-flash',
|
|
723
|
+
contents=[types.Part.from_text(text='What is your name?')],
|
|
724
|
+
)
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
def test_from_bytes_image(client):
|
|
728
|
+
client.models.generate_content(
|
|
729
|
+
model='gemini-2.5-flash',
|
|
730
|
+
contents=[
|
|
731
|
+
'What is this image about?',
|
|
732
|
+
types.Part.from_bytes(data=image_bytes, mime_type='image/png'),
|
|
733
|
+
],
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
def test_from_bytes_image_dict(client):
|
|
738
|
+
client.models.generate_content(
|
|
739
|
+
model='gemini-2.5-flash',
|
|
740
|
+
contents=[
|
|
741
|
+
{'text': 'What is this image about?'},
|
|
742
|
+
{'inline_data': {'data': image_bytes, 'mimeType': 'image/png'}},
|
|
743
|
+
],
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def test_from_bytes_image_none(client):
|
|
748
|
+
with pytest.raises(errors.ClientError) as e:
|
|
749
|
+
client.models.generate_content(
|
|
750
|
+
model='gemini-2.5-flash',
|
|
751
|
+
contents=[
|
|
752
|
+
{'text': 'What is this image about?'},
|
|
753
|
+
{'inline_data': {'data': None, 'mimeType': 'image/png'}},
|
|
754
|
+
],
|
|
755
|
+
)
|
|
756
|
+
assert 'INVALID_ARGUMENT' in str(e)
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
def test_from_bytes_video(client):
|
|
760
|
+
client.models.generate_content(
|
|
761
|
+
model='gemini-2.5-flash',
|
|
762
|
+
contents=[
|
|
763
|
+
'What is this video about?',
|
|
764
|
+
types.Part.from_bytes(data=video_bytes, mime_type='video/mp4'),
|
|
765
|
+
],
|
|
766
|
+
)
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
def test_from_bytes_audio(client):
|
|
770
|
+
client.models.generate_content(
|
|
771
|
+
model='gemini-2.5-flash',
|
|
772
|
+
contents=[
|
|
773
|
+
'What is this audio about?',
|
|
774
|
+
types.Part.from_bytes(data=audio_bytes, mime_type='audio/mpeg'),
|
|
775
|
+
],
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
def test_from_bytes_pdf(client):
|
|
780
|
+
client.models.generate_content(
|
|
781
|
+
model='gemini-2.5-flash',
|
|
782
|
+
contents=[
|
|
783
|
+
'What is this pdf about?',
|
|
784
|
+
types.Part.from_bytes(data=pdf_bytes, mime_type='application/pdf'),
|
|
785
|
+
],
|
|
786
|
+
)
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def test_from_function_call_response(client):
|
|
790
|
+
function_call = types.Part.from_function_call(
|
|
791
|
+
name='get_weather', args={'location': 'Boston'}
|
|
792
|
+
)
|
|
793
|
+
function_response = types.Part.from_function_response(
|
|
794
|
+
name='get_weather', response={'weather': 'sunny'}
|
|
795
|
+
)
|
|
796
|
+
response = client.models.generate_content(
|
|
797
|
+
model='gemini-2.5-flash',
|
|
798
|
+
contents=[
|
|
799
|
+
'what is the weather in Boston?',
|
|
800
|
+
function_call,
|
|
801
|
+
function_response,
|
|
802
|
+
],
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
assert 'sunny' in response.text
|
|
806
|
+
assert 'Boston' in response.text
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
@pytest.mark.asyncio
|
|
810
|
+
async def test_image_base64_stream_async(client):
|
|
811
|
+
async for part in await client.aio.models.generate_content_stream(
|
|
812
|
+
model='gemini-2.5-flash',
|
|
813
|
+
contents=[
|
|
814
|
+
'What is this image about?',
|
|
815
|
+
{'inline_data': {'data': image_string, 'mimeType': 'image/png'}},
|
|
816
|
+
],
|
|
817
|
+
):
|
|
818
|
+
pass
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
# function_call and function_response are tested in generate_content_tools.py
|