google-genai 1.19.0__py3-none-any.whl → 1.21.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/_api_client.py +449 -137
- google/genai/_common.py +88 -1
- google/genai/_live_converters.py +174 -414
- google/genai/_replay_api_client.py +10 -9
- google/genai/_tokens_converters.py +81 -176
- google/genai/_transformers.py +19 -40
- google/genai/batches.py +47 -64
- google/genai/caches.py +132 -222
- google/genai/chats.py +9 -14
- google/genai/client.py +1 -1
- google/genai/errors.py +32 -6
- google/genai/files.py +89 -103
- google/genai/live.py +15 -20
- google/genai/live_music.py +4 -5
- google/genai/models.py +412 -558
- google/genai/operations.py +36 -68
- google/genai/tokens.py +11 -6
- google/genai/tunings.py +65 -113
- google/genai/types.py +305 -92
- google/genai/version.py +1 -1
- {google_genai-1.19.0.dist-info → google_genai-1.21.0.dist-info}/METADATA +47 -1
- google_genai-1.21.0.dist-info/RECORD +35 -0
- google_genai-1.19.0.dist-info/RECORD +0 -35
- {google_genai-1.19.0.dist-info → google_genai-1.21.0.dist-info}/WHEEL +0 -0
- {google_genai-1.19.0.dist-info → google_genai-1.21.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.19.0.dist-info → google_genai-1.21.0.dist-info}/top_level.txt +0 -0
google/genai/types.py
CHANGED
@@ -1124,6 +1124,63 @@ class ContentDict(TypedDict, total=False):
|
|
1124
1124
|
ContentOrDict = Union[Content, ContentDict]
|
1125
1125
|
|
1126
1126
|
|
1127
|
+
class HttpRetryOptions(_common.BaseModel):
|
1128
|
+
"""HTTP retry options to be used in each of the requests."""
|
1129
|
+
|
1130
|
+
attempts: Optional[int] = Field(
|
1131
|
+
default=None,
|
1132
|
+
description="""Maximum number of attempts, including the original request.
|
1133
|
+
If 0 or 1, it means no retries.""",
|
1134
|
+
)
|
1135
|
+
initial_delay: Optional[float] = Field(
|
1136
|
+
default=None,
|
1137
|
+
description="""Initial delay before the first retry, in fractions of a second.""",
|
1138
|
+
)
|
1139
|
+
max_delay: Optional[float] = Field(
|
1140
|
+
default=None,
|
1141
|
+
description="""Maximum delay between retries, in fractions of a second.""",
|
1142
|
+
)
|
1143
|
+
exp_base: Optional[float] = Field(
|
1144
|
+
default=None,
|
1145
|
+
description="""Multiplier by which the delay increases after each attempt.""",
|
1146
|
+
)
|
1147
|
+
jitter: Optional[float] = Field(
|
1148
|
+
default=None, description="""Randomness factor for the delay."""
|
1149
|
+
)
|
1150
|
+
http_status_codes: Optional[list[int]] = Field(
|
1151
|
+
default=None,
|
1152
|
+
description="""List of HTTP status codes that should trigger a retry.
|
1153
|
+
If not specified, a default set of retryable codes may be used.""",
|
1154
|
+
)
|
1155
|
+
|
1156
|
+
|
1157
|
+
class HttpRetryOptionsDict(TypedDict, total=False):
|
1158
|
+
"""HTTP retry options to be used in each of the requests."""
|
1159
|
+
|
1160
|
+
attempts: Optional[int]
|
1161
|
+
"""Maximum number of attempts, including the original request.
|
1162
|
+
If 0 or 1, it means no retries."""
|
1163
|
+
|
1164
|
+
initial_delay: Optional[float]
|
1165
|
+
"""Initial delay before the first retry, in fractions of a second."""
|
1166
|
+
|
1167
|
+
max_delay: Optional[float]
|
1168
|
+
"""Maximum delay between retries, in fractions of a second."""
|
1169
|
+
|
1170
|
+
exp_base: Optional[float]
|
1171
|
+
"""Multiplier by which the delay increases after each attempt."""
|
1172
|
+
|
1173
|
+
jitter: Optional[float]
|
1174
|
+
"""Randomness factor for the delay."""
|
1175
|
+
|
1176
|
+
http_status_codes: Optional[list[int]]
|
1177
|
+
"""List of HTTP status codes that should trigger a retry.
|
1178
|
+
If not specified, a default set of retryable codes may be used."""
|
1179
|
+
|
1180
|
+
|
1181
|
+
HttpRetryOptionsOrDict = Union[HttpRetryOptions, HttpRetryOptionsDict]
|
1182
|
+
|
1183
|
+
|
1127
1184
|
class HttpOptions(_common.BaseModel):
|
1128
1185
|
"""HTTP options to be used in each of the requests."""
|
1129
1186
|
|
@@ -1147,6 +1204,13 @@ class HttpOptions(_common.BaseModel):
|
|
1147
1204
|
async_client_args: Optional[dict[str, Any]] = Field(
|
1148
1205
|
default=None, description="""Args passed to the async HTTP client."""
|
1149
1206
|
)
|
1207
|
+
extra_body: Optional[dict[str, Any]] = Field(
|
1208
|
+
default=None,
|
1209
|
+
description="""Extra parameters to add to the request body.""",
|
1210
|
+
)
|
1211
|
+
retry_options: Optional[HttpRetryOptions] = Field(
|
1212
|
+
default=None, description="""HTTP retry options for the request."""
|
1213
|
+
)
|
1150
1214
|
|
1151
1215
|
|
1152
1216
|
class HttpOptionsDict(TypedDict, total=False):
|
@@ -1170,6 +1234,12 @@ class HttpOptionsDict(TypedDict, total=False):
|
|
1170
1234
|
async_client_args: Optional[dict[str, Any]]
|
1171
1235
|
"""Args passed to the async HTTP client."""
|
1172
1236
|
|
1237
|
+
extra_body: Optional[dict[str, Any]]
|
1238
|
+
"""Extra parameters to add to the request body."""
|
1239
|
+
|
1240
|
+
retry_options: Optional[HttpRetryOptionsDict]
|
1241
|
+
"""HTTP retry options for the request."""
|
1242
|
+
|
1173
1243
|
|
1174
1244
|
HttpOptionsOrDict = Union[HttpOptions, HttpOptionsDict]
|
1175
1245
|
|
@@ -1616,22 +1686,22 @@ class Schema(_common.BaseModel):
|
|
1616
1686
|
if field_value is None:
|
1617
1687
|
continue
|
1618
1688
|
if field_name not in google_schema_field_names:
|
1619
|
-
raise ValueError(
|
1689
|
+
raise ValueError(
|
1620
1690
|
f'JSONSchema field "{field_name}" is not supported by the '
|
1621
1691
|
'Schema object. And the "raise_error_on_unsupported_field" '
|
1622
1692
|
'argument is set to True. If you still want to convert '
|
1623
1693
|
'it into the Schema object, please either remove the field '
|
1624
1694
|
f'"{field_name}" from the JSONSchema object, or leave the '
|
1625
1695
|
'"raise_error_on_unsupported_field" unset.'
|
1626
|
-
)
|
1696
|
+
)
|
1627
1697
|
if (
|
1628
1698
|
field_name in gemini_api_unsupported_field_names
|
1629
1699
|
and api_option == 'GEMINI_API'
|
1630
1700
|
):
|
1631
|
-
raise ValueError(
|
1701
|
+
raise ValueError(
|
1632
1702
|
f'The "{field_name}" field is not supported by the Schema '
|
1633
1703
|
'object for GEMINI_API.'
|
1634
|
-
)
|
1704
|
+
)
|
1635
1705
|
|
1636
1706
|
def copy_schema_fields(
|
1637
1707
|
json_schema_dict: dict[str, Any],
|
@@ -1916,10 +1986,18 @@ class FunctionDeclaration(_common.BaseModel):
|
|
1916
1986
|
default=None,
|
1917
1987
|
description="""Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1""",
|
1918
1988
|
)
|
1989
|
+
parameters_json_schema: Optional[Any] = Field(
|
1990
|
+
default=None,
|
1991
|
+
description="""Optional. Describes the parameters to the function in JSON Schema format. The schema must describe an object where the properties are the parameters to the function. For example: ``` { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": ["name", "age"], "propertyOrdering": ["name", "age"] } ``` This field is mutually exclusive with `parameters`.""",
|
1992
|
+
)
|
1919
1993
|
response: Optional[Schema] = Field(
|
1920
1994
|
default=None,
|
1921
1995
|
description="""Optional. Describes the output from this function in JSON Schema format. Reflects the Open API 3.03 Response Object. The Schema defines the type used for the response value of the function.""",
|
1922
1996
|
)
|
1997
|
+
response_json_schema: Optional[Any] = Field(
|
1998
|
+
default=None,
|
1999
|
+
description="""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`.""",
|
2000
|
+
)
|
1923
2001
|
|
1924
2002
|
@classmethod
|
1925
2003
|
def from_callable_with_api_option(
|
@@ -2041,9 +2119,15 @@ class FunctionDeclarationDict(TypedDict, total=False):
|
|
2041
2119
|
parameters: Optional[SchemaDict]
|
2042
2120
|
"""Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1"""
|
2043
2121
|
|
2122
|
+
parameters_json_schema: Optional[Any]
|
2123
|
+
"""Optional. Describes the parameters to the function in JSON Schema format. The schema must describe an object where the properties are the parameters to the function. For example: ``` { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": ["name", "age"], "propertyOrdering": ["name", "age"] } ``` This field is mutually exclusive with `parameters`."""
|
2124
|
+
|
2044
2125
|
response: Optional[SchemaDict]
|
2045
2126
|
"""Optional. Describes the output from this function in JSON Schema format. Reflects the Open API 3.03 Response Object. The Schema defines the type used for the response value of the function."""
|
2046
2127
|
|
2128
|
+
response_json_schema: Optional[Any]
|
2129
|
+
"""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`."""
|
2130
|
+
|
2047
2131
|
|
2048
2132
|
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
|
2049
2133
|
|
@@ -2375,6 +2459,42 @@ class UrlContextDict(TypedDict, total=False):
|
|
2375
2459
|
UrlContextOrDict = Union[UrlContext, UrlContextDict]
|
2376
2460
|
|
2377
2461
|
|
2462
|
+
class VertexAISearchDataStoreSpec(_common.BaseModel):
|
2463
|
+
"""Define data stores within engine to filter on in a search call and configurations for those data stores.
|
2464
|
+
|
2465
|
+
For more information, see
|
2466
|
+
https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec
|
2467
|
+
"""
|
2468
|
+
|
2469
|
+
data_store: Optional[str] = Field(
|
2470
|
+
default=None,
|
2471
|
+
description="""Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
|
2472
|
+
)
|
2473
|
+
filter: Optional[str] = Field(
|
2474
|
+
default=None,
|
2475
|
+
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)""",
|
2476
|
+
)
|
2477
|
+
|
2478
|
+
|
2479
|
+
class VertexAISearchDataStoreSpecDict(TypedDict, total=False):
|
2480
|
+
"""Define data stores within engine to filter on in a search call and configurations for those data stores.
|
2481
|
+
|
2482
|
+
For more information, see
|
2483
|
+
https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec
|
2484
|
+
"""
|
2485
|
+
|
2486
|
+
data_store: Optional[str]
|
2487
|
+
"""Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
|
2488
|
+
|
2489
|
+
filter: Optional[str]
|
2490
|
+
"""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)"""
|
2491
|
+
|
2492
|
+
|
2493
|
+
VertexAISearchDataStoreSpecOrDict = Union[
|
2494
|
+
VertexAISearchDataStoreSpec, VertexAISearchDataStoreSpecDict
|
2495
|
+
]
|
2496
|
+
|
2497
|
+
|
2378
2498
|
class VertexAISearch(_common.BaseModel):
|
2379
2499
|
"""Retrieve from Vertex AI Search datastore or engine for grounding.
|
2380
2500
|
|
@@ -2382,6 +2502,10 @@ class VertexAISearch(_common.BaseModel):
|
|
2382
2502
|
https://cloud.google.com/products/agent-builder
|
2383
2503
|
"""
|
2384
2504
|
|
2505
|
+
data_store_specs: Optional[list[VertexAISearchDataStoreSpec]] = Field(
|
2506
|
+
default=None,
|
2507
|
+
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.""",
|
2508
|
+
)
|
2385
2509
|
datastore: Optional[str] = Field(
|
2386
2510
|
default=None,
|
2387
2511
|
description="""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
|
@@ -2407,6 +2531,9 @@ class VertexAISearchDict(TypedDict, total=False):
|
|
2407
2531
|
https://cloud.google.com/products/agent-builder
|
2408
2532
|
"""
|
2409
2533
|
|
2534
|
+
data_store_specs: Optional[list[VertexAISearchDataStoreSpecDict]]
|
2535
|
+
"""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."""
|
2536
|
+
|
2410
2537
|
datastore: Optional[str]
|
2411
2538
|
"""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
|
2412
2539
|
|
@@ -2632,6 +2759,10 @@ class VertexRagStore(_common.BaseModel):
|
|
2632
2759
|
default=None,
|
2633
2760
|
description="""Optional. Number of top k results to return from the selected corpora.""",
|
2634
2761
|
)
|
2762
|
+
store_context: Optional[bool] = Field(
|
2763
|
+
default=None,
|
2764
|
+
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.""",
|
2765
|
+
)
|
2635
2766
|
vector_distance_threshold: Optional[float] = Field(
|
2636
2767
|
default=None,
|
2637
2768
|
description="""Optional. Only return results with vector distance smaller than the threshold.""",
|
@@ -2653,6 +2784,9 @@ class VertexRagStoreDict(TypedDict, total=False):
|
|
2653
2784
|
similarity_top_k: Optional[int]
|
2654
2785
|
"""Optional. Number of top k results to return from the selected corpora."""
|
2655
2786
|
|
2787
|
+
store_context: Optional[bool]
|
2788
|
+
"""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."""
|
2789
|
+
|
2656
2790
|
vector_distance_threshold: Optional[float]
|
2657
2791
|
"""Optional. Only return results with vector distance smaller than the threshold."""
|
2658
2792
|
|
@@ -6655,6 +6789,10 @@ class GenerationConfig(_common.BaseModel):
|
|
6655
6789
|
default=None,
|
6656
6790
|
description="""Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response.""",
|
6657
6791
|
)
|
6792
|
+
response_json_schema: Optional[Any] = Field(
|
6793
|
+
default=None,
|
6794
|
+
description="""Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set.""",
|
6795
|
+
)
|
6658
6796
|
routing_config: Optional[GenerationConfigRoutingConfig] = Field(
|
6659
6797
|
default=None, description="""Optional. Routing configuration."""
|
6660
6798
|
)
|
@@ -6722,6 +6860,9 @@ class GenerationConfigDict(TypedDict, total=False):
|
|
6722
6860
|
response_schema: Optional[SchemaDict]
|
6723
6861
|
"""Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response."""
|
6724
6862
|
|
6863
|
+
response_json_schema: Optional[Any]
|
6864
|
+
"""Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set."""
|
6865
|
+
|
6725
6866
|
routing_config: Optional[GenerationConfigRoutingConfigDict]
|
6726
6867
|
"""Optional. Routing configuration."""
|
6727
6868
|
|
@@ -6967,6 +7108,109 @@ ComputeTokensResponseOrDict = Union[
|
|
6967
7108
|
]
|
6968
7109
|
|
6969
7110
|
|
7111
|
+
class Video(_common.BaseModel):
|
7112
|
+
"""A generated video."""
|
7113
|
+
|
7114
|
+
uri: Optional[str] = Field(
|
7115
|
+
default=None, description="""Path to another storage."""
|
7116
|
+
)
|
7117
|
+
video_bytes: Optional[bytes] = Field(
|
7118
|
+
default=None, description="""Video bytes."""
|
7119
|
+
)
|
7120
|
+
mime_type: Optional[str] = Field(
|
7121
|
+
default=None, description="""Video encoding, for example "video/mp4"."""
|
7122
|
+
)
|
7123
|
+
|
7124
|
+
@classmethod
|
7125
|
+
def from_file(
|
7126
|
+
cls, *, location: str, mime_type: Optional[str] = None
|
7127
|
+
) -> 'Video':
|
7128
|
+
"""Loads a video from a local file.
|
7129
|
+
|
7130
|
+
Args:
|
7131
|
+
location: The local path to load the video from.
|
7132
|
+
mime_type: The MIME type of the video. If not provided, the MIME type
|
7133
|
+
will be automatically determined.
|
7134
|
+
|
7135
|
+
Returns:
|
7136
|
+
A loaded video as an `Video` object.
|
7137
|
+
"""
|
7138
|
+
import mimetypes # pylint: disable=g-import-not-at-top
|
7139
|
+
import pathlib # pylint: disable=g-import-not-at-top
|
7140
|
+
|
7141
|
+
video_bytes = pathlib.Path(location).read_bytes()
|
7142
|
+
|
7143
|
+
if not mime_type:
|
7144
|
+
mime_type, _ = mimetypes.guess_type(location)
|
7145
|
+
video = cls(video_bytes=video_bytes, mime_type=mime_type)
|
7146
|
+
return video
|
7147
|
+
|
7148
|
+
def save(
|
7149
|
+
self,
|
7150
|
+
path: str,
|
7151
|
+
) -> None:
|
7152
|
+
"""Saves the video to a file.
|
7153
|
+
|
7154
|
+
Args:
|
7155
|
+
path: Local path where to save the video.
|
7156
|
+
"""
|
7157
|
+
import pathlib # pylint: disable=g-import-not-at-top
|
7158
|
+
|
7159
|
+
if not self.video_bytes:
|
7160
|
+
raise NotImplementedError('Saving remote videos is not supported.')
|
7161
|
+
|
7162
|
+
pathlib.Path(path).write_bytes(self.video_bytes)
|
7163
|
+
|
7164
|
+
def show(self) -> None:
|
7165
|
+
"""Shows the video.
|
7166
|
+
|
7167
|
+
If the video has no mime_type, it is assumed to be video/mp4.
|
7168
|
+
|
7169
|
+
This method only works in a notebook environment.
|
7170
|
+
"""
|
7171
|
+
if self.uri and not self.video_bytes:
|
7172
|
+
raise ValueError('Showing remote videos is not supported.')
|
7173
|
+
if not self.video_bytes:
|
7174
|
+
raise ValueError('Video has no bytes.')
|
7175
|
+
|
7176
|
+
mime_type = self.mime_type or 'video/mp4'
|
7177
|
+
|
7178
|
+
try:
|
7179
|
+
from IPython import display as IPython_display
|
7180
|
+
except ImportError:
|
7181
|
+
IPython_display = None
|
7182
|
+
|
7183
|
+
if IPython_display:
|
7184
|
+
IPython_display.display(
|
7185
|
+
IPython_display.Video(
|
7186
|
+
data=self.video_bytes, mimetype=mime_type, embed=True
|
7187
|
+
)
|
7188
|
+
)
|
7189
|
+
|
7190
|
+
def __repr__(self) -> str:
|
7191
|
+
video_bytes = '<video_bytes>' if self.video_bytes else 'None'
|
7192
|
+
return (
|
7193
|
+
f'Video(uri={self.uri}, video_bytes={video_bytes},'
|
7194
|
+
f' mime_type={self.mime_type})'
|
7195
|
+
)
|
7196
|
+
|
7197
|
+
|
7198
|
+
class VideoDict(TypedDict, total=False):
|
7199
|
+
"""A generated video."""
|
7200
|
+
|
7201
|
+
uri: Optional[str]
|
7202
|
+
"""Path to another storage."""
|
7203
|
+
|
7204
|
+
video_bytes: Optional[bytes]
|
7205
|
+
"""Video bytes."""
|
7206
|
+
|
7207
|
+
mime_type: Optional[str]
|
7208
|
+
"""Video encoding, for example "video/mp4"."""
|
7209
|
+
|
7210
|
+
|
7211
|
+
VideoOrDict = Union[Video, VideoDict]
|
7212
|
+
|
7213
|
+
|
6970
7214
|
class GenerateVideosConfig(_common.BaseModel):
|
6971
7215
|
"""Configuration for generating videos."""
|
6972
7216
|
|
@@ -7018,6 +7262,10 @@ class GenerateVideosConfig(_common.BaseModel):
|
|
7018
7262
|
default=None,
|
7019
7263
|
description="""Whether to generate audio along with the video.""",
|
7020
7264
|
)
|
7265
|
+
last_frame: Optional[Image] = Field(
|
7266
|
+
default=None,
|
7267
|
+
description="""Image to use as the last frame of generated videos. Only supported for image to video use cases.""",
|
7268
|
+
)
|
7021
7269
|
|
7022
7270
|
|
7023
7271
|
class GenerateVideosConfigDict(TypedDict, total=False):
|
@@ -7062,6 +7310,9 @@ class GenerateVideosConfigDict(TypedDict, total=False):
|
|
7062
7310
|
generate_audio: Optional[bool]
|
7063
7311
|
"""Whether to generate audio along with the video."""
|
7064
7312
|
|
7313
|
+
last_frame: Optional[ImageDict]
|
7314
|
+
"""Image to use as the last frame of generated videos. Only supported for image to video use cases."""
|
7315
|
+
|
7065
7316
|
|
7066
7317
|
GenerateVideosConfigOrDict = Union[
|
7067
7318
|
GenerateVideosConfig, GenerateVideosConfigDict
|
@@ -7069,7 +7320,7 @@ GenerateVideosConfigOrDict = Union[
|
|
7069
7320
|
|
7070
7321
|
|
7071
7322
|
class _GenerateVideosParameters(_common.BaseModel):
|
7072
|
-
"""Class that represents the parameters for generating
|
7323
|
+
"""Class that represents the parameters for generating videos."""
|
7073
7324
|
|
7074
7325
|
model: Optional[str] = Field(
|
7075
7326
|
default=None,
|
@@ -7083,7 +7334,12 @@ class _GenerateVideosParameters(_common.BaseModel):
|
|
7083
7334
|
image: Optional[Image] = Field(
|
7084
7335
|
default=None,
|
7085
7336
|
description="""The input image for generating the videos.
|
7086
|
-
Optional if prompt is provided.""",
|
7337
|
+
Optional if prompt or video is provided.""",
|
7338
|
+
)
|
7339
|
+
video: Optional[Video] = Field(
|
7340
|
+
default=None,
|
7341
|
+
description="""The input video for video extension use cases.
|
7342
|
+
Optional if prompt or image is provided.""",
|
7087
7343
|
)
|
7088
7344
|
config: Optional[GenerateVideosConfig] = Field(
|
7089
7345
|
default=None, description="""Configuration for generating videos."""
|
@@ -7091,7 +7347,7 @@ class _GenerateVideosParameters(_common.BaseModel):
|
|
7091
7347
|
|
7092
7348
|
|
7093
7349
|
class _GenerateVideosParametersDict(TypedDict, total=False):
|
7094
|
-
"""Class that represents the parameters for generating
|
7350
|
+
"""Class that represents the parameters for generating videos."""
|
7095
7351
|
|
7096
7352
|
model: Optional[str]
|
7097
7353
|
"""ID of the model to use. For a list of models, see `Google models
|
@@ -7102,7 +7358,11 @@ class _GenerateVideosParametersDict(TypedDict, total=False):
|
|
7102
7358
|
|
7103
7359
|
image: Optional[ImageDict]
|
7104
7360
|
"""The input image for generating the videos.
|
7105
|
-
Optional if prompt is provided."""
|
7361
|
+
Optional if prompt or video is provided."""
|
7362
|
+
|
7363
|
+
video: Optional[VideoDict]
|
7364
|
+
"""The input video for video extension use cases.
|
7365
|
+
Optional if prompt or image is provided."""
|
7106
7366
|
|
7107
7367
|
config: Optional[GenerateVideosConfigDict]
|
7108
7368
|
"""Configuration for generating videos."""
|
@@ -7113,85 +7373,6 @@ _GenerateVideosParametersOrDict = Union[
|
|
7113
7373
|
]
|
7114
7374
|
|
7115
7375
|
|
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
7376
|
class GeneratedVideo(_common.BaseModel):
|
7196
7377
|
"""A generated video."""
|
7197
7378
|
|
@@ -9169,6 +9350,10 @@ class CreateFileConfig(_common.BaseModel):
|
|
9169
9350
|
http_options: Optional[HttpOptions] = Field(
|
9170
9351
|
default=None, description="""Used to override HTTP request options."""
|
9171
9352
|
)
|
9353
|
+
should_return_http_response: Optional[bool] = Field(
|
9354
|
+
default=None,
|
9355
|
+
description=""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field.""",
|
9356
|
+
)
|
9172
9357
|
|
9173
9358
|
|
9174
9359
|
class CreateFileConfigDict(TypedDict, total=False):
|
@@ -9177,6 +9362,9 @@ class CreateFileConfigDict(TypedDict, total=False):
|
|
9177
9362
|
http_options: Optional[HttpOptionsDict]
|
9178
9363
|
"""Used to override HTTP request options."""
|
9179
9364
|
|
9365
|
+
should_return_http_response: Optional[bool]
|
9366
|
+
""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field."""
|
9367
|
+
|
9180
9368
|
|
9181
9369
|
CreateFileConfigOrDict = Union[CreateFileConfig, CreateFileConfigDict]
|
9182
9370
|
|
@@ -9219,20 +9407,45 @@ _CreateFileParametersOrDict = Union[
|
|
9219
9407
|
]
|
9220
9408
|
|
9221
9409
|
|
9410
|
+
class HttpResponse(_common.BaseModel):
|
9411
|
+
"""A wrapper class for the http response."""
|
9412
|
+
|
9413
|
+
headers: Optional[dict[str, str]] = Field(
|
9414
|
+
default=None,
|
9415
|
+
description="""Used to retain the processed HTTP headers in the response.""",
|
9416
|
+
)
|
9417
|
+
body: Optional[str] = Field(
|
9418
|
+
default=None,
|
9419
|
+
description="""The raw HTTP response body, in JSON format.""",
|
9420
|
+
)
|
9421
|
+
|
9422
|
+
|
9423
|
+
class HttpResponseDict(TypedDict, total=False):
|
9424
|
+
"""A wrapper class for the http response."""
|
9425
|
+
|
9426
|
+
headers: Optional[dict[str, str]]
|
9427
|
+
"""Used to retain the processed HTTP headers in the response."""
|
9428
|
+
|
9429
|
+
body: Optional[str]
|
9430
|
+
"""The raw HTTP response body, in JSON format."""
|
9431
|
+
|
9432
|
+
|
9433
|
+
HttpResponseOrDict = Union[HttpResponse, HttpResponseDict]
|
9434
|
+
|
9435
|
+
|
9222
9436
|
class CreateFileResponse(_common.BaseModel):
|
9223
9437
|
"""Response for the create file method."""
|
9224
9438
|
|
9225
|
-
|
9226
|
-
default=None,
|
9227
|
-
description="""Used to retain the HTTP headers in the request""",
|
9439
|
+
sdk_http_response: Optional[HttpResponse] = Field(
|
9440
|
+
default=None, description="""Used to retain the full HTTP response."""
|
9228
9441
|
)
|
9229
9442
|
|
9230
9443
|
|
9231
9444
|
class CreateFileResponseDict(TypedDict, total=False):
|
9232
9445
|
"""Response for the create file method."""
|
9233
9446
|
|
9234
|
-
|
9235
|
-
"""Used to retain the HTTP
|
9447
|
+
sdk_http_response: Optional[HttpResponseDict]
|
9448
|
+
"""Used to retain the full HTTP response."""
|
9236
9449
|
|
9237
9450
|
|
9238
9451
|
CreateFileResponseOrDict = Union[CreateFileResponse, CreateFileResponseDict]
|
google/genai/version.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: google-genai
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.21.0
|
4
4
|
Summary: GenAI Python SDK
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
6
6
|
License: Apache-2.0
|
@@ -25,8 +25,11 @@ Requires-Dist: google-auth<3.0.0,>=2.14.1
|
|
25
25
|
Requires-Dist: httpx<1.0.0,>=0.28.1
|
26
26
|
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
27
27
|
Requires-Dist: requests<3.0.0,>=2.28.1
|
28
|
+
Requires-Dist: tenacity<9.0.0,>=8.2.3
|
28
29
|
Requires-Dist: websockets<15.1.0,>=13.0.0
|
29
30
|
Requires-Dist: typing-extensions<5.0.0,>=4.11.0
|
31
|
+
Provides-Extra: aiohttp
|
32
|
+
Requires-Dist: aiohttp<4.0.0; extra == "aiohttp"
|
30
33
|
Dynamic: license-file
|
31
34
|
|
32
35
|
# Google Gen AI SDK
|
@@ -140,6 +143,49 @@ client = genai.Client(
|
|
140
143
|
)
|
141
144
|
```
|
142
145
|
|
146
|
+
### Faster async client option: Aiohttp
|
147
|
+
|
148
|
+
By default we use httpx for both sync and async client implementations. In order
|
149
|
+
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
|
150
|
+
SDK we configure `trust_env=True` to match with the default behavior of httpx.
|
151
|
+
Additional args of `aiohttp.ClientSession.request()` ([see _RequestOptions args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
|
152
|
+
through the following way:
|
153
|
+
|
154
|
+
```python
|
155
|
+
|
156
|
+
http_options = types.HttpOptions(
|
157
|
+
async_client_args={'cookies': ..., 'ssl': ...},
|
158
|
+
)
|
159
|
+
|
160
|
+
client=Client(..., http_options=http_options)
|
161
|
+
```
|
162
|
+
|
163
|
+
### Proxy
|
164
|
+
|
165
|
+
Both httpx and aiohttp libraries use `urllib.request.getproxies` from
|
166
|
+
environment variables. Before client initialization, you may set proxy (and
|
167
|
+
optional SSL_CERT_FILE) by setting the environment variables:
|
168
|
+
|
169
|
+
|
170
|
+
```bash
|
171
|
+
export HTTPS_PROXY='http://username:password@proxy_uri:port'
|
172
|
+
export SSL_CERT_FILE='client.pem'
|
173
|
+
```
|
174
|
+
|
175
|
+
If you need `socks5` proxy, httpx [supports](https://www.python-httpx.org/advanced/proxies/#socks) `socks5` proxy if you pass it via
|
176
|
+
args to `httpx.Client()`. You may install `httpx[socks]` to use it.
|
177
|
+
Then, you can pass it through the following way:
|
178
|
+
|
179
|
+
```python
|
180
|
+
|
181
|
+
http_options = types.HttpOptions(
|
182
|
+
client_args={'proxy': 'socks5://user:pass@host:port'},
|
183
|
+
async_client_args={'proxy': 'socks5://user:pass@host:port'},,
|
184
|
+
)
|
185
|
+
|
186
|
+
client=Client(..., http_options=http_options)
|
187
|
+
```
|
188
|
+
|
143
189
|
## Types
|
144
190
|
|
145
191
|
Parameter types can be specified as either dictionaries(`TypedDict`) or
|