google-genai 1.1.0__py3-none-any.whl → 1.3.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 +152 -48
- google/genai/_api_module.py +5 -0
- google/genai/_common.py +12 -0
- google/genai/_extra_utils.py +7 -2
- google/genai/_replay_api_client.py +32 -1
- google/genai/_transformers.py +40 -10
- google/genai/batches.py +6 -3
- google/genai/caches.py +13 -10
- google/genai/client.py +22 -11
- google/genai/errors.py +18 -3
- google/genai/files.py +8 -5
- google/genai/live.py +64 -41
- google/genai/models.py +661 -87
- google/genai/{_operations.py → operations.py} +260 -20
- google/genai/tunings.py +3 -0
- google/genai/types.py +439 -7
- google/genai/version.py +1 -1
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/METADATA +126 -15
- google_genai-1.3.0.dist-info/RECORD +27 -0
- google_genai-1.1.0.dist-info/RECORD +0 -27
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/LICENSE +0 -0
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/WHEEL +0 -0
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/top_level.txt +0 -0
google/genai/models.py
CHANGED
@@ -28,6 +28,8 @@ from ._common import get_value_by_path as getv
|
|
28
28
|
from ._common import set_value_by_path as setv
|
29
29
|
from .pagers import AsyncPager, Pager
|
30
30
|
|
31
|
+
logger = logging.getLogger('google_genai.models')
|
32
|
+
|
31
33
|
|
32
34
|
def _Part_to_mldev(
|
33
35
|
api_client: ApiClient,
|
@@ -174,8 +176,10 @@ def _Schema_to_mldev(
|
|
174
176
|
raise ValueError('example parameter is not supported in Gemini API.')
|
175
177
|
|
176
178
|
if getv(from_object, ['property_ordering']) is not None:
|
177
|
-
|
178
|
-
|
179
|
+
setv(
|
180
|
+
to_object,
|
181
|
+
['propertyOrdering'],
|
182
|
+
getv(from_object, ['property_ordering']),
|
179
183
|
)
|
180
184
|
|
181
185
|
if getv(from_object, ['pattern']) is not None:
|
@@ -924,8 +928,8 @@ def _GenerateContentConfig_to_mldev(
|
|
924
928
|
)
|
925
929
|
|
926
930
|
if getv(from_object, ['media_resolution']) is not None:
|
927
|
-
|
928
|
-
'
|
931
|
+
setv(
|
932
|
+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
|
929
933
|
)
|
930
934
|
|
931
935
|
if getv(from_object, ['speech_config']) is not None:
|
@@ -2787,14 +2791,200 @@ def _ComputeTokensParameters_to_vertex(
|
|
2787
2791
|
return to_object
|
2788
2792
|
|
2789
2793
|
|
2790
|
-
def
|
2791
|
-
|
2792
|
-
|
2793
|
-
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2794
|
+
def _GenerateVideosConfig_to_mldev(
|
2795
|
+
api_client: ApiClient,
|
2796
|
+
from_object: Union[dict, object],
|
2797
|
+
parent_object: dict = None,
|
2798
|
+
) -> dict:
|
2799
|
+
to_object = {}
|
2800
|
+
|
2801
|
+
if getv(from_object, ['number_of_videos']) is not None:
|
2802
|
+
setv(
|
2803
|
+
parent_object,
|
2804
|
+
['parameters', 'sampleCount'],
|
2805
|
+
getv(from_object, ['number_of_videos']),
|
2806
|
+
)
|
2807
|
+
|
2808
|
+
if getv(from_object, ['output_gcs_uri']) is not None:
|
2809
|
+
raise ValueError('output_gcs_uri parameter is not supported in Gemini API.')
|
2810
|
+
|
2811
|
+
if getv(from_object, ['fps']) is not None:
|
2812
|
+
raise ValueError('fps parameter is not supported in Gemini API.')
|
2813
|
+
|
2814
|
+
if getv(from_object, ['duration_seconds']) is not None:
|
2815
|
+
raise ValueError(
|
2816
|
+
'duration_seconds parameter is not supported in Gemini API.'
|
2817
|
+
)
|
2818
|
+
|
2819
|
+
if getv(from_object, ['seed']) is not None:
|
2820
|
+
raise ValueError('seed parameter is not supported in Gemini API.')
|
2821
|
+
|
2822
|
+
if getv(from_object, ['aspect_ratio']) is not None:
|
2823
|
+
setv(
|
2824
|
+
parent_object,
|
2825
|
+
['parameters', 'aspectRatio'],
|
2826
|
+
getv(from_object, ['aspect_ratio']),
|
2827
|
+
)
|
2828
|
+
|
2829
|
+
if getv(from_object, ['resolution']) is not None:
|
2830
|
+
raise ValueError('resolution parameter is not supported in Gemini API.')
|
2831
|
+
|
2832
|
+
if getv(from_object, ['person_generation']) is not None:
|
2833
|
+
setv(
|
2834
|
+
parent_object,
|
2835
|
+
['parameters', 'personGeneration'],
|
2836
|
+
getv(from_object, ['person_generation']),
|
2837
|
+
)
|
2838
|
+
|
2839
|
+
if getv(from_object, ['pubsub_topic']) is not None:
|
2840
|
+
raise ValueError('pubsub_topic parameter is not supported in Gemini API.')
|
2841
|
+
|
2842
|
+
if getv(from_object, ['negative_prompt']) is not None:
|
2843
|
+
setv(
|
2844
|
+
parent_object,
|
2845
|
+
['parameters', 'negativePrompt'],
|
2846
|
+
getv(from_object, ['negative_prompt']),
|
2847
|
+
)
|
2848
|
+
|
2849
|
+
if getv(from_object, ['enhance_prompt']) is not None:
|
2850
|
+
raise ValueError('enhance_prompt parameter is not supported in Gemini API.')
|
2851
|
+
|
2852
|
+
return to_object
|
2853
|
+
|
2854
|
+
|
2855
|
+
def _GenerateVideosConfig_to_vertex(
|
2856
|
+
api_client: ApiClient,
|
2857
|
+
from_object: Union[dict, object],
|
2858
|
+
parent_object: dict = None,
|
2859
|
+
) -> dict:
|
2860
|
+
to_object = {}
|
2861
|
+
|
2862
|
+
if getv(from_object, ['number_of_videos']) is not None:
|
2863
|
+
setv(
|
2864
|
+
parent_object,
|
2865
|
+
['parameters', 'sampleCount'],
|
2866
|
+
getv(from_object, ['number_of_videos']),
|
2867
|
+
)
|
2868
|
+
|
2869
|
+
if getv(from_object, ['output_gcs_uri']) is not None:
|
2870
|
+
setv(
|
2871
|
+
parent_object,
|
2872
|
+
['parameters', 'storageUri'],
|
2873
|
+
getv(from_object, ['output_gcs_uri']),
|
2874
|
+
)
|
2875
|
+
|
2876
|
+
if getv(from_object, ['fps']) is not None:
|
2877
|
+
setv(parent_object, ['parameters', 'fps'], getv(from_object, ['fps']))
|
2878
|
+
|
2879
|
+
if getv(from_object, ['duration_seconds']) is not None:
|
2880
|
+
setv(
|
2881
|
+
parent_object,
|
2882
|
+
['parameters', 'durationSeconds'],
|
2883
|
+
getv(from_object, ['duration_seconds']),
|
2884
|
+
)
|
2885
|
+
|
2886
|
+
if getv(from_object, ['seed']) is not None:
|
2887
|
+
setv(parent_object, ['parameters', 'seed'], getv(from_object, ['seed']))
|
2888
|
+
|
2889
|
+
if getv(from_object, ['aspect_ratio']) is not None:
|
2890
|
+
setv(
|
2891
|
+
parent_object,
|
2892
|
+
['parameters', 'aspectRatio'],
|
2893
|
+
getv(from_object, ['aspect_ratio']),
|
2894
|
+
)
|
2895
|
+
|
2896
|
+
if getv(from_object, ['resolution']) is not None:
|
2897
|
+
setv(
|
2898
|
+
parent_object,
|
2899
|
+
['parameters', 'resolution'],
|
2900
|
+
getv(from_object, ['resolution']),
|
2901
|
+
)
|
2902
|
+
|
2903
|
+
if getv(from_object, ['person_generation']) is not None:
|
2904
|
+
setv(
|
2905
|
+
parent_object,
|
2906
|
+
['parameters', 'personGeneration'],
|
2907
|
+
getv(from_object, ['person_generation']),
|
2908
|
+
)
|
2909
|
+
|
2910
|
+
if getv(from_object, ['pubsub_topic']) is not None:
|
2911
|
+
setv(
|
2912
|
+
parent_object,
|
2913
|
+
['parameters', 'pubsubTopic'],
|
2914
|
+
getv(from_object, ['pubsub_topic']),
|
2915
|
+
)
|
2916
|
+
|
2917
|
+
if getv(from_object, ['negative_prompt']) is not None:
|
2918
|
+
setv(
|
2919
|
+
parent_object,
|
2920
|
+
['parameters', 'negativePrompt'],
|
2921
|
+
getv(from_object, ['negative_prompt']),
|
2922
|
+
)
|
2923
|
+
|
2924
|
+
if getv(from_object, ['enhance_prompt']) is not None:
|
2925
|
+
setv(
|
2926
|
+
parent_object,
|
2927
|
+
['parameters', 'enhancePrompt'],
|
2928
|
+
getv(from_object, ['enhance_prompt']),
|
2929
|
+
)
|
2930
|
+
|
2931
|
+
return to_object
|
2932
|
+
|
2933
|
+
|
2934
|
+
def _GenerateVideosParameters_to_mldev(
|
2935
|
+
api_client: ApiClient,
|
2936
|
+
from_object: Union[dict, object],
|
2937
|
+
parent_object: dict = None,
|
2938
|
+
) -> dict:
|
2939
|
+
to_object = {}
|
2940
|
+
if getv(from_object, ['model']) is not None:
|
2941
|
+
setv(
|
2942
|
+
to_object,
|
2943
|
+
['_url', 'model'],
|
2944
|
+
t.t_model(api_client, getv(from_object, ['model'])),
|
2945
|
+
)
|
2946
|
+
|
2947
|
+
if getv(from_object, ['prompt']) is not None:
|
2948
|
+
setv(to_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt']))
|
2949
|
+
|
2950
|
+
if getv(from_object, ['config']) is not None:
|
2951
|
+
setv(
|
2952
|
+
to_object,
|
2953
|
+
['config'],
|
2954
|
+
_GenerateVideosConfig_to_mldev(
|
2955
|
+
api_client, getv(from_object, ['config']), to_object
|
2956
|
+
),
|
2957
|
+
)
|
2958
|
+
|
2959
|
+
return to_object
|
2960
|
+
|
2961
|
+
|
2962
|
+
def _GenerateVideosParameters_to_vertex(
|
2963
|
+
api_client: ApiClient,
|
2964
|
+
from_object: Union[dict, object],
|
2965
|
+
parent_object: dict = None,
|
2966
|
+
) -> dict:
|
2967
|
+
to_object = {}
|
2968
|
+
if getv(from_object, ['model']) is not None:
|
2969
|
+
setv(
|
2970
|
+
to_object,
|
2971
|
+
['_url', 'model'],
|
2972
|
+
t.t_model(api_client, getv(from_object, ['model'])),
|
2973
|
+
)
|
2974
|
+
|
2975
|
+
if getv(from_object, ['prompt']) is not None:
|
2976
|
+
setv(to_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt']))
|
2977
|
+
|
2978
|
+
if getv(from_object, ['config']) is not None:
|
2979
|
+
setv(
|
2980
|
+
to_object,
|
2981
|
+
['config'],
|
2982
|
+
_GenerateVideosConfig_to_vertex(
|
2983
|
+
api_client, getv(from_object, ['config']), to_object
|
2984
|
+
),
|
2985
|
+
)
|
2986
|
+
|
2987
|
+
return to_object
|
2798
2988
|
|
2799
2989
|
|
2800
2990
|
def _SafetyFilterLevel_to_mldev_enum_validate(enum_value: Any):
|
@@ -3796,6 +3986,216 @@ def _ComputeTokensResponse_from_vertex(
|
|
3796
3986
|
return to_object
|
3797
3987
|
|
3798
3988
|
|
3989
|
+
def _Video_from_mldev(
|
3990
|
+
api_client: ApiClient,
|
3991
|
+
from_object: Union[dict, object],
|
3992
|
+
parent_object: dict = None,
|
3993
|
+
) -> dict:
|
3994
|
+
to_object = {}
|
3995
|
+
if getv(from_object, ['uri']) is not None:
|
3996
|
+
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
3997
|
+
|
3998
|
+
if getv(from_object, ['encodedVideo']) is not None:
|
3999
|
+
setv(
|
4000
|
+
to_object,
|
4001
|
+
['video_bytes'],
|
4002
|
+
t.t_bytes(api_client, getv(from_object, ['encodedVideo'])),
|
4003
|
+
)
|
4004
|
+
|
4005
|
+
if getv(from_object, ['encoding']) is not None:
|
4006
|
+
setv(to_object, ['mime_type'], getv(from_object, ['encoding']))
|
4007
|
+
|
4008
|
+
return to_object
|
4009
|
+
|
4010
|
+
|
4011
|
+
def _Video_from_vertex(
|
4012
|
+
api_client: ApiClient,
|
4013
|
+
from_object: Union[dict, object],
|
4014
|
+
parent_object: dict = None,
|
4015
|
+
) -> dict:
|
4016
|
+
to_object = {}
|
4017
|
+
if getv(from_object, ['gcsUri']) is not None:
|
4018
|
+
setv(to_object, ['uri'], getv(from_object, ['gcsUri']))
|
4019
|
+
|
4020
|
+
if getv(from_object, ['bytesBase64Encoded']) is not None:
|
4021
|
+
setv(
|
4022
|
+
to_object,
|
4023
|
+
['video_bytes'],
|
4024
|
+
t.t_bytes(api_client, getv(from_object, ['bytesBase64Encoded'])),
|
4025
|
+
)
|
4026
|
+
|
4027
|
+
if getv(from_object, ['mimeType']) is not None:
|
4028
|
+
setv(to_object, ['mime_type'], getv(from_object, ['mimeType']))
|
4029
|
+
|
4030
|
+
return to_object
|
4031
|
+
|
4032
|
+
|
4033
|
+
def _GeneratedVideo_from_mldev(
|
4034
|
+
api_client: ApiClient,
|
4035
|
+
from_object: Union[dict, object],
|
4036
|
+
parent_object: dict = None,
|
4037
|
+
) -> dict:
|
4038
|
+
to_object = {}
|
4039
|
+
if getv(from_object, ['_self']) is not None:
|
4040
|
+
setv(
|
4041
|
+
to_object,
|
4042
|
+
['video'],
|
4043
|
+
_Video_from_mldev(api_client, getv(from_object, ['_self']), to_object),
|
4044
|
+
)
|
4045
|
+
|
4046
|
+
return to_object
|
4047
|
+
|
4048
|
+
|
4049
|
+
def _GeneratedVideo_from_vertex(
|
4050
|
+
api_client: ApiClient,
|
4051
|
+
from_object: Union[dict, object],
|
4052
|
+
parent_object: dict = None,
|
4053
|
+
) -> dict:
|
4054
|
+
to_object = {}
|
4055
|
+
if getv(from_object, ['_self']) is not None:
|
4056
|
+
setv(
|
4057
|
+
to_object,
|
4058
|
+
['video'],
|
4059
|
+
_Video_from_vertex(api_client, getv(from_object, ['_self']), to_object),
|
4060
|
+
)
|
4061
|
+
|
4062
|
+
return to_object
|
4063
|
+
|
4064
|
+
|
4065
|
+
def _GenerateVideosResponse_from_mldev(
|
4066
|
+
api_client: ApiClient,
|
4067
|
+
from_object: Union[dict, object],
|
4068
|
+
parent_object: dict = None,
|
4069
|
+
) -> dict:
|
4070
|
+
to_object = {}
|
4071
|
+
if getv(from_object, ['videos']) is not None:
|
4072
|
+
setv(
|
4073
|
+
to_object,
|
4074
|
+
['generated_videos'],
|
4075
|
+
[
|
4076
|
+
_GeneratedVideo_from_mldev(api_client, item, to_object)
|
4077
|
+
for item in getv(from_object, ['videos'])
|
4078
|
+
],
|
4079
|
+
)
|
4080
|
+
|
4081
|
+
if getv(from_object, ['raiMediaFilteredCount']) is not None:
|
4082
|
+
setv(
|
4083
|
+
to_object,
|
4084
|
+
['rai_media_filtered_count'],
|
4085
|
+
getv(from_object, ['raiMediaFilteredCount']),
|
4086
|
+
)
|
4087
|
+
|
4088
|
+
if getv(from_object, ['raiMediaFilteredReasons']) is not None:
|
4089
|
+
setv(
|
4090
|
+
to_object,
|
4091
|
+
['rai_media_filtered_reasons'],
|
4092
|
+
getv(from_object, ['raiMediaFilteredReasons']),
|
4093
|
+
)
|
4094
|
+
|
4095
|
+
return to_object
|
4096
|
+
|
4097
|
+
|
4098
|
+
def _GenerateVideosResponse_from_vertex(
|
4099
|
+
api_client: ApiClient,
|
4100
|
+
from_object: Union[dict, object],
|
4101
|
+
parent_object: dict = None,
|
4102
|
+
) -> dict:
|
4103
|
+
to_object = {}
|
4104
|
+
if getv(from_object, ['videos']) is not None:
|
4105
|
+
setv(
|
4106
|
+
to_object,
|
4107
|
+
['generated_videos'],
|
4108
|
+
[
|
4109
|
+
_GeneratedVideo_from_vertex(api_client, item, to_object)
|
4110
|
+
for item in getv(from_object, ['videos'])
|
4111
|
+
],
|
4112
|
+
)
|
4113
|
+
|
4114
|
+
if getv(from_object, ['raiMediaFilteredCount']) is not None:
|
4115
|
+
setv(
|
4116
|
+
to_object,
|
4117
|
+
['rai_media_filtered_count'],
|
4118
|
+
getv(from_object, ['raiMediaFilteredCount']),
|
4119
|
+
)
|
4120
|
+
|
4121
|
+
if getv(from_object, ['raiMediaFilteredReasons']) is not None:
|
4122
|
+
setv(
|
4123
|
+
to_object,
|
4124
|
+
['rai_media_filtered_reasons'],
|
4125
|
+
getv(from_object, ['raiMediaFilteredReasons']),
|
4126
|
+
)
|
4127
|
+
|
4128
|
+
return to_object
|
4129
|
+
|
4130
|
+
|
4131
|
+
def _GenerateVideosOperation_from_mldev(
|
4132
|
+
api_client: ApiClient,
|
4133
|
+
from_object: Union[dict, object],
|
4134
|
+
parent_object: dict = None,
|
4135
|
+
) -> dict:
|
4136
|
+
to_object = {}
|
4137
|
+
if getv(from_object, ['name']) is not None:
|
4138
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
4139
|
+
|
4140
|
+
if getv(from_object, ['metadata']) is not None:
|
4141
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
4142
|
+
|
4143
|
+
if getv(from_object, ['done']) is not None:
|
4144
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
4145
|
+
|
4146
|
+
if getv(from_object, ['error']) is not None:
|
4147
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
4148
|
+
|
4149
|
+
if getv(from_object, ['response']) is not None:
|
4150
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
4151
|
+
|
4152
|
+
if getv(from_object, ['response', 'generateVideoResponse']) is not None:
|
4153
|
+
setv(
|
4154
|
+
to_object,
|
4155
|
+
['result'],
|
4156
|
+
_GenerateVideosResponse_from_mldev(
|
4157
|
+
api_client,
|
4158
|
+
getv(from_object, ['response', 'generateVideoResponse']),
|
4159
|
+
to_object,
|
4160
|
+
),
|
4161
|
+
)
|
4162
|
+
|
4163
|
+
return to_object
|
4164
|
+
|
4165
|
+
|
4166
|
+
def _GenerateVideosOperation_from_vertex(
|
4167
|
+
api_client: ApiClient,
|
4168
|
+
from_object: Union[dict, object],
|
4169
|
+
parent_object: dict = None,
|
4170
|
+
) -> dict:
|
4171
|
+
to_object = {}
|
4172
|
+
if getv(from_object, ['name']) is not None:
|
4173
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
4174
|
+
|
4175
|
+
if getv(from_object, ['metadata']) is not None:
|
4176
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
4177
|
+
|
4178
|
+
if getv(from_object, ['done']) is not None:
|
4179
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
4180
|
+
|
4181
|
+
if getv(from_object, ['error']) is not None:
|
4182
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
4183
|
+
|
4184
|
+
if getv(from_object, ['response']) is not None:
|
4185
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
4186
|
+
|
4187
|
+
if getv(from_object, ['response']) is not None:
|
4188
|
+
setv(
|
4189
|
+
to_object,
|
4190
|
+
['result'],
|
4191
|
+
_GenerateVideosResponse_from_vertex(
|
4192
|
+
api_client, getv(from_object, ['response']), to_object
|
4193
|
+
),
|
4194
|
+
)
|
4195
|
+
|
4196
|
+
return to_object
|
4197
|
+
|
4198
|
+
|
3799
4199
|
class Models(_api_module.BaseModule):
|
3800
4200
|
|
3801
4201
|
def _generate_content(
|
@@ -3923,7 +4323,7 @@ class Models(_api_module.BaseModule):
|
|
3923
4323
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
3924
4324
|
config: Optional[types.EmbedContentConfigOrDict] = None,
|
3925
4325
|
) -> types.EmbedContentResponse:
|
3926
|
-
"""Calculates embeddings for the given contents
|
4326
|
+
"""Calculates embeddings for the given contents. Only text is supported.
|
3927
4327
|
|
3928
4328
|
Args:
|
3929
4329
|
model (str): The model to use.
|
@@ -4015,7 +4415,7 @@ class Models(_api_module.BaseModule):
|
|
4015
4415
|
.. code-block:: python
|
4016
4416
|
|
4017
4417
|
response = client.models.generate_images(
|
4018
|
-
model='imagen-3.0-generate-
|
4418
|
+
model='imagen-3.0-generate-002',
|
4019
4419
|
prompt='Man with a dog',
|
4020
4420
|
config=types.GenerateImagesConfig(
|
4021
4421
|
number_of_images= 1,
|
@@ -4455,10 +4855,11 @@ class Models(_api_module.BaseModule):
|
|
4455
4855
|
) -> types.CountTokensResponse:
|
4456
4856
|
"""Counts the number of tokens in the given content.
|
4457
4857
|
|
4858
|
+
Multimodal input is supported for Gemini models.
|
4859
|
+
|
4458
4860
|
Args:
|
4459
4861
|
model (str): The model to use for counting tokens.
|
4460
4862
|
contents (list[types.Content]): The content to count tokens for.
|
4461
|
-
Multimodal input is supported for Gemini models.
|
4462
4863
|
config (CountTokensConfig): The configuration for counting tokens.
|
4463
4864
|
|
4464
4865
|
Usage:
|
@@ -4530,14 +4931,15 @@ class Models(_api_module.BaseModule):
|
|
4530
4931
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
4531
4932
|
config: Optional[types.ComputeTokensConfigOrDict] = None,
|
4532
4933
|
) -> types.ComputeTokensResponse:
|
4533
|
-
"""Return a list of tokens based on the input
|
4934
|
+
"""Return a list of tokens based on the input contents.
|
4935
|
+
|
4936
|
+
Only text is supported.
|
4534
4937
|
|
4535
4938
|
This method is not supported by the Gemini Developer API.
|
4536
4939
|
|
4537
4940
|
Args:
|
4538
4941
|
model (str): The model to use.
|
4539
|
-
contents (list[shared.Content]): The content to compute tokens for.
|
4540
|
-
text is supported.
|
4942
|
+
contents (list[shared.Content]): The content to compute tokens for.
|
4541
4943
|
|
4542
4944
|
Usage:
|
4543
4945
|
|
@@ -4600,6 +5002,88 @@ class Models(_api_module.BaseModule):
|
|
4600
5002
|
self._api_client._verify_response(return_value)
|
4601
5003
|
return return_value
|
4602
5004
|
|
5005
|
+
@_common.experimental_warning(
|
5006
|
+
'This method is experimental and may change in future versions.'
|
5007
|
+
)
|
5008
|
+
def generate_videos(
|
5009
|
+
self,
|
5010
|
+
*,
|
5011
|
+
model: str,
|
5012
|
+
prompt: Optional[str] = None,
|
5013
|
+
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
5014
|
+
) -> types.GenerateVideosOperation:
|
5015
|
+
"""Generates videos based on a text description and configuration.
|
5016
|
+
|
5017
|
+
Args:
|
5018
|
+
model: The model to use.
|
5019
|
+
instances: A list of prompts, images and videos to generate videos from.
|
5020
|
+
config: Configuration for generation.
|
5021
|
+
|
5022
|
+
Usage:
|
5023
|
+
|
5024
|
+
```
|
5025
|
+
operation = client.models.generate_videos(
|
5026
|
+
model="veo-2.0-generate-001",
|
5027
|
+
prompt="A neon hologram of a cat driving at top speed",
|
5028
|
+
)
|
5029
|
+
while not operation.done:
|
5030
|
+
time.sleep(10)
|
5031
|
+
operation = client.operations.get(operation)
|
5032
|
+
|
5033
|
+
operation.result.generated_videos[0].video.uri
|
5034
|
+
```
|
5035
|
+
"""
|
5036
|
+
|
5037
|
+
parameter_model = types._GenerateVideosParameters(
|
5038
|
+
model=model,
|
5039
|
+
prompt=prompt,
|
5040
|
+
config=config,
|
5041
|
+
)
|
5042
|
+
|
5043
|
+
if self._api_client.vertexai:
|
5044
|
+
request_dict = _GenerateVideosParameters_to_vertex(
|
5045
|
+
self._api_client, parameter_model
|
5046
|
+
)
|
5047
|
+
path = '{model}:predictLongRunning'.format_map(request_dict.get('_url'))
|
5048
|
+
else:
|
5049
|
+
request_dict = _GenerateVideosParameters_to_mldev(
|
5050
|
+
self._api_client, parameter_model
|
5051
|
+
)
|
5052
|
+
path = '{model}:predictLongRunning'.format_map(request_dict.get('_url'))
|
5053
|
+
query_params = request_dict.get('_query')
|
5054
|
+
if query_params:
|
5055
|
+
path = f'{path}?{urlencode(query_params)}'
|
5056
|
+
# TODO: remove the hack that pops config.
|
5057
|
+
request_dict.pop('config', None)
|
5058
|
+
|
5059
|
+
http_options = None
|
5060
|
+
if isinstance(config, dict):
|
5061
|
+
http_options = config.get('http_options', None)
|
5062
|
+
elif hasattr(config, 'http_options'):
|
5063
|
+
http_options = config.http_options
|
5064
|
+
|
5065
|
+
request_dict = _common.convert_to_dict(request_dict)
|
5066
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
5067
|
+
|
5068
|
+
response_dict = self._api_client.request(
|
5069
|
+
'post', path, request_dict, http_options
|
5070
|
+
)
|
5071
|
+
|
5072
|
+
if self._api_client.vertexai:
|
5073
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
5074
|
+
self._api_client, response_dict
|
5075
|
+
)
|
5076
|
+
else:
|
5077
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
5078
|
+
self._api_client, response_dict
|
5079
|
+
)
|
5080
|
+
|
5081
|
+
return_value = types.GenerateVideosOperation._from_response(
|
5082
|
+
response=response_dict, kwargs=parameter_model
|
5083
|
+
)
|
5084
|
+
self._api_client._verify_response(return_value)
|
5085
|
+
return return_value
|
5086
|
+
|
4603
5087
|
def generate_content(
|
4604
5088
|
self,
|
4605
5089
|
*,
|
@@ -4609,19 +5093,19 @@ class Models(_api_module.BaseModule):
|
|
4609
5093
|
) -> types.GenerateContentResponse:
|
4610
5094
|
"""Makes an API request to generate content using a model.
|
4611
5095
|
|
4612
|
-
For the `model` parameter, supported
|
4613
|
-
-
|
4614
|
-
-
|
5096
|
+
For the `model` parameter, supported formats for Vertex AI API include:
|
5097
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
5098
|
+
- The full resource name starts with 'projects/', for example:
|
4615
5099
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-1.5-flash-002'
|
4616
|
-
-
|
5100
|
+
- The partial resource name with 'publishers/', for example:
|
4617
5101
|
'publishers/google/models/gemini-1.5-flash-002' or
|
4618
5102
|
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
4619
5103
|
- `/` separated publisher and model name, for example:
|
4620
5104
|
'google/gemini-1.5-flash-002' or 'meta/llama-3.1-405b-instruct-maas'
|
4621
5105
|
|
4622
|
-
For the `model` parameter, supported
|
4623
|
-
-
|
4624
|
-
-
|
5106
|
+
For the `model` parameter, supported formats for Gemini API include:
|
5107
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
5108
|
+
- The model name starts with 'models/', for example:
|
4625
5109
|
'models/gemini-1.5-flash-002'
|
4626
5110
|
- if you would like to use a tuned model, the model name starts with
|
4627
5111
|
'tunedModels/', for example:
|
@@ -4669,7 +5153,7 @@ class Models(_api_module.BaseModule):
|
|
4669
5153
|
model=model, contents=contents, config=config
|
4670
5154
|
)
|
4671
5155
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
4672
|
-
|
5156
|
+
logger.info(
|
4673
5157
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
4674
5158
|
)
|
4675
5159
|
automatic_function_calling_history = []
|
@@ -4680,10 +5164,10 @@ class Models(_api_module.BaseModule):
|
|
4680
5164
|
response = self._generate_content(
|
4681
5165
|
model=model, contents=contents, config=config
|
4682
5166
|
)
|
4683
|
-
|
5167
|
+
logger.info(f'AFC remote call {i} is done.')
|
4684
5168
|
remaining_remote_calls_afc -= 1
|
4685
5169
|
if remaining_remote_calls_afc == 0:
|
4686
|
-
|
5170
|
+
logger.info('Reached max remote calls for automatic function calling.')
|
4687
5171
|
|
4688
5172
|
function_map = _extra_utils.get_function_map(config)
|
4689
5173
|
if not function_map:
|
@@ -4728,21 +5212,21 @@ class Models(_api_module.BaseModule):
|
|
4728
5212
|
) -> Iterator[types.GenerateContentResponse]:
|
4729
5213
|
"""Makes an API request to generate content using a model and yields the model's response in chunks.
|
4730
5214
|
|
4731
|
-
For the `model` parameter, supported
|
4732
|
-
-
|
4733
|
-
-
|
5215
|
+
For the `model` parameter, supported formats for Vertex AI API include:
|
5216
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
5217
|
+
- The full resource name starts with 'projects/', for example:
|
4734
5218
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-1.5-flash-002'
|
4735
|
-
-
|
5219
|
+
- The partial resource name with 'publishers/', for example:
|
4736
5220
|
'publishers/google/models/gemini-1.5-flash-002' or
|
4737
5221
|
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
4738
5222
|
- `/` separated publisher and model name, for example:
|
4739
5223
|
'google/gemini-1.5-flash-002' or 'meta/llama-3.1-405b-instruct-maas'
|
4740
5224
|
|
4741
|
-
For the `model` parameter, supported
|
4742
|
-
-
|
4743
|
-
-
|
5225
|
+
For the `model` parameter, supported formats for Gemini API include:
|
5226
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
5227
|
+
- The model name starts with 'models/', for example:
|
4744
5228
|
'models/gemini-1.5-flash-002'
|
4745
|
-
-
|
5229
|
+
- If you would like to use a tuned model, the model name starts with
|
4746
5230
|
'tunedModels/', for example:
|
4747
5231
|
'tunedModels/1234567890123456789'
|
4748
5232
|
|
@@ -4790,7 +5274,7 @@ class Models(_api_module.BaseModule):
|
|
4790
5274
|
return
|
4791
5275
|
|
4792
5276
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
4793
|
-
|
5277
|
+
logger.info(
|
4794
5278
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
4795
5279
|
)
|
4796
5280
|
automatic_function_calling_history = []
|
@@ -4802,10 +5286,10 @@ class Models(_api_module.BaseModule):
|
|
4802
5286
|
response = self._generate_content_stream(
|
4803
5287
|
model=model, contents=contents, config=config
|
4804
5288
|
)
|
4805
|
-
|
5289
|
+
logger.info(f'AFC remote call {i} is done.')
|
4806
5290
|
remaining_remote_calls_afc -= 1
|
4807
5291
|
if remaining_remote_calls_afc == 0:
|
4808
|
-
|
5292
|
+
logger.info('Reached max remote calls for automatic function calling.')
|
4809
5293
|
|
4810
5294
|
function_map = _extra_utils.get_function_map(config)
|
4811
5295
|
|
@@ -4817,6 +5301,12 @@ class Models(_api_module.BaseModule):
|
|
4817
5301
|
if not function_map:
|
4818
5302
|
yield chunk
|
4819
5303
|
else:
|
5304
|
+
if (
|
5305
|
+
not chunk.candidates
|
5306
|
+
or not chunk.candidates[0].content
|
5307
|
+
or not chunk.candidates[0].content.parts
|
5308
|
+
):
|
5309
|
+
break
|
4820
5310
|
func_response_parts = _extra_utils.get_function_response_parts(
|
4821
5311
|
chunk, function_map
|
4822
5312
|
)
|
@@ -4831,20 +5321,16 @@ class Models(_api_module.BaseModule):
|
|
4831
5321
|
automatic_function_calling_history
|
4832
5322
|
)
|
4833
5323
|
yield chunk
|
5324
|
+
if (
|
5325
|
+
not chunk.candidates
|
5326
|
+
or not chunk.candidates[0].content
|
5327
|
+
or not chunk.candidates[0].content.parts
|
5328
|
+
):
|
5329
|
+
break
|
4834
5330
|
func_response_parts = _extra_utils.get_function_response_parts(
|
4835
5331
|
chunk, function_map
|
4836
5332
|
)
|
4837
5333
|
|
4838
|
-
if not chunk:
|
4839
|
-
break
|
4840
|
-
if (
|
4841
|
-
not chunk
|
4842
|
-
or not chunk.candidates
|
4843
|
-
or not chunk.candidates[0].content
|
4844
|
-
or not chunk.candidates[0].content.parts
|
4845
|
-
):
|
4846
|
-
break
|
4847
|
-
|
4848
5334
|
if not function_map:
|
4849
5335
|
break
|
4850
5336
|
if not func_response_parts:
|
@@ -4906,7 +5392,7 @@ class Models(_api_module.BaseModule):
|
|
4906
5392
|
|
4907
5393
|
# Convert to API config.
|
4908
5394
|
config = config or {}
|
4909
|
-
config_dct = config if isinstance(config, dict) else config.
|
5395
|
+
config_dct = config if isinstance(config, dict) else config.model_dump()
|
4910
5396
|
api_config = types._UpscaleImageAPIConfigDict(**config_dct) # pylint: disable=protected-access
|
4911
5397
|
|
4912
5398
|
# Provide default values through API config.
|
@@ -5103,7 +5589,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
5103
5589
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
5104
5590
|
config: Optional[types.EmbedContentConfigOrDict] = None,
|
5105
5591
|
) -> types.EmbedContentResponse:
|
5106
|
-
"""Calculates embeddings for the given contents
|
5592
|
+
"""Calculates embeddings for the given contents. Only text is supported.
|
5107
5593
|
|
5108
5594
|
Args:
|
5109
5595
|
model (str): The model to use.
|
@@ -5114,7 +5600,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
5114
5600
|
|
5115
5601
|
.. code-block:: python
|
5116
5602
|
|
5117
|
-
embeddings = client.models.embed_content(
|
5603
|
+
embeddings = await client.aio.models.embed_content(
|
5118
5604
|
model= 'text-embedding-004',
|
5119
5605
|
contents=[
|
5120
5606
|
'What is your name?',
|
@@ -5194,8 +5680,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
5194
5680
|
|
5195
5681
|
.. code-block:: python
|
5196
5682
|
|
5197
|
-
response = client.models.generate_images(
|
5198
|
-
model='imagen-3.0-generate-
|
5683
|
+
response = await client.aio.models.generate_images(
|
5684
|
+
model='imagen-3.0-generate-002',
|
5199
5685
|
prompt='Man with a dog',
|
5200
5686
|
config=types.GenerateImagesConfig(
|
5201
5687
|
number_of_images= 1,
|
@@ -5292,7 +5778,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
5292
5778
|
mask_dilation=0.06,
|
5293
5779
|
),
|
5294
5780
|
)
|
5295
|
-
response = client.models.edit_image(
|
5781
|
+
response = await client.aio.models.edit_image(
|
5296
5782
|
model='imagen-3.0-capability-preview-0930',
|
5297
5783
|
prompt='man with dog',
|
5298
5784
|
reference_images=[raw_ref_image, mask_ref_image],
|
@@ -5635,17 +6121,18 @@ class AsyncModels(_api_module.BaseModule):
|
|
5635
6121
|
) -> types.CountTokensResponse:
|
5636
6122
|
"""Counts the number of tokens in the given content.
|
5637
6123
|
|
6124
|
+
Multimodal input is supported for Gemini models.
|
6125
|
+
|
5638
6126
|
Args:
|
5639
6127
|
model (str): The model to use for counting tokens.
|
5640
6128
|
contents (list[types.Content]): The content to count tokens for.
|
5641
|
-
Multimodal input is supported for Gemini models.
|
5642
6129
|
config (CountTokensConfig): The configuration for counting tokens.
|
5643
6130
|
|
5644
6131
|
Usage:
|
5645
6132
|
|
5646
6133
|
.. code-block:: python
|
5647
6134
|
|
5648
|
-
response = client.models.count_tokens(
|
6135
|
+
response = await client.aio.models.count_tokens(
|
5649
6136
|
model='gemini-1.5-flash',
|
5650
6137
|
contents='What is your name?',
|
5651
6138
|
)
|
@@ -5710,20 +6197,21 @@ class AsyncModels(_api_module.BaseModule):
|
|
5710
6197
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
5711
6198
|
config: Optional[types.ComputeTokensConfigOrDict] = None,
|
5712
6199
|
) -> types.ComputeTokensResponse:
|
5713
|
-
"""Return a list of tokens based on the input
|
6200
|
+
"""Return a list of tokens based on the input contents.
|
6201
|
+
|
6202
|
+
Only text is supported.
|
5714
6203
|
|
5715
6204
|
This method is not supported by the Gemini Developer API.
|
5716
6205
|
|
5717
6206
|
Args:
|
5718
6207
|
model (str): The model to use.
|
5719
|
-
contents (list[shared.Content]): The content to compute tokens for.
|
5720
|
-
text is supported.
|
6208
|
+
contents (list[shared.Content]): The content to compute tokens for.
|
5721
6209
|
|
5722
6210
|
Usage:
|
5723
6211
|
|
5724
6212
|
.. code-block:: python
|
5725
6213
|
|
5726
|
-
response = client.models.compute_tokens(
|
6214
|
+
response = await client.aio.models.compute_tokens(
|
5727
6215
|
model='gemini-1.5-flash',
|
5728
6216
|
contents='What is your name?',
|
5729
6217
|
)
|
@@ -5780,6 +6268,88 @@ class AsyncModels(_api_module.BaseModule):
|
|
5780
6268
|
self._api_client._verify_response(return_value)
|
5781
6269
|
return return_value
|
5782
6270
|
|
6271
|
+
@_common.experimental_warning(
|
6272
|
+
'This method is experimental and may change in future versions.'
|
6273
|
+
)
|
6274
|
+
async def generate_videos(
|
6275
|
+
self,
|
6276
|
+
*,
|
6277
|
+
model: str,
|
6278
|
+
prompt: Optional[str] = None,
|
6279
|
+
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
6280
|
+
) -> types.GenerateVideosOperation:
|
6281
|
+
"""Generates videos based on a text description and configuration.
|
6282
|
+
|
6283
|
+
Args:
|
6284
|
+
model: The model to use.
|
6285
|
+
instances: A list of prompts, images and videos to generate videos from.
|
6286
|
+
config: Configuration for generation.
|
6287
|
+
|
6288
|
+
Usage:
|
6289
|
+
|
6290
|
+
```
|
6291
|
+
operation = client.models.generate_videos(
|
6292
|
+
model="veo-2.0-generate-001",
|
6293
|
+
prompt="A neon hologram of a cat driving at top speed",
|
6294
|
+
)
|
6295
|
+
while not operation.done:
|
6296
|
+
time.sleep(10)
|
6297
|
+
operation = client.operations.get(operation)
|
6298
|
+
|
6299
|
+
operation.result.generated_videos[0].video.uri
|
6300
|
+
```
|
6301
|
+
"""
|
6302
|
+
|
6303
|
+
parameter_model = types._GenerateVideosParameters(
|
6304
|
+
model=model,
|
6305
|
+
prompt=prompt,
|
6306
|
+
config=config,
|
6307
|
+
)
|
6308
|
+
|
6309
|
+
if self._api_client.vertexai:
|
6310
|
+
request_dict = _GenerateVideosParameters_to_vertex(
|
6311
|
+
self._api_client, parameter_model
|
6312
|
+
)
|
6313
|
+
path = '{model}:predictLongRunning'.format_map(request_dict.get('_url'))
|
6314
|
+
else:
|
6315
|
+
request_dict = _GenerateVideosParameters_to_mldev(
|
6316
|
+
self._api_client, parameter_model
|
6317
|
+
)
|
6318
|
+
path = '{model}:predictLongRunning'.format_map(request_dict.get('_url'))
|
6319
|
+
query_params = request_dict.get('_query')
|
6320
|
+
if query_params:
|
6321
|
+
path = f'{path}?{urlencode(query_params)}'
|
6322
|
+
# TODO: remove the hack that pops config.
|
6323
|
+
request_dict.pop('config', None)
|
6324
|
+
|
6325
|
+
http_options = None
|
6326
|
+
if isinstance(config, dict):
|
6327
|
+
http_options = config.get('http_options', None)
|
6328
|
+
elif hasattr(config, 'http_options'):
|
6329
|
+
http_options = config.http_options
|
6330
|
+
|
6331
|
+
request_dict = _common.convert_to_dict(request_dict)
|
6332
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
6333
|
+
|
6334
|
+
response_dict = await self._api_client.async_request(
|
6335
|
+
'post', path, request_dict, http_options
|
6336
|
+
)
|
6337
|
+
|
6338
|
+
if self._api_client.vertexai:
|
6339
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
6340
|
+
self._api_client, response_dict
|
6341
|
+
)
|
6342
|
+
else:
|
6343
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
6344
|
+
self._api_client, response_dict
|
6345
|
+
)
|
6346
|
+
|
6347
|
+
return_value = types.GenerateVideosOperation._from_response(
|
6348
|
+
response=response_dict, kwargs=parameter_model
|
6349
|
+
)
|
6350
|
+
self._api_client._verify_response(return_value)
|
6351
|
+
return return_value
|
6352
|
+
|
5783
6353
|
async def generate_content(
|
5784
6354
|
self,
|
5785
6355
|
*,
|
@@ -5821,7 +6391,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
5821
6391
|
model=model, contents=contents, config=config
|
5822
6392
|
)
|
5823
6393
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
5824
|
-
|
6394
|
+
logger.info(
|
5825
6395
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
5826
6396
|
)
|
5827
6397
|
automatic_function_calling_history = []
|
@@ -5832,7 +6402,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
5832
6402
|
)
|
5833
6403
|
remaining_remote_calls_afc -= 1
|
5834
6404
|
if remaining_remote_calls_afc == 0:
|
5835
|
-
|
6405
|
+
logger.info('Reached max remote calls for automatic function calling.')
|
5836
6406
|
|
5837
6407
|
function_map = _extra_utils.get_function_map(config)
|
5838
6408
|
if not function_map:
|
@@ -5878,21 +6448,21 @@ class AsyncModels(_api_module.BaseModule):
|
|
5878
6448
|
) -> Awaitable[AsyncIterator[types.GenerateContentResponse]]:
|
5879
6449
|
"""Makes an API request to generate content using a model and yields the model's response in chunks.
|
5880
6450
|
|
5881
|
-
For the `model` parameter, supported
|
5882
|
-
-
|
5883
|
-
-
|
6451
|
+
For the `model` parameter, supported formats for Vertex AI API include:
|
6452
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
6453
|
+
- The full resource name starts with 'projects/', for example:
|
5884
6454
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-1.5-flash-002'
|
5885
|
-
-
|
6455
|
+
- The partial resource name with 'publishers/', for example:
|
5886
6456
|
'publishers/google/models/gemini-1.5-flash-002' or
|
5887
6457
|
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
5888
6458
|
- `/` separated publisher and model name, for example:
|
5889
6459
|
'google/gemini-1.5-flash-002' or 'meta/llama-3.1-405b-instruct-maas'
|
5890
6460
|
|
5891
|
-
For the `model` parameter, supported
|
5892
|
-
-
|
5893
|
-
-
|
6461
|
+
For the `model` parameter, supported formats for Gemini API include:
|
6462
|
+
- The Gemini model ID, for example: 'gemini-1.5-flash-002'
|
6463
|
+
- The model name starts with 'models/', for example:
|
5894
6464
|
'models/gemini-1.5-flash-002'
|
5895
|
-
-
|
6465
|
+
- If you would like to use a tuned model, the model name starts with
|
5896
6466
|
'tunedModels/', for example:
|
5897
6467
|
'tunedModels/1234567890123456789'
|
5898
6468
|
|
@@ -5946,10 +6516,11 @@ class AsyncModels(_api_module.BaseModule):
|
|
5946
6516
|
|
5947
6517
|
async def async_generator(model, contents, config):
|
5948
6518
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
5949
|
-
|
6519
|
+
logger.info(
|
5950
6520
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
5951
6521
|
)
|
5952
6522
|
automatic_function_calling_history = []
|
6523
|
+
func_response_parts = None
|
5953
6524
|
chunk = None
|
5954
6525
|
i = 0
|
5955
6526
|
while remaining_remote_calls_afc > 0:
|
@@ -5957,10 +6528,10 @@ class AsyncModels(_api_module.BaseModule):
|
|
5957
6528
|
response = await self._generate_content_stream(
|
5958
6529
|
model=model, contents=contents, config=config
|
5959
6530
|
)
|
5960
|
-
|
6531
|
+
logger.info(f'AFC remote call {i} is done.')
|
5961
6532
|
remaining_remote_calls_afc -= 1
|
5962
6533
|
if remaining_remote_calls_afc == 0:
|
5963
|
-
|
6534
|
+
logger.info(
|
5964
6535
|
'Reached max remote calls for automatic function calling.'
|
5965
6536
|
)
|
5966
6537
|
|
@@ -5974,6 +6545,12 @@ class AsyncModels(_api_module.BaseModule):
|
|
5974
6545
|
if not function_map:
|
5975
6546
|
yield chunk
|
5976
6547
|
else:
|
6548
|
+
if (
|
6549
|
+
not chunk.candidates
|
6550
|
+
or not chunk.candidates[0].content
|
6551
|
+
or not chunk.candidates[0].content.parts
|
6552
|
+
):
|
6553
|
+
break
|
5977
6554
|
func_response_parts = _extra_utils.get_function_response_parts(
|
5978
6555
|
chunk, function_map
|
5979
6556
|
)
|
@@ -5989,18 +6566,15 @@ class AsyncModels(_api_module.BaseModule):
|
|
5989
6566
|
automatic_function_calling_history
|
5990
6567
|
)
|
5991
6568
|
yield chunk
|
6569
|
+
if (
|
6570
|
+
not chunk.candidates
|
6571
|
+
or not chunk.candidates[0].content
|
6572
|
+
or not chunk.candidates[0].content.parts
|
6573
|
+
):
|
6574
|
+
break
|
5992
6575
|
func_response_parts = _extra_utils.get_function_response_parts(
|
5993
6576
|
chunk, function_map
|
5994
6577
|
)
|
5995
|
-
if not chunk:
|
5996
|
-
break
|
5997
|
-
if (
|
5998
|
-
not chunk
|
5999
|
-
or not chunk.candidates
|
6000
|
-
or not chunk.candidates[0].content
|
6001
|
-
or not chunk.candidates[0].content.parts
|
6002
|
-
):
|
6003
|
-
break
|
6004
6578
|
if not function_map:
|
6005
6579
|
break
|
6006
6580
|
|
@@ -6030,8 +6604,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
6030
6604
|
) -> AsyncPager[types.Model]:
|
6031
6605
|
"""Makes an API request to list the available models.
|
6032
6606
|
|
6033
|
-
If `query_base` is set to True in the config
|
6034
|
-
available base models. If set to False
|
6607
|
+
If `query_base` is set to True in the config or not set (default), the
|
6608
|
+
API will return all available base models. If set to False, it will return
|
6035
6609
|
all tuned models.
|
6036
6610
|
|
6037
6611
|
Args:
|
@@ -6056,6 +6630,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
6056
6630
|
types._ListModelsParameters(config=config).config
|
6057
6631
|
or types.ListModelsConfig()
|
6058
6632
|
)
|
6633
|
+
if config.query_base is None:
|
6634
|
+
config.query_base = True
|
6059
6635
|
if self._api_client.vertexai:
|
6060
6636
|
config = config.copy()
|
6061
6637
|
if not config.query_base:
|
@@ -6066,8 +6642,6 @@ class AsyncModels(_api_module.BaseModule):
|
|
6066
6642
|
if filter_value
|
6067
6643
|
else 'labels.tune-type:*'
|
6068
6644
|
)
|
6069
|
-
if not config.query_base:
|
6070
|
-
config.query_base = False
|
6071
6645
|
return AsyncPager(
|
6072
6646
|
'models',
|
6073
6647
|
self._list,
|