google-genai 1.0.0rc0__py3-none-any.whl → 1.2.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
@@ -22,9 +22,10 @@ import json
22
22
  import logging
23
23
  import sys
24
24
  import typing
25
- from typing import Any, Callable, GenericAlias, Literal, Optional, Type, TypedDict, Union
25
+ from typing import Any, Callable, GenericAlias, Literal, Optional, Union
26
26
  import pydantic
27
27
  from pydantic import Field
28
+ from typing_extensions import TypedDict
28
29
  from . import _common
29
30
 
30
31
  if sys.version_info >= (3, 10):
@@ -43,7 +44,7 @@ if typing.TYPE_CHECKING:
43
44
  PIL_Image = PIL.Image.Image
44
45
  _is_pillow_image_imported = True
45
46
  else:
46
- PIL_Image: Type = Any
47
+ PIL_Image: typing.Type = Any
47
48
  try:
48
49
  import PIL.Image
49
50
 
@@ -723,10 +724,6 @@ class HttpOptions(_common.BaseModel):
723
724
  timeout: Optional[int] = Field(
724
725
  default=None, description="""Timeout for the request in milliseconds."""
725
726
  )
726
- deprecated_response_payload: Optional[dict[str, Any]] = Field(
727
- default=None,
728
- description="""This field is deprecated. If set, the response payload will be returned int the supplied dict.""",
729
- )
730
727
 
731
728
 
732
729
  class HttpOptionsDict(TypedDict, total=False):
@@ -744,9 +741,6 @@ class HttpOptionsDict(TypedDict, total=False):
744
741
  timeout: Optional[int]
745
742
  """Timeout for the request in milliseconds."""
746
743
 
747
- deprecated_response_payload: Optional[dict[str, Any]]
748
- """This field is deprecated. If set, the response payload will be returned int the supplied dict."""
749
-
750
744
 
751
745
  HttpOptionsOrDict = Union[HttpOptions, HttpOptionsDict]
752
746
 
@@ -978,13 +972,24 @@ class FunctionDeclaration(_common.BaseModel):
978
972
  )
979
973
 
980
974
  @classmethod
981
- def from_callable(
975
+ def from_callable_with_api_option(
982
976
  cls,
983
977
  *,
984
- client,
985
978
  callable: Callable,
979
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
986
980
  ) -> 'FunctionDeclaration':
987
- """Converts a Callable to a FunctionDeclaration based on the client."""
981
+ """Converts a Callable to a FunctionDeclaration based on the API option.
982
+
983
+ Supported API option is 'VERTEX_AI' or 'GEMINI_API'. If api_option is unset,
984
+ it will default to 'GEMINI_API'. If unsupported api_option is provided, it
985
+ will raise ValueError.
986
+ """
987
+ supported_api_options = ['VERTEX_AI', 'GEMINI_API']
988
+ if api_option not in supported_api_options:
989
+ raise ValueError(
990
+ f'Unsupported api_option value: {api_option}. Supported api_option'
991
+ f' value is one of: {supported_api_options}.'
992
+ )
988
993
  from . import _automatic_function_calling_util
989
994
 
990
995
  parameters_properties = {}
@@ -995,7 +1000,7 @@ class FunctionDeclaration(_common.BaseModel):
995
1000
  inspect.Parameter.POSITIONAL_ONLY,
996
1001
  ):
997
1002
  schema = _automatic_function_calling_util._parse_schema_from_parameter(
998
- client, param, callable.__name__
1003
+ api_option, param, callable.__name__
999
1004
  )
1000
1005
  parameters_properties[name] = schema
1001
1006
  declaration = FunctionDeclaration(
@@ -1007,13 +1012,13 @@ class FunctionDeclaration(_common.BaseModel):
1007
1012
  type='OBJECT',
1008
1013
  properties=parameters_properties,
1009
1014
  )
1010
- if client.vertexai:
1015
+ if api_option == 'VERTEX_AI':
1011
1016
  declaration.parameters.required = (
1012
1017
  _automatic_function_calling_util._get_required_fields(
1013
1018
  declaration.parameters
1014
1019
  )
1015
1020
  )
1016
- if not client.vertexai:
1021
+ if api_option == 'GEMINI_API':
1017
1022
  return declaration
1018
1023
 
1019
1024
  return_annotation = inspect.signature(callable).return_annotation
@@ -1022,7 +1027,7 @@ class FunctionDeclaration(_common.BaseModel):
1022
1027
 
1023
1028
  declaration.response = (
1024
1029
  _automatic_function_calling_util._parse_schema_from_parameter(
1025
- client,
1030
+ api_option,
1026
1031
  inspect.Parameter(
1027
1032
  'return_value',
1028
1033
  inspect.Parameter.POSITIONAL_OR_KEYWORD,
@@ -1033,6 +1038,23 @@ class FunctionDeclaration(_common.BaseModel):
1033
1038
  )
1034
1039
  return declaration
1035
1040
 
1041
+ @classmethod
1042
+ def from_callable(
1043
+ cls,
1044
+ *,
1045
+ client,
1046
+ callable: Callable,
1047
+ ) -> 'FunctionDeclaration':
1048
+ """Converts a Callable to a FunctionDeclaration based on the client."""
1049
+ if client.vertexai:
1050
+ return cls.from_callable_with_api_option(
1051
+ callable=callable, api_option='VERTEX_AI'
1052
+ )
1053
+ else:
1054
+ return cls.from_callable_with_api_option(
1055
+ callable=callable, api_option='GEMINI_API'
1056
+ )
1057
+
1036
1058
 
1037
1059
  class FunctionDeclarationDict(TypedDict, total=False):
1038
1060
  """Defines a function that the model can generate JSON inputs for.
@@ -1571,7 +1593,7 @@ class File(_common.BaseModel):
1571
1593
  )
1572
1594
  expiration_time: Optional[datetime.datetime] = Field(
1573
1595
  default=None,
1574
- description="""Optional. The human-readable display name for the `File`. The display name must be no more than 512 characters in length, including spaces. Example: 'Welcome Image'""",
1596
+ description="""Output only. The timestamp of when the `File` will be deleted. Only set if the `File` is scheduled to expire.""",
1575
1597
  )
1576
1598
  update_time: Optional[datetime.datetime] = Field(
1577
1599
  default=None,
@@ -1622,7 +1644,7 @@ class FileDict(TypedDict, total=False):
1622
1644
  """Output only. The timestamp of when the `File` was created."""
1623
1645
 
1624
1646
  expiration_time: Optional[datetime.datetime]
1625
- """Optional. The human-readable display name for the `File`. The display name must be no more than 512 characters in length, including spaces. Example: 'Welcome Image'"""
1647
+ """Output only. The timestamp of when the `File` will be deleted. Only set if the `File` is scheduled to expire."""
1626
1648
 
1627
1649
  update_time: Optional[datetime.datetime]
1628
1650
  """Output only. The timestamp of when the `File` was last updated."""
@@ -1916,6 +1938,20 @@ class GenerateContentConfig(_common.BaseModel):
1916
1938
  """,
1917
1939
  )
1918
1940
 
1941
+ @pydantic.field_validator('response_schema', mode='before')
1942
+ @classmethod
1943
+ def _convert_literal_to_enum(cls, value):
1944
+ if typing.get_origin(value) is typing.Literal:
1945
+ enum_vals = typing.get_args(value)
1946
+ if not all(isinstance(arg, str) for arg in enum_vals):
1947
+ # This doesn't stop execution, it tells pydantic to raise a ValidationError
1948
+ # when the class is instantiated with an unsupported Literal
1949
+ raise ValueError(f'Literal type {value} must be a list of strings.')
1950
+ # The title 'PlaceholderLiteralEnum' is removed from the generated Schema
1951
+ # before sending the request
1952
+ return Enum('PlaceholderLiteralEnum', {s: s for s in enum_vals})
1953
+ return value
1954
+
1919
1955
 
1920
1956
  class GenerateContentConfigDict(TypedDict, total=False):
1921
1957
  """Optional model configuration parameters.
@@ -2822,7 +2858,7 @@ class GenerateContentResponse(_common.BaseModel):
2822
2858
  text = ''
2823
2859
  any_text_part_text = False
2824
2860
  for part in self.candidates[0].content.parts:
2825
- for field_name, field_value in part.dict(
2861
+ for field_name, field_value in part.model_dump(
2826
2862
  exclude={'text', 'thought'}
2827
2863
  ).items():
2828
2864
  if field_value is not None:
@@ -2890,6 +2926,11 @@ class GenerateContentResponse(_common.BaseModel):
2890
2926
  enum_value = result.text.replace('"', '')
2891
2927
  try:
2892
2928
  result.parsed = response_schema(enum_value)
2929
+ if (
2930
+ hasattr(response_schema, '__name__')
2931
+ and response_schema.__name__ == 'PlaceholderLiteralEnum'
2932
+ ):
2933
+ result.parsed = str(response_schema(enum_value).name)
2893
2934
  except ValueError:
2894
2935
  pass
2895
2936
  elif isinstance(response_schema, GenericAlias) or isinstance(
@@ -5961,22 +6002,51 @@ _CreateTuningJobParametersOrDict = Union[
5961
6002
  ]
5962
6003
 
5963
6004
 
5964
- class TuningJobOrOperation(_common.BaseModel):
5965
- """A tuning job or an long-running-operation that resolves to a tuning job."""
6005
+ class Operation(_common.BaseModel):
6006
+ """A long-running operation."""
6007
+
6008
+ name: Optional[str] = Field(
6009
+ default=None,
6010
+ description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""",
6011
+ )
6012
+ metadata: Optional[dict[str, Any]] = Field(
6013
+ default=None,
6014
+ description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""",
6015
+ )
6016
+ done: Optional[bool] = Field(
6017
+ default=None,
6018
+ description="""If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""",
6019
+ )
6020
+ error: Optional[dict[str, Any]] = Field(
6021
+ default=None,
6022
+ description="""The error result of the operation in case of failure or cancellation.""",
6023
+ )
6024
+ response: Optional[dict[str, Any]] = Field(
6025
+ default=None,
6026
+ description="""The normal response of the operation in case of success.""",
6027
+ )
5966
6028
 
5967
- tuning_job: Optional[TuningJob] = Field(default=None, description="""""")
5968
6029
 
6030
+ class OperationDict(TypedDict, total=False):
6031
+ """A long-running operation."""
5969
6032
 
5970
- class TuningJobOrOperationDict(TypedDict, total=False):
5971
- """A tuning job or an long-running-operation that resolves to a tuning job."""
6033
+ name: Optional[str]
6034
+ """The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`."""
5972
6035
 
5973
- tuning_job: Optional[TuningJobDict]
5974
- """"""
6036
+ metadata: Optional[dict[str, Any]]
6037
+ """Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any."""
5975
6038
 
6039
+ done: Optional[bool]
6040
+ """If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available."""
5976
6041
 
5977
- TuningJobOrOperationOrDict = Union[
5978
- TuningJobOrOperation, TuningJobOrOperationDict
5979
- ]
6042
+ error: Optional[dict[str, Any]]
6043
+ """The error result of the operation in case of failure or cancellation."""
6044
+
6045
+ response: Optional[dict[str, Any]]
6046
+ """The normal response of the operation in case of success."""
6047
+
6048
+
6049
+ OperationOrDict = Union[Operation, OperationDict]
5980
6050
 
5981
6051
 
5982
6052
  class CreateCachedContentConfig(_common.BaseModel):
@@ -6583,13 +6653,17 @@ _CreateFileParametersOrDict = Union[
6583
6653
  class CreateFileResponse(_common.BaseModel):
6584
6654
  """Response for the create file method."""
6585
6655
 
6586
- pass
6656
+ http_headers: Optional[dict[str, str]] = Field(
6657
+ default=None,
6658
+ description="""Used to retain the HTTP headers in the request""",
6659
+ )
6587
6660
 
6588
6661
 
6589
6662
  class CreateFileResponseDict(TypedDict, total=False):
6590
6663
  """Response for the create file method."""
6591
6664
 
6592
- pass
6665
+ http_headers: Optional[dict[str, str]]
6666
+ """Used to retain the HTTP headers in the request"""
6593
6667
 
6594
6668
 
6595
6669
  CreateFileResponseOrDict = Union[CreateFileResponse, CreateFileResponseDict]
@@ -7285,53 +7359,6 @@ _GetOperationParametersOrDict = Union[
7285
7359
  ]
7286
7360
 
7287
7361
 
7288
- class Operation(_common.BaseModel):
7289
- """A long-running operation."""
7290
-
7291
- name: Optional[str] = Field(
7292
- default=None,
7293
- description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""",
7294
- )
7295
- metadata: Optional[dict[str, Any]] = Field(
7296
- default=None,
7297
- description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""",
7298
- )
7299
- done: Optional[bool] = Field(
7300
- default=None,
7301
- description="""If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""",
7302
- )
7303
- error: Optional[dict[str, Any]] = Field(
7304
- default=None,
7305
- description="""The error result of the operation in case of failure or cancellation.""",
7306
- )
7307
- response: Optional[dict[str, Any]] = Field(
7308
- default=None,
7309
- description="""The normal response of the operation in case of success.""",
7310
- )
7311
-
7312
-
7313
- class OperationDict(TypedDict, total=False):
7314
- """A long-running operation."""
7315
-
7316
- name: Optional[str]
7317
- """The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`."""
7318
-
7319
- metadata: Optional[dict[str, Any]]
7320
- """Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any."""
7321
-
7322
- done: Optional[bool]
7323
- """If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available."""
7324
-
7325
- error: Optional[dict[str, Any]]
7326
- """The error result of the operation in case of failure or cancellation."""
7327
-
7328
- response: Optional[dict[str, Any]]
7329
- """The normal response of the operation in case of success."""
7330
-
7331
-
7332
- OperationOrDict = Union[Operation, OperationDict]
7333
-
7334
-
7335
7362
  class FetchPredictOperationConfig(_common.BaseModel):
7336
7363
 
7337
7364
  http_options: Optional[HttpOptions] = Field(
google/genai/version.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- __version__ = '1.0.0rc0' # x-release-please-version
16
+ __version__ = '1.2.0' # x-release-please-version