google-genai 1.50.1__py3-none-any.whl → 1.52.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
@@ -116,6 +116,15 @@ else:
116
116
  logger = logging.getLogger('google_genai.types')
117
117
  _from_json_schema_warning_logged = False
118
118
  _json_schema_warning_logged = False
119
+ _response_text_warning_logged = False
120
+ _response_text_non_text_warning_logged = False
121
+ _response_parts_warning_logged = False
122
+ _response_function_calls_warning_logged = False
123
+ _response_executable_code_warning_logged = False
124
+ _response_code_execution_warning_logged = False
125
+ _live_server_text_warning_logged = False
126
+ _live_server_data_warning_logged = False
127
+
119
128
 
120
129
  T = typing.TypeVar('T', bound='GenerateContentResponse')
121
130
 
@@ -257,6 +266,17 @@ class PhishBlockThreshold(_common.CaseInSensitiveEnum):
257
266
  """Blocks Extremely high confidence URL that is risky."""
258
267
 
259
268
 
269
+ class ThinkingLevel(_common.CaseInSensitiveEnum):
270
+ """The level of thoughts tokens that the model should generate."""
271
+
272
+ THINKING_LEVEL_UNSPECIFIED = 'THINKING_LEVEL_UNSPECIFIED'
273
+ """Default value."""
274
+ LOW = 'LOW'
275
+ """Low thinking level."""
276
+ HIGH = 'HIGH'
277
+ """High thinking level."""
278
+
279
+
260
280
  class HarmCategory(_common.CaseInSensitiveEnum):
261
281
  """Harm category."""
262
282
 
@@ -542,6 +562,30 @@ class TuningTask(_common.CaseInSensitiveEnum):
542
562
  """Tuning task for reference to video."""
543
563
 
544
564
 
565
+ class PartMediaResolutionLevel(_common.CaseInSensitiveEnum):
566
+ """The tokenization quality used for given media."""
567
+
568
+ MEDIA_RESOLUTION_UNSPECIFIED = 'MEDIA_RESOLUTION_UNSPECIFIED'
569
+ """Media resolution has not been set."""
570
+ MEDIA_RESOLUTION_LOW = 'MEDIA_RESOLUTION_LOW'
571
+ """Media resolution set to low."""
572
+ MEDIA_RESOLUTION_MEDIUM = 'MEDIA_RESOLUTION_MEDIUM'
573
+ """Media resolution set to medium."""
574
+ MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH'
575
+ """Media resolution set to high."""
576
+
577
+
578
+ class ResourceScope(_common.CaseInSensitiveEnum):
579
+ """Resource scope."""
580
+
581
+ COLLECTION = 'COLLECTION'
582
+ """When setting base_url, this value configures resource scope to be the collection.
583
+ The resource name will not include api version, project, or location.
584
+ For example, if base_url is set to "https://aiplatform.googleapis.com",
585
+ then the resource name for a Model would be
586
+ "https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview"""
587
+
588
+
545
589
  class JSONSchemaType(Enum):
546
590
  """The type of the data supported by JSON Schema.
547
591
 
@@ -921,39 +965,34 @@ class LiveMusicPlaybackControl(_common.CaseInSensitiveEnum):
921
965
  Retains the current prompts and config."""
922
966
 
923
967
 
924
- class FunctionCall(_common.BaseModel):
925
- """A function call."""
968
+ class PartMediaResolution(_common.BaseModel):
969
+ """Media resolution for the input media."""
926
970
 
927
- id: Optional[str] = Field(
928
- default=None,
929
- description="""The unique id of the function call. If populated, the client to execute the
930
- `function_call` and return the response with the matching `id`.""",
931
- )
932
- args: Optional[dict[str, Any]] = Field(
971
+ level: Optional[PartMediaResolutionLevel] = Field(
933
972
  default=None,
934
- description="""Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.""",
973
+ description="""The tokenization quality used for given media.
974
+ """,
935
975
  )
936
- name: Optional[str] = Field(
976
+ num_tokens: Optional[int] = Field(
937
977
  default=None,
938
- description="""Optional. The name of the function to call. Matches [FunctionDeclaration.name].""",
978
+ description="""Specifies the required sequence length for media tokenization.
979
+ """,
939
980
  )
940
981
 
941
982
 
942
- class FunctionCallDict(TypedDict, total=False):
943
- """A function call."""
944
-
945
- id: Optional[str]
946
- """The unique id of the function call. If populated, the client to execute the
947
- `function_call` and return the response with the matching `id`."""
983
+ class PartMediaResolutionDict(TypedDict, total=False):
984
+ """Media resolution for the input media."""
948
985
 
949
- args: Optional[dict[str, Any]]
950
- """Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details."""
986
+ level: Optional[PartMediaResolutionLevel]
987
+ """The tokenization quality used for given media.
988
+ """
951
989
 
952
- name: Optional[str]
953
- """Optional. The name of the function to call. Matches [FunctionDeclaration.name]."""
990
+ num_tokens: Optional[int]
991
+ """Specifies the required sequence length for media tokenization.
992
+ """
954
993
 
955
994
 
956
- FunctionCallOrDict = Union[FunctionCall, FunctionCallDict]
995
+ PartMediaResolutionOrDict = Union[PartMediaResolution, PartMediaResolutionDict]
957
996
 
958
997
 
959
998
  class CodeExecutionResult(_common.BaseModel):
@@ -1056,6 +1095,111 @@ class FileDataDict(TypedDict, total=False):
1056
1095
  FileDataOrDict = Union[FileData, FileDataDict]
1057
1096
 
1058
1097
 
1098
+ class PartialArg(_common.BaseModel):
1099
+ """Partial argument value of the function call.
1100
+
1101
+ This data type is not supported in Gemini API.
1102
+ """
1103
+
1104
+ null_value: Optional[Literal['NULL_VALUE']] = Field(
1105
+ default=None, description="""Optional. Represents a null value."""
1106
+ )
1107
+ number_value: Optional[float] = Field(
1108
+ default=None, description="""Optional. Represents a double value."""
1109
+ )
1110
+ string_value: Optional[str] = Field(
1111
+ default=None, description="""Optional. Represents a string value."""
1112
+ )
1113
+ bool_value: Optional[bool] = Field(
1114
+ default=None, description="""Optional. Represents a boolean value."""
1115
+ )
1116
+ json_path: Optional[str] = Field(
1117
+ default=None,
1118
+ description="""Required. A JSON Path (RFC 9535) to the argument being streamed. https://datatracker.ietf.org/doc/html/rfc9535. e.g. "$.foo.bar[0].data".""",
1119
+ )
1120
+ will_continue: Optional[bool] = Field(
1121
+ default=None,
1122
+ description="""Optional. Whether this is not the last part of the same json_path. If true, another PartialArg message for the current json_path is expected to follow.""",
1123
+ )
1124
+
1125
+
1126
+ class PartialArgDict(TypedDict, total=False):
1127
+ """Partial argument value of the function call.
1128
+
1129
+ This data type is not supported in Gemini API.
1130
+ """
1131
+
1132
+ null_value: Optional[Literal['NULL_VALUE']]
1133
+ """Optional. Represents a null value."""
1134
+
1135
+ number_value: Optional[float]
1136
+ """Optional. Represents a double value."""
1137
+
1138
+ string_value: Optional[str]
1139
+ """Optional. Represents a string value."""
1140
+
1141
+ bool_value: Optional[bool]
1142
+ """Optional. Represents a boolean value."""
1143
+
1144
+ json_path: Optional[str]
1145
+ """Required. A JSON Path (RFC 9535) to the argument being streamed. https://datatracker.ietf.org/doc/html/rfc9535. e.g. "$.foo.bar[0].data"."""
1146
+
1147
+ will_continue: Optional[bool]
1148
+ """Optional. Whether this is not the last part of the same json_path. If true, another PartialArg message for the current json_path is expected to follow."""
1149
+
1150
+
1151
+ PartialArgOrDict = Union[PartialArg, PartialArgDict]
1152
+
1153
+
1154
+ class FunctionCall(_common.BaseModel):
1155
+ """A function call."""
1156
+
1157
+ id: Optional[str] = Field(
1158
+ default=None,
1159
+ description="""The unique id of the function call. If populated, the client to execute the
1160
+ `function_call` and return the response with the matching `id`.""",
1161
+ )
1162
+ args: Optional[dict[str, Any]] = Field(
1163
+ default=None,
1164
+ description="""Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.""",
1165
+ )
1166
+ name: Optional[str] = Field(
1167
+ default=None,
1168
+ description="""Optional. The name of the function to call. Matches [FunctionDeclaration.name].""",
1169
+ )
1170
+ partial_args: Optional[list[PartialArg]] = Field(
1171
+ default=None,
1172
+ description="""Optional. The partial argument value of the function call. If provided, represents the arguments/fields that are streamed incrementally. This field is not supported in Gemini API.""",
1173
+ )
1174
+ will_continue: Optional[bool] = Field(
1175
+ default=None,
1176
+ description="""Optional. Whether this is the last part of the FunctionCall. If true, another partial message for the current FunctionCall is expected to follow. This field is not supported in Gemini API.""",
1177
+ )
1178
+
1179
+
1180
+ class FunctionCallDict(TypedDict, total=False):
1181
+ """A function call."""
1182
+
1183
+ id: Optional[str]
1184
+ """The unique id of the function call. If populated, the client to execute the
1185
+ `function_call` and return the response with the matching `id`."""
1186
+
1187
+ args: Optional[dict[str, Any]]
1188
+ """Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details."""
1189
+
1190
+ name: Optional[str]
1191
+ """Optional. The name of the function to call. Matches [FunctionDeclaration.name]."""
1192
+
1193
+ partial_args: Optional[list[PartialArgDict]]
1194
+ """Optional. The partial argument value of the function call. If provided, represents the arguments/fields that are streamed incrementally. This field is not supported in Gemini API."""
1195
+
1196
+ will_continue: Optional[bool]
1197
+ """Optional. Whether this is the last part of the FunctionCall. If true, another partial message for the current FunctionCall is expected to follow. This field is not supported in Gemini API."""
1198
+
1199
+
1200
+ FunctionCallOrDict = Union[FunctionCall, FunctionCallDict]
1201
+
1202
+
1059
1203
  class FunctionResponseBlob(_common.BaseModel):
1060
1204
  """Raw media bytes for function response.
1061
1205
 
@@ -1070,6 +1214,11 @@ class FunctionResponseBlob(_common.BaseModel):
1070
1214
  data: Optional[bytes] = Field(
1071
1215
  default=None, description="""Required. Inline media bytes."""
1072
1216
  )
1217
+ display_name: Optional[str] = Field(
1218
+ default=None,
1219
+ description="""Optional. Display name of the blob.
1220
+ Used to provide a label or filename to distinguish blobs.""",
1221
+ )
1073
1222
 
1074
1223
 
1075
1224
  class FunctionResponseBlobDict(TypedDict, total=False):
@@ -1085,6 +1234,10 @@ class FunctionResponseBlobDict(TypedDict, total=False):
1085
1234
  data: Optional[bytes]
1086
1235
  """Required. Inline media bytes."""
1087
1236
 
1237
+ display_name: Optional[str]
1238
+ """Optional. Display name of the blob.
1239
+ Used to provide a label or filename to distinguish blobs."""
1240
+
1088
1241
 
1089
1242
  FunctionResponseBlobOrDict = Union[
1090
1243
  FunctionResponseBlob, FunctionResponseBlobDict
@@ -1101,6 +1254,11 @@ class FunctionResponseFileData(_common.BaseModel):
1101
1254
  default=None,
1102
1255
  description="""Required. The IANA standard MIME type of the source data.""",
1103
1256
  )
1257
+ display_name: Optional[str] = Field(
1258
+ default=None,
1259
+ description="""Optional. Display name of the file.
1260
+ Used to provide a label or filename to distinguish files.""",
1261
+ )
1104
1262
 
1105
1263
 
1106
1264
  class FunctionResponseFileDataDict(TypedDict, total=False):
@@ -1112,6 +1270,10 @@ class FunctionResponseFileDataDict(TypedDict, total=False):
1112
1270
  mime_type: Optional[str]
1113
1271
  """Required. The IANA standard MIME type of the source data."""
1114
1272
 
1273
+ display_name: Optional[str]
1274
+ """Optional. Display name of the file.
1275
+ Used to provide a label or filename to distinguish files."""
1276
+
1115
1277
 
1116
1278
  FunctionResponseFileDataOrDict = Union[
1117
1279
  FunctionResponseFileData, FunctionResponseFileDataDict
@@ -1351,11 +1513,10 @@ class Part(_common.BaseModel):
1351
1513
  instance is considered invalid.
1352
1514
  """
1353
1515
 
1354
- function_call: Optional[FunctionCall] = Field(
1516
+ media_resolution: Optional[PartMediaResolution] = Field(
1355
1517
  default=None,
1356
- description="""A predicted [FunctionCall] returned from the model that contains a string
1357
- representing the [FunctionDeclaration.name] and a structured JSON object
1358
- containing the parameters and their values.""",
1518
+ description="""Media resolution for the input media.
1519
+ """,
1359
1520
  )
1360
1521
  code_execution_result: Optional[CodeExecutionResult] = Field(
1361
1522
  default=None,
@@ -1368,6 +1529,10 @@ class Part(_common.BaseModel):
1368
1529
  file_data: Optional[FileData] = Field(
1369
1530
  default=None, description="""Optional. URI based data."""
1370
1531
  )
1532
+ function_call: Optional[FunctionCall] = Field(
1533
+ default=None,
1534
+ description="""Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values.""",
1535
+ )
1371
1536
  function_response: Optional[FunctionResponse] = Field(
1372
1537
  default=None,
1373
1538
  description="""Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model.""",
@@ -1472,9 +1637,31 @@ class Part(_common.BaseModel):
1472
1637
  return None
1473
1638
  return self.inline_data.as_image()
1474
1639
 
1640
+ @classmethod
1641
+ def _t_part_media_resolution(
1642
+ cls,
1643
+ part_media_resolution: Union[
1644
+ 'PartMediaResolutionOrDict', 'PartMediaResolutionLevel', str
1645
+ ],
1646
+ ) -> PartMediaResolution:
1647
+ if isinstance(part_media_resolution, str):
1648
+ part_media_resolution = PartMediaResolution(level=part_media_resolution)
1649
+ elif isinstance(part_media_resolution, PartMediaResolutionLevel):
1650
+ part_media_resolution = PartMediaResolution(level=part_media_resolution)
1651
+ elif isinstance(part_media_resolution, dict):
1652
+ part_media_resolution = PartMediaResolution(**part_media_resolution)
1653
+
1654
+ return part_media_resolution
1655
+
1475
1656
  @classmethod
1476
1657
  def from_uri(
1477
- cls, *, file_uri: str, mime_type: Optional[str] = None
1658
+ cls,
1659
+ *,
1660
+ file_uri: str,
1661
+ mime_type: Optional[str] = None,
1662
+ media_resolution: Optional[
1663
+ Union['PartMediaResolutionOrDict', 'PartMediaResolutionLevel', str]
1664
+ ] = None,
1478
1665
  ) -> 'Part':
1479
1666
  """Creates a Part from a file uri.
1480
1667
 
@@ -1489,20 +1676,33 @@ class Part(_common.BaseModel):
1489
1676
  mime_type, _ = mimetypes.guess_type(file_uri)
1490
1677
  if not mime_type:
1491
1678
  raise ValueError(f'Failed to determine mime type for file: {file_uri}')
1679
+ if media_resolution is not None:
1680
+ media_resolution = cls._t_part_media_resolution(media_resolution)
1492
1681
  file_data = FileData(file_uri=file_uri, mime_type=mime_type)
1493
- return cls(file_data=file_data)
1682
+ return cls(file_data=file_data, media_resolution=media_resolution)
1494
1683
 
1495
1684
  @classmethod
1496
1685
  def from_text(cls, *, text: str) -> 'Part':
1497
1686
  return cls(text=text)
1498
1687
 
1499
1688
  @classmethod
1500
- def from_bytes(cls, *, data: bytes, mime_type: str) -> 'Part':
1689
+ def from_bytes(
1690
+ cls,
1691
+ *,
1692
+ data: bytes,
1693
+ mime_type: str,
1694
+ media_resolution: Optional[
1695
+ Union['PartMediaResolutionOrDict', 'PartMediaResolutionLevel', str]
1696
+ ] = None,
1697
+ ) -> 'Part':
1501
1698
  inline_data = Blob(
1502
1699
  data=data,
1503
1700
  mime_type=mime_type,
1504
1701
  )
1505
- return cls(inline_data=inline_data)
1702
+ if media_resolution is not None:
1703
+ media_resolution = cls._t_part_media_resolution(media_resolution)
1704
+
1705
+ return cls(inline_data=inline_data, media_resolution=media_resolution)
1506
1706
 
1507
1707
  @classmethod
1508
1708
  def from_function_call(cls, *, name: str, args: dict[str, Any]) -> 'Part':
@@ -1543,10 +1743,9 @@ class PartDict(TypedDict, total=False):
1543
1743
  instance is considered invalid.
1544
1744
  """
1545
1745
 
1546
- function_call: Optional[FunctionCallDict]
1547
- """A predicted [FunctionCall] returned from the model that contains a string
1548
- representing the [FunctionDeclaration.name] and a structured JSON object
1549
- containing the parameters and their values."""
1746
+ media_resolution: Optional[PartMediaResolutionDict]
1747
+ """Media resolution for the input media.
1748
+ """
1550
1749
 
1551
1750
  code_execution_result: Optional[CodeExecutionResultDict]
1552
1751
  """Optional. Result of executing the [ExecutableCode]."""
@@ -1557,6 +1756,9 @@ class PartDict(TypedDict, total=False):
1557
1756
  file_data: Optional[FileDataDict]
1558
1757
  """Optional. URI based data."""
1559
1758
 
1759
+ function_call: Optional[FunctionCallDict]
1760
+ """Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values."""
1761
+
1560
1762
  function_response: Optional[FunctionResponseDict]
1561
1763
  """Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model."""
1562
1764
 
@@ -1672,6 +1874,10 @@ class HttpOptions(_common.BaseModel):
1672
1874
  default=None,
1673
1875
  description="""The base URL for the AI platform service endpoint.""",
1674
1876
  )
1877
+ base_url_resource_scope: Optional[ResourceScope] = Field(
1878
+ default=None,
1879
+ description="""The resource scope used to constructing the resource name when base_url is set""",
1880
+ )
1675
1881
  api_version: Optional[str] = Field(
1676
1882
  default=None, description="""Specifies the version of the API to use."""
1677
1883
  )
@@ -1715,6 +1921,9 @@ class HttpOptionsDict(TypedDict, total=False):
1715
1921
  base_url: Optional[str]
1716
1922
  """The base URL for the AI platform service endpoint."""
1717
1923
 
1924
+ base_url_resource_scope: Optional[ResourceScope]
1925
+ """The resource scope used to constructing the resource name when base_url is set"""
1926
+
1718
1927
  api_version: Optional[str]
1719
1928
  """Specifies the version of the API to use."""
1720
1929
 
@@ -4042,6 +4251,10 @@ class FunctionCallingConfig(_common.BaseModel):
4042
4251
  default=None,
4043
4252
  description="""Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided.""",
4044
4253
  )
4254
+ stream_function_call_arguments: Optional[bool] = Field(
4255
+ default=None,
4256
+ description="""Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API.""",
4257
+ )
4045
4258
 
4046
4259
 
4047
4260
  class FunctionCallingConfigDict(TypedDict, total=False):
@@ -4053,6 +4266,9 @@ class FunctionCallingConfigDict(TypedDict, total=False):
4053
4266
  allowed_function_names: Optional[list[str]]
4054
4267
  """Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided."""
4055
4268
 
4269
+ stream_function_call_arguments: Optional[bool]
4270
+ """Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API."""
4271
+
4056
4272
 
4057
4273
  FunctionCallingConfigOrDict = Union[
4058
4274
  FunctionCallingConfig, FunctionCallingConfigDict
@@ -4223,6 +4439,10 @@ class ThinkingConfig(_common.BaseModel):
4223
4439
  description="""Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
4224
4440
  """,
4225
4441
  )
4442
+ thinking_level: Optional[ThinkingLevel] = Field(
4443
+ default=None,
4444
+ description="""Optional. The level of thoughts tokens that the model should generate.""",
4445
+ )
4226
4446
 
4227
4447
 
4228
4448
  class ThinkingConfigDict(TypedDict, total=False):
@@ -4236,6 +4456,9 @@ class ThinkingConfigDict(TypedDict, total=False):
4236
4456
  """Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
4237
4457
  """
4238
4458
 
4459
+ thinking_level: Optional[ThinkingLevel]
4460
+ """Optional. The level of thoughts tokens that the model should generate."""
4461
+
4239
4462
 
4240
4463
  ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
4241
4464
 
@@ -4254,6 +4477,16 @@ class ImageConfig(_common.BaseModel):
4254
4477
  values are `1K`, `2K`, `4K`. If not specified, the model will use default
4255
4478
  value `1K`.""",
4256
4479
  )
4480
+ output_mime_type: Optional[str] = Field(
4481
+ default=None,
4482
+ description="""MIME type of the generated image. This field is not
4483
+ supported in Gemini API.""",
4484
+ )
4485
+ output_compression_quality: Optional[int] = Field(
4486
+ default=None,
4487
+ description="""Compression quality of the generated image (for
4488
+ ``image/jpeg`` only). This field is not supported in Gemini API.""",
4489
+ )
4257
4490
 
4258
4491
 
4259
4492
  class ImageConfigDict(TypedDict, total=False):
@@ -4268,6 +4501,14 @@ class ImageConfigDict(TypedDict, total=False):
4268
4501
  values are `1K`, `2K`, `4K`. If not specified, the model will use default
4269
4502
  value `1K`."""
4270
4503
 
4504
+ output_mime_type: Optional[str]
4505
+ """MIME type of the generated image. This field is not
4506
+ supported in Gemini API."""
4507
+
4508
+ output_compression_quality: Optional[int]
4509
+ """Compression quality of the generated image (for
4510
+ ``image/jpeg`` only). This field is not supported in Gemini API."""
4511
+
4271
4512
 
4272
4513
  ImageConfigOrDict = Union[ImageConfig, ImageConfigDict]
4273
4514
 
@@ -6290,16 +6531,12 @@ class GenerateContentResponse(_common.BaseModel):
6290
6531
  description="""First candidate from the parsed response if response_schema is provided. Not available for streaming.""",
6291
6532
  )
6292
6533
 
6293
- def _get_text(self, warn_property: Optional[str] = None) -> Optional[str]:
6534
+ def _get_text(self) -> Optional[str]:
6294
6535
  """Returns the concatenation of all text parts in the response.
6295
6536
 
6296
6537
  This is an internal method that allows customizing or disabling the warning
6297
6538
  message.
6298
6539
 
6299
- Args:
6300
- warn_property: The property name that is being accessed. This is used to
6301
- customize the warning message. If None, no warning will be logged.
6302
-
6303
6540
  Returns:
6304
6541
  The concatenation of all text parts in the response.
6305
6542
  """
@@ -6309,13 +6546,14 @@ class GenerateContentResponse(_common.BaseModel):
6309
6546
  or not self.candidates[0].content.parts
6310
6547
  ):
6311
6548
  return None
6312
- if len(self.candidates) > 1 and warn_property:
6549
+ global _response_text_warning_logged
6550
+ if len(self.candidates) > 1 and not _response_text_warning_logged:
6313
6551
  logger.warning(
6314
- f'there are {len(self.candidates)} candidates, returning'
6315
- f' {warn_property} result from the first candidate. Access'
6316
- ' response.candidates directly to get the result from other'
6317
- ' candidates.'
6552
+ f'there are {len(self.candidates)} candidates, returning text result'
6553
+ ' from the first candidate. Access response.candidates directly to'
6554
+ ' get the result from other candidates.'
6318
6555
  )
6556
+ _response_text_warning_logged = True
6319
6557
  text = ''
6320
6558
  any_text_part_text = False
6321
6559
  non_text_parts = []
@@ -6330,30 +6568,37 @@ class GenerateContentResponse(_common.BaseModel):
6330
6568
  continue
6331
6569
  any_text_part_text = True
6332
6570
  text += part.text
6333
- if non_text_parts and warn_property:
6571
+ global _response_text_non_text_warning_logged
6572
+ if non_text_parts and not _response_text_non_text_warning_logged:
6334
6573
  logger.warning(
6335
6574
  'Warning: there are non-text parts in the response:'
6336
- f' {non_text_parts}, returning concatenated {warn_property} result'
6575
+ f' {non_text_parts}, returning concatenated text result'
6337
6576
  ' from text parts. Check the full candidates.content.parts accessor'
6338
6577
  ' to get the full model response.'
6339
6578
  )
6579
+ _response_text_non_text_warning_logged = True
6340
6580
  # part.text == '' is different from part.text is None
6341
6581
  return text if any_text_part_text else None
6342
6582
 
6343
6583
  @property
6344
6584
  def parts(self) -> Optional[list[Part]]:
6345
- """Returns the content-parts in the response."""
6585
+ """Returns the content-parts in the response.
6586
+
6587
+ If there are multiple candidates, returns the parts from only the first one.
6588
+ """
6346
6589
  if (
6347
6590
  not self.candidates
6348
6591
  or self.candidates[0].content is None
6349
6592
  or self.candidates[0].content.parts is None
6350
6593
  ):
6351
6594
  return None
6352
- if len(self.candidates) > 1:
6595
+ global _response_parts_warning_logged
6596
+ if len(self.candidates) > 1 and not _response_parts_warning_logged:
6353
6597
  logger.warning(
6354
6598
  'Warning: there are multiple candidates in the response, returning'
6355
6599
  ' parts from the first one.'
6356
6600
  )
6601
+ _response_parts_warning_logged = True
6357
6602
 
6358
6603
  return self.candidates[0].content.parts
6359
6604
 
@@ -6362,23 +6607,32 @@ class GenerateContentResponse(_common.BaseModel):
6362
6607
  """Returns the concatenation of all text parts in the response.
6363
6608
 
6364
6609
  If there are multiple candidates, returns the text from only the first one.
6610
+ If there are non-text parts in the response, this returns only the text
6611
+ parts.
6365
6612
  """
6366
- return self._get_text(warn_property='text')
6613
+ return self._get_text()
6367
6614
 
6368
6615
  @property
6369
6616
  def function_calls(self) -> Optional[list[FunctionCall]]:
6370
- """Returns the list of function calls in the response."""
6617
+ """Returns the list of function calls in the response.
6618
+
6619
+ If there are multiple candidates, this returns the function calls from only
6620
+ the
6621
+ first one.
6622
+ """
6371
6623
  if (
6372
6624
  not self.candidates
6373
6625
  or not self.candidates[0].content
6374
6626
  or not self.candidates[0].content.parts
6375
6627
  ):
6376
6628
  return None
6377
- if len(self.candidates) > 1:
6629
+ global _response_function_calls_warning_logged
6630
+ if len(self.candidates) > 1 and not _response_function_calls_warning_logged:
6378
6631
  logger.warning(
6379
6632
  'Warning: there are multiple candidates in the response, returning'
6380
6633
  ' function calls from the first one.'
6381
6634
  )
6635
+ _response_function_calls_warning_logged = True
6382
6636
  function_calls = [
6383
6637
  part.function_call
6384
6638
  for part in self.candidates[0].content.parts
@@ -6389,18 +6643,28 @@ class GenerateContentResponse(_common.BaseModel):
6389
6643
 
6390
6644
  @property
6391
6645
  def executable_code(self) -> Optional[str]:
6392
- """Returns the executable code in the response."""
6646
+ """Returns the executable code in the response.
6647
+
6648
+ If there are multiple candidates, this returns the executable code from only
6649
+ the
6650
+ first one.
6651
+ """
6393
6652
  if (
6394
6653
  not self.candidates
6395
6654
  or not self.candidates[0].content
6396
6655
  or not self.candidates[0].content.parts
6397
6656
  ):
6398
6657
  return None
6399
- if len(self.candidates) > 1:
6658
+ global _response_executable_code_warning_logged
6659
+ if (
6660
+ len(self.candidates) > 1
6661
+ and not _response_executable_code_warning_logged
6662
+ ):
6400
6663
  logging.warning(
6401
6664
  'Warning: there are multiple candidates in the response, returning'
6402
6665
  ' executable code from the first one.'
6403
6666
  )
6667
+ _response_executable_code_warning_logged = True
6404
6668
  for part in self.candidates[0].content.parts:
6405
6669
  if part.executable_code is not None:
6406
6670
  return part.executable_code.code
@@ -6408,18 +6672,25 @@ class GenerateContentResponse(_common.BaseModel):
6408
6672
 
6409
6673
  @property
6410
6674
  def code_execution_result(self) -> Optional[str]:
6411
- """Returns the code execution result in the response."""
6675
+ """Returns the code execution result in the response.
6676
+
6677
+ If there are multiple candidates, this returns the code execution result
6678
+ from only the
6679
+ first one.
6680
+ """
6412
6681
  if (
6413
6682
  not self.candidates
6414
6683
  or not self.candidates[0].content
6415
6684
  or not self.candidates[0].content.parts
6416
6685
  ):
6417
6686
  return None
6418
- if len(self.candidates) > 1:
6687
+ global _response_code_execution_warning_logged
6688
+ if len(self.candidates) > 1 and not _response_code_execution_warning_logged:
6419
6689
  logging.warning(
6420
6690
  'Warning: there are multiple candidates in the response, returning'
6421
6691
  ' code execution result from the first one.'
6422
6692
  )
6693
+ _response_code_execution_warning_logged = True
6423
6694
  for part in self.candidates[0].content.parts:
6424
6695
  if part.code_execution_result is not None:
6425
6696
  return part.code_execution_result.output
@@ -15911,7 +16182,11 @@ class LiveServerMessage(_common.BaseModel):
15911
16182
 
15912
16183
  @property
15913
16184
  def text(self) -> Optional[str]:
15914
- """Returns the concatenation of all text parts in the response."""
16185
+ """Returns the concatenation of all text parts in the response.
16186
+
16187
+ If there are non-text parts in the response, only the concatenated text
16188
+ result from text parts will be returned.
16189
+ """
15915
16190
  if (
15916
16191
  not self.server_content
15917
16192
  or not self.server_content
@@ -15931,17 +16206,23 @@ class LiveServerMessage(_common.BaseModel):
15931
16206
  if isinstance(part.thought, bool) and part.thought:
15932
16207
  continue
15933
16208
  text += part.text
15934
- if non_text_parts:
16209
+ global _live_server_text_warning_logged
16210
+ if non_text_parts and not _live_server_text_warning_logged:
15935
16211
  logger.warning(
15936
16212
  'Warning: there are non-text parts in the response:'
15937
16213
  f' {non_text_parts}, returning concatenated text result from text'
15938
16214
  ' parts, check out the non text parts for full response from model.'
15939
16215
  )
16216
+ _live_server_text_warning_logged = True
15940
16217
  return text if text else None
15941
16218
 
15942
16219
  @property
15943
16220
  def data(self) -> Optional[bytes]:
15944
- """Returns the concatenation of all inline data parts in the response."""
16221
+ """Returns the concatenation of all inline data parts in the response.
16222
+
16223
+ If there are non-data parts in the response, only the concatenated data
16224
+ result from the data parts will be returned.
16225
+ """
15945
16226
  if (
15946
16227
  not self.server_content
15947
16228
  or not self.server_content
@@ -15959,12 +16240,14 @@ class LiveServerMessage(_common.BaseModel):
15959
16240
  non_data_parts.append(field_name)
15960
16241
  if part.inline_data and isinstance(part.inline_data.data, bytes):
15961
16242
  concatenated_data += part.inline_data.data
15962
- if non_data_parts:
16243
+ global _live_server_data_warning_logged
16244
+ if non_data_parts and not _live_server_data_warning_logged:
15963
16245
  logger.warning(
15964
16246
  'Warning: there are non-data parts in the response:'
15965
16247
  f' {non_data_parts}, returning concatenated data result from data'
15966
16248
  ' parts, check out the non data parts for full response from model.'
15967
16249
  )
16250
+ _live_server_data_warning_logged = True
15968
16251
  return concatenated_data if len(concatenated_data) > 0 else None
15969
16252
 
15970
16253