google-genai 1.19.0__py3-none-any.whl → 1.20.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/errors.py CHANGED
@@ -22,6 +22,7 @@ import json
22
22
 
23
23
  if TYPE_CHECKING:
24
24
  from .replay_api_client import ReplayResponse
25
+ import aiohttp
25
26
 
26
27
 
27
28
  class APIError(Exception):
@@ -36,7 +37,9 @@ class APIError(Exception):
36
37
  self,
37
38
  code: int,
38
39
  response_json: Any,
39
- response: Optional[Union['ReplayResponse', httpx.Response]] = None,
40
+ response: Optional[
41
+ Union['ReplayResponse', httpx.Response, 'aiohttp.ClientResponse']
42
+ ] = None,
40
43
  ):
41
44
  self.response = response
42
45
  self.details = response_json
@@ -106,12 +109,17 @@ class APIError(Exception):
106
109
 
107
110
  @classmethod
108
111
  async def raise_for_async_response(
109
- cls, response: Union['ReplayResponse', httpx.Response]
112
+ cls,
113
+ response: Union[
114
+ 'ReplayResponse', httpx.Response, 'aiohttp.ClientResponse'
115
+ ],
110
116
  ) -> None:
111
117
  """Raises an error with detailed error message if the response has an error status."""
112
- if response.status_code == 200:
113
- return
118
+ status_code = 0
119
+ response_json = None
114
120
  if isinstance(response, httpx.Response):
121
+ if response.status_code == 200:
122
+ return
115
123
  try:
116
124
  await response.aread()
117
125
  response_json = response.json()
@@ -121,10 +129,28 @@ class APIError(Exception):
121
129
  'message': message,
122
130
  'status': response.reason_phrase,
123
131
  }
132
+ status_code = response.status_code
124
133
  else:
125
- response_json = response.body_segments[0].get('error', {})
134
+ try:
135
+ import aiohttp # pylint: disable=g-import-not-at-top
136
+
137
+ if isinstance(response, aiohttp.ClientResponse):
138
+ if response.status == 200:
139
+ return
140
+ try:
141
+ response_json = await response.json()
142
+ except aiohttp.client_exceptions.ContentTypeError:
143
+ message = await response.text()
144
+ response_json = {
145
+ 'message': message,
146
+ 'status': response.reason,
147
+ }
148
+ status_code = response.status
149
+ else:
150
+ response_json = response.body_segments[0].get('error', {})
151
+ except ImportError:
152
+ response_json = response.body_segments[0].get('error', {})
126
153
 
127
- status_code = response.status_code
128
154
  if 400 <= status_code < 500:
129
155
  raise ClientError(status_code, response_json, response)
130
156
  elif 500 <= status_code < 600:
google/genai/files.py CHANGED
@@ -22,6 +22,7 @@ import os
22
22
  import pathlib
23
23
  from typing import Any, Optional, Union
24
24
  from urllib.parse import urlencode
25
+
25
26
  from . import _api_module
26
27
  from . import _common
27
28
  from . import _transformers as t
@@ -1152,15 +1153,18 @@ class AsyncFiles(_api_module.BaseModule):
1152
1153
  response = await self._create(
1153
1154
  file=file_obj, config=types.CreateFileConfig(http_options=http_options)
1154
1155
  )
1155
- if (
1156
- response.http_headers is None
1157
- or 'x-goog-upload-url' not in response.http_headers
1156
+ if response.http_headers is None or (
1157
+ 'x-goog-upload-url' not in response.http_headers
1158
+ and 'X-Goog-Upload-URL' not in response.http_headers
1158
1159
  ):
1159
1160
  raise KeyError(
1160
1161
  'Failed to create file. Upload URL did not returned from the create'
1161
1162
  ' file request.'
1162
1163
  )
1163
- upload_url = response.http_headers['x-goog-upload-url']
1164
+ elif 'x-goog-upload-url' in response.http_headers:
1165
+ upload_url = response.http_headers['x-goog-upload-url']
1166
+ else:
1167
+ upload_url = response.http_headers['X-Goog-Upload-URL']
1164
1168
 
1165
1169
  if isinstance(file, io.IOBase):
1166
1170
  return_file = await self._api_client.async_upload_file(
google/genai/models.py CHANGED
@@ -18,6 +18,7 @@
18
18
  import logging
19
19
  from typing import Any, AsyncIterator, Awaitable, Iterator, Optional, Union
20
20
  from urllib.parse import urlencode
21
+
21
22
  from . import _api_module
22
23
  from . import _common
23
24
  from . import _extra_utils
@@ -1364,6 +1365,28 @@ def _Image_to_mldev(
1364
1365
  return to_object
1365
1366
 
1366
1367
 
1368
+ def _Video_to_mldev(
1369
+ api_client: BaseApiClient,
1370
+ from_object: Union[dict[str, Any], object],
1371
+ parent_object: Optional[dict[str, Any]] = None,
1372
+ ) -> dict[str, Any]:
1373
+ to_object: dict[str, Any] = {}
1374
+ if getv(from_object, ['uri']) is not None:
1375
+ setv(to_object, ['video', 'uri'], getv(from_object, ['uri']))
1376
+
1377
+ if getv(from_object, ['video_bytes']) is not None:
1378
+ setv(
1379
+ to_object,
1380
+ ['video', 'encodedVideo'],
1381
+ t.t_bytes(api_client, getv(from_object, ['video_bytes'])),
1382
+ )
1383
+
1384
+ if getv(from_object, ['mime_type']) is not None:
1385
+ setv(to_object, ['encoding'], getv(from_object, ['mime_type']))
1386
+
1387
+ return to_object
1388
+
1389
+
1367
1390
  def _GenerateVideosConfig_to_mldev(
1368
1391
  api_client: BaseApiClient,
1369
1392
  from_object: Union[dict[str, Any], object],
@@ -1431,6 +1454,9 @@ def _GenerateVideosConfig_to_mldev(
1431
1454
  if getv(from_object, ['generate_audio']) is not None:
1432
1455
  raise ValueError('generate_audio parameter is not supported in Gemini API.')
1433
1456
 
1457
+ if getv(from_object, ['last_frame']) is not None:
1458
+ raise ValueError('last_frame parameter is not supported in Gemini API.')
1459
+
1434
1460
  return to_object
1435
1461
 
1436
1462
 
@@ -1457,6 +1483,9 @@ def _GenerateVideosParameters_to_mldev(
1457
1483
  _Image_to_mldev(api_client, getv(from_object, ['image']), to_object),
1458
1484
  )
1459
1485
 
1486
+ if getv(from_object, ['video']) is not None:
1487
+ raise ValueError('video parameter is not supported in Gemini API.')
1488
+
1460
1489
  if getv(from_object, ['config']) is not None:
1461
1490
  setv(
1462
1491
  to_object,
@@ -3233,6 +3262,28 @@ def _ComputeTokensParameters_to_vertex(
3233
3262
  return to_object
3234
3263
 
3235
3264
 
3265
+ def _Video_to_vertex(
3266
+ api_client: BaseApiClient,
3267
+ from_object: Union[dict[str, Any], object],
3268
+ parent_object: Optional[dict[str, Any]] = None,
3269
+ ) -> dict[str, Any]:
3270
+ to_object: dict[str, Any] = {}
3271
+ if getv(from_object, ['uri']) is not None:
3272
+ setv(to_object, ['gcsUri'], getv(from_object, ['uri']))
3273
+
3274
+ if getv(from_object, ['video_bytes']) is not None:
3275
+ setv(
3276
+ to_object,
3277
+ ['bytesBase64Encoded'],
3278
+ t.t_bytes(api_client, getv(from_object, ['video_bytes'])),
3279
+ )
3280
+
3281
+ if getv(from_object, ['mime_type']) is not None:
3282
+ setv(to_object, ['mimeType'], getv(from_object, ['mime_type']))
3283
+
3284
+ return to_object
3285
+
3286
+
3236
3287
  def _GenerateVideosConfig_to_vertex(
3237
3288
  api_client: BaseApiClient,
3238
3289
  from_object: Union[dict[str, Any], object],
@@ -3316,6 +3367,15 @@ def _GenerateVideosConfig_to_vertex(
3316
3367
  getv(from_object, ['generate_audio']),
3317
3368
  )
3318
3369
 
3370
+ if getv(from_object, ['last_frame']) is not None:
3371
+ setv(
3372
+ parent_object,
3373
+ ['instances[0]', 'lastFrame'],
3374
+ _Image_to_vertex(
3375
+ api_client, getv(from_object, ['last_frame']), to_object
3376
+ ),
3377
+ )
3378
+
3319
3379
  return to_object
3320
3380
 
3321
3381
 
@@ -3342,6 +3402,13 @@ def _GenerateVideosParameters_to_vertex(
3342
3402
  _Image_to_vertex(api_client, getv(from_object, ['image']), to_object),
3343
3403
  )
3344
3404
 
3405
+ if getv(from_object, ['video']) is not None:
3406
+ setv(
3407
+ to_object,
3408
+ ['instances[0]', 'video'],
3409
+ _Video_to_vertex(api_client, getv(from_object, ['video']), to_object),
3410
+ )
3411
+
3345
3412
  if getv(from_object, ['config']) is not None:
3346
3413
  setv(
3347
3414
  to_object,
@@ -5797,13 +5864,26 @@ class Models(_api_module.BaseModule):
5797
5864
  model: str,
5798
5865
  prompt: Optional[str] = None,
5799
5866
  image: Optional[types.ImageOrDict] = None,
5867
+ video: Optional[types.VideoOrDict] = None,
5800
5868
  config: Optional[types.GenerateVideosConfigOrDict] = None,
5801
5869
  ) -> types.GenerateVideosOperation:
5802
- """Generates videos based on a text description and configuration.
5870
+ """Generates videos based on an input (text, image, or video) and configuration.
5871
+
5872
+ The following use cases are supported:
5873
+ 1. Text to video generation.
5874
+ 2a. Image to video generation (additional text prompt is optional).
5875
+ 2b. Image to video generation with frame interpolation (specify last_frame
5876
+ in config).
5877
+ 3. Video extension (additional text prompt is optional)
5803
5878
 
5804
5879
  Args:
5805
5880
  model: The model to use.
5806
- instances: A list of prompts, images and videos to generate videos from.
5881
+ prompt: The text prompt for generating the videos. Optional for image to
5882
+ video use cases.
5883
+ image: The input image for generating the videos. Optional if prompt is
5884
+ provided.
5885
+ video: The input video for video extension use cases. Optional if prompt
5886
+ or image is provided.
5807
5887
  config: Configuration for generation.
5808
5888
 
5809
5889
  Usage:
@@ -5825,6 +5905,7 @@ class Models(_api_module.BaseModule):
5825
5905
  model=model,
5826
5906
  prompt=prompt,
5827
5907
  image=image,
5908
+ video=video,
5828
5909
  config=config,
5829
5910
  )
5830
5911
 
@@ -7327,13 +7408,26 @@ class AsyncModels(_api_module.BaseModule):
7327
7408
  model: str,
7328
7409
  prompt: Optional[str] = None,
7329
7410
  image: Optional[types.ImageOrDict] = None,
7411
+ video: Optional[types.VideoOrDict] = None,
7330
7412
  config: Optional[types.GenerateVideosConfigOrDict] = None,
7331
7413
  ) -> types.GenerateVideosOperation:
7332
- """Generates videos based on a text description and configuration.
7414
+ """Generates videos based on an input (text, image, or video) and configuration.
7415
+
7416
+ The following use cases are supported:
7417
+ 1. Text to video generation.
7418
+ 2a. Image to video generation (additional text prompt is optional).
7419
+ 2b. Image to video generation with frame interpolation (specify last_frame
7420
+ in config).
7421
+ 3. Video extension (additional text prompt is optional)
7333
7422
 
7334
7423
  Args:
7335
7424
  model: The model to use.
7336
- instances: A list of prompts, images and videos to generate videos from.
7425
+ prompt: The text prompt for generating the videos. Optional for image to
7426
+ video use cases.
7427
+ image: The input image for generating the videos. Optional if prompt is
7428
+ provided.
7429
+ video: The input video for video extension use cases. Optional if prompt
7430
+ or image is provided.
7337
7431
  config: Configuration for generation.
7338
7432
 
7339
7433
  Usage:
@@ -7355,6 +7449,7 @@ class AsyncModels(_api_module.BaseModule):
7355
7449
  model=model,
7356
7450
  prompt=prompt,
7357
7451
  image=image,
7452
+ video=video,
7358
7453
  config=config,
7359
7454
  )
7360
7455
 
@@ -7663,8 +7758,10 @@ class AsyncModels(_api_module.BaseModule):
7663
7758
  or not chunk.candidates[0].content.parts
7664
7759
  ):
7665
7760
  break
7666
- func_response_parts = _extra_utils.get_function_response_parts(
7667
- chunk, function_map
7761
+ func_response_parts = (
7762
+ await _extra_utils.get_function_response_parts_async(
7763
+ chunk, function_map
7764
+ )
7668
7765
  )
7669
7766
  if not function_map:
7670
7767
  break
@@ -18,6 +18,7 @@
18
18
  import logging
19
19
  from typing import Any, Optional, Union
20
20
  from urllib.parse import urlencode
21
+
21
22
  from . import _api_module
22
23
  from . import _common
23
24
  from . import _transformers as t
google/genai/tunings.py CHANGED
@@ -18,6 +18,7 @@
18
18
  import logging
19
19
  from typing import Any, Optional, Union
20
20
  from urllib.parse import urlencode
21
+
21
22
  from . import _api_module
22
23
  from . import _common
23
24
  from . import _transformers as t
google/genai/types.py CHANGED
@@ -2375,6 +2375,42 @@ class UrlContextDict(TypedDict, total=False):
2375
2375
  UrlContextOrDict = Union[UrlContext, UrlContextDict]
2376
2376
 
2377
2377
 
2378
+ class VertexAISearchDataStoreSpec(_common.BaseModel):
2379
+ """Define data stores within engine to filter on in a search call and configurations for those data stores.
2380
+
2381
+ For more information, see
2382
+ https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec
2383
+ """
2384
+
2385
+ data_store: Optional[str] = Field(
2386
+ default=None,
2387
+ description="""Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
2388
+ )
2389
+ filter: Optional[str] = Field(
2390
+ default=None,
2391
+ description="""Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)""",
2392
+ )
2393
+
2394
+
2395
+ class VertexAISearchDataStoreSpecDict(TypedDict, total=False):
2396
+ """Define data stores within engine to filter on in a search call and configurations for those data stores.
2397
+
2398
+ For more information, see
2399
+ https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec
2400
+ """
2401
+
2402
+ data_store: Optional[str]
2403
+ """Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
2404
+
2405
+ filter: Optional[str]
2406
+ """Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)"""
2407
+
2408
+
2409
+ VertexAISearchDataStoreSpecOrDict = Union[
2410
+ VertexAISearchDataStoreSpec, VertexAISearchDataStoreSpecDict
2411
+ ]
2412
+
2413
+
2378
2414
  class VertexAISearch(_common.BaseModel):
2379
2415
  """Retrieve from Vertex AI Search datastore or engine for grounding.
2380
2416
 
@@ -2382,6 +2418,10 @@ class VertexAISearch(_common.BaseModel):
2382
2418
  https://cloud.google.com/products/agent-builder
2383
2419
  """
2384
2420
 
2421
+ data_store_specs: Optional[list[VertexAISearchDataStoreSpec]] = Field(
2422
+ default=None,
2423
+ description="""Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used.""",
2424
+ )
2385
2425
  datastore: Optional[str] = Field(
2386
2426
  default=None,
2387
2427
  description="""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
@@ -2407,6 +2447,9 @@ class VertexAISearchDict(TypedDict, total=False):
2407
2447
  https://cloud.google.com/products/agent-builder
2408
2448
  """
2409
2449
 
2450
+ data_store_specs: Optional[list[VertexAISearchDataStoreSpecDict]]
2451
+ """Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used."""
2452
+
2410
2453
  datastore: Optional[str]
2411
2454
  """Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
2412
2455
 
@@ -2632,6 +2675,10 @@ class VertexRagStore(_common.BaseModel):
2632
2675
  default=None,
2633
2676
  description="""Optional. Number of top k results to return from the selected corpora.""",
2634
2677
  )
2678
+ store_context: Optional[bool] = Field(
2679
+ default=None,
2680
+ description="""Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions.""",
2681
+ )
2635
2682
  vector_distance_threshold: Optional[float] = Field(
2636
2683
  default=None,
2637
2684
  description="""Optional. Only return results with vector distance smaller than the threshold.""",
@@ -2653,6 +2700,9 @@ class VertexRagStoreDict(TypedDict, total=False):
2653
2700
  similarity_top_k: Optional[int]
2654
2701
  """Optional. Number of top k results to return from the selected corpora."""
2655
2702
 
2703
+ store_context: Optional[bool]
2704
+ """Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions."""
2705
+
2656
2706
  vector_distance_threshold: Optional[float]
2657
2707
  """Optional. Only return results with vector distance smaller than the threshold."""
2658
2708
 
@@ -6967,6 +7017,109 @@ ComputeTokensResponseOrDict = Union[
6967
7017
  ]
6968
7018
 
6969
7019
 
7020
+ class Video(_common.BaseModel):
7021
+ """A generated video."""
7022
+
7023
+ uri: Optional[str] = Field(
7024
+ default=None, description="""Path to another storage."""
7025
+ )
7026
+ video_bytes: Optional[bytes] = Field(
7027
+ default=None, description="""Video bytes."""
7028
+ )
7029
+ mime_type: Optional[str] = Field(
7030
+ default=None, description="""Video encoding, for example "video/mp4"."""
7031
+ )
7032
+
7033
+ @classmethod
7034
+ def from_file(
7035
+ cls, *, location: str, mime_type: Optional[str] = None
7036
+ ) -> 'Video':
7037
+ """Loads a video from a local file.
7038
+
7039
+ Args:
7040
+ location: The local path to load the video from.
7041
+ mime_type: The MIME type of the video. If not provided, the MIME type
7042
+ will be automatically determined.
7043
+
7044
+ Returns:
7045
+ A loaded video as an `Video` object.
7046
+ """
7047
+ import mimetypes # pylint: disable=g-import-not-at-top
7048
+ import pathlib # pylint: disable=g-import-not-at-top
7049
+
7050
+ video_bytes = pathlib.Path(location).read_bytes()
7051
+
7052
+ if not mime_type:
7053
+ mime_type, _ = mimetypes.guess_type(location)
7054
+ video = cls(video_bytes=video_bytes, mime_type=mime_type)
7055
+ return video
7056
+
7057
+ def save(
7058
+ self,
7059
+ path: str,
7060
+ ) -> None:
7061
+ """Saves the video to a file.
7062
+
7063
+ Args:
7064
+ path: Local path where to save the video.
7065
+ """
7066
+ import pathlib # pylint: disable=g-import-not-at-top
7067
+
7068
+ if not self.video_bytes:
7069
+ raise NotImplementedError('Saving remote videos is not supported.')
7070
+
7071
+ pathlib.Path(path).write_bytes(self.video_bytes)
7072
+
7073
+ def show(self) -> None:
7074
+ """Shows the video.
7075
+
7076
+ If the video has no mime_type, it is assumed to be video/mp4.
7077
+
7078
+ This method only works in a notebook environment.
7079
+ """
7080
+ if self.uri and not self.video_bytes:
7081
+ raise ValueError('Showing remote videos is not supported.')
7082
+ if not self.video_bytes:
7083
+ raise ValueError('Video has no bytes.')
7084
+
7085
+ mime_type = self.mime_type or 'video/mp4'
7086
+
7087
+ try:
7088
+ from IPython import display as IPython_display
7089
+ except ImportError:
7090
+ IPython_display = None
7091
+
7092
+ if IPython_display:
7093
+ IPython_display.display(
7094
+ IPython_display.Video(
7095
+ data=self.video_bytes, mimetype=mime_type, embed=True
7096
+ )
7097
+ )
7098
+
7099
+ def __repr__(self) -> str:
7100
+ video_bytes = '<video_bytes>' if self.video_bytes else 'None'
7101
+ return (
7102
+ f'Video(uri={self.uri}, video_bytes={video_bytes},'
7103
+ f' mime_type={self.mime_type})'
7104
+ )
7105
+
7106
+
7107
+ class VideoDict(TypedDict, total=False):
7108
+ """A generated video."""
7109
+
7110
+ uri: Optional[str]
7111
+ """Path to another storage."""
7112
+
7113
+ video_bytes: Optional[bytes]
7114
+ """Video bytes."""
7115
+
7116
+ mime_type: Optional[str]
7117
+ """Video encoding, for example "video/mp4"."""
7118
+
7119
+
7120
+ VideoOrDict = Union[Video, VideoDict]
7121
+
7122
+
6970
7123
  class GenerateVideosConfig(_common.BaseModel):
6971
7124
  """Configuration for generating videos."""
6972
7125
 
@@ -7018,6 +7171,10 @@ class GenerateVideosConfig(_common.BaseModel):
7018
7171
  default=None,
7019
7172
  description="""Whether to generate audio along with the video.""",
7020
7173
  )
7174
+ last_frame: Optional[Image] = Field(
7175
+ default=None,
7176
+ description="""Image to use as the last frame of generated videos. Only supported for image to video use cases.""",
7177
+ )
7021
7178
 
7022
7179
 
7023
7180
  class GenerateVideosConfigDict(TypedDict, total=False):
@@ -7062,6 +7219,9 @@ class GenerateVideosConfigDict(TypedDict, total=False):
7062
7219
  generate_audio: Optional[bool]
7063
7220
  """Whether to generate audio along with the video."""
7064
7221
 
7222
+ last_frame: Optional[ImageDict]
7223
+ """Image to use as the last frame of generated videos. Only supported for image to video use cases."""
7224
+
7065
7225
 
7066
7226
  GenerateVideosConfigOrDict = Union[
7067
7227
  GenerateVideosConfig, GenerateVideosConfigDict
@@ -7069,7 +7229,7 @@ GenerateVideosConfigOrDict = Union[
7069
7229
 
7070
7230
 
7071
7231
  class _GenerateVideosParameters(_common.BaseModel):
7072
- """Class that represents the parameters for generating an image."""
7232
+ """Class that represents the parameters for generating videos."""
7073
7233
 
7074
7234
  model: Optional[str] = Field(
7075
7235
  default=None,
@@ -7083,7 +7243,12 @@ class _GenerateVideosParameters(_common.BaseModel):
7083
7243
  image: Optional[Image] = Field(
7084
7244
  default=None,
7085
7245
  description="""The input image for generating the videos.
7086
- Optional if prompt is provided.""",
7246
+ Optional if prompt or video is provided.""",
7247
+ )
7248
+ video: Optional[Video] = Field(
7249
+ default=None,
7250
+ description="""The input video for video extension use cases.
7251
+ Optional if prompt or image is provided.""",
7087
7252
  )
7088
7253
  config: Optional[GenerateVideosConfig] = Field(
7089
7254
  default=None, description="""Configuration for generating videos."""
@@ -7091,7 +7256,7 @@ class _GenerateVideosParameters(_common.BaseModel):
7091
7256
 
7092
7257
 
7093
7258
  class _GenerateVideosParametersDict(TypedDict, total=False):
7094
- """Class that represents the parameters for generating an image."""
7259
+ """Class that represents the parameters for generating videos."""
7095
7260
 
7096
7261
  model: Optional[str]
7097
7262
  """ID of the model to use. For a list of models, see `Google models
@@ -7102,7 +7267,11 @@ class _GenerateVideosParametersDict(TypedDict, total=False):
7102
7267
 
7103
7268
  image: Optional[ImageDict]
7104
7269
  """The input image for generating the videos.
7105
- Optional if prompt is provided."""
7270
+ Optional if prompt or video is provided."""
7271
+
7272
+ video: Optional[VideoDict]
7273
+ """The input video for video extension use cases.
7274
+ Optional if prompt or image is provided."""
7106
7275
 
7107
7276
  config: Optional[GenerateVideosConfigDict]
7108
7277
  """Configuration for generating videos."""
@@ -7113,85 +7282,6 @@ _GenerateVideosParametersOrDict = Union[
7113
7282
  ]
7114
7283
 
7115
7284
 
7116
- class Video(_common.BaseModel):
7117
- """A generated video."""
7118
-
7119
- uri: Optional[str] = Field(
7120
- default=None, description="""Path to another storage."""
7121
- )
7122
- video_bytes: Optional[bytes] = Field(
7123
- default=None, description="""Video bytes."""
7124
- )
7125
- mime_type: Optional[str] = Field(
7126
- default=None, description="""Video encoding, for example "video/mp4"."""
7127
- )
7128
-
7129
- def save(
7130
- self,
7131
- path: str,
7132
- ) -> None:
7133
- """Saves the video to a file.
7134
-
7135
- Args:
7136
- path: Local path where to save the video.
7137
- """
7138
- import pathlib # pylint: disable=g-import-not-at-top
7139
-
7140
- if not self.video_bytes:
7141
- raise NotImplementedError('Saving remote videos is not supported.')
7142
-
7143
- pathlib.Path(path).write_bytes(self.video_bytes)
7144
-
7145
- def show(self) -> None:
7146
- """Shows the video.
7147
-
7148
- If the video has no mime_type, it is assumed to be video/mp4.
7149
-
7150
- This method only works in a notebook environment.
7151
- """
7152
- if self.uri and not self.video_bytes:
7153
- raise ValueError('Showing remote videos is not supported.')
7154
- if not self.video_bytes:
7155
- raise ValueError('Video has no bytes.')
7156
-
7157
- mime_type = self.mime_type or 'video/mp4'
7158
-
7159
- try:
7160
- from IPython import display as IPython_display
7161
- except ImportError:
7162
- IPython_display = None
7163
-
7164
- if IPython_display:
7165
- IPython_display.display(
7166
- IPython_display.Video(
7167
- data=self.video_bytes, mimetype=mime_type, embed=True
7168
- )
7169
- )
7170
-
7171
- def __repr__(self) -> str:
7172
- video_bytes = '<video_bytes>' if self.video_bytes else 'None'
7173
- return (
7174
- f'Video(uri={self.uri}, video_bytes={video_bytes},'
7175
- f' mime_type={self.mime_type})'
7176
- )
7177
-
7178
-
7179
- class VideoDict(TypedDict, total=False):
7180
- """A generated video."""
7181
-
7182
- uri: Optional[str]
7183
- """Path to another storage."""
7184
-
7185
- video_bytes: Optional[bytes]
7186
- """Video bytes."""
7187
-
7188
- mime_type: Optional[str]
7189
- """Video encoding, for example "video/mp4"."""
7190
-
7191
-
7192
- VideoOrDict = Union[Video, VideoDict]
7193
-
7194
-
7195
7285
  class GeneratedVideo(_common.BaseModel):
7196
7286
  """A generated video."""
7197
7287
 
google/genai/version.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- __version__ = '1.19.0' # x-release-please-version
16
+ __version__ = '1.20.0' # x-release-please-version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.19.0
3
+ Version: 1.20.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -27,6 +27,8 @@ Requires-Dist: pydantic<3.0.0,>=2.0.0
27
27
  Requires-Dist: requests<3.0.0,>=2.28.1
28
28
  Requires-Dist: websockets<15.1.0,>=13.0.0
29
29
  Requires-Dist: typing-extensions<5.0.0,>=4.11.0
30
+ Provides-Extra: aiohttp
31
+ Requires-Dist: aiohttp<4.0.0; extra == "aiohttp"
30
32
  Dynamic: license-file
31
33
 
32
34
  # Google Gen AI SDK