google-genai 1.55.0__py3-none-any.whl → 1.56.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.
Files changed (241) hide show
  1. google/genai/_interactions/_base_client.py +8 -2
  2. google/genai/_interactions/resources/interactions.py +6 -6
  3. google/genai/_interactions/types/__init__.py +2 -0
  4. google/genai/_interactions/types/audio_content.py +0 -1
  5. google/genai/_interactions/types/audio_content_param.py +0 -1
  6. google/genai/_interactions/types/code_execution_call_content.py +0 -1
  7. google/genai/_interactions/types/code_execution_call_content_param.py +0 -1
  8. google/genai/_interactions/types/code_execution_result_content.py +0 -1
  9. google/genai/_interactions/types/code_execution_result_content_param.py +0 -1
  10. google/genai/_interactions/types/content_delta.py +7 -23
  11. google/genai/_interactions/types/deep_research_agent_config.py +0 -1
  12. google/genai/_interactions/types/deep_research_agent_config_param.py +0 -1
  13. google/genai/_interactions/types/document_content.py +3 -2
  14. google/genai/_interactions/types/document_content_param.py +3 -2
  15. google/genai/{tests/__init__.py → _interactions/types/document_mime_type.py} +5 -3
  16. google/genai/{tests/afc/__init__.py → _interactions/types/document_mime_type_param.py} +8 -4
  17. google/genai/_interactions/types/dynamic_agent_config.py +0 -1
  18. google/genai/_interactions/types/dynamic_agent_config_param.py +0 -1
  19. google/genai/_interactions/types/file_search_result_content.py +0 -1
  20. google/genai/_interactions/types/file_search_result_content_param.py +0 -1
  21. google/genai/_interactions/types/function_call_content.py +0 -1
  22. google/genai/_interactions/types/function_call_content_param.py +0 -1
  23. google/genai/_interactions/types/function_result_content.py +1 -2
  24. google/genai/_interactions/types/function_result_content_param.py +1 -2
  25. google/genai/_interactions/types/google_search_call_content.py +0 -1
  26. google/genai/_interactions/types/google_search_call_content_param.py +0 -1
  27. google/genai/_interactions/types/google_search_result_content.py +0 -1
  28. google/genai/_interactions/types/google_search_result_content_param.py +0 -1
  29. google/genai/_interactions/types/image_content.py +1 -2
  30. google/genai/_interactions/types/image_content_param.py +1 -2
  31. google/genai/_interactions/types/mcp_server_tool_call_content.py +0 -1
  32. google/genai/_interactions/types/mcp_server_tool_call_content_param.py +0 -1
  33. google/genai/_interactions/types/mcp_server_tool_result_content.py +1 -2
  34. google/genai/_interactions/types/mcp_server_tool_result_content_param.py +1 -2
  35. google/genai/_interactions/types/text_content.py +0 -1
  36. google/genai/_interactions/types/text_content_param.py +0 -1
  37. google/genai/_interactions/types/thinking_level.py +1 -1
  38. google/genai/_interactions/types/thought_content.py +0 -1
  39. google/genai/_interactions/types/thought_content_param.py +0 -1
  40. google/genai/_interactions/types/url_context_call_content.py +0 -1
  41. google/genai/_interactions/types/url_context_call_content_param.py +0 -1
  42. google/genai/_interactions/types/url_context_result_content.py +0 -1
  43. google/genai/_interactions/types/url_context_result_content_param.py +0 -1
  44. google/genai/_interactions/types/video_content.py +1 -2
  45. google/genai/_interactions/types/video_content_param.py +1 -2
  46. google/genai/_live_converters.py +2 -30
  47. google/genai/client.py +3 -1
  48. google/genai/models.py +2 -29
  49. google/genai/tunings.py +1 -27
  50. google/genai/types.py +20 -22
  51. google/genai/version.py +1 -1
  52. {google_genai-1.55.0.dist-info → google_genai-1.56.0.dist-info}/METADATA +224 -22
  53. google_genai-1.56.0.dist-info/RECORD +162 -0
  54. google/genai/tests/afc/test_convert_if_exist_pydantic_model.py +0 -309
  55. google/genai/tests/afc/test_convert_number_values_for_function_call_args.py +0 -63
  56. google/genai/tests/afc/test_find_afc_incompatible_tool_indexes.py +0 -240
  57. google/genai/tests/afc/test_generate_content_stream_afc.py +0 -530
  58. google/genai/tests/afc/test_generate_content_stream_afc_thoughts.py +0 -77
  59. google/genai/tests/afc/test_get_function_map.py +0 -176
  60. google/genai/tests/afc/test_get_function_response_parts.py +0 -277
  61. google/genai/tests/afc/test_get_max_remote_calls_for_afc.py +0 -130
  62. google/genai/tests/afc/test_invoke_function_from_dict_args.py +0 -241
  63. google/genai/tests/afc/test_raise_error_for_afc_incompatible_config.py +0 -159
  64. google/genai/tests/afc/test_should_append_afc_history.py +0 -53
  65. google/genai/tests/afc/test_should_disable_afc.py +0 -214
  66. google/genai/tests/batches/__init__.py +0 -17
  67. google/genai/tests/batches/test_cancel.py +0 -77
  68. google/genai/tests/batches/test_create.py +0 -78
  69. google/genai/tests/batches/test_create_with_bigquery.py +0 -113
  70. google/genai/tests/batches/test_create_with_file.py +0 -82
  71. google/genai/tests/batches/test_create_with_gcs.py +0 -125
  72. google/genai/tests/batches/test_create_with_inlined_requests.py +0 -255
  73. google/genai/tests/batches/test_delete.py +0 -86
  74. google/genai/tests/batches/test_embedding.py +0 -157
  75. google/genai/tests/batches/test_get.py +0 -78
  76. google/genai/tests/batches/test_list.py +0 -79
  77. google/genai/tests/caches/__init__.py +0 -17
  78. google/genai/tests/caches/constants.py +0 -29
  79. google/genai/tests/caches/test_create.py +0 -210
  80. google/genai/tests/caches/test_create_custom_url.py +0 -105
  81. google/genai/tests/caches/test_delete.py +0 -54
  82. google/genai/tests/caches/test_delete_custom_url.py +0 -52
  83. google/genai/tests/caches/test_get.py +0 -94
  84. google/genai/tests/caches/test_get_custom_url.py +0 -52
  85. google/genai/tests/caches/test_list.py +0 -68
  86. google/genai/tests/caches/test_update.py +0 -70
  87. google/genai/tests/caches/test_update_custom_url.py +0 -58
  88. google/genai/tests/chats/__init__.py +0 -1
  89. google/genai/tests/chats/test_get_history.py +0 -597
  90. google/genai/tests/chats/test_send_message.py +0 -844
  91. google/genai/tests/chats/test_validate_response.py +0 -90
  92. google/genai/tests/client/__init__.py +0 -17
  93. google/genai/tests/client/test_async_stream.py +0 -427
  94. google/genai/tests/client/test_client_close.py +0 -197
  95. google/genai/tests/client/test_client_initialization.py +0 -1687
  96. google/genai/tests/client/test_client_requests.py +0 -355
  97. google/genai/tests/client/test_custom_client.py +0 -77
  98. google/genai/tests/client/test_http_options.py +0 -178
  99. google/genai/tests/client/test_replay_client_equality.py +0 -168
  100. google/genai/tests/client/test_retries.py +0 -846
  101. google/genai/tests/client/test_upload_errors.py +0 -136
  102. google/genai/tests/common/__init__.py +0 -17
  103. google/genai/tests/common/test_common.py +0 -954
  104. google/genai/tests/conftest.py +0 -162
  105. google/genai/tests/documents/__init__.py +0 -17
  106. google/genai/tests/documents/test_delete.py +0 -51
  107. google/genai/tests/documents/test_get.py +0 -85
  108. google/genai/tests/documents/test_list.py +0 -72
  109. google/genai/tests/errors/__init__.py +0 -1
  110. google/genai/tests/errors/test_api_error.py +0 -417
  111. google/genai/tests/file_search_stores/__init__.py +0 -17
  112. google/genai/tests/file_search_stores/test_create.py +0 -66
  113. google/genai/tests/file_search_stores/test_delete.py +0 -64
  114. google/genai/tests/file_search_stores/test_get.py +0 -94
  115. google/genai/tests/file_search_stores/test_import_file.py +0 -112
  116. google/genai/tests/file_search_stores/test_list.py +0 -57
  117. google/genai/tests/file_search_stores/test_upload_to_file_search_store.py +0 -141
  118. google/genai/tests/files/__init__.py +0 -17
  119. google/genai/tests/files/test_delete.py +0 -46
  120. google/genai/tests/files/test_download.py +0 -85
  121. google/genai/tests/files/test_get.py +0 -46
  122. google/genai/tests/files/test_list.py +0 -72
  123. google/genai/tests/files/test_upload.py +0 -255
  124. google/genai/tests/imports/test_no_optional_imports.py +0 -28
  125. google/genai/tests/interactions/test_integration.py +0 -80
  126. google/genai/tests/live/__init__.py +0 -16
  127. google/genai/tests/live/test_live.py +0 -2177
  128. google/genai/tests/live/test_live_music.py +0 -362
  129. google/genai/tests/live/test_live_response.py +0 -163
  130. google/genai/tests/live/test_send_client_content.py +0 -147
  131. google/genai/tests/live/test_send_realtime_input.py +0 -268
  132. google/genai/tests/live/test_send_tool_response.py +0 -222
  133. google/genai/tests/local_tokenizer/__init__.py +0 -17
  134. google/genai/tests/local_tokenizer/test_local_tokenizer.py +0 -343
  135. google/genai/tests/local_tokenizer/test_local_tokenizer_loader.py +0 -235
  136. google/genai/tests/mcp/__init__.py +0 -17
  137. google/genai/tests/mcp/test_has_mcp_tool_usage.py +0 -89
  138. google/genai/tests/mcp/test_mcp_to_gemini_tools.py +0 -191
  139. google/genai/tests/mcp/test_parse_config_for_mcp_sessions.py +0 -201
  140. google/genai/tests/mcp/test_parse_config_for_mcp_usage.py +0 -130
  141. google/genai/tests/mcp/test_set_mcp_usage_header.py +0 -72
  142. google/genai/tests/models/__init__.py +0 -17
  143. google/genai/tests/models/constants.py +0 -8
  144. google/genai/tests/models/test_compute_tokens.py +0 -120
  145. google/genai/tests/models/test_count_tokens.py +0 -159
  146. google/genai/tests/models/test_delete.py +0 -107
  147. google/genai/tests/models/test_edit_image.py +0 -264
  148. google/genai/tests/models/test_embed_content.py +0 -94
  149. google/genai/tests/models/test_function_call_streaming.py +0 -442
  150. google/genai/tests/models/test_generate_content.py +0 -2502
  151. google/genai/tests/models/test_generate_content_cached_content.py +0 -132
  152. google/genai/tests/models/test_generate_content_config_zero_value.py +0 -103
  153. google/genai/tests/models/test_generate_content_from_apikey.py +0 -44
  154. google/genai/tests/models/test_generate_content_http_options.py +0 -40
  155. google/genai/tests/models/test_generate_content_image_generation.py +0 -143
  156. google/genai/tests/models/test_generate_content_mcp.py +0 -343
  157. google/genai/tests/models/test_generate_content_media_resolution.py +0 -97
  158. google/genai/tests/models/test_generate_content_model.py +0 -139
  159. google/genai/tests/models/test_generate_content_part.py +0 -821
  160. google/genai/tests/models/test_generate_content_thought.py +0 -76
  161. google/genai/tests/models/test_generate_content_tools.py +0 -1761
  162. google/genai/tests/models/test_generate_images.py +0 -191
  163. google/genai/tests/models/test_generate_videos.py +0 -759
  164. google/genai/tests/models/test_get.py +0 -104
  165. google/genai/tests/models/test_list.py +0 -233
  166. google/genai/tests/models/test_recontext_image.py +0 -189
  167. google/genai/tests/models/test_segment_image.py +0 -148
  168. google/genai/tests/models/test_update.py +0 -95
  169. google/genai/tests/models/test_upscale_image.py +0 -157
  170. google/genai/tests/operations/__init__.py +0 -17
  171. google/genai/tests/operations/test_get.py +0 -38
  172. google/genai/tests/public_samples/__init__.py +0 -17
  173. google/genai/tests/public_samples/test_gemini_text_only.py +0 -34
  174. google/genai/tests/pytest_helper.py +0 -229
  175. google/genai/tests/shared/__init__.py +0 -16
  176. google/genai/tests/shared/batches/__init__.py +0 -14
  177. google/genai/tests/shared/batches/test_create_delete.py +0 -57
  178. google/genai/tests/shared/batches/test_create_get_cancel.py +0 -56
  179. google/genai/tests/shared/batches/test_list.py +0 -40
  180. google/genai/tests/shared/caches/__init__.py +0 -14
  181. google/genai/tests/shared/caches/test_create_get_delete.py +0 -67
  182. google/genai/tests/shared/caches/test_create_update_get.py +0 -71
  183. google/genai/tests/shared/caches/test_list.py +0 -40
  184. google/genai/tests/shared/chats/__init__.py +0 -14
  185. google/genai/tests/shared/chats/test_send_message.py +0 -48
  186. google/genai/tests/shared/chats/test_send_message_stream.py +0 -50
  187. google/genai/tests/shared/files/__init__.py +0 -14
  188. google/genai/tests/shared/files/test_list.py +0 -41
  189. google/genai/tests/shared/files/test_upload_get_delete.py +0 -54
  190. google/genai/tests/shared/models/__init__.py +0 -14
  191. google/genai/tests/shared/models/test_compute_tokens.py +0 -41
  192. google/genai/tests/shared/models/test_count_tokens.py +0 -40
  193. google/genai/tests/shared/models/test_edit_image.py +0 -67
  194. google/genai/tests/shared/models/test_embed.py +0 -40
  195. google/genai/tests/shared/models/test_generate_content.py +0 -39
  196. google/genai/tests/shared/models/test_generate_content_stream.py +0 -54
  197. google/genai/tests/shared/models/test_generate_images.py +0 -40
  198. google/genai/tests/shared/models/test_generate_videos.py +0 -38
  199. google/genai/tests/shared/models/test_list.py +0 -37
  200. google/genai/tests/shared/models/test_recontext_image.py +0 -55
  201. google/genai/tests/shared/models/test_segment_image.py +0 -52
  202. google/genai/tests/shared/models/test_upscale_image.py +0 -52
  203. google/genai/tests/shared/tunings/__init__.py +0 -16
  204. google/genai/tests/shared/tunings/test_create.py +0 -46
  205. google/genai/tests/shared/tunings/test_create_get_cancel.py +0 -56
  206. google/genai/tests/shared/tunings/test_list.py +0 -39
  207. google/genai/tests/tokens/__init__.py +0 -16
  208. google/genai/tests/tokens/test_create.py +0 -154
  209. google/genai/tests/transformers/__init__.py +0 -17
  210. google/genai/tests/transformers/test_blobs.py +0 -71
  211. google/genai/tests/transformers/test_bytes.py +0 -15
  212. google/genai/tests/transformers/test_duck_type.py +0 -96
  213. google/genai/tests/transformers/test_function_responses.py +0 -72
  214. google/genai/tests/transformers/test_schema.py +0 -653
  215. google/genai/tests/transformers/test_t_batch.py +0 -286
  216. google/genai/tests/transformers/test_t_content.py +0 -160
  217. google/genai/tests/transformers/test_t_contents.py +0 -398
  218. google/genai/tests/transformers/test_t_part.py +0 -85
  219. google/genai/tests/transformers/test_t_parts.py +0 -87
  220. google/genai/tests/transformers/test_t_tool.py +0 -157
  221. google/genai/tests/transformers/test_t_tools.py +0 -195
  222. google/genai/tests/tunings/__init__.py +0 -16
  223. google/genai/tests/tunings/test_cancel.py +0 -39
  224. google/genai/tests/tunings/test_end_to_end.py +0 -106
  225. google/genai/tests/tunings/test_get.py +0 -67
  226. google/genai/tests/tunings/test_list.py +0 -75
  227. google/genai/tests/tunings/test_tune.py +0 -268
  228. google/genai/tests/types/__init__.py +0 -16
  229. google/genai/tests/types/test_bytes_internal.py +0 -271
  230. google/genai/tests/types/test_bytes_type.py +0 -152
  231. google/genai/tests/types/test_future.py +0 -101
  232. google/genai/tests/types/test_optional_types.py +0 -36
  233. google/genai/tests/types/test_part_type.py +0 -616
  234. google/genai/tests/types/test_schema_from_json_schema.py +0 -417
  235. google/genai/tests/types/test_schema_json_schema.py +0 -468
  236. google/genai/tests/types/test_types.py +0 -2903
  237. google_genai-1.55.0.dist-info/RECORD +0 -345
  238. /google/genai/{tests/interactions/__init__.py → _interactions/py.typed} +0 -0
  239. {google_genai-1.55.0.dist-info → google_genai-1.56.0.dist-info}/WHEEL +0 -0
  240. {google_genai-1.55.0.dist-info → google_genai-1.56.0.dist-info}/licenses/LICENSE +0 -0
  241. {google_genai-1.55.0.dist-info → google_genai-1.56.0.dist-info}/top_level.txt +0 -0
@@ -1,821 +0,0 @@
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