google-genai 1.10.0__py3-none-any.whl → 1.12.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/types.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Google LLC
1
+ # Copyright 2025 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ import logging
23
23
  import sys
24
24
  import types as builtin_types
25
25
  import typing
26
- from typing import Any, Callable, Literal, Optional, Union, _UnionGenericAlias # type: ignore
26
+ from typing import Any, Callable, Literal, Optional, Sequence, Union, _UnionGenericAlias # type: ignore
27
27
  import pydantic
28
28
  from pydantic import Field
29
29
  from typing_extensions import TypedDict
@@ -40,6 +40,7 @@ else:
40
40
 
41
41
  _is_pillow_image_imported = False
42
42
  if typing.TYPE_CHECKING:
43
+ from ._api_client import BaseApiClient
43
44
  import PIL.Image
44
45
 
45
46
  PIL_Image = PIL.Image.Image
@@ -139,6 +140,7 @@ class FinishReason(_common.CaseInSensitiveEnum):
139
140
  MAX_TOKENS = 'MAX_TOKENS'
140
141
  SAFETY = 'SAFETY'
141
142
  RECITATION = 'RECITATION'
143
+ LANGUAGE = 'LANGUAGE'
142
144
  OTHER = 'OTHER'
143
145
  BLOCKLIST = 'BLOCKLIST'
144
146
  PROHIBITED_CONTENT = 'PROHIBITED_CONTENT'
@@ -236,6 +238,17 @@ class AdapterSize(_common.CaseInSensitiveEnum):
236
238
  ADAPTER_SIZE_THIRTY_TWO = 'ADAPTER_SIZE_THIRTY_TWO'
237
239
 
238
240
 
241
+ class FeatureSelectionPreference(_common.CaseInSensitiveEnum):
242
+ """Options for feature selection preference."""
243
+
244
+ FEATURE_SELECTION_PREFERENCE_UNSPECIFIED = (
245
+ 'FEATURE_SELECTION_PREFERENCE_UNSPECIFIED'
246
+ )
247
+ PRIORITIZE_QUALITY = 'PRIORITIZE_QUALITY'
248
+ BALANCED = 'BALANCED'
249
+ PRIORITIZE_COST = 'PRIORITIZE_COST'
250
+
251
+
239
252
  class DynamicRetrievalConfigMode(_common.CaseInSensitiveEnum):
240
253
  """Config for the dynamic retrieval config mode."""
241
254
 
@@ -630,7 +643,22 @@ class Part(_common.BaseModel):
630
643
  )
631
644
 
632
645
  @classmethod
633
- def from_uri(cls, *, file_uri: str, mime_type: str) -> 'Part':
646
+ def from_uri(
647
+ cls, *, file_uri: str, mime_type: Optional[str] = None
648
+ ) -> 'Part':
649
+ """Creates a Part from a file uri.
650
+
651
+ Args:
652
+ file_uri (str): The uri of the file
653
+ mime_type (str): mime_type: The MIME type of the image. If not provided,
654
+ the MIME type will be automatically determined.
655
+ """
656
+ if mime_type is None:
657
+ import mimetypes
658
+
659
+ mime_type, _ = mimetypes.guess_type(file_uri)
660
+ if not mime_type:
661
+ raise ValueError(f'Failed to determine mime type for file: {file_uri}')
634
662
  file_data = FileData(file_uri=file_uri, mime_type=mime_type)
635
663
  return cls(file_data=file_data)
636
664
 
@@ -820,6 +848,12 @@ class HttpOptions(_common.BaseModel):
820
848
  timeout: Optional[int] = Field(
821
849
  default=None, description="""Timeout for the request in milliseconds."""
822
850
  )
851
+ client_args: Optional[dict[str, Any]] = Field(
852
+ default=None, description="""Args passed to the HTTP client."""
853
+ )
854
+ async_client_args: Optional[dict[str, Any]] = Field(
855
+ default=None, description="""Args passed to the async HTTP client."""
856
+ )
823
857
 
824
858
 
825
859
  class HttpOptionsDict(TypedDict, total=False):
@@ -837,10 +871,173 @@ class HttpOptionsDict(TypedDict, total=False):
837
871
  timeout: Optional[int]
838
872
  """Timeout for the request in milliseconds."""
839
873
 
874
+ client_args: Optional[dict[str, Any]]
875
+ """Args passed to the HTTP client."""
876
+
877
+ async_client_args: Optional[dict[str, Any]]
878
+ """Args passed to the async HTTP client."""
879
+
840
880
 
841
881
  HttpOptionsOrDict = Union[HttpOptions, HttpOptionsDict]
842
882
 
843
883
 
884
+ class JSONSchemaType(Enum):
885
+ """The type of the data supported by JSON Schema.
886
+
887
+ The values of the enums are lower case strings, while the values of the enums
888
+ for the Type class are upper case strings.
889
+ """
890
+
891
+ NULL = 'null'
892
+ BOOLEAN = 'boolean'
893
+ OBJECT = 'object'
894
+ ARRAY = 'array'
895
+ NUMBER = 'number'
896
+ INTEGER = 'integer'
897
+ STRING = 'string'
898
+
899
+
900
+ class JSONSchema(pydantic.BaseModel):
901
+ """A subset of JSON Schema according to 2020-12 JSON Schema draft.
902
+
903
+ Represents a subset of a JSON Schema object that is used by the Gemini model.
904
+ The difference between this class and the Schema class is that this class is
905
+ compatible with OpenAPI 3.1 schema objects. And the Schema class is used to
906
+ make API call to Gemini model.
907
+ """
908
+
909
+ type: Optional[Union[JSONSchemaType, list[JSONSchemaType]]] = Field(
910
+ default=None,
911
+ description="""Validation succeeds if the type of the instance matches the type represented by the given type, or matches at least one of the given types.""",
912
+ )
913
+ format: Optional[str] = Field(
914
+ default=None,
915
+ description='Define semantic information about a string instance.',
916
+ )
917
+ title: Optional[str] = Field(
918
+ default=None,
919
+ description=(
920
+ 'A preferably short description about the purpose of the instance'
921
+ ' described by the schema.'
922
+ ),
923
+ )
924
+ description: Optional[str] = Field(
925
+ default=None,
926
+ description=(
927
+ 'An explanation about the purpose of the instance described by the'
928
+ ' schema.'
929
+ ),
930
+ )
931
+ default: Optional[Any] = Field(
932
+ default=None,
933
+ description=(
934
+ 'This keyword can be used to supply a default JSON value associated'
935
+ ' with a particular schema.'
936
+ ),
937
+ )
938
+ items: Optional['JSONSchema'] = Field(
939
+ default=None,
940
+ description=(
941
+ 'Validation succeeds if each element of the instance not covered by'
942
+ ' prefixItems validates against this schema.'
943
+ ),
944
+ )
945
+ min_items: Optional[int] = Field(
946
+ default=None,
947
+ description=(
948
+ 'An array instance is valid if its size is greater than, or equal to,'
949
+ ' the value of this keyword.'
950
+ ),
951
+ )
952
+ max_items: Optional[int] = Field(
953
+ default=None,
954
+ description=(
955
+ 'An array instance is valid if its size is less than, or equal to,'
956
+ ' the value of this keyword.'
957
+ ),
958
+ )
959
+ enum: Optional[list[Any]] = Field(
960
+ default=None,
961
+ description=(
962
+ 'Validation succeeds if the instance is equal to one of the elements'
963
+ ' in this keyword’s array value.'
964
+ ),
965
+ )
966
+ properties: Optional[dict[str, 'JSONSchema']] = Field(
967
+ default=None,
968
+ description=(
969
+ 'Validation succeeds if, for each name that appears in both the'
970
+ ' instance and as a name within this keyword’s value, the child'
971
+ ' instance for that name successfully validates against the'
972
+ ' corresponding schema.'
973
+ ),
974
+ )
975
+ required: Optional[list[str]] = Field(
976
+ default=None,
977
+ description=(
978
+ 'An object instance is valid against this keyword if every item in'
979
+ ' the array is the name of a property in the instance.'
980
+ ),
981
+ )
982
+ min_properties: Optional[int] = Field(
983
+ default=None,
984
+ description=(
985
+ 'An object instance is valid if its number of properties is greater'
986
+ ' than, or equal to, the value of this keyword.'
987
+ ),
988
+ )
989
+ max_properties: Optional[int] = Field(
990
+ default=None,
991
+ description=(
992
+ 'An object instance is valid if its number of properties is less'
993
+ ' than, or equal to, the value of this keyword.'
994
+ ),
995
+ )
996
+ minimum: Optional[float] = Field(
997
+ default=None,
998
+ description=(
999
+ 'Validation succeeds if the numeric instance is greater than or equal'
1000
+ ' to the given number.'
1001
+ ),
1002
+ )
1003
+ maximum: Optional[float] = Field(
1004
+ default=None,
1005
+ description=(
1006
+ 'Validation succeeds if the numeric instance is less than or equal to'
1007
+ ' the given number.'
1008
+ ),
1009
+ )
1010
+ min_length: Optional[int] = Field(
1011
+ default=None,
1012
+ description=(
1013
+ 'A string instance is valid against this keyword if its length is'
1014
+ ' greater than, or equal to, the value of this keyword.'
1015
+ ),
1016
+ )
1017
+ max_length: Optional[int] = Field(
1018
+ default=None,
1019
+ description=(
1020
+ 'A string instance is valid against this keyword if its length is'
1021
+ ' less than, or equal to, the value of this keyword.'
1022
+ ),
1023
+ )
1024
+ pattern: Optional[str] = Field(
1025
+ default=None,
1026
+ description=(
1027
+ 'A string instance is considered valid if the regular expression'
1028
+ ' matches the instance successfully.'
1029
+ ),
1030
+ )
1031
+ any_of: Optional[list['JSONSchema']] = Field(
1032
+ default=None,
1033
+ description=(
1034
+ 'An instance validates successfully against this keyword if it'
1035
+ ' validates successfully against at least one schema defined by this'
1036
+ ' keyword’s value.'
1037
+ ),
1038
+ )
1039
+
1040
+
844
1041
  class Schema(_common.BaseModel):
845
1042
  """Schema that defines the format of input and output data.
846
1043
 
@@ -932,6 +1129,348 @@ class Schema(_common.BaseModel):
932
1129
  default=None, description="""Optional. The type of the data."""
933
1130
  )
934
1131
 
1132
+ @property
1133
+ def json_schema(self) -> JSONSchema:
1134
+ """Converts the Schema object to a JSONSchema object, that is compatible with 2020-12 JSON Schema draft.
1135
+
1136
+ If a Schema field is not supported by JSONSchema, it will be ignored.
1137
+ """
1138
+ json_schema_field_names: set[str] = set(JSONSchema.model_fields.keys())
1139
+ schema_field_names: tuple[str] = (
1140
+ 'items',
1141
+ ) # 'additional_properties' to come
1142
+ list_schema_field_names: tuple[str] = (
1143
+ 'any_of', # 'one_of', 'all_of', 'not' to come
1144
+ )
1145
+ dict_schema_field_names: tuple[str] = ('properties',) # 'defs' to come
1146
+
1147
+ def convert_schema(schema: Union['Schema', dict[str, Any]]) -> JSONSchema:
1148
+ if isinstance(schema, pydantic.BaseModel):
1149
+ schema_dict = schema.model_dump()
1150
+ else:
1151
+ schema_dict = schema
1152
+ json_schema = JSONSchema()
1153
+ for field_name, field_value in schema_dict.items():
1154
+ if field_value is None:
1155
+ continue
1156
+ elif field_name == 'nullable':
1157
+ json_schema.type = JSONSchemaType.NULL
1158
+ elif field_name not in json_schema_field_names:
1159
+ continue
1160
+ elif field_name == 'type':
1161
+ if field_value == Type.TYPE_UNSPECIFIED:
1162
+ continue
1163
+ json_schema_type = JSONSchemaType(field_value.lower())
1164
+ if json_schema.type is None:
1165
+ json_schema.type = json_schema_type
1166
+ elif isinstance(json_schema.type, JSONSchemaType):
1167
+ existing_type: JSONSchemaType = json_schema.type
1168
+ json_schema.type = [existing_type, json_schema_type]
1169
+ elif isinstance(json_schema.type, list):
1170
+ json_schema.type.append(json_schema_type)
1171
+ elif field_name in schema_field_names:
1172
+ schema_field_value: 'JSONSchema' = convert_schema(field_value)
1173
+ setattr(json_schema, field_name, schema_field_value)
1174
+ elif field_name in list_schema_field_names:
1175
+ list_schema_field_value: list['JSONSchema'] = [
1176
+ convert_schema(this_field_value)
1177
+ for this_field_value in field_value
1178
+ ]
1179
+ setattr(json_schema, field_name, list_schema_field_value)
1180
+ elif field_name in dict_schema_field_names:
1181
+ dict_schema_field_value: dict[str, 'JSONSchema'] = {
1182
+ key: convert_schema(value) for key, value in field_value.items()
1183
+ }
1184
+ setattr(json_schema, field_name, dict_schema_field_value)
1185
+ else:
1186
+ setattr(json_schema, field_name, field_value)
1187
+
1188
+ return json_schema
1189
+
1190
+ return convert_schema(self)
1191
+
1192
+ @classmethod
1193
+ def from_json_schema(
1194
+ cls,
1195
+ *,
1196
+ json_schema: JSONSchema,
1197
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
1198
+ raise_error_on_unsupported_field: bool = False,
1199
+ ) -> 'Schema':
1200
+ """Converts a JSONSchema object to a Schema object.
1201
+
1202
+ The JSONSchema is compatible with 2020-12 JSON Schema draft, specified by
1203
+ OpenAPI 3.1.
1204
+
1205
+ Args:
1206
+ json_schema: JSONSchema object to be converted.
1207
+ api_option: API option to be used. If set to 'VERTEX_AI', the JSONSchema
1208
+ will be converted to a Schema object that is compatible with Vertex AI
1209
+ API. If set to 'GEMINI_API', the JSONSchema will be converted to a
1210
+ Schema object that is compatible with Gemini API. Default is
1211
+ 'GEMINI_API'.
1212
+ raise_error_on_unsupported_field: If set to True, an error will be
1213
+ raised if the JSONSchema contains any unsupported fields. Default is
1214
+ False.
1215
+
1216
+ Returns:
1217
+ Schema object that is compatible with the specified API option.
1218
+ Raises:
1219
+ ValueError: If the JSONSchema contains any unsupported fields and
1220
+ raise_error_on_unsupported_field is set to True. Or if the JSONSchema
1221
+ is not compatible with the specified API option.
1222
+ """
1223
+ google_schema_field_names: set[str] = set(cls.model_fields.keys())
1224
+ schema_field_names: tuple[str, ...] = (
1225
+ 'items',
1226
+ ) # 'additional_properties' to come
1227
+ list_schema_field_names: tuple[str, ...] = (
1228
+ 'any_of', # 'one_of', 'all_of', 'not' to come
1229
+ )
1230
+ dict_schema_field_names: tuple[str, ...] = ('properties',) # 'defs' to come
1231
+
1232
+ number_integer_related_field_names: tuple[str, ...] = (
1233
+ 'description',
1234
+ 'enum',
1235
+ 'format',
1236
+ 'maximum',
1237
+ 'minimum',
1238
+ 'title',
1239
+ )
1240
+ string_related_field_names: tuple[str, ...] = (
1241
+ 'description',
1242
+ 'enum',
1243
+ 'format',
1244
+ 'max_length',
1245
+ 'min_length',
1246
+ 'pattern',
1247
+ 'title',
1248
+ )
1249
+ object_related_field_names: tuple[str, ...] = (
1250
+ 'any_of',
1251
+ 'description',
1252
+ 'max_properties',
1253
+ 'min_properties',
1254
+ 'properties',
1255
+ 'required',
1256
+ 'title',
1257
+ )
1258
+ array_related_field_names: tuple[str, ...] = (
1259
+ 'description',
1260
+ 'items',
1261
+ 'max_items',
1262
+ 'min_items',
1263
+ 'title',
1264
+ )
1265
+ boolean_related_field_names: tuple[str, ...] = (
1266
+ 'description',
1267
+ 'title',
1268
+ )
1269
+ # placeholder for potential gemini api unsupported fields
1270
+ gemini_api_unsupported_field_names: tuple[str, ...] = ()
1271
+
1272
+ def normalize_json_schema_type(
1273
+ json_schema_type: Optional[
1274
+ Union[JSONSchemaType, Sequence[JSONSchemaType], str, Sequence[str]]
1275
+ ],
1276
+ ) -> tuple[list[str], bool]:
1277
+ """Returns (non_null_types, nullable)"""
1278
+ if json_schema_type is None:
1279
+ return [], False
1280
+ if isinstance(json_schema_type, str):
1281
+ if json_schema_type == JSONSchemaType.NULL.value:
1282
+ return [], True
1283
+ return [json_schema_type], False
1284
+ if isinstance(json_schema_type, JSONSchemaType):
1285
+ if json_schema_type == JSONSchemaType.NULL:
1286
+ return [], True
1287
+ return [json_schema_type.value], False
1288
+ non_null_types = []
1289
+ nullable = False
1290
+ for type_value in json_schema_type:
1291
+ if isinstance(type_value, JSONSchemaType):
1292
+ type_value = type_value.value
1293
+ if type_value == JSONSchemaType.NULL.value:
1294
+ nullable = True
1295
+ else:
1296
+ non_null_types.append(type_value)
1297
+ return non_null_types, nullable
1298
+
1299
+ def raise_error_if_cannot_convert(
1300
+ json_schema_dict: dict[str, Any],
1301
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'],
1302
+ raise_error_on_unsupported_field: bool,
1303
+ ) -> None:
1304
+ """Raises an error if the JSONSchema cannot be converted to the specified Schema object."""
1305
+ if not raise_error_on_unsupported_field:
1306
+ return
1307
+ for field_name, field_value in json_schema_dict.items():
1308
+ if field_value is None:
1309
+ continue
1310
+ if field_name not in google_schema_field_names:
1311
+ raise ValueError((
1312
+ f'JSONSchema field "{field_name}" is not supported by the '
1313
+ 'Schema object. And the "raise_error_on_unsupported_field" '
1314
+ 'argument is set to True. If you still want to convert '
1315
+ 'it into the Schema object, please either remove the field '
1316
+ f'"{field_name}" from the JSONSchema object, or leave the '
1317
+ '"raise_error_on_unsupported_field" unset.'
1318
+ ))
1319
+ if (
1320
+ field_name in gemini_api_unsupported_field_names
1321
+ and api_option == 'GEMINI_API'
1322
+ ):
1323
+ raise ValueError((
1324
+ f'The "{field_name}" field is not supported by the Schema '
1325
+ 'object for GEMINI_API.'
1326
+ ))
1327
+
1328
+ def copy_schema_fields(
1329
+ json_schema_dict: dict[str, Any],
1330
+ related_fields_to_copy: tuple[str, ...],
1331
+ sub_schema_in_any_of: dict[str, Any],
1332
+ ) -> None:
1333
+ """Copies the fields from json_schema_dict to sub_schema_in_any_of."""
1334
+ for field_name in related_fields_to_copy:
1335
+ sub_schema_in_any_of[field_name] = json_schema_dict.get(
1336
+ field_name, None
1337
+ )
1338
+
1339
+ def convert_json_schema(
1340
+ json_schema: JSONSchema,
1341
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'],
1342
+ raise_error_on_unsupported_field: bool,
1343
+ ) -> 'Schema':
1344
+ schema = Schema()
1345
+ json_schema_dict = json_schema.model_dump()
1346
+ raise_error_if_cannot_convert(
1347
+ json_schema_dict=json_schema_dict,
1348
+ api_option=api_option,
1349
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
1350
+ )
1351
+
1352
+ # At the highest level of the logic, there are two passes:
1353
+ # Pass 1: the JSONSchema.type is union-like,
1354
+ # e.g. ['null', 'string', 'array'].
1355
+ # for this case, we need to split the JSONSchema into multiple
1356
+ # sub-schemas, and copy them into the any_of field of the Schema.
1357
+ # And when we copy the non-type fields into any_of field,
1358
+ # we only copy the fields related to the specific type.
1359
+ # Detailed logic is commented below with `Pass 1` keyword tag.
1360
+ # Pass 2: the JSONSchema.type is not union-like,
1361
+ # e.g. 'string', ['string'], ['null', 'string'].
1362
+ # for this case, no splitting is needed. Detailed
1363
+ # logic is commented below with `Pass 2` keyword tag.
1364
+ #
1365
+ #
1366
+ # Pass 1: the JSONSchema.type is union-like
1367
+ # e.g. ['null', 'string', 'array'].
1368
+ non_null_types, nullable = normalize_json_schema_type(
1369
+ json_schema_dict.get('type', None)
1370
+ )
1371
+ if len(non_null_types) > 1:
1372
+ logger.warning(
1373
+ 'JSONSchema type is union-like, e.g. ["null", "string", "array"]. '
1374
+ 'Converting it into multiple sub-schemas, and copying them into '
1375
+ 'the any_of field of the Schema. The value of `default` field is '
1376
+ 'ignored because it is ambiguous to tell which sub-schema it '
1377
+ 'belongs to.'
1378
+ )
1379
+ reformed_json_schema = JSONSchema()
1380
+ # start splitting the JSONSchema into multiple sub-schemas
1381
+ any_of = []
1382
+ if nullable:
1383
+ schema.nullable = True
1384
+ for normalized_type in non_null_types:
1385
+ sub_schema_in_any_of = {'type': normalized_type}
1386
+ if normalized_type == JSONSchemaType.BOOLEAN.value:
1387
+ copy_schema_fields(
1388
+ json_schema_dict=json_schema_dict,
1389
+ related_fields_to_copy=boolean_related_field_names,
1390
+ sub_schema_in_any_of=sub_schema_in_any_of,
1391
+ )
1392
+ elif normalized_type in (
1393
+ JSONSchemaType.NUMBER.value,
1394
+ JSONSchemaType.INTEGER.value,
1395
+ ):
1396
+ copy_schema_fields(
1397
+ json_schema_dict=json_schema_dict,
1398
+ related_fields_to_copy=number_integer_related_field_names,
1399
+ sub_schema_in_any_of=sub_schema_in_any_of,
1400
+ )
1401
+ elif normalized_type == JSONSchemaType.STRING.value:
1402
+ copy_schema_fields(
1403
+ json_schema_dict=json_schema_dict,
1404
+ related_fields_to_copy=string_related_field_names,
1405
+ sub_schema_in_any_of=sub_schema_in_any_of,
1406
+ )
1407
+ elif normalized_type == JSONSchemaType.ARRAY.value:
1408
+ copy_schema_fields(
1409
+ json_schema_dict=json_schema_dict,
1410
+ related_fields_to_copy=array_related_field_names,
1411
+ sub_schema_in_any_of=sub_schema_in_any_of,
1412
+ )
1413
+ elif normalized_type == JSONSchemaType.OBJECT.value:
1414
+ copy_schema_fields(
1415
+ json_schema_dict=json_schema_dict,
1416
+ related_fields_to_copy=object_related_field_names,
1417
+ sub_schema_in_any_of=sub_schema_in_any_of,
1418
+ )
1419
+ any_of.append(JSONSchema(**sub_schema_in_any_of))
1420
+ reformed_json_schema.any_of = any_of
1421
+ json_schema_dict = reformed_json_schema.model_dump()
1422
+
1423
+ # Pass 2: the JSONSchema.type is not union-like,
1424
+ # e.g. 'string', ['string'], ['null', 'string'].
1425
+ for field_name, field_value in json_schema_dict.items():
1426
+ if field_value is None:
1427
+ continue
1428
+ if field_name in schema_field_names:
1429
+ schema_field_value: 'Schema' = convert_json_schema(
1430
+ json_schema=JSONSchema(**field_value),
1431
+ api_option=api_option,
1432
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
1433
+ )
1434
+ setattr(schema, field_name, schema_field_value)
1435
+ elif field_name in list_schema_field_names:
1436
+ list_schema_field_value: list['Schema'] = [
1437
+ convert_json_schema(
1438
+ json_schema=JSONSchema(**this_field_value),
1439
+ api_option=api_option,
1440
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
1441
+ )
1442
+ for this_field_value in field_value
1443
+ ]
1444
+ setattr(schema, field_name, list_schema_field_value)
1445
+ elif field_name in dict_schema_field_names:
1446
+ dict_schema_field_value: dict[str, 'Schema'] = {
1447
+ key: convert_json_schema(
1448
+ json_schema=JSONSchema(**value),
1449
+ api_option=api_option,
1450
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
1451
+ )
1452
+ for key, value in field_value.items()
1453
+ }
1454
+ setattr(schema, field_name, dict_schema_field_value)
1455
+ elif field_name == 'type':
1456
+ # non_null_types can only be empty or have one element.
1457
+ # because already handled union-like case above.
1458
+ non_null_types, nullable = normalize_json_schema_type(field_value)
1459
+ if nullable:
1460
+ schema.nullable = True
1461
+ if non_null_types:
1462
+ schema.type = Type(non_null_types[0])
1463
+ else:
1464
+ setattr(schema, field_name, field_value)
1465
+
1466
+ return schema
1467
+
1468
+ return convert_json_schema(
1469
+ json_schema=json_schema,
1470
+ api_option=api_option,
1471
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
1472
+ )
1473
+
935
1474
 
936
1475
  class SchemaDict(TypedDict, total=False):
937
1476
  """Schema that defines the format of input and output data.
@@ -1009,6 +1548,26 @@ class SchemaDict(TypedDict, total=False):
1009
1548
  SchemaOrDict = Union[Schema, SchemaDict]
1010
1549
 
1011
1550
 
1551
+ class ModelSelectionConfig(_common.BaseModel):
1552
+ """Config for model selection."""
1553
+
1554
+ feature_selection_preference: Optional[FeatureSelectionPreference] = Field(
1555
+ default=None, description="""Options for feature selection preference."""
1556
+ )
1557
+
1558
+
1559
+ class ModelSelectionConfigDict(TypedDict, total=False):
1560
+ """Config for model selection."""
1561
+
1562
+ feature_selection_preference: Optional[FeatureSelectionPreference]
1563
+ """Options for feature selection preference."""
1564
+
1565
+
1566
+ ModelSelectionConfigOrDict = Union[
1567
+ ModelSelectionConfig, ModelSelectionConfigDict
1568
+ ]
1569
+
1570
+
1012
1571
  class SafetySetting(_common.BaseModel):
1013
1572
  """Safety settings."""
1014
1573
 
@@ -1071,7 +1630,7 @@ class FunctionDeclaration(_common.BaseModel):
1071
1630
  def from_callable_with_api_option(
1072
1631
  cls,
1073
1632
  *,
1074
- callable: Callable,
1633
+ callable: Callable[..., Any],
1075
1634
  api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
1076
1635
  ) -> 'FunctionDeclaration':
1077
1636
  """Converts a Callable to a FunctionDeclaration based on the API option.
@@ -1137,8 +1696,8 @@ class FunctionDeclaration(_common.BaseModel):
1137
1696
  def from_callable(
1138
1697
  cls,
1139
1698
  *,
1140
- client,
1141
- callable: Callable,
1699
+ client: 'BaseApiClient',
1700
+ callable: Callable[..., Any],
1142
1701
  ) -> 'FunctionDeclaration':
1143
1702
  """Converts a Callable to a FunctionDeclaration based on the client."""
1144
1703
  if client.vertexai:
@@ -1301,6 +1860,168 @@ VertexRagStoreRagResourceOrDict = Union[
1301
1860
  ]
1302
1861
 
1303
1862
 
1863
+ class RagRetrievalConfigFilter(_common.BaseModel):
1864
+ """Config for filters."""
1865
+
1866
+ metadata_filter: Optional[str] = Field(
1867
+ default=None, description="""Optional. String for metadata filtering."""
1868
+ )
1869
+ vector_distance_threshold: Optional[float] = Field(
1870
+ default=None,
1871
+ description="""Optional. Only returns contexts with vector distance smaller than the threshold.""",
1872
+ )
1873
+ vector_similarity_threshold: Optional[float] = Field(
1874
+ default=None,
1875
+ description="""Optional. Only returns contexts with vector similarity larger than the threshold.""",
1876
+ )
1877
+
1878
+
1879
+ class RagRetrievalConfigFilterDict(TypedDict, total=False):
1880
+ """Config for filters."""
1881
+
1882
+ metadata_filter: Optional[str]
1883
+ """Optional. String for metadata filtering."""
1884
+
1885
+ vector_distance_threshold: Optional[float]
1886
+ """Optional. Only returns contexts with vector distance smaller than the threshold."""
1887
+
1888
+ vector_similarity_threshold: Optional[float]
1889
+ """Optional. Only returns contexts with vector similarity larger than the threshold."""
1890
+
1891
+
1892
+ RagRetrievalConfigFilterOrDict = Union[
1893
+ RagRetrievalConfigFilter, RagRetrievalConfigFilterDict
1894
+ ]
1895
+
1896
+
1897
+ class RagRetrievalConfigHybridSearch(_common.BaseModel):
1898
+ """Config for Hybrid Search."""
1899
+
1900
+ alpha: Optional[float] = Field(
1901
+ default=None,
1902
+ description="""Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally.""",
1903
+ )
1904
+
1905
+
1906
+ class RagRetrievalConfigHybridSearchDict(TypedDict, total=False):
1907
+ """Config for Hybrid Search."""
1908
+
1909
+ alpha: Optional[float]
1910
+ """Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally."""
1911
+
1912
+
1913
+ RagRetrievalConfigHybridSearchOrDict = Union[
1914
+ RagRetrievalConfigHybridSearch, RagRetrievalConfigHybridSearchDict
1915
+ ]
1916
+
1917
+
1918
+ class RagRetrievalConfigRankingLlmRanker(_common.BaseModel):
1919
+ """Config for LlmRanker."""
1920
+
1921
+ model_name: Optional[str] = Field(
1922
+ default=None,
1923
+ description="""Optional. The model name used for ranking. Format: `gemini-1.5-pro`""",
1924
+ )
1925
+
1926
+
1927
+ class RagRetrievalConfigRankingLlmRankerDict(TypedDict, total=False):
1928
+ """Config for LlmRanker."""
1929
+
1930
+ model_name: Optional[str]
1931
+ """Optional. The model name used for ranking. Format: `gemini-1.5-pro`"""
1932
+
1933
+
1934
+ RagRetrievalConfigRankingLlmRankerOrDict = Union[
1935
+ RagRetrievalConfigRankingLlmRanker, RagRetrievalConfigRankingLlmRankerDict
1936
+ ]
1937
+
1938
+
1939
+ class RagRetrievalConfigRankingRankService(_common.BaseModel):
1940
+ """Config for Rank Service."""
1941
+
1942
+ model_name: Optional[str] = Field(
1943
+ default=None,
1944
+ description="""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`""",
1945
+ )
1946
+
1947
+
1948
+ class RagRetrievalConfigRankingRankServiceDict(TypedDict, total=False):
1949
+ """Config for Rank Service."""
1950
+
1951
+ model_name: Optional[str]
1952
+ """Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`"""
1953
+
1954
+
1955
+ RagRetrievalConfigRankingRankServiceOrDict = Union[
1956
+ RagRetrievalConfigRankingRankService,
1957
+ RagRetrievalConfigRankingRankServiceDict,
1958
+ ]
1959
+
1960
+
1961
+ class RagRetrievalConfigRanking(_common.BaseModel):
1962
+ """Config for ranking and reranking."""
1963
+
1964
+ llm_ranker: Optional[RagRetrievalConfigRankingLlmRanker] = Field(
1965
+ default=None, description="""Optional. Config for LlmRanker."""
1966
+ )
1967
+ rank_service: Optional[RagRetrievalConfigRankingRankService] = Field(
1968
+ default=None, description="""Optional. Config for Rank Service."""
1969
+ )
1970
+
1971
+
1972
+ class RagRetrievalConfigRankingDict(TypedDict, total=False):
1973
+ """Config for ranking and reranking."""
1974
+
1975
+ llm_ranker: Optional[RagRetrievalConfigRankingLlmRankerDict]
1976
+ """Optional. Config for LlmRanker."""
1977
+
1978
+ rank_service: Optional[RagRetrievalConfigRankingRankServiceDict]
1979
+ """Optional. Config for Rank Service."""
1980
+
1981
+
1982
+ RagRetrievalConfigRankingOrDict = Union[
1983
+ RagRetrievalConfigRanking, RagRetrievalConfigRankingDict
1984
+ ]
1985
+
1986
+
1987
+ class RagRetrievalConfig(_common.BaseModel):
1988
+ """Specifies the context retrieval config."""
1989
+
1990
+ filter: Optional[RagRetrievalConfigFilter] = Field(
1991
+ default=None, description="""Optional. Config for filters."""
1992
+ )
1993
+ hybrid_search: Optional[RagRetrievalConfigHybridSearch] = Field(
1994
+ default=None, description="""Optional. Config for Hybrid Search."""
1995
+ )
1996
+ ranking: Optional[RagRetrievalConfigRanking] = Field(
1997
+ default=None,
1998
+ description="""Optional. Config for ranking and reranking.""",
1999
+ )
2000
+ top_k: Optional[int] = Field(
2001
+ default=None,
2002
+ description="""Optional. The number of contexts to retrieve.""",
2003
+ )
2004
+
2005
+
2006
+ class RagRetrievalConfigDict(TypedDict, total=False):
2007
+ """Specifies the context retrieval config."""
2008
+
2009
+ filter: Optional[RagRetrievalConfigFilterDict]
2010
+ """Optional. Config for filters."""
2011
+
2012
+ hybrid_search: Optional[RagRetrievalConfigHybridSearchDict]
2013
+ """Optional. Config for Hybrid Search."""
2014
+
2015
+ ranking: Optional[RagRetrievalConfigRankingDict]
2016
+ """Optional. Config for ranking and reranking."""
2017
+
2018
+ top_k: Optional[int]
2019
+ """Optional. The number of contexts to retrieve."""
2020
+
2021
+
2022
+ RagRetrievalConfigOrDict = Union[RagRetrievalConfig, RagRetrievalConfigDict]
2023
+
2024
+
1304
2025
  class VertexRagStore(_common.BaseModel):
1305
2026
  """Retrieve from Vertex RAG Store for grounding."""
1306
2027
 
@@ -1312,6 +2033,10 @@ class VertexRagStore(_common.BaseModel):
1312
2033
  default=None,
1313
2034
  description="""Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support.""",
1314
2035
  )
2036
+ rag_retrieval_config: Optional[RagRetrievalConfig] = Field(
2037
+ default=None,
2038
+ description="""Optional. The retrieval config for the Rag query.""",
2039
+ )
1315
2040
  similarity_top_k: Optional[int] = Field(
1316
2041
  default=None,
1317
2042
  description="""Optional. Number of top k results to return from the selected corpora.""",
@@ -1331,6 +2056,9 @@ class VertexRagStoreDict(TypedDict, total=False):
1331
2056
  rag_resources: Optional[list[VertexRagStoreRagResourceDict]]
1332
2057
  """Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support."""
1333
2058
 
2059
+ rag_retrieval_config: Optional[RagRetrievalConfigDict]
2060
+ """Optional. The retrieval config for the Rag query."""
2061
+
1334
2062
  similarity_top_k: Optional[int]
1335
2063
  """Optional. Number of top k results to return from the selected corpora."""
1336
2064
 
@@ -1444,11 +2172,11 @@ class ToolDict(TypedDict, total=False):
1444
2172
 
1445
2173
 
1446
2174
  ToolOrDict = Union[Tool, ToolDict]
1447
- ToolListUnion = list[Union[Tool, Callable]]
1448
- ToolListUnionDict = list[Union[ToolDict, Callable]]
2175
+ ToolListUnion = list[Union[Tool, Callable[..., Any]]]
2176
+ ToolListUnionDict = list[Union[ToolDict, Callable[..., Any]]]
1449
2177
 
1450
2178
  SchemaUnion = Union[
1451
- dict, type, Schema, builtin_types.GenericAlias, VersionedUnionType # type: ignore[valid-type]
2179
+ dict[Any, Any], type, Schema, builtin_types.GenericAlias, VersionedUnionType # type: ignore[valid-type]
1452
2180
  ]
1453
2181
  SchemaUnionDict = Union[SchemaUnion, SchemaDict]
1454
2182
 
@@ -1554,6 +2282,12 @@ class SpeechConfig(_common.BaseModel):
1554
2282
  description="""The configuration for the speaker to use.
1555
2283
  """,
1556
2284
  )
2285
+ language_code: Optional[str] = Field(
2286
+ default=None,
2287
+ description="""Language code (ISO 639. e.g. en-US) for the speech synthesization.
2288
+ Only available for Live API.
2289
+ """,
2290
+ )
1557
2291
 
1558
2292
 
1559
2293
  class SpeechConfigDict(TypedDict, total=False):
@@ -1563,6 +2297,11 @@ class SpeechConfigDict(TypedDict, total=False):
1563
2297
  """The configuration for the speaker to use.
1564
2298
  """
1565
2299
 
2300
+ language_code: Optional[str]
2301
+ """Language code (ISO 639. e.g. en-US) for the speech synthesization.
2302
+ Only available for Live API.
2303
+ """
2304
+
1566
2305
 
1567
2306
  SpeechConfigOrDict = Union[SpeechConfig, SpeechConfigDict]
1568
2307
 
@@ -1990,6 +2729,11 @@ class GenerateContentConfig(_common.BaseModel):
1990
2729
  description="""Configuration for model router requests.
1991
2730
  """,
1992
2731
  )
2732
+ model_selection_config: Optional[ModelSelectionConfig] = Field(
2733
+ default=None,
2734
+ description="""Configuration for model selection.
2735
+ """,
2736
+ )
1993
2737
  safety_settings: Optional[list[SafetySetting]] = Field(
1994
2738
  default=None,
1995
2739
  description="""Safety settings in the request to block unsafe content in the
@@ -2052,7 +2796,7 @@ class GenerateContentConfig(_common.BaseModel):
2052
2796
 
2053
2797
  @pydantic.field_validator('response_schema', mode='before')
2054
2798
  @classmethod
2055
- def _convert_literal_to_enum(cls, value):
2799
+ def _convert_literal_to_enum(cls, value: Any) -> Union[Any, EnumMeta]:
2056
2800
  if typing.get_origin(value) is typing.Literal:
2057
2801
  enum_vals = typing.get_args(value)
2058
2802
  if not all(isinstance(arg, str) for arg in enum_vals):
@@ -2155,6 +2899,10 @@ class GenerateContentConfigDict(TypedDict, total=False):
2155
2899
  """Configuration for model router requests.
2156
2900
  """
2157
2901
 
2902
+ model_selection_config: Optional[ModelSelectionConfigDict]
2903
+ """Configuration for model selection.
2904
+ """
2905
+
2158
2906
  safety_settings: Optional[list[SafetySettingDict]]
2159
2907
  """Safety settings in the request to block unsafe content in the
2160
2908
  response.
@@ -3041,7 +3789,7 @@ class GenerateContentResponse(_common.BaseModel):
3041
3789
  default=None, description="""Usage metadata about the response(s)."""
3042
3790
  )
3043
3791
  automatic_function_calling_history: Optional[list[Content]] = None
3044
- parsed: Optional[Union[pydantic.BaseModel, dict, Enum]] = Field(
3792
+ parsed: Optional[Union[pydantic.BaseModel, dict[Any, Any], Enum]] = Field(
3045
3793
  default=None,
3046
3794
  description="""First candidate from the parsed response if response_schema is provided. Not available for streaming.""",
3047
3795
  )
@@ -3761,7 +4509,7 @@ class Image(_common.BaseModel):
3761
4509
  default=None, description="""The MIME type of the image."""
3762
4510
  )
3763
4511
 
3764
- _loaded_image = None
4512
+ _loaded_image: Optional['PIL_Image'] = None
3765
4513
 
3766
4514
  """Image."""
3767
4515
 
@@ -3807,7 +4555,7 @@ class Image(_common.BaseModel):
3807
4555
  image = cls(image_bytes=image_bytes, mime_type=mime_type)
3808
4556
  return image
3809
4557
 
3810
- def show(self):
4558
+ def show(self) -> None:
3811
4559
  """Shows the image.
3812
4560
 
3813
4561
  This method only works in a notebook environment.
@@ -3821,7 +4569,7 @@ class Image(_common.BaseModel):
3821
4569
  IPython_display.display(self._pil_image)
3822
4570
 
3823
4571
  @property
3824
- def _pil_image(self) -> 'PIL_Image':
4572
+ def _pil_image(self) -> Optional['PIL_Image']:
3825
4573
  PIL_Image: Optional[builtin_types.ModuleType]
3826
4574
  try:
3827
4575
  from PIL import Image as PIL_Image
@@ -3840,7 +4588,7 @@ class Image(_common.BaseModel):
3840
4588
  self._loaded_image = PIL_Image.open(io.BytesIO(self.image_bytes))
3841
4589
  return self._loaded_image
3842
4590
 
3843
- def save(self, location: str):
4591
+ def save(self, location: str) -> None:
3844
4592
  """Saves the image to a file.
3845
4593
 
3846
4594
  Args:
@@ -5391,7 +6139,7 @@ class Video(_common.BaseModel):
5391
6139
 
5392
6140
  pathlib.Path(path).write_bytes(self.video_bytes)
5393
6141
 
5394
- def show(self):
6142
+ def show(self) -> None:
5395
6143
  """Shows the video.
5396
6144
 
5397
6145
  If the video has no mime_type, it is assumed to be video/mp4.
@@ -5399,9 +6147,9 @@ class Video(_common.BaseModel):
5399
6147
  This method only works in a notebook environment.
5400
6148
  """
5401
6149
  if self.uri and not self.video_bytes:
5402
- return ValueError('Showing remote videos is not supported.')
6150
+ raise ValueError('Showing remote videos is not supported.')
5403
6151
  if not self.video_bytes:
5404
- return ValueError('Video has no bytes.')
6152
+ raise ValueError('Video has no bytes.')
5405
6153
 
5406
6154
  mime_type = self.mime_type or 'video/mp4'
5407
6155
 
@@ -5417,7 +6165,7 @@ class Video(_common.BaseModel):
5417
6165
  )
5418
6166
  )
5419
6167
 
5420
- def __repr__(self):
6168
+ def __repr__(self) -> str:
5421
6169
  video_bytes = '<video_bytes>' if self.video_bytes else 'None'
5422
6170
  return (
5423
6171
  f'Video(uri={self.uri}, video_bytes={video_bytes},'
@@ -8481,7 +9229,7 @@ class RawReferenceImage(_common.BaseModel):
8481
9229
 
8482
9230
  @pydantic.model_validator(mode='before')
8483
9231
  @classmethod
8484
- def _validate_mask_image_config(self, values):
9232
+ def _validate_mask_image_config(self, values: Any) -> Any:
8485
9233
  if 'reference_type' in values:
8486
9234
  raise ValueError('Cannot set internal reference_type field directly.')
8487
9235
  values['reference_type'] = 'REFERENCE_TYPE_RAW'
@@ -8543,7 +9291,7 @@ class MaskReferenceImage(_common.BaseModel):
8543
9291
 
8544
9292
  @pydantic.model_validator(mode='before')
8545
9293
  @classmethod
8546
- def _validate_mask_image_config(self, values):
9294
+ def _validate_mask_image_config(self, values: Any) -> Any:
8547
9295
  config = values.get('config', None)
8548
9296
  values['mask_image_config'] = config
8549
9297
  if 'reference_type' in values:
@@ -8614,7 +9362,7 @@ class ControlReferenceImage(_common.BaseModel):
8614
9362
 
8615
9363
  @pydantic.model_validator(mode='before')
8616
9364
  @classmethod
8617
- def _validate_mask_image_config(self, values):
9365
+ def _validate_mask_image_config(self, values: Any) -> Any:
8618
9366
  config = values.get('config', None)
8619
9367
  values['control_image_config'] = config
8620
9368
  if 'reference_type' in values:
@@ -8685,7 +9433,7 @@ class StyleReferenceImage(_common.BaseModel):
8685
9433
 
8686
9434
  @pydantic.model_validator(mode='before')
8687
9435
  @classmethod
8688
- def _validate_mask_image_config(self, values):
9436
+ def _validate_mask_image_config(self, values: Any) -> Any:
8689
9437
  config = values.get('config', None)
8690
9438
  values['style_image_config'] = config
8691
9439
  if 'reference_type' in values:
@@ -8752,7 +9500,7 @@ class SubjectReferenceImage(_common.BaseModel):
8752
9500
 
8753
9501
  @pydantic.model_validator(mode='before')
8754
9502
  @classmethod
8755
- def _validate_mask_image_config(self, values):
9503
+ def _validate_mask_image_config(self, values: Any) -> Any:
8756
9504
  config = values.get('config', None)
8757
9505
  values['subject_image_config'] = config
8758
9506
  if 'reference_type' in values:
@@ -9411,6 +10159,23 @@ ContextWindowCompressionConfigOrDict = Union[
9411
10159
  ]
9412
10160
 
9413
10161
 
10162
+ class AudioTranscriptionConfig(_common.BaseModel):
10163
+ """The audio transcription configuration in Setup."""
10164
+
10165
+ pass
10166
+
10167
+
10168
+ class AudioTranscriptionConfigDict(TypedDict, total=False):
10169
+ """The audio transcription configuration in Setup."""
10170
+
10171
+ pass
10172
+
10173
+
10174
+ AudioTranscriptionConfigOrDict = Union[
10175
+ AudioTranscriptionConfig, AudioTranscriptionConfigDict
10176
+ ]
10177
+
10178
+
9414
10179
  class LiveClientSetup(_common.BaseModel):
9415
10180
  """Message contains configuration that will apply for the duration of the streaming session."""
9416
10181
 
@@ -9427,7 +10192,7 @@ class LiveClientSetup(_common.BaseModel):
9427
10192
  Note: only a subset of fields are supported.
9428
10193
  """,
9429
10194
  )
9430
- system_instruction: Optional[Content] = Field(
10195
+ system_instruction: Optional[ContentUnion] = Field(
9431
10196
  default=None,
9432
10197
  description="""The user provided system instructions for the model.
9433
10198
  Note: only text should be used in parts and content in each part will be
@@ -9469,7 +10234,7 @@ class LiveClientSetupDict(TypedDict, total=False):
9469
10234
  Note: only a subset of fields are supported.
9470
10235
  """
9471
10236
 
9472
- system_instruction: Optional[ContentDict]
10237
+ system_instruction: Optional[ContentUnionDict]
9473
10238
  """The user provided system instructions for the model.
9474
10239
  Note: only text should be used in parts and content in each part will be
9475
10240
  in a separate paragraph."""
@@ -9613,6 +10378,33 @@ class LiveClientRealtimeInput(_common.BaseModel):
9613
10378
  media_chunks: Optional[list[Blob]] = Field(
9614
10379
  default=None, description="""Inlined bytes data for media input."""
9615
10380
  )
10381
+ audio: Optional[Blob] = Field(
10382
+ default=None, description="""The realtime audio input stream."""
10383
+ )
10384
+ audio_stream_end: Optional[bool] = Field(
10385
+ default=None,
10386
+ description="""
10387
+ Indicates that the audio stream has ended, e.g. because the microphone was
10388
+ turned off.
10389
+
10390
+ This should only be sent when automatic activity detection is enabled
10391
+ (which is the default).
10392
+
10393
+ The client can reopen the stream by sending an audio message.
10394
+ """,
10395
+ )
10396
+ video: Optional[Blob] = Field(
10397
+ default=None, description="""The realtime video input stream."""
10398
+ )
10399
+ text: Optional[str] = Field(
10400
+ default=None, description="""The realtime text input stream."""
10401
+ )
10402
+ activity_start: Optional[ActivityStart] = Field(
10403
+ default=None, description="""Marks the start of user activity."""
10404
+ )
10405
+ activity_end: Optional[ActivityEnd] = Field(
10406
+ default=None, description="""Marks the end of user activity."""
10407
+ )
9616
10408
 
9617
10409
 
9618
10410
  class LiveClientRealtimeInputDict(TypedDict, total=False):
@@ -9635,6 +10427,32 @@ class LiveClientRealtimeInputDict(TypedDict, total=False):
9635
10427
  media_chunks: Optional[list[BlobDict]]
9636
10428
  """Inlined bytes data for media input."""
9637
10429
 
10430
+ audio: Optional[BlobDict]
10431
+ """The realtime audio input stream."""
10432
+
10433
+ audio_stream_end: Optional[bool]
10434
+ """
10435
+ Indicates that the audio stream has ended, e.g. because the microphone was
10436
+ turned off.
10437
+
10438
+ This should only be sent when automatic activity detection is enabled
10439
+ (which is the default).
10440
+
10441
+ The client can reopen the stream by sending an audio message.
10442
+ """
10443
+
10444
+ video: Optional[BlobDict]
10445
+ """The realtime video input stream."""
10446
+
10447
+ text: Optional[str]
10448
+ """The realtime text input stream."""
10449
+
10450
+ activity_start: Optional[ActivityStartDict]
10451
+ """Marks the start of user activity."""
10452
+
10453
+ activity_end: Optional[ActivityEndDict]
10454
+ """Marks the end of user activity."""
10455
+
9638
10456
 
9639
10457
  LiveClientRealtimeInputOrDict = Union[
9640
10458
  LiveClientRealtimeInput, LiveClientRealtimeInputDict
@@ -9718,23 +10536,6 @@ class LiveClientMessageDict(TypedDict, total=False):
9718
10536
  LiveClientMessageOrDict = Union[LiveClientMessage, LiveClientMessageDict]
9719
10537
 
9720
10538
 
9721
- class AudioTranscriptionConfig(_common.BaseModel):
9722
- """The audio transcription configuration in Setup."""
9723
-
9724
- pass
9725
-
9726
-
9727
- class AudioTranscriptionConfigDict(TypedDict, total=False):
9728
- """The audio transcription configuration in Setup."""
9729
-
9730
- pass
9731
-
9732
-
9733
- AudioTranscriptionConfigOrDict = Union[
9734
- AudioTranscriptionConfig, AudioTranscriptionConfigDict
9735
- ]
9736
-
9737
-
9738
10539
  class LiveConnectConfig(_common.BaseModel):
9739
10540
  """Session config for the API connection."""
9740
10541
 
@@ -9794,7 +10595,7 @@ class LiveConnectConfig(_common.BaseModel):
9794
10595
  description="""The speech generation configuration.
9795
10596
  """,
9796
10597
  )
9797
- system_instruction: Optional[Content] = Field(
10598
+ system_instruction: Optional[ContentUnion] = Field(
9798
10599
  default=None,
9799
10600
  description="""The user provided system instructions for the model.
9800
10601
  Note: only text should be used in parts and content in each part will be
@@ -9825,6 +10626,10 @@ If included the server will send SessionResumptionUpdate messages.""",
9825
10626
  specified for the output audio.
9826
10627
  """,
9827
10628
  )
10629
+ realtime_input_config: Optional[RealtimeInputConfig] = Field(
10630
+ default=None,
10631
+ description="""Configures the realtime input behavior in BidiGenerateContent.""",
10632
+ )
9828
10633
  context_window_compression: Optional[ContextWindowCompressionConfig] = Field(
9829
10634
  default=None,
9830
10635
  description="""Configures context window compression mechanism.
@@ -9883,7 +10688,7 @@ class LiveConnectConfigDict(TypedDict, total=False):
9883
10688
  """The speech generation configuration.
9884
10689
  """
9885
10690
 
9886
- system_instruction: Optional[ContentDict]
10691
+ system_instruction: Optional[ContentUnionDict]
9887
10692
  """The user provided system instructions for the model.
9888
10693
  Note: only text should be used in parts and content in each part will be
9889
10694
  in a separate paragraph."""
@@ -9909,6 +10714,9 @@ If included the server will send SessionResumptionUpdate messages."""
9909
10714
  specified for the output audio.
9910
10715
  """
9911
10716
 
10717
+ realtime_input_config: Optional[RealtimeInputConfigDict]
10718
+ """Configures the realtime input behavior in BidiGenerateContent."""
10719
+
9912
10720
  context_window_compression: Optional[ContextWindowCompressionConfigDict]
9913
10721
  """Configures context window compression mechanism.
9914
10722
 
@@ -9916,3 +10724,114 @@ If included the server will send SessionResumptionUpdate messages."""
9916
10724
 
9917
10725
 
9918
10726
  LiveConnectConfigOrDict = Union[LiveConnectConfig, LiveConnectConfigDict]
10727
+
10728
+
10729
+ class LiveConnectParameters(_common.BaseModel):
10730
+ """Parameters for connecting to the live API."""
10731
+
10732
+ model: Optional[str] = Field(
10733
+ default=None,
10734
+ description="""ID of the model to use. For a list of models, see `Google models
10735
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_.""",
10736
+ )
10737
+ config: Optional[LiveConnectConfig] = Field(
10738
+ default=None,
10739
+ description="""Optional configuration parameters for the request.
10740
+ """,
10741
+ )
10742
+
10743
+
10744
+ class LiveConnectParametersDict(TypedDict, total=False):
10745
+ """Parameters for connecting to the live API."""
10746
+
10747
+ model: Optional[str]
10748
+ """ID of the model to use. For a list of models, see `Google models
10749
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_."""
10750
+
10751
+ config: Optional[LiveConnectConfigDict]
10752
+ """Optional configuration parameters for the request.
10753
+ """
10754
+
10755
+
10756
+ LiveConnectParametersOrDict = Union[
10757
+ LiveConnectParameters, LiveConnectParametersDict
10758
+ ]
10759
+
10760
+
10761
+ BlobImageUnion = Union[Blob, PIL.Image.Image]
10762
+
10763
+
10764
+ BlobImageUnionDict = Union[BlobImageUnion, BlobDict]
10765
+
10766
+
10767
+ class LiveSendRealtimeInputParameters(_common.BaseModel):
10768
+ """Parameters for sending realtime input to the live API."""
10769
+
10770
+ media: Optional[BlobImageUnion] = Field(
10771
+ default=None, description="""Realtime input to send to the session."""
10772
+ )
10773
+ audio: Optional[Blob] = Field(
10774
+ default=None, description="""The realtime audio input stream."""
10775
+ )
10776
+ audio_stream_end: Optional[bool] = Field(
10777
+ default=None,
10778
+ description="""
10779
+ Indicates that the audio stream has ended, e.g. because the microphone was
10780
+ turned off.
10781
+
10782
+ This should only be sent when automatic activity detection is enabled
10783
+ (which is the default).
10784
+
10785
+ The client can reopen the stream by sending an audio message.
10786
+ """,
10787
+ )
10788
+ video: Optional[BlobImageUnion] = Field(
10789
+ default=None, description="""The realtime video input stream."""
10790
+ )
10791
+ text: Optional[str] = Field(
10792
+ default=None, description="""The realtime text input stream."""
10793
+ )
10794
+ activity_start: Optional[ActivityStart] = Field(
10795
+ default=None, description="""Marks the start of user activity."""
10796
+ )
10797
+ activity_end: Optional[ActivityEnd] = Field(
10798
+ default=None, description="""Marks the end of user activity."""
10799
+ )
10800
+
10801
+
10802
+ class LiveSendRealtimeInputParametersDict(TypedDict, total=False):
10803
+ """Parameters for sending realtime input to the live API."""
10804
+
10805
+ media: Optional[BlobImageUnionDict]
10806
+ """Realtime input to send to the session."""
10807
+
10808
+ audio: Optional[BlobDict]
10809
+ """The realtime audio input stream."""
10810
+
10811
+ audio_stream_end: Optional[bool]
10812
+ """
10813
+ Indicates that the audio stream has ended, e.g. because the microphone was
10814
+ turned off.
10815
+
10816
+ This should only be sent when automatic activity detection is enabled
10817
+ (which is the default).
10818
+
10819
+ The client can reopen the stream by sending an audio message.
10820
+ """
10821
+
10822
+ video: Optional[BlobImageUnionDict]
10823
+ """The realtime video input stream."""
10824
+
10825
+ text: Optional[str]
10826
+ """The realtime text input stream."""
10827
+
10828
+ activity_start: Optional[ActivityStartDict]
10829
+ """Marks the start of user activity."""
10830
+
10831
+ activity_end: Optional[ActivityEndDict]
10832
+ """Marks the end of user activity."""
10833
+
10834
+
10835
+ LiveSendRealtimeInputParametersOrDict = Union[
10836
+ LiveSendRealtimeInputParameters, LiveSendRealtimeInputParametersDict
10837
+ ]