google-genai 1.3.0__py3-none-any.whl → 1.4.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
@@ -21,8 +21,9 @@ import inspect
21
21
  import json
22
22
  import logging
23
23
  import sys
24
+ import types as builtin_types
24
25
  import typing
25
- from typing import Any, Callable, GenericAlias, Literal, Optional, Union
26
+ from typing import Any, Callable, Literal, Optional, Union, _UnionGenericAlias
26
27
  import pydantic
27
28
  from pydantic import Field
28
29
  from typing_extensions import TypedDict
@@ -30,11 +31,11 @@ from . import _common
30
31
 
31
32
  if sys.version_info >= (3, 10):
32
33
  # Supports both Union[t1, t2] and t1 | t2
33
- VersionedUnionType = Union[typing.types.UnionType, typing._UnionGenericAlias]
34
- _UNION_TYPES = (typing.Union, typing.types.UnionType)
34
+ VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias]
35
+ _UNION_TYPES = (typing.Union, builtin_types.UnionType)
35
36
  else:
36
37
  # Supports only Union[t1, t2]
37
- VersionedUnionType = typing._UnionGenericAlias
38
+ VersionedUnionType = _UnionGenericAlias
38
39
  _UNION_TYPES = (typing.Union,)
39
40
 
40
41
  _is_pillow_image_imported = False
@@ -73,7 +74,7 @@ class Language(_common.CaseInSensitiveEnum):
73
74
 
74
75
 
75
76
  class Type(_common.CaseInSensitiveEnum):
76
- """A basic data type."""
77
+ """Optional. The type of the data."""
77
78
 
78
79
  TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED'
79
80
  STRING = 'STRING'
@@ -714,13 +715,12 @@ class UserContent(Content):
714
715
  """
715
716
 
716
717
  role: Literal['user'] = Field(default='user', init=False, frozen=True)
717
- parts: list[Part] = Field(init=False)
718
+ parts: list[Part] = Field()
718
719
 
719
- @pydantic.field_validator('parts', mode='before')
720
- def validate_parts(cls, value):
720
+ def __init__(self, parts: Union['PartUnionDict', list['PartUnionDict']]):
721
721
  from . import _transformers as t
722
722
 
723
- return t.t_parts(None, parts=value)
723
+ super().__init__(parts=t.t_parts(None, parts=parts))
724
724
 
725
725
 
726
726
  class ModelContent(Content):
@@ -743,13 +743,12 @@ class ModelContent(Content):
743
743
  """
744
744
 
745
745
  role: Literal['model'] = Field(default='model', init=False, frozen=True)
746
- parts: list[Part] = Field(init=False)
746
+ parts: list[Part] = Field()
747
747
 
748
- @pydantic.field_validator('parts', mode='before')
749
- def validate_parts(cls, value):
748
+ def __init__(self, parts: Union['PartUnionDict', list['PartUnionDict']]):
750
749
  from . import _transformers as t
751
750
 
752
- return t.t_parts(None, parts=value)
751
+ super().__init__(parts=t.t_parts(None, parts=parts))
753
752
 
754
753
 
755
754
  class ContentDict(TypedDict, total=False):
@@ -812,18 +811,10 @@ class Schema(_common.BaseModel):
812
811
  Represents a select subset of an OpenAPI 3.0 schema object.
813
812
  """
814
813
 
815
- min_items: Optional[int] = Field(
816
- default=None,
817
- description="""Optional. Minimum number of the elements for Type.ARRAY.""",
818
- )
819
814
  example: Optional[Any] = Field(
820
815
  default=None,
821
816
  description="""Optional. Example of the object. Will only populated when the object is the root.""",
822
817
  )
823
- property_ordering: Optional[list[str]] = Field(
824
- default=None,
825
- description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
826
- )
827
818
  pattern: Optional[str] = Field(
828
819
  default=None,
829
820
  description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
@@ -835,7 +826,7 @@ class Schema(_common.BaseModel):
835
826
  default: Optional[Any] = Field(
836
827
  default=None, description="""Optional. Default value of the data."""
837
828
  )
838
- any_of: list['Schema'] = Field(
829
+ any_of: Optional[list['Schema']] = Field(
839
830
  default=None,
840
831
  description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
841
832
  )
@@ -854,25 +845,14 @@ class Schema(_common.BaseModel):
854
845
  default=None,
855
846
  description="""Optional. Minimum number of the properties for Type.OBJECT.""",
856
847
  )
857
- max_items: Optional[int] = Field(
858
- default=None,
859
- description="""Optional. Maximum number of the elements for Type.ARRAY.""",
860
- )
861
848
  maximum: Optional[float] = Field(
862
849
  default=None,
863
850
  description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
864
851
  )
865
- nullable: Optional[bool] = Field(
866
- default=None,
867
- description="""Optional. Indicates if the value may be null.""",
868
- )
869
852
  max_properties: Optional[int] = Field(
870
853
  default=None,
871
854
  description="""Optional. Maximum number of the properties for Type.OBJECT.""",
872
855
  )
873
- type: Optional[Type] = Field(
874
- default=None, description="""Optional. The type of the data."""
875
- )
876
856
  description: Optional[str] = Field(
877
857
  default=None, description="""Optional. The description of the data."""
878
858
  )
@@ -884,18 +864,37 @@ class Schema(_common.BaseModel):
884
864
  default=None,
885
865
  description="""Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc""",
886
866
  )
887
- items: 'Schema' = Field(
867
+ items: Optional['Schema'] = Field(
888
868
  default=None,
889
869
  description="""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY.""",
890
870
  )
891
- properties: dict[str, 'Schema'] = Field(
871
+ max_items: Optional[int] = Field(
872
+ default=None,
873
+ description="""Optional. Maximum number of the elements for Type.ARRAY.""",
874
+ )
875
+ min_items: Optional[int] = Field(
876
+ default=None,
877
+ description="""Optional. Minimum number of the elements for Type.ARRAY.""",
878
+ )
879
+ nullable: Optional[bool] = Field(
880
+ default=None,
881
+ description="""Optional. Indicates if the value may be null.""",
882
+ )
883
+ properties: Optional[dict[str, 'Schema']] = Field(
892
884
  default=None,
893
885
  description="""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.""",
894
886
  )
887
+ property_ordering: Optional[list[str]] = Field(
888
+ default=None,
889
+ description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
890
+ )
895
891
  required: Optional[list[str]] = Field(
896
892
  default=None,
897
893
  description="""Optional. Required properties of Type.OBJECT.""",
898
894
  )
895
+ type: Optional[Type] = Field(
896
+ default=None, description="""Optional. The type of the data."""
897
+ )
899
898
 
900
899
 
901
900
  class SchemaDict(TypedDict, total=False):
@@ -904,15 +903,9 @@ class SchemaDict(TypedDict, total=False):
904
903
  Represents a select subset of an OpenAPI 3.0 schema object.
905
904
  """
906
905
 
907
- min_items: Optional[int]
908
- """Optional. Minimum number of the elements for Type.ARRAY."""
909
-
910
906
  example: Optional[Any]
911
907
  """Optional. Example of the object. Will only populated when the object is the root."""
912
908
 
913
- property_ordering: Optional[list[str]]
914
- """Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
915
-
916
909
  pattern: Optional[str]
917
910
  """Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
918
911
 
@@ -922,7 +915,7 @@ class SchemaDict(TypedDict, total=False):
922
915
  default: Optional[Any]
923
916
  """Optional. Default value of the data."""
924
917
 
925
- any_of: list['SchemaDict']
918
+ any_of: Optional[list['SchemaDict']]
926
919
  """Optional. The value should be validated against any (one or more) of the subschemas in the list."""
927
920
 
928
921
  max_length: Optional[int]
@@ -937,21 +930,12 @@ class SchemaDict(TypedDict, total=False):
937
930
  min_properties: Optional[int]
938
931
  """Optional. Minimum number of the properties for Type.OBJECT."""
939
932
 
940
- max_items: Optional[int]
941
- """Optional. Maximum number of the elements for Type.ARRAY."""
942
-
943
933
  maximum: Optional[float]
944
934
  """Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
945
935
 
946
- nullable: Optional[bool]
947
- """Optional. Indicates if the value may be null."""
948
-
949
936
  max_properties: Optional[int]
950
937
  """Optional. Maximum number of the properties for Type.OBJECT."""
951
938
 
952
- type: Optional[Type]
953
- """Optional. The type of the data."""
954
-
955
939
  description: Optional[str]
956
940
  """Optional. The description of the data."""
957
941
 
@@ -961,15 +945,30 @@ class SchemaDict(TypedDict, total=False):
961
945
  format: Optional[str]
962
946
  """Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc"""
963
947
 
964
- items: 'SchemaDict'
948
+ items: Optional['SchemaDict']
965
949
  """Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY."""
966
950
 
967
- properties: dict[str, 'SchemaDict']
951
+ max_items: Optional[int]
952
+ """Optional. Maximum number of the elements for Type.ARRAY."""
953
+
954
+ min_items: Optional[int]
955
+ """Optional. Minimum number of the elements for Type.ARRAY."""
956
+
957
+ nullable: Optional[bool]
958
+ """Optional. Indicates if the value may be null."""
959
+
960
+ properties: Optional[dict[str, 'SchemaDict']]
968
961
  """Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT."""
969
962
 
963
+ property_ordering: Optional[list[str]]
964
+ """Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
965
+
970
966
  required: Optional[list[str]]
971
967
  """Optional. Required properties of Type.OBJECT."""
972
968
 
969
+ type: Optional[Type]
970
+ """Optional. The type of the data."""
971
+
973
972
 
974
973
  SchemaOrDict = Union[Schema, SchemaDict]
975
974
 
@@ -1749,7 +1748,9 @@ ContentUnion = Union[Content, list[PartUnion], PartUnion]
1749
1748
  ContentUnionDict = Union[ContentUnion, ContentDict]
1750
1749
 
1751
1750
 
1752
- SchemaUnion = Union[dict, type, Schema, GenericAlias, VersionedUnionType]
1751
+ SchemaUnion = Union[
1752
+ dict, type, Schema, builtin_types.GenericAlias, VersionedUnionType
1753
+ ]
1753
1754
 
1754
1755
 
1755
1756
  SchemaUnionDict = Union[SchemaUnion, SchemaDict]
@@ -2884,6 +2885,16 @@ class GenerateContentResponse(_common.BaseModel):
2884
2885
  description="""Response variations returned by the model.
2885
2886
  """,
2886
2887
  )
2888
+ create_time: Optional[datetime.datetime] = Field(
2889
+ default=None,
2890
+ description="""Timestamp when the request is made to the server.
2891
+ """,
2892
+ )
2893
+ response_id: Optional[str] = Field(
2894
+ default=None,
2895
+ description="""Identifier for each response.
2896
+ """,
2897
+ )
2887
2898
  model_version: Optional[str] = Field(
2888
2899
  default=None,
2889
2900
  description="""Output only. The model version used to generate the response.""",
@@ -2896,7 +2907,7 @@ class GenerateContentResponse(_common.BaseModel):
2896
2907
  default=None, description="""Usage metadata about the response(s)."""
2897
2908
  )
2898
2909
  automatic_function_calling_history: Optional[list[Content]] = None
2899
- parsed: Union[pydantic.BaseModel, dict, Enum] = Field(
2910
+ parsed: Optional[Union[pydantic.BaseModel, dict, Enum]] = Field(
2900
2911
  default=None,
2901
2912
  description="""Parsed response if response_schema is provided. Not available for streaming.""",
2902
2913
  )
@@ -2918,20 +2929,24 @@ class GenerateContentResponse(_common.BaseModel):
2918
2929
  )
2919
2930
  text = ''
2920
2931
  any_text_part_text = False
2932
+ non_text_parts = []
2921
2933
  for part in self.candidates[0].content.parts:
2922
2934
  for field_name, field_value in part.model_dump(
2923
2935
  exclude={'text', 'thought'}
2924
2936
  ).items():
2925
2937
  if field_value is not None:
2926
- raise ValueError(
2927
- 'GenerateContentResponse.text only supports text parts, but got'
2928
- f' {field_name} part'
2929
- )
2938
+ non_text_parts.append(field_name)
2930
2939
  if isinstance(part.text, str):
2931
2940
  if isinstance(part.thought, bool) and part.thought:
2932
2941
  continue
2933
2942
  any_text_part_text = True
2934
2943
  text += part.text
2944
+ if non_text_parts:
2945
+ logger.warning(
2946
+ 'Warning: there are non-text parts in the response:'
2947
+ f' {non_text_parts},returning concatenated text from text parts,check'
2948
+ ' out the non text parts for full response from model.'
2949
+ )
2935
2950
  # part.text == '' is different from part.text is None
2936
2951
  return text if any_text_part_text else None
2937
2952
 
@@ -2998,8 +3013,8 @@ class GenerateContentResponse(_common.BaseModel):
2998
3013
  @classmethod
2999
3014
  def _from_response(
3000
3015
  cls, *, response: dict[str, object], kwargs: dict[str, object]
3001
- ):
3002
- result = super()._from_response(response, kwargs)
3016
+ ) -> _common.BaseModel:
3017
+ result = super()._from_response(response=response, kwargs=kwargs)
3003
3018
 
3004
3019
  # Handles response schema.
3005
3020
  response_schema = _common.get_value_by_path(
@@ -3008,7 +3023,7 @@ class GenerateContentResponse(_common.BaseModel):
3008
3023
  if (
3009
3024
  inspect.isclass(response_schema)
3010
3025
  and not (
3011
- isinstance(response_schema, GenericAlias)
3026
+ isinstance(response_schema, builtin_types.GenericAlias)
3012
3027
  ) # Needed for Python 3.9 and 3.10
3013
3028
  and issubclass(response_schema, pydantic.BaseModel)
3014
3029
  ):
@@ -3032,7 +3047,7 @@ class GenerateContentResponse(_common.BaseModel):
3032
3047
  result.parsed = str(response_schema(enum_value).name)
3033
3048
  except ValueError:
3034
3049
  pass
3035
- elif isinstance(response_schema, GenericAlias) or isinstance(
3050
+ elif isinstance(response_schema, builtin_types.GenericAlias) or isinstance(
3036
3051
  response_schema, type
3037
3052
  ):
3038
3053
 
@@ -3066,7 +3081,7 @@ class GenerateContentResponse(_common.BaseModel):
3066
3081
  if issubclass(union_type, pydantic.BaseModel):
3067
3082
  try:
3068
3083
 
3069
- class Placeholder(pydantic.BaseModel):
3084
+ class Placeholder(pydantic.BaseModel): # type: ignore[no-redef]
3070
3085
  placeholder: response_schema
3071
3086
 
3072
3087
  parsed = {'placeholder': json.loads(result.text)}
@@ -3093,6 +3108,14 @@ class GenerateContentResponseDict(TypedDict, total=False):
3093
3108
  """Response variations returned by the model.
3094
3109
  """
3095
3110
 
3111
+ create_time: Optional[datetime.datetime]
3112
+ """Timestamp when the request is made to the server.
3113
+ """
3114
+
3115
+ response_id: Optional[str]
3116
+ """Identifier for each response.
3117
+ """
3118
+
3096
3119
  model_version: Optional[str]
3097
3120
  """Output only. The model version used to generate the response."""
3098
3121
 
@@ -3370,6 +3393,11 @@ class GenerateImagesConfig(_common.BaseModel):
3370
3393
  description="""Number of images to generate.
3371
3394
  """,
3372
3395
  )
3396
+ aspect_ratio: Optional[str] = Field(
3397
+ default=None,
3398
+ description="""Aspect ratio of the generated images.
3399
+ """,
3400
+ )
3373
3401
  guidance_scale: Optional[float] = Field(
3374
3402
  default=None,
3375
3403
  description="""Controls how much the model adheres to the text prompt. Large
@@ -3425,11 +3453,6 @@ class GenerateImagesConfig(_common.BaseModel):
3425
3453
  description="""Whether to add a watermark to the generated images.
3426
3454
  """,
3427
3455
  )
3428
- aspect_ratio: Optional[str] = Field(
3429
- default=None,
3430
- description="""Aspect ratio of the generated images.
3431
- """,
3432
- )
3433
3456
  enhance_prompt: Optional[bool] = Field(
3434
3457
  default=None,
3435
3458
  description="""Whether to use the prompt rewriting logic.
@@ -3455,6 +3478,10 @@ class GenerateImagesConfigDict(TypedDict, total=False):
3455
3478
  """Number of images to generate.
3456
3479
  """
3457
3480
 
3481
+ aspect_ratio: Optional[str]
3482
+ """Aspect ratio of the generated images.
3483
+ """
3484
+
3458
3485
  guidance_scale: Optional[float]
3459
3486
  """Controls how much the model adheres to the text prompt. Large
3460
3487
  values increase output and prompt alignment, but may compromise image
@@ -3500,10 +3527,6 @@ class GenerateImagesConfigDict(TypedDict, total=False):
3500
3527
  """Whether to add a watermark to the generated images.
3501
3528
  """
3502
3529
 
3503
- aspect_ratio: Optional[str]
3504
- """Aspect ratio of the generated images.
3505
- """
3506
-
3507
3530
  enhance_prompt: Optional[bool]
3508
3531
  """Whether to use the prompt rewriting logic.
3509
3532
  """
@@ -3626,7 +3649,8 @@ class Image(_common.BaseModel):
3626
3649
  IPython_display.display(self._pil_image)
3627
3650
 
3628
3651
  @property
3629
- def _pil_image(self) -> 'PIL_Image.Image':
3652
+ def _pil_image(self) -> 'PIL_Image':
3653
+ PIL_Image: Optional[builtin_types.ModuleType]
3630
3654
  try:
3631
3655
  from PIL import Image as PIL_Image
3632
3656
  except ImportError:
@@ -3895,7 +3919,8 @@ class _ReferenceImageAPI(_common.BaseModel):
3895
3919
  default=None, description="""The id of the reference image."""
3896
3920
  )
3897
3921
  reference_type: Optional[str] = Field(
3898
- default=None, description="""The type of the reference image."""
3922
+ default=None,
3923
+ description="""The type of the reference image. Only set by the SDK.""",
3899
3924
  )
3900
3925
  mask_image_config: Optional[MaskReferenceConfig] = Field(
3901
3926
  default=None,
@@ -3925,7 +3950,7 @@ class _ReferenceImageAPIDict(TypedDict, total=False):
3925
3950
  """The id of the reference image."""
3926
3951
 
3927
3952
  reference_type: Optional[str]
3928
- """The type of the reference image."""
3953
+ """The type of the reference image. Only set by the SDK."""
3929
3954
 
3930
3955
  mask_image_config: Optional[MaskReferenceConfigDict]
3931
3956
  """Configuration for the mask reference image."""
@@ -3964,6 +3989,11 @@ class EditImageConfig(_common.BaseModel):
3964
3989
  description="""Number of images to generate.
3965
3990
  """,
3966
3991
  )
3992
+ aspect_ratio: Optional[str] = Field(
3993
+ default=None,
3994
+ description="""Aspect ratio of the generated images.
3995
+ """,
3996
+ )
3967
3997
  guidance_scale: Optional[float] = Field(
3968
3998
  default=None,
3969
3999
  description="""Controls how much the model adheres to the text prompt. Large
@@ -4038,6 +4068,10 @@ class EditImageConfigDict(TypedDict, total=False):
4038
4068
  """Number of images to generate.
4039
4069
  """
4040
4070
 
4071
+ aspect_ratio: Optional[str]
4072
+ """Aspect ratio of the generated images.
4073
+ """
4074
+
4041
4075
  guidance_scale: Optional[float]
4042
4076
  """Controls how much the model adheres to the text prompt. Large
4043
4077
  values increase output and prompt alignment, but may compromise image
@@ -5080,8 +5114,6 @@ class Video(_common.BaseModel):
5080
5114
  def save(
5081
5115
  self,
5082
5116
  path: str,
5083
- # *,
5084
- # client: Optional[ApiClient] = None,
5085
5117
  ) -> None:
5086
5118
  """Saves the video to a file.
5087
5119
 
@@ -5090,15 +5122,10 @@ class Video(_common.BaseModel):
5090
5122
  """
5091
5123
  import pathlib # pylint: disable=g-import-not-at-top
5092
5124
 
5093
- if not self.data:
5125
+ if not self.video_bytes:
5094
5126
  raise NotImplementedError('Saving remote videos is not supported.')
5095
- if not self.uri:
5096
- raise ValueError('No data or uri provided.')
5097
- if not client:
5098
- raise ValueError('Client is required to save remote videos.')
5099
- self.data = client.files.download(self.uri)
5100
5127
 
5101
- pathlib.Path(path).write_bytes(self.data)
5128
+ pathlib.Path(path).write_bytes(self.video_bytes)
5102
5129
 
5103
5130
  def show(self):
5104
5131
  """Shows the video.
@@ -8195,19 +8222,17 @@ class RawReferenceImage(_common.BaseModel):
8195
8222
  default=None, description="""The id of the reference image."""
8196
8223
  )
8197
8224
  reference_type: Optional[str] = Field(
8198
- default=None, description="""The type of the reference image."""
8225
+ default=None,
8226
+ description="""The type of the reference image. Only set by the SDK.""",
8199
8227
  )
8200
8228
 
8201
- def __init__(
8202
- self,
8203
- reference_image: Optional[Image] = None,
8204
- reference_id: Optional[int] = None,
8205
- ):
8206
- super().__init__(
8207
- reference_image=reference_image,
8208
- reference_id=reference_id,
8209
- reference_type='REFERENCE_TYPE_RAW',
8210
- )
8229
+ @pydantic.model_validator(mode='before')
8230
+ @classmethod
8231
+ def _validate_mask_image_config(self, values):
8232
+ if 'reference_type' in values:
8233
+ raise ValueError('Cannot set internal reference_type field directly.')
8234
+ values['reference_type'] = 'REFERENCE_TYPE_RAW'
8235
+ return values
8211
8236
 
8212
8237
 
8213
8238
  class RawReferenceImageDict(TypedDict, total=False):
@@ -8225,7 +8250,7 @@ class RawReferenceImageDict(TypedDict, total=False):
8225
8250
  """The id of the reference image."""
8226
8251
 
8227
8252
  reference_type: Optional[str]
8228
- """The type of the reference image."""
8253
+ """The type of the reference image. Only set by the SDK."""
8229
8254
 
8230
8255
 
8231
8256
  RawReferenceImageOrDict = Union[RawReferenceImage, RawReferenceImageDict]
@@ -8251,7 +8276,8 @@ class MaskReferenceImage(_common.BaseModel):
8251
8276
  default=None, description="""The id of the reference image."""
8252
8277
  )
8253
8278
  reference_type: Optional[str] = Field(
8254
- default=None, description="""The type of the reference image."""
8279
+ default=None,
8280
+ description="""The type of the reference image. Only set by the SDK.""",
8255
8281
  )
8256
8282
  config: Optional[MaskReferenceConfig] = Field(
8257
8283
  default=None,
@@ -8262,18 +8288,15 @@ class MaskReferenceImage(_common.BaseModel):
8262
8288
  default=None, description=""""""
8263
8289
  )
8264
8290
 
8265
- def __init__(
8266
- self,
8267
- reference_image: Optional[Image] = None,
8268
- reference_id: Optional[int] = None,
8269
- config: Optional['MaskReferenceConfig'] = None,
8270
- ):
8271
- super().__init__(
8272
- reference_image=reference_image,
8273
- reference_id=reference_id,
8274
- reference_type='REFERENCE_TYPE_MASK',
8275
- )
8276
- self.mask_image_config = config
8291
+ @pydantic.model_validator(mode='before')
8292
+ @classmethod
8293
+ def _validate_mask_image_config(self, values):
8294
+ config = values.get('config', None)
8295
+ values['mask_image_config'] = config
8296
+ if 'reference_type' in values:
8297
+ raise ValueError('Cannot set internal reference_type field directly.')
8298
+ values['reference_type'] = 'REFERENCE_TYPE_MASK'
8299
+ return values
8277
8300
 
8278
8301
 
8279
8302
  class MaskReferenceImageDict(TypedDict, total=False):
@@ -8295,7 +8318,7 @@ class MaskReferenceImageDict(TypedDict, total=False):
8295
8318
  """The id of the reference image."""
8296
8319
 
8297
8320
  reference_type: Optional[str]
8298
- """The type of the reference image."""
8321
+ """The type of the reference image. Only set by the SDK."""
8299
8322
 
8300
8323
  config: Optional[MaskReferenceConfigDict]
8301
8324
  """Configuration for the mask reference image."""
@@ -8324,7 +8347,8 @@ class ControlReferenceImage(_common.BaseModel):
8324
8347
  default=None, description="""The id of the reference image."""
8325
8348
  )
8326
8349
  reference_type: Optional[str] = Field(
8327
- default=None, description="""The type of the reference image."""
8350
+ default=None,
8351
+ description="""The type of the reference image. Only set by the SDK.""",
8328
8352
  )
8329
8353
  config: Optional[ControlReferenceConfig] = Field(
8330
8354
  default=None,
@@ -8335,18 +8359,15 @@ class ControlReferenceImage(_common.BaseModel):
8335
8359
  default=None, description=""""""
8336
8360
  )
8337
8361
 
8338
- def __init__(
8339
- self,
8340
- reference_image: Optional[Image] = None,
8341
- reference_id: Optional[int] = None,
8342
- config: Optional['ControlReferenceConfig'] = None,
8343
- ):
8344
- super().__init__(
8345
- reference_image=reference_image,
8346
- reference_id=reference_id,
8347
- reference_type='REFERENCE_TYPE_CONTROL',
8348
- )
8349
- self.control_image_config = config
8362
+ @pydantic.model_validator(mode='before')
8363
+ @classmethod
8364
+ def _validate_mask_image_config(self, values):
8365
+ config = values.get('config', None)
8366
+ values['control_image_config'] = config
8367
+ if 'reference_type' in values:
8368
+ raise ValueError('Cannot set internal reference_type field directly.')
8369
+ values['reference_type'] = 'REFERENCE_TYPE_CONTROL'
8370
+ return values
8350
8371
 
8351
8372
 
8352
8373
  class ControlReferenceImageDict(TypedDict, total=False):
@@ -8368,7 +8389,7 @@ class ControlReferenceImageDict(TypedDict, total=False):
8368
8389
  """The id of the reference image."""
8369
8390
 
8370
8391
  reference_type: Optional[str]
8371
- """The type of the reference image."""
8392
+ """The type of the reference image. Only set by the SDK."""
8372
8393
 
8373
8394
  config: Optional[ControlReferenceConfigDict]
8374
8395
  """Configuration for the control reference image."""
@@ -8397,7 +8418,8 @@ class StyleReferenceImage(_common.BaseModel):
8397
8418
  default=None, description="""The id of the reference image."""
8398
8419
  )
8399
8420
  reference_type: Optional[str] = Field(
8400
- default=None, description="""The type of the reference image."""
8421
+ default=None,
8422
+ description="""The type of the reference image. Only set by the SDK.""",
8401
8423
  )
8402
8424
  config: Optional[StyleReferenceConfig] = Field(
8403
8425
  default=None,
@@ -8408,18 +8430,15 @@ class StyleReferenceImage(_common.BaseModel):
8408
8430
  default=None, description=""""""
8409
8431
  )
8410
8432
 
8411
- def __init__(
8412
- self,
8413
- reference_image: Optional[Image] = None,
8414
- reference_id: Optional[int] = None,
8415
- config: Optional['StyleReferenceConfig'] = None,
8416
- ):
8417
- super().__init__(
8418
- reference_image=reference_image,
8419
- reference_id=reference_id,
8420
- reference_type='REFERENCE_TYPE_STYLE',
8421
- )
8422
- self.style_image_config = config
8433
+ @pydantic.model_validator(mode='before')
8434
+ @classmethod
8435
+ def _validate_mask_image_config(self, values):
8436
+ config = values.get('config', None)
8437
+ values['style_image_config'] = config
8438
+ if 'reference_type' in values:
8439
+ raise ValueError('Cannot set internal reference_type field directly.')
8440
+ values['reference_type'] = 'REFERENCE_TYPE_STYLE'
8441
+ return values
8423
8442
 
8424
8443
 
8425
8444
  class StyleReferenceImageDict(TypedDict, total=False):
@@ -8439,7 +8458,7 @@ class StyleReferenceImageDict(TypedDict, total=False):
8439
8458
  """The id of the reference image."""
8440
8459
 
8441
8460
  reference_type: Optional[str]
8442
- """The type of the reference image."""
8461
+ """The type of the reference image. Only set by the SDK."""
8443
8462
 
8444
8463
  config: Optional[StyleReferenceConfigDict]
8445
8464
  """Configuration for the style reference image."""
@@ -8466,7 +8485,8 @@ class SubjectReferenceImage(_common.BaseModel):
8466
8485
  default=None, description="""The id of the reference image."""
8467
8486
  )
8468
8487
  reference_type: Optional[str] = Field(
8469
- default=None, description="""The type of the reference image."""
8488
+ default=None,
8489
+ description="""The type of the reference image. Only set by the SDK.""",
8470
8490
  )
8471
8491
  config: Optional[SubjectReferenceConfig] = Field(
8472
8492
  default=None,
@@ -8477,18 +8497,15 @@ class SubjectReferenceImage(_common.BaseModel):
8477
8497
  default=None, description=""""""
8478
8498
  )
8479
8499
 
8480
- def __init__(
8481
- self,
8482
- reference_image: Optional[Image] = None,
8483
- reference_id: Optional[int] = None,
8484
- config: Optional['SubjectReferenceConfig'] = None,
8485
- ):
8486
- super().__init__(
8487
- reference_image=reference_image,
8488
- reference_id=reference_id,
8489
- reference_type='REFERENCE_TYPE_SUBJECT',
8490
- )
8491
- self.subject_image_config = config
8500
+ @pydantic.model_validator(mode='before')
8501
+ @classmethod
8502
+ def _validate_mask_image_config(self, values):
8503
+ config = values.get('config', None)
8504
+ values['subject_image_config'] = config
8505
+ if 'reference_type' in values:
8506
+ raise ValueError('Cannot set internal reference_type field directly.')
8507
+ values['reference_type'] = 'REFERENCE_TYPE_SUBJECT'
8508
+ return values
8492
8509
 
8493
8510
 
8494
8511
  class SubjectReferenceImageDict(TypedDict, total=False):
@@ -8508,7 +8525,7 @@ class SubjectReferenceImageDict(TypedDict, total=False):
8508
8525
  """The id of the reference image."""
8509
8526
 
8510
8527
  reference_type: Optional[str]
8511
- """The type of the reference image."""
8528
+ """The type of the reference image. Only set by the SDK."""
8512
8529
 
8513
8530
  config: Optional[SubjectReferenceConfigDict]
8514
8531
  """Configuration for the subject reference image."""
@@ -8729,7 +8746,7 @@ The following fields are supported:
8729
8746
  Note: only text should be used in parts and content in each part will be
8730
8747
  in a separate paragraph.""",
8731
8748
  )
8732
- tools: Optional[list[Tool]] = Field(
8749
+ tools: Optional[ToolListUnion] = Field(
8733
8750
  default=None,
8734
8751
  description=""" A list of `Tools` the model may use to generate the next response.
8735
8752
 
@@ -8766,7 +8783,7 @@ The following fields are supported:
8766
8783
  Note: only text should be used in parts and content in each part will be
8767
8784
  in a separate paragraph."""
8768
8785
 
8769
- tools: Optional[list[ToolDict]]
8786
+ tools: Optional[ToolListUnionDict]
8770
8787
  """ A list of `Tools` the model may use to generate the next response.
8771
8788
 
8772
8789
  A `Tool` is a piece of code that enables the system to interact with
@@ -8978,7 +8995,7 @@ class LiveConnectConfig(_common.BaseModel):
8978
8995
  Note: only text should be used in parts and content in each part will be
8979
8996
  in a separate paragraph.""",
8980
8997
  )
8981
- tools: Optional[list[Tool]] = Field(
8998
+ tools: Optional[ToolListUnion] = Field(
8982
8999
  default=None,
8983
9000
  description="""A list of `Tools` the model may use to generate the next response.
8984
9001
 
@@ -9008,7 +9025,7 @@ class LiveConnectConfigDict(TypedDict, total=False):
9008
9025
  Note: only text should be used in parts and content in each part will be
9009
9026
  in a separate paragraph."""
9010
9027
 
9011
- tools: Optional[list[ToolDict]]
9028
+ tools: Optional[ToolListUnionDict]
9012
9029
  """A list of `Tools` the model may use to generate the next response.
9013
9030
 
9014
9031
  A `Tool` is a piece of code that enables the system to interact with