google-genai 1.5.0__py3-none-any.whl → 1.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/_api_client.py +196 -141
- google/genai/_automatic_function_calling_util.py +4 -14
- google/genai/_common.py +7 -5
- google/genai/_replay_api_client.py +6 -3
- google/genai/_transformers.py +61 -37
- google/genai/batches.py +4 -0
- google/genai/caches.py +20 -26
- google/genai/chats.py +137 -46
- google/genai/client.py +3 -2
- google/genai/errors.py +11 -19
- google/genai/files.py +9 -9
- google/genai/live.py +276 -93
- google/genai/models.py +245 -68
- google/genai/operations.py +30 -2
- google/genai/pagers.py +3 -5
- google/genai/tunings.py +31 -21
- google/genai/types.py +88 -33
- google/genai/version.py +1 -1
- {google_genai-1.5.0.dist-info → google_genai-1.7.0.dist-info}/METADATA +201 -31
- google_genai-1.7.0.dist-info/RECORD +27 -0
- {google_genai-1.5.0.dist-info → google_genai-1.7.0.dist-info}/WHEEL +1 -1
- google_genai-1.5.0.dist-info/RECORD +0 -27
- {google_genai-1.5.0.dist-info → google_genai-1.7.0.dist-info}/LICENSE +0 -0
- {google_genai-1.5.0.dist-info → google_genai-1.7.0.dist-info}/top_level.txt +0 -0
google/genai/tunings.py
CHANGED
@@ -332,7 +332,7 @@ def _CreateTuningJobConfig_to_vertex(
|
|
332
332
|
|
333
333
|
if getv(from_object, ['learning_rate_multiplier']) is not None:
|
334
334
|
setv(
|
335
|
-
|
335
|
+
parent_object,
|
336
336
|
['supervisedTuningSpec', 'hyperParameters', 'learningRateMultiplier'],
|
337
337
|
getv(from_object, ['learning_rate_multiplier']),
|
338
338
|
)
|
@@ -781,13 +781,13 @@ class Tunings(_api_module.BaseModule):
|
|
781
781
|
def _list(
|
782
782
|
self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None
|
783
783
|
) -> types.ListTuningJobsResponse:
|
784
|
-
"""Lists
|
784
|
+
"""Lists `TuningJob` objects.
|
785
785
|
|
786
786
|
Args:
|
787
787
|
config: The configuration for the list request.
|
788
788
|
|
789
789
|
Returns:
|
790
|
-
A list of
|
790
|
+
A list of `TuningJob` objects.
|
791
791
|
"""
|
792
792
|
|
793
793
|
parameter_model = types._ListTuningJobsParameters(
|
@@ -855,7 +855,7 @@ class Tunings(_api_module.BaseModule):
|
|
855
855
|
training_dataset: types.TuningDatasetOrDict,
|
856
856
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
857
857
|
) -> types.TuningJob:
|
858
|
-
"""Creates a supervised fine-tuning job.
|
858
|
+
"""Creates a supervised fine-tuning job and returns the TuningJob object.
|
859
859
|
|
860
860
|
Args:
|
861
861
|
base_model: The name of the model to tune.
|
@@ -922,7 +922,7 @@ class Tunings(_api_module.BaseModule):
|
|
922
922
|
training_dataset: types.TuningDatasetOrDict,
|
923
923
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
924
924
|
) -> types.Operation:
|
925
|
-
"""Creates a supervised fine-tuning job.
|
925
|
+
"""Creates a supervised fine-tuning job and returns the TuningJob object.
|
926
926
|
|
927
927
|
Args:
|
928
928
|
base_model: The name of the model to tune.
|
@@ -999,7 +999,11 @@ class Tunings(_api_module.BaseModule):
|
|
999
999
|
config: Optional[types.GetTuningJobConfigOrDict] = None,
|
1000
1000
|
) -> types.TuningJob:
|
1001
1001
|
job = self._get(name=name, config=config)
|
1002
|
-
if
|
1002
|
+
if (
|
1003
|
+
job.experiment
|
1004
|
+
and self._api_client.vertexai
|
1005
|
+
and self._api_client.project is not None
|
1006
|
+
):
|
1003
1007
|
_IpythonUtils.display_experiment_button(
|
1004
1008
|
experiment=job.experiment,
|
1005
1009
|
project=self._api_client.project,
|
@@ -1029,11 +1033,12 @@ class Tunings(_api_module.BaseModule):
|
|
1029
1033
|
training_dataset=training_dataset,
|
1030
1034
|
config=config,
|
1031
1035
|
)
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1036
|
+
if operation.metadata is not None and 'tunedModel' in operation.metadata:
|
1037
|
+
tuned_model_name = operation.metadata['tunedModel']
|
1038
|
+
else:
|
1039
|
+
if operation.name is None:
|
1040
|
+
raise ValueError('Operation name is required.')
|
1041
|
+
tuned_model_name = operation.name.partition('/operations/')[0]
|
1037
1042
|
tuning_job = types.TuningJob(
|
1038
1043
|
name=tuned_model_name,
|
1039
1044
|
state=types.JobState.JOB_STATE_QUEUED,
|
@@ -1120,13 +1125,13 @@ class AsyncTunings(_api_module.BaseModule):
|
|
1120
1125
|
async def _list(
|
1121
1126
|
self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None
|
1122
1127
|
) -> types.ListTuningJobsResponse:
|
1123
|
-
"""Lists
|
1128
|
+
"""Lists `TuningJob` objects.
|
1124
1129
|
|
1125
1130
|
Args:
|
1126
1131
|
config: The configuration for the list request.
|
1127
1132
|
|
1128
1133
|
Returns:
|
1129
|
-
A list of
|
1134
|
+
A list of `TuningJob` objects.
|
1130
1135
|
"""
|
1131
1136
|
|
1132
1137
|
parameter_model = types._ListTuningJobsParameters(
|
@@ -1194,7 +1199,7 @@ class AsyncTunings(_api_module.BaseModule):
|
|
1194
1199
|
training_dataset: types.TuningDatasetOrDict,
|
1195
1200
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
1196
1201
|
) -> types.TuningJob:
|
1197
|
-
"""Creates a supervised fine-tuning job.
|
1202
|
+
"""Creates a supervised fine-tuning job and returns the TuningJob object.
|
1198
1203
|
|
1199
1204
|
Args:
|
1200
1205
|
base_model: The name of the model to tune.
|
@@ -1261,7 +1266,7 @@ class AsyncTunings(_api_module.BaseModule):
|
|
1261
1266
|
training_dataset: types.TuningDatasetOrDict,
|
1262
1267
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
1263
1268
|
) -> types.Operation:
|
1264
|
-
"""Creates a supervised fine-tuning job.
|
1269
|
+
"""Creates a supervised fine-tuning job and returns the TuningJob object.
|
1265
1270
|
|
1266
1271
|
Args:
|
1267
1272
|
base_model: The name of the model to tune.
|
@@ -1338,7 +1343,11 @@ class AsyncTunings(_api_module.BaseModule):
|
|
1338
1343
|
config: Optional[types.GetTuningJobConfigOrDict] = None,
|
1339
1344
|
) -> types.TuningJob:
|
1340
1345
|
job = await self._get(name=name, config=config)
|
1341
|
-
if
|
1346
|
+
if (
|
1347
|
+
job.experiment
|
1348
|
+
and self._api_client.vertexai
|
1349
|
+
and self._api_client.project is not None
|
1350
|
+
):
|
1342
1351
|
_IpythonUtils.display_experiment_button(
|
1343
1352
|
experiment=job.experiment,
|
1344
1353
|
project=self._api_client.project,
|
@@ -1368,11 +1377,12 @@ class AsyncTunings(_api_module.BaseModule):
|
|
1368
1377
|
training_dataset=training_dataset,
|
1369
1378
|
config=config,
|
1370
1379
|
)
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1380
|
+
if operation.metadata is not None and 'tunedModel' in operation.metadata:
|
1381
|
+
tuned_model_name = operation.metadata['tunedModel']
|
1382
|
+
else:
|
1383
|
+
if operation.name is None:
|
1384
|
+
raise ValueError('Operation name is required.')
|
1385
|
+
tuned_model_name = operation.name.partition('/operations/')[0]
|
1376
1386
|
tuning_job = types.TuningJob(
|
1377
1387
|
name=tuned_model_name,
|
1378
1388
|
state=types.JobState.JOB_STATE_QUEUED,
|
google/genai/types.py
CHANGED
@@ -719,7 +719,9 @@ class UserContent(Content):
|
|
719
719
|
role: Literal['user'] = Field(default='user', init=False, frozen=True)
|
720
720
|
parts: list[Part] = Field()
|
721
721
|
|
722
|
-
def __init__(
|
722
|
+
def __init__(
|
723
|
+
self, parts: Union['PartUnionDict', list['PartUnionDict'], list['Part']]
|
724
|
+
):
|
723
725
|
from . import _transformers as t
|
724
726
|
|
725
727
|
super().__init__(parts=t.t_parts(parts=parts))
|
@@ -747,7 +749,9 @@ class ModelContent(Content):
|
|
747
749
|
role: Literal['model'] = Field(default='model', init=False, frozen=True)
|
748
750
|
parts: list[Part] = Field()
|
749
751
|
|
750
|
-
def __init__(
|
752
|
+
def __init__(
|
753
|
+
self, parts: Union['PartUnionDict', list['PartUnionDict'], list['Part']]
|
754
|
+
):
|
751
755
|
from . import _transformers as t
|
752
756
|
|
753
757
|
super().__init__(parts=t.t_parts(parts=parts))
|
@@ -821,17 +825,9 @@ class Schema(_common.BaseModel):
|
|
821
825
|
default=None,
|
822
826
|
description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
|
823
827
|
)
|
824
|
-
minimum: Optional[float] = Field(
|
825
|
-
default=None,
|
826
|
-
description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
|
827
|
-
)
|
828
828
|
default: Optional[Any] = Field(
|
829
829
|
default=None, description="""Optional. Default value of the data."""
|
830
830
|
)
|
831
|
-
any_of: Optional[list['Schema']] = Field(
|
832
|
-
default=None,
|
833
|
-
description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
|
834
|
-
)
|
835
831
|
max_length: Optional[int] = Field(
|
836
832
|
default=None,
|
837
833
|
description="""Optional. Maximum length of the Type.STRING""",
|
@@ -847,14 +843,14 @@ class Schema(_common.BaseModel):
|
|
847
843
|
default=None,
|
848
844
|
description="""Optional. Minimum number of the properties for Type.OBJECT.""",
|
849
845
|
)
|
850
|
-
maximum: Optional[float] = Field(
|
851
|
-
default=None,
|
852
|
-
description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
|
853
|
-
)
|
854
846
|
max_properties: Optional[int] = Field(
|
855
847
|
default=None,
|
856
848
|
description="""Optional. Maximum number of the properties for Type.OBJECT.""",
|
857
849
|
)
|
850
|
+
any_of: Optional[list['Schema']] = Field(
|
851
|
+
default=None,
|
852
|
+
description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
|
853
|
+
)
|
858
854
|
description: Optional[str] = Field(
|
859
855
|
default=None, description="""Optional. The description of the data."""
|
860
856
|
)
|
@@ -874,10 +870,18 @@ class Schema(_common.BaseModel):
|
|
874
870
|
default=None,
|
875
871
|
description="""Optional. Maximum number of the elements for Type.ARRAY.""",
|
876
872
|
)
|
873
|
+
maximum: Optional[float] = Field(
|
874
|
+
default=None,
|
875
|
+
description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
|
876
|
+
)
|
877
877
|
min_items: Optional[int] = Field(
|
878
878
|
default=None,
|
879
879
|
description="""Optional. Minimum number of the elements for Type.ARRAY.""",
|
880
880
|
)
|
881
|
+
minimum: Optional[float] = Field(
|
882
|
+
default=None,
|
883
|
+
description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
|
884
|
+
)
|
881
885
|
nullable: Optional[bool] = Field(
|
882
886
|
default=None,
|
883
887
|
description="""Optional. Indicates if the value may be null.""",
|
@@ -911,15 +915,9 @@ class SchemaDict(TypedDict, total=False):
|
|
911
915
|
pattern: Optional[str]
|
912
916
|
"""Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
|
913
917
|
|
914
|
-
minimum: Optional[float]
|
915
|
-
"""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
|
916
|
-
|
917
918
|
default: Optional[Any]
|
918
919
|
"""Optional. Default value of the data."""
|
919
920
|
|
920
|
-
any_of: Optional[list['SchemaDict']]
|
921
|
-
"""Optional. The value should be validated against any (one or more) of the subschemas in the list."""
|
922
|
-
|
923
921
|
max_length: Optional[int]
|
924
922
|
"""Optional. Maximum length of the Type.STRING"""
|
925
923
|
|
@@ -932,12 +930,12 @@ class SchemaDict(TypedDict, total=False):
|
|
932
930
|
min_properties: Optional[int]
|
933
931
|
"""Optional. Minimum number of the properties for Type.OBJECT."""
|
934
932
|
|
935
|
-
maximum: Optional[float]
|
936
|
-
"""Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
|
937
|
-
|
938
933
|
max_properties: Optional[int]
|
939
934
|
"""Optional. Maximum number of the properties for Type.OBJECT."""
|
940
935
|
|
936
|
+
any_of: Optional[list['SchemaDict']]
|
937
|
+
"""Optional. The value should be validated against any (one or more) of the subschemas in the list."""
|
938
|
+
|
941
939
|
description: Optional[str]
|
942
940
|
"""Optional. The description of the data."""
|
943
941
|
|
@@ -953,9 +951,15 @@ class SchemaDict(TypedDict, total=False):
|
|
953
951
|
max_items: Optional[int]
|
954
952
|
"""Optional. Maximum number of the elements for Type.ARRAY."""
|
955
953
|
|
954
|
+
maximum: Optional[float]
|
955
|
+
"""Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
|
956
|
+
|
956
957
|
min_items: Optional[int]
|
957
958
|
"""Optional. Minimum number of the elements for Type.ARRAY."""
|
958
959
|
|
960
|
+
minimum: Optional[float]
|
961
|
+
"""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
|
962
|
+
|
959
963
|
nullable: Optional[bool]
|
960
964
|
"""Optional. Indicates if the value may be null."""
|
961
965
|
|
@@ -1074,12 +1078,11 @@ class FunctionDeclaration(_common.BaseModel):
|
|
1074
1078
|
type='OBJECT',
|
1075
1079
|
properties=parameters_properties,
|
1076
1080
|
)
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
)
|
1081
|
+
declaration.parameters.required = (
|
1082
|
+
_automatic_function_calling_util._get_required_fields(
|
1083
|
+
declaration.parameters
|
1084
|
+
)
|
1085
|
+
)
|
1083
1086
|
if api_option == 'GEMINI_API':
|
1084
1087
|
return declaration
|
1085
1088
|
|
@@ -1663,7 +1666,7 @@ class File(_common.BaseModel):
|
|
1663
1666
|
)
|
1664
1667
|
sha256_hash: Optional[str] = Field(
|
1665
1668
|
default=None,
|
1666
|
-
description="""Output only. SHA-256 hash of the uploaded bytes.""",
|
1669
|
+
description="""Output only. SHA-256 hash of the uploaded bytes. The hash value is encoded in base64 format.""",
|
1667
1670
|
)
|
1668
1671
|
uri: Optional[str] = Field(
|
1669
1672
|
default=None, description="""Output only. The URI of the `File`."""
|
@@ -1712,7 +1715,7 @@ class FileDict(TypedDict, total=False):
|
|
1712
1715
|
"""Output only. The timestamp of when the `File` was last updated."""
|
1713
1716
|
|
1714
1717
|
sha256_hash: Optional[str]
|
1715
|
-
"""Output only. SHA-256 hash of the uploaded bytes."""
|
1718
|
+
"""Output only. SHA-256 hash of the uploaded bytes. The hash value is encoded in base64 format."""
|
1716
1719
|
|
1717
1720
|
uri: Optional[str]
|
1718
1721
|
"""Output only. The URI of the `File`."""
|
@@ -3745,6 +3748,36 @@ class ImageDict(TypedDict, total=False):
|
|
3745
3748
|
ImageOrDict = Union[Image, ImageDict]
|
3746
3749
|
|
3747
3750
|
|
3751
|
+
class SafetyAttributes(_common.BaseModel):
|
3752
|
+
"""Safety attributes of a GeneratedImage or the user-provided prompt."""
|
3753
|
+
|
3754
|
+
categories: Optional[list[str]] = Field(
|
3755
|
+
default=None,
|
3756
|
+
description="""List of RAI categories.
|
3757
|
+
""",
|
3758
|
+
)
|
3759
|
+
scores: Optional[list[float]] = Field(
|
3760
|
+
default=None,
|
3761
|
+
description="""List of scores of each categories.
|
3762
|
+
""",
|
3763
|
+
)
|
3764
|
+
|
3765
|
+
|
3766
|
+
class SafetyAttributesDict(TypedDict, total=False):
|
3767
|
+
"""Safety attributes of a GeneratedImage or the user-provided prompt."""
|
3768
|
+
|
3769
|
+
categories: Optional[list[str]]
|
3770
|
+
"""List of RAI categories.
|
3771
|
+
"""
|
3772
|
+
|
3773
|
+
scores: Optional[list[float]]
|
3774
|
+
"""List of scores of each categories.
|
3775
|
+
"""
|
3776
|
+
|
3777
|
+
|
3778
|
+
SafetyAttributesOrDict = Union[SafetyAttributes, SafetyAttributesDict]
|
3779
|
+
|
3780
|
+
|
3748
3781
|
class GeneratedImage(_common.BaseModel):
|
3749
3782
|
"""An output image."""
|
3750
3783
|
|
@@ -3759,6 +3792,12 @@ class GeneratedImage(_common.BaseModel):
|
|
3759
3792
|
response.
|
3760
3793
|
""",
|
3761
3794
|
)
|
3795
|
+
safety_attributes: Optional[SafetyAttributes] = Field(
|
3796
|
+
default=None,
|
3797
|
+
description="""Safety attributes of the image. Lists of RAI categories and their
|
3798
|
+
scores of each content.
|
3799
|
+
""",
|
3800
|
+
)
|
3762
3801
|
enhanced_prompt: Optional[str] = Field(
|
3763
3802
|
default=None,
|
3764
3803
|
description="""The rewritten prompt used for the image generation if the prompt
|
@@ -3779,6 +3818,11 @@ class GeneratedImageDict(TypedDict, total=False):
|
|
3779
3818
|
response.
|
3780
3819
|
"""
|
3781
3820
|
|
3821
|
+
safety_attributes: Optional[SafetyAttributesDict]
|
3822
|
+
"""Safety attributes of the image. Lists of RAI categories and their
|
3823
|
+
scores of each content.
|
3824
|
+
"""
|
3825
|
+
|
3782
3826
|
enhanced_prompt: Optional[str]
|
3783
3827
|
"""The rewritten prompt used for the image generation if the prompt
|
3784
3828
|
enhancer is enabled.
|
@@ -4070,6 +4114,11 @@ class EditImageConfig(_common.BaseModel):
|
|
4070
4114
|
default=None,
|
4071
4115
|
description="""Describes the editing mode for the request.""",
|
4072
4116
|
)
|
4117
|
+
base_steps: Optional[int] = Field(
|
4118
|
+
default=None,
|
4119
|
+
description="""The number of sampling steps. A higher value has better image
|
4120
|
+
quality, while a lower value has better latency.""",
|
4121
|
+
)
|
4073
4122
|
|
4074
4123
|
|
4075
4124
|
class EditImageConfigDict(TypedDict, total=False):
|
@@ -4138,6 +4187,10 @@ class EditImageConfigDict(TypedDict, total=False):
|
|
4138
4187
|
edit_mode: Optional[EditMode]
|
4139
4188
|
"""Describes the editing mode for the request."""
|
4140
4189
|
|
4190
|
+
base_steps: Optional[int]
|
4191
|
+
"""The number of sampling steps. A higher value has better image
|
4192
|
+
quality, while a lower value has better latency."""
|
4193
|
+
|
4141
4194
|
|
4142
4195
|
EditImageConfigOrDict = Union[EditImageConfig, EditImageConfigDict]
|
4143
4196
|
|
@@ -5178,8 +5231,10 @@ class Video(_common.BaseModel):
|
|
5178
5231
|
IPython_display = None
|
5179
5232
|
|
5180
5233
|
if IPython_display:
|
5181
|
-
|
5182
|
-
|
5234
|
+
IPython_display.display(
|
5235
|
+
IPython_display.Video(
|
5236
|
+
data=self.video_bytes, mimetype=mime_type, embed=True
|
5237
|
+
)
|
5183
5238
|
)
|
5184
5239
|
|
5185
5240
|
def __repr__(self):
|
google/genai/version.py
CHANGED