google-genai 1.12.1__py3-none-any.whl → 1.14.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 +59 -17
- google/genai/_base_url.py +50 -0
- google/genai/_live_converters.py +231 -203
- google/genai/_transformers.py +2 -2
- google/genai/batches.py +2 -2
- google/genai/caches.py +236 -198
- google/genai/chats.py +4 -4
- google/genai/client.py +21 -9
- google/genai/live.py +9 -6
- google/genai/models.py +260 -230
- google/genai/types.py +1380 -1045
- google/genai/version.py +1 -1
- {google_genai-1.12.1.dist-info → google_genai-1.14.0.dist-info}/METADATA +8 -6
- google_genai-1.14.0.dist-info/RECORD +30 -0
- {google_genai-1.12.1.dist-info → google_genai-1.14.0.dist-info}/WHEEL +1 -1
- google_genai-1.12.1.dist-info/RECORD +0 -29
- {google_genai-1.12.1.dist-info → google_genai-1.14.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.12.1.dist-info → google_genai-1.14.0.dist-info}/top_level.txt +0 -0
google/genai/types.py
CHANGED
@@ -76,18 +76,6 @@ class Language(_common.CaseInSensitiveEnum):
|
|
76
76
|
PYTHON = 'PYTHON'
|
77
77
|
|
78
78
|
|
79
|
-
class Type(_common.CaseInSensitiveEnum):
|
80
|
-
"""Optional. The type of the data."""
|
81
|
-
|
82
|
-
TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED'
|
83
|
-
STRING = 'STRING'
|
84
|
-
NUMBER = 'NUMBER'
|
85
|
-
INTEGER = 'INTEGER'
|
86
|
-
BOOLEAN = 'BOOLEAN'
|
87
|
-
ARRAY = 'ARRAY'
|
88
|
-
OBJECT = 'OBJECT'
|
89
|
-
|
90
|
-
|
91
79
|
class HarmCategory(_common.CaseInSensitiveEnum):
|
92
80
|
"""Required. Harm category."""
|
93
81
|
|
@@ -129,6 +117,30 @@ class Mode(_common.CaseInSensitiveEnum):
|
|
129
117
|
MODE_DYNAMIC = 'MODE_DYNAMIC'
|
130
118
|
|
131
119
|
|
120
|
+
class AuthType(_common.CaseInSensitiveEnum):
|
121
|
+
"""Type of auth scheme."""
|
122
|
+
|
123
|
+
AUTH_TYPE_UNSPECIFIED = 'AUTH_TYPE_UNSPECIFIED'
|
124
|
+
NO_AUTH = 'NO_AUTH'
|
125
|
+
API_KEY_AUTH = 'API_KEY_AUTH'
|
126
|
+
HTTP_BASIC_AUTH = 'HTTP_BASIC_AUTH'
|
127
|
+
GOOGLE_SERVICE_ACCOUNT_AUTH = 'GOOGLE_SERVICE_ACCOUNT_AUTH'
|
128
|
+
OAUTH = 'OAUTH'
|
129
|
+
OIDC_AUTH = 'OIDC_AUTH'
|
130
|
+
|
131
|
+
|
132
|
+
class Type(_common.CaseInSensitiveEnum):
|
133
|
+
"""Optional. The type of the data."""
|
134
|
+
|
135
|
+
TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED'
|
136
|
+
STRING = 'STRING'
|
137
|
+
NUMBER = 'NUMBER'
|
138
|
+
INTEGER = 'INTEGER'
|
139
|
+
BOOLEAN = 'BOOLEAN'
|
140
|
+
ARRAY = 'ARRAY'
|
141
|
+
OBJECT = 'OBJECT'
|
142
|
+
|
143
|
+
|
132
144
|
class FinishReason(_common.CaseInSensitiveEnum):
|
133
145
|
"""Output only. The reason why the model stopped generating tokens.
|
134
146
|
|
@@ -881,1257 +893,1436 @@ class HttpOptionsDict(TypedDict, total=False):
|
|
881
893
|
HttpOptionsOrDict = Union[HttpOptions, HttpOptionsDict]
|
882
894
|
|
883
895
|
|
884
|
-
class
|
885
|
-
"""
|
896
|
+
class ModelSelectionConfig(_common.BaseModel):
|
897
|
+
"""Config for model selection."""
|
886
898
|
|
887
|
-
|
888
|
-
|
889
|
-
|
899
|
+
feature_selection_preference: Optional[FeatureSelectionPreference] = Field(
|
900
|
+
default=None, description="""Options for feature selection preference."""
|
901
|
+
)
|
890
902
|
|
891
|
-
NULL = 'null'
|
892
|
-
BOOLEAN = 'boolean'
|
893
|
-
OBJECT = 'object'
|
894
|
-
ARRAY = 'array'
|
895
|
-
NUMBER = 'number'
|
896
|
-
INTEGER = 'integer'
|
897
|
-
STRING = 'string'
|
898
903
|
|
904
|
+
class ModelSelectionConfigDict(TypedDict, total=False):
|
905
|
+
"""Config for model selection."""
|
899
906
|
|
900
|
-
|
901
|
-
"""
|
907
|
+
feature_selection_preference: Optional[FeatureSelectionPreference]
|
908
|
+
"""Options for feature selection preference."""
|
902
909
|
|
903
|
-
Represents a subset of a JSON Schema object that is used by the Gemini model.
|
904
|
-
The difference between this class and the Schema class is that this class is
|
905
|
-
compatible with OpenAPI 3.1 schema objects. And the Schema class is used to
|
906
|
-
make API call to Gemini model.
|
907
|
-
"""
|
908
910
|
|
909
|
-
|
911
|
+
ModelSelectionConfigOrDict = Union[
|
912
|
+
ModelSelectionConfig, ModelSelectionConfigDict
|
913
|
+
]
|
914
|
+
|
915
|
+
|
916
|
+
class SafetySetting(_common.BaseModel):
|
917
|
+
"""Safety settings."""
|
918
|
+
|
919
|
+
method: Optional[HarmBlockMethod] = Field(
|
910
920
|
default=None,
|
911
|
-
description="""
|
921
|
+
description="""Determines if the harm block method uses probability or probability
|
922
|
+
and severity scores.""",
|
912
923
|
)
|
913
|
-
|
914
|
-
default=None,
|
915
|
-
description='Define semantic information about a string instance.',
|
924
|
+
category: Optional[HarmCategory] = Field(
|
925
|
+
default=None, description="""Required. Harm category."""
|
916
926
|
)
|
917
|
-
|
918
|
-
default=None,
|
919
|
-
description=(
|
920
|
-
'A preferably short description about the purpose of the instance'
|
921
|
-
' described by the schema.'
|
922
|
-
),
|
927
|
+
threshold: Optional[HarmBlockThreshold] = Field(
|
928
|
+
default=None, description="""Required. The harm block threshold."""
|
923
929
|
)
|
924
|
-
|
930
|
+
|
931
|
+
|
932
|
+
class SafetySettingDict(TypedDict, total=False):
|
933
|
+
"""Safety settings."""
|
934
|
+
|
935
|
+
method: Optional[HarmBlockMethod]
|
936
|
+
"""Determines if the harm block method uses probability or probability
|
937
|
+
and severity scores."""
|
938
|
+
|
939
|
+
category: Optional[HarmCategory]
|
940
|
+
"""Required. Harm category."""
|
941
|
+
|
942
|
+
threshold: Optional[HarmBlockThreshold]
|
943
|
+
"""Required. The harm block threshold."""
|
944
|
+
|
945
|
+
|
946
|
+
SafetySettingOrDict = Union[SafetySetting, SafetySettingDict]
|
947
|
+
|
948
|
+
|
949
|
+
class GoogleSearch(_common.BaseModel):
|
950
|
+
"""Tool to support Google Search in Model. Powered by Google."""
|
951
|
+
|
952
|
+
pass
|
953
|
+
|
954
|
+
|
955
|
+
class GoogleSearchDict(TypedDict, total=False):
|
956
|
+
"""Tool to support Google Search in Model. Powered by Google."""
|
957
|
+
|
958
|
+
pass
|
959
|
+
|
960
|
+
|
961
|
+
GoogleSearchOrDict = Union[GoogleSearch, GoogleSearchDict]
|
962
|
+
|
963
|
+
|
964
|
+
class DynamicRetrievalConfig(_common.BaseModel):
|
965
|
+
"""Describes the options to customize dynamic retrieval."""
|
966
|
+
|
967
|
+
mode: Optional[DynamicRetrievalConfigMode] = Field(
|
925
968
|
default=None,
|
926
|
-
description=
|
927
|
-
'An explanation about the purpose of the instance described by the'
|
928
|
-
' schema.'
|
929
|
-
),
|
969
|
+
description="""The mode of the predictor to be used in dynamic retrieval.""",
|
930
970
|
)
|
931
|
-
|
971
|
+
dynamic_threshold: Optional[float] = Field(
|
932
972
|
default=None,
|
933
|
-
description=
|
934
|
-
'This keyword can be used to supply a default JSON value associated'
|
935
|
-
' with a particular schema.'
|
936
|
-
),
|
973
|
+
description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
|
937
974
|
)
|
938
|
-
|
975
|
+
|
976
|
+
|
977
|
+
class DynamicRetrievalConfigDict(TypedDict, total=False):
|
978
|
+
"""Describes the options to customize dynamic retrieval."""
|
979
|
+
|
980
|
+
mode: Optional[DynamicRetrievalConfigMode]
|
981
|
+
"""The mode of the predictor to be used in dynamic retrieval."""
|
982
|
+
|
983
|
+
dynamic_threshold: Optional[float]
|
984
|
+
"""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used."""
|
985
|
+
|
986
|
+
|
987
|
+
DynamicRetrievalConfigOrDict = Union[
|
988
|
+
DynamicRetrievalConfig, DynamicRetrievalConfigDict
|
989
|
+
]
|
990
|
+
|
991
|
+
|
992
|
+
class GoogleSearchRetrieval(_common.BaseModel):
|
993
|
+
"""Tool to retrieve public web data for grounding, powered by Google."""
|
994
|
+
|
995
|
+
dynamic_retrieval_config: Optional[DynamicRetrievalConfig] = Field(
|
939
996
|
default=None,
|
940
|
-
description=
|
941
|
-
'Validation succeeds if each element of the instance not covered by'
|
942
|
-
' prefixItems validates against this schema.'
|
943
|
-
),
|
997
|
+
description="""Specifies the dynamic retrieval configuration for the given source.""",
|
944
998
|
)
|
945
|
-
|
999
|
+
|
1000
|
+
|
1001
|
+
class GoogleSearchRetrievalDict(TypedDict, total=False):
|
1002
|
+
"""Tool to retrieve public web data for grounding, powered by Google."""
|
1003
|
+
|
1004
|
+
dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
|
1005
|
+
"""Specifies the dynamic retrieval configuration for the given source."""
|
1006
|
+
|
1007
|
+
|
1008
|
+
GoogleSearchRetrievalOrDict = Union[
|
1009
|
+
GoogleSearchRetrieval, GoogleSearchRetrievalDict
|
1010
|
+
]
|
1011
|
+
|
1012
|
+
|
1013
|
+
class EnterpriseWebSearch(_common.BaseModel):
|
1014
|
+
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance."""
|
1015
|
+
|
1016
|
+
pass
|
1017
|
+
|
1018
|
+
|
1019
|
+
class EnterpriseWebSearchDict(TypedDict, total=False):
|
1020
|
+
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance."""
|
1021
|
+
|
1022
|
+
pass
|
1023
|
+
|
1024
|
+
|
1025
|
+
EnterpriseWebSearchOrDict = Union[EnterpriseWebSearch, EnterpriseWebSearchDict]
|
1026
|
+
|
1027
|
+
|
1028
|
+
class ApiKeyConfig(_common.BaseModel):
|
1029
|
+
"""Config for authentication with API key."""
|
1030
|
+
|
1031
|
+
api_key_string: Optional[str] = Field(
|
946
1032
|
default=None,
|
947
|
-
description=
|
948
|
-
'An array instance is valid if its size is greater than, or equal to,'
|
949
|
-
' the value of this keyword.'
|
950
|
-
),
|
1033
|
+
description="""The API key to be used in the request directly.""",
|
951
1034
|
)
|
952
|
-
|
1035
|
+
|
1036
|
+
|
1037
|
+
class ApiKeyConfigDict(TypedDict, total=False):
|
1038
|
+
"""Config for authentication with API key."""
|
1039
|
+
|
1040
|
+
api_key_string: Optional[str]
|
1041
|
+
"""The API key to be used in the request directly."""
|
1042
|
+
|
1043
|
+
|
1044
|
+
ApiKeyConfigOrDict = Union[ApiKeyConfig, ApiKeyConfigDict]
|
1045
|
+
|
1046
|
+
|
1047
|
+
class AuthConfigGoogleServiceAccountConfig(_common.BaseModel):
|
1048
|
+
"""Config for Google Service Account Authentication."""
|
1049
|
+
|
1050
|
+
service_account: Optional[str] = Field(
|
953
1051
|
default=None,
|
954
|
-
description=(
|
955
|
-
'An array instance is valid if its size is less than, or equal to,'
|
956
|
-
' the value of this keyword.'
|
957
|
-
),
|
1052
|
+
description="""Optional. The service account that the extension execution service runs as. - If the service account is specified, the `iam.serviceAccounts.getAccessToken` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the specified service account. - If not specified, the Vertex AI Extension Service Agent will be used to execute the Extension.""",
|
958
1053
|
)
|
959
|
-
|
1054
|
+
|
1055
|
+
|
1056
|
+
class AuthConfigGoogleServiceAccountConfigDict(TypedDict, total=False):
|
1057
|
+
"""Config for Google Service Account Authentication."""
|
1058
|
+
|
1059
|
+
service_account: Optional[str]
|
1060
|
+
"""Optional. The service account that the extension execution service runs as. - If the service account is specified, the `iam.serviceAccounts.getAccessToken` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the specified service account. - If not specified, the Vertex AI Extension Service Agent will be used to execute the Extension."""
|
1061
|
+
|
1062
|
+
|
1063
|
+
AuthConfigGoogleServiceAccountConfigOrDict = Union[
|
1064
|
+
AuthConfigGoogleServiceAccountConfig,
|
1065
|
+
AuthConfigGoogleServiceAccountConfigDict,
|
1066
|
+
]
|
1067
|
+
|
1068
|
+
|
1069
|
+
class AuthConfigHttpBasicAuthConfig(_common.BaseModel):
|
1070
|
+
"""Config for HTTP Basic Authentication."""
|
1071
|
+
|
1072
|
+
credential_secret: Optional[str] = Field(
|
960
1073
|
default=None,
|
961
|
-
description=(
|
962
|
-
'Validation succeeds if the instance is equal to one of the elements'
|
963
|
-
' in this keyword’s array value.'
|
964
|
-
),
|
1074
|
+
description="""Required. The name of the SecretManager secret version resource storing the base64 encoded credentials. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If specified, the `secretmanager.versions.access` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the specified resource.""",
|
965
1075
|
)
|
966
|
-
|
1076
|
+
|
1077
|
+
|
1078
|
+
class AuthConfigHttpBasicAuthConfigDict(TypedDict, total=False):
|
1079
|
+
"""Config for HTTP Basic Authentication."""
|
1080
|
+
|
1081
|
+
credential_secret: Optional[str]
|
1082
|
+
"""Required. The name of the SecretManager secret version resource storing the base64 encoded credentials. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If specified, the `secretmanager.versions.access` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the specified resource."""
|
1083
|
+
|
1084
|
+
|
1085
|
+
AuthConfigHttpBasicAuthConfigOrDict = Union[
|
1086
|
+
AuthConfigHttpBasicAuthConfig, AuthConfigHttpBasicAuthConfigDict
|
1087
|
+
]
|
1088
|
+
|
1089
|
+
|
1090
|
+
class AuthConfigOauthConfig(_common.BaseModel):
|
1091
|
+
"""Config for user oauth."""
|
1092
|
+
|
1093
|
+
access_token: Optional[str] = Field(
|
967
1094
|
default=None,
|
968
|
-
description=
|
969
|
-
'Validation succeeds if, for each name that appears in both the'
|
970
|
-
' instance and as a name within this keyword’s value, the child'
|
971
|
-
' instance for that name successfully validates against the'
|
972
|
-
' corresponding schema.'
|
973
|
-
),
|
1095
|
+
description="""Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
|
974
1096
|
)
|
975
|
-
|
1097
|
+
service_account: Optional[str] = Field(
|
976
1098
|
default=None,
|
977
|
-
description=(
|
978
|
-
'An object instance is valid against this keyword if every item in'
|
979
|
-
' the array is the name of a property in the instance.'
|
980
|
-
),
|
1099
|
+
description="""The service account used to generate access tokens for executing the Extension. - If the service account is specified, the `iam.serviceAccounts.getAccessToken` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the provided service account.""",
|
981
1100
|
)
|
982
|
-
|
1101
|
+
|
1102
|
+
|
1103
|
+
class AuthConfigOauthConfigDict(TypedDict, total=False):
|
1104
|
+
"""Config for user oauth."""
|
1105
|
+
|
1106
|
+
access_token: Optional[str]
|
1107
|
+
"""Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
|
1108
|
+
|
1109
|
+
service_account: Optional[str]
|
1110
|
+
"""The service account used to generate access tokens for executing the Extension. - If the service account is specified, the `iam.serviceAccounts.getAccessToken` permission should be granted to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the provided service account."""
|
1111
|
+
|
1112
|
+
|
1113
|
+
AuthConfigOauthConfigOrDict = Union[
|
1114
|
+
AuthConfigOauthConfig, AuthConfigOauthConfigDict
|
1115
|
+
]
|
1116
|
+
|
1117
|
+
|
1118
|
+
class AuthConfigOidcConfig(_common.BaseModel):
|
1119
|
+
"""Config for user OIDC auth."""
|
1120
|
+
|
1121
|
+
id_token: Optional[str] = Field(
|
983
1122
|
default=None,
|
984
|
-
description=
|
985
|
-
'An object instance is valid if its number of properties is greater'
|
986
|
-
' than, or equal to, the value of this keyword.'
|
987
|
-
),
|
1123
|
+
description="""OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
|
988
1124
|
)
|
989
|
-
|
1125
|
+
service_account: Optional[str] = Field(
|
990
1126
|
default=None,
|
991
|
-
description=(
|
992
|
-
'An object instance is valid if its number of properties is less'
|
993
|
-
' than, or equal to, the value of this keyword.'
|
994
|
-
),
|
1127
|
+
description="""The service account used to generate an OpenID Connect (OIDC)-compatible JWT token signed by the Google OIDC Provider (accounts.google.com) for extension endpoint (https://cloud.google.com/iam/docs/create-short-lived-credentials-direct#sa-credentials-oidc). - The audience for the token will be set to the URL in the server url defined in the OpenApi spec. - If the service account is provided, the service account should grant `iam.serviceAccounts.getOpenIdToken` permission to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents).""",
|
995
1128
|
)
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1129
|
+
|
1130
|
+
|
1131
|
+
class AuthConfigOidcConfigDict(TypedDict, total=False):
|
1132
|
+
"""Config for user OIDC auth."""
|
1133
|
+
|
1134
|
+
id_token: Optional[str]
|
1135
|
+
"""OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
|
1136
|
+
|
1137
|
+
service_account: Optional[str]
|
1138
|
+
"""The service account used to generate an OpenID Connect (OIDC)-compatible JWT token signed by the Google OIDC Provider (accounts.google.com) for extension endpoint (https://cloud.google.com/iam/docs/create-short-lived-credentials-direct#sa-credentials-oidc). - The audience for the token will be set to the URL in the server url defined in the OpenApi spec. - If the service account is provided, the service account should grant `iam.serviceAccounts.getOpenIdToken` permission to Vertex AI Extension Service Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents)."""
|
1139
|
+
|
1140
|
+
|
1141
|
+
AuthConfigOidcConfigOrDict = Union[
|
1142
|
+
AuthConfigOidcConfig, AuthConfigOidcConfigDict
|
1143
|
+
]
|
1144
|
+
|
1145
|
+
|
1146
|
+
class AuthConfig(_common.BaseModel):
|
1147
|
+
"""Auth configuration to run the extension."""
|
1148
|
+
|
1149
|
+
api_key_config: Optional[ApiKeyConfig] = Field(
|
1150
|
+
default=None, description="""Config for API key auth."""
|
1002
1151
|
)
|
1003
|
-
|
1004
|
-
default=None,
|
1005
|
-
description=(
|
1006
|
-
'Validation succeeds if the numeric instance is less than or equal to'
|
1007
|
-
' the given number.'
|
1008
|
-
),
|
1152
|
+
auth_type: Optional[AuthType] = Field(
|
1153
|
+
default=None, description="""Type of auth scheme."""
|
1009
1154
|
)
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
' greater than, or equal to, the value of this keyword.'
|
1015
|
-
),
|
1155
|
+
google_service_account_config: Optional[
|
1156
|
+
AuthConfigGoogleServiceAccountConfig
|
1157
|
+
] = Field(
|
1158
|
+
default=None, description="""Config for Google Service Account auth."""
|
1016
1159
|
)
|
1017
|
-
|
1018
|
-
default=None,
|
1019
|
-
description=(
|
1020
|
-
'A string instance is valid against this keyword if its length is'
|
1021
|
-
' less than, or equal to, the value of this keyword.'
|
1022
|
-
),
|
1160
|
+
http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfig] = Field(
|
1161
|
+
default=None, description="""Config for HTTP Basic auth."""
|
1023
1162
|
)
|
1024
|
-
|
1025
|
-
default=None,
|
1026
|
-
description=(
|
1027
|
-
'A string instance is considered valid if the regular expression'
|
1028
|
-
' matches the instance successfully.'
|
1029
|
-
),
|
1163
|
+
oauth_config: Optional[AuthConfigOauthConfig] = Field(
|
1164
|
+
default=None, description="""Config for user oauth."""
|
1030
1165
|
)
|
1031
|
-
|
1032
|
-
default=None,
|
1033
|
-
description=(
|
1034
|
-
'An instance validates successfully against this keyword if it'
|
1035
|
-
' validates successfully against at least one schema defined by this'
|
1036
|
-
' keyword’s value.'
|
1037
|
-
),
|
1166
|
+
oidc_config: Optional[AuthConfigOidcConfig] = Field(
|
1167
|
+
default=None, description="""Config for user OIDC auth."""
|
1038
1168
|
)
|
1039
1169
|
|
1040
1170
|
|
1041
|
-
class
|
1042
|
-
"""
|
1171
|
+
class AuthConfigDict(TypedDict, total=False):
|
1172
|
+
"""Auth configuration to run the extension."""
|
1043
1173
|
|
1044
|
-
|
1045
|
-
"""
|
1174
|
+
api_key_config: Optional[ApiKeyConfigDict]
|
1175
|
+
"""Config for API key auth."""
|
1046
1176
|
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1177
|
+
auth_type: Optional[AuthType]
|
1178
|
+
"""Type of auth scheme."""
|
1179
|
+
|
1180
|
+
google_service_account_config: Optional[
|
1181
|
+
AuthConfigGoogleServiceAccountConfigDict
|
1182
|
+
]
|
1183
|
+
"""Config for Google Service Account auth."""
|
1184
|
+
|
1185
|
+
http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfigDict]
|
1186
|
+
"""Config for HTTP Basic auth."""
|
1187
|
+
|
1188
|
+
oauth_config: Optional[AuthConfigOauthConfigDict]
|
1189
|
+
"""Config for user oauth."""
|
1190
|
+
|
1191
|
+
oidc_config: Optional[AuthConfigOidcConfigDict]
|
1192
|
+
"""Config for user OIDC auth."""
|
1193
|
+
|
1194
|
+
|
1195
|
+
AuthConfigOrDict = Union[AuthConfig, AuthConfigDict]
|
1196
|
+
|
1197
|
+
|
1198
|
+
class GoogleMaps(_common.BaseModel):
|
1199
|
+
"""Tool to support Google Maps in Model."""
|
1200
|
+
|
1201
|
+
auth_config: Optional[AuthConfig] = Field(
|
1059
1202
|
default=None,
|
1060
|
-
description="""Optional.
|
1203
|
+
description="""Optional. Auth config for the Google Maps tool.""",
|
1061
1204
|
)
|
1062
|
-
|
1205
|
+
|
1206
|
+
|
1207
|
+
class GoogleMapsDict(TypedDict, total=False):
|
1208
|
+
"""Tool to support Google Maps in Model."""
|
1209
|
+
|
1210
|
+
auth_config: Optional[AuthConfigDict]
|
1211
|
+
"""Optional. Auth config for the Google Maps tool."""
|
1212
|
+
|
1213
|
+
|
1214
|
+
GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]
|
1215
|
+
|
1216
|
+
|
1217
|
+
class VertexAISearch(_common.BaseModel):
|
1218
|
+
"""Retrieve from Vertex AI Search datastore or engine for grounding.
|
1219
|
+
|
1220
|
+
datastore and engine are mutually exclusive. See
|
1221
|
+
https://cloud.google.com/products/agent-builder
|
1222
|
+
"""
|
1223
|
+
|
1224
|
+
datastore: Optional[str] = Field(
|
1063
1225
|
default=None,
|
1064
|
-
description="""Optional.
|
1226
|
+
description="""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
|
1065
1227
|
)
|
1066
|
-
|
1228
|
+
engine: Optional[str] = Field(
|
1067
1229
|
default=None,
|
1068
|
-
description="""Optional.
|
1230
|
+
description="""Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`""",
|
1069
1231
|
)
|
1070
|
-
|
1232
|
+
|
1233
|
+
|
1234
|
+
class VertexAISearchDict(TypedDict, total=False):
|
1235
|
+
"""Retrieve from Vertex AI Search datastore or engine for grounding.
|
1236
|
+
|
1237
|
+
datastore and engine are mutually exclusive. See
|
1238
|
+
https://cloud.google.com/products/agent-builder
|
1239
|
+
"""
|
1240
|
+
|
1241
|
+
datastore: Optional[str]
|
1242
|
+
"""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
|
1243
|
+
|
1244
|
+
engine: Optional[str]
|
1245
|
+
"""Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`"""
|
1246
|
+
|
1247
|
+
|
1248
|
+
VertexAISearchOrDict = Union[VertexAISearch, VertexAISearchDict]
|
1249
|
+
|
1250
|
+
|
1251
|
+
class VertexRagStoreRagResource(_common.BaseModel):
|
1252
|
+
"""The definition of the Rag resource."""
|
1253
|
+
|
1254
|
+
rag_corpus: Optional[str] = Field(
|
1071
1255
|
default=None,
|
1072
|
-
description="""Optional.
|
1256
|
+
description="""Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`""",
|
1073
1257
|
)
|
1074
|
-
|
1258
|
+
rag_file_ids: Optional[list[str]] = Field(
|
1075
1259
|
default=None,
|
1076
|
-
description="""Optional. The
|
1260
|
+
description="""Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.""",
|
1077
1261
|
)
|
1078
|
-
|
1079
|
-
|
1262
|
+
|
1263
|
+
|
1264
|
+
class VertexRagStoreRagResourceDict(TypedDict, total=False):
|
1265
|
+
"""The definition of the Rag resource."""
|
1266
|
+
|
1267
|
+
rag_corpus: Optional[str]
|
1268
|
+
"""Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`"""
|
1269
|
+
|
1270
|
+
rag_file_ids: Optional[list[str]]
|
1271
|
+
"""Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field."""
|
1272
|
+
|
1273
|
+
|
1274
|
+
VertexRagStoreRagResourceOrDict = Union[
|
1275
|
+
VertexRagStoreRagResource, VertexRagStoreRagResourceDict
|
1276
|
+
]
|
1277
|
+
|
1278
|
+
|
1279
|
+
class RagRetrievalConfigFilter(_common.BaseModel):
|
1280
|
+
"""Config for filters."""
|
1281
|
+
|
1282
|
+
metadata_filter: Optional[str] = Field(
|
1283
|
+
default=None, description="""Optional. String for metadata filtering."""
|
1080
1284
|
)
|
1081
|
-
|
1285
|
+
vector_distance_threshold: Optional[float] = Field(
|
1082
1286
|
default=None,
|
1083
|
-
description="""Optional.
|
1287
|
+
description="""Optional. Only returns contexts with vector distance smaller than the threshold.""",
|
1084
1288
|
)
|
1085
|
-
|
1289
|
+
vector_similarity_threshold: Optional[float] = Field(
|
1086
1290
|
default=None,
|
1087
|
-
description="""Optional.
|
1291
|
+
description="""Optional. Only returns contexts with vector similarity larger than the threshold.""",
|
1088
1292
|
)
|
1089
|
-
|
1293
|
+
|
1294
|
+
|
1295
|
+
class RagRetrievalConfigFilterDict(TypedDict, total=False):
|
1296
|
+
"""Config for filters."""
|
1297
|
+
|
1298
|
+
metadata_filter: Optional[str]
|
1299
|
+
"""Optional. String for metadata filtering."""
|
1300
|
+
|
1301
|
+
vector_distance_threshold: Optional[float]
|
1302
|
+
"""Optional. Only returns contexts with vector distance smaller than the threshold."""
|
1303
|
+
|
1304
|
+
vector_similarity_threshold: Optional[float]
|
1305
|
+
"""Optional. Only returns contexts with vector similarity larger than the threshold."""
|
1306
|
+
|
1307
|
+
|
1308
|
+
RagRetrievalConfigFilterOrDict = Union[
|
1309
|
+
RagRetrievalConfigFilter, RagRetrievalConfigFilterDict
|
1310
|
+
]
|
1311
|
+
|
1312
|
+
|
1313
|
+
class RagRetrievalConfigHybridSearch(_common.BaseModel):
|
1314
|
+
"""Config for Hybrid Search."""
|
1315
|
+
|
1316
|
+
alpha: Optional[float] = Field(
|
1090
1317
|
default=None,
|
1091
|
-
description="""Optional.
|
1318
|
+
description="""Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally.""",
|
1092
1319
|
)
|
1093
|
-
|
1320
|
+
|
1321
|
+
|
1322
|
+
class RagRetrievalConfigHybridSearchDict(TypedDict, total=False):
|
1323
|
+
"""Config for Hybrid Search."""
|
1324
|
+
|
1325
|
+
alpha: Optional[float]
|
1326
|
+
"""Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally."""
|
1327
|
+
|
1328
|
+
|
1329
|
+
RagRetrievalConfigHybridSearchOrDict = Union[
|
1330
|
+
RagRetrievalConfigHybridSearch, RagRetrievalConfigHybridSearchDict
|
1331
|
+
]
|
1332
|
+
|
1333
|
+
|
1334
|
+
class RagRetrievalConfigRankingLlmRanker(_common.BaseModel):
|
1335
|
+
"""Config for LlmRanker."""
|
1336
|
+
|
1337
|
+
model_name: Optional[str] = Field(
|
1094
1338
|
default=None,
|
1095
|
-
description="""Optional.
|
1339
|
+
description="""Optional. The model name used for ranking. Format: `gemini-1.5-pro`""",
|
1096
1340
|
)
|
1097
|
-
|
1341
|
+
|
1342
|
+
|
1343
|
+
class RagRetrievalConfigRankingLlmRankerDict(TypedDict, total=False):
|
1344
|
+
"""Config for LlmRanker."""
|
1345
|
+
|
1346
|
+
model_name: Optional[str]
|
1347
|
+
"""Optional. The model name used for ranking. Format: `gemini-1.5-pro`"""
|
1348
|
+
|
1349
|
+
|
1350
|
+
RagRetrievalConfigRankingLlmRankerOrDict = Union[
|
1351
|
+
RagRetrievalConfigRankingLlmRanker, RagRetrievalConfigRankingLlmRankerDict
|
1352
|
+
]
|
1353
|
+
|
1354
|
+
|
1355
|
+
class RagRetrievalConfigRankingRankService(_common.BaseModel):
|
1356
|
+
"""Config for Rank Service."""
|
1357
|
+
|
1358
|
+
model_name: Optional[str] = Field(
|
1098
1359
|
default=None,
|
1099
|
-
description="""Optional.
|
1360
|
+
description="""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`""",
|
1100
1361
|
)
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1362
|
+
|
1363
|
+
|
1364
|
+
class RagRetrievalConfigRankingRankServiceDict(TypedDict, total=False):
|
1365
|
+
"""Config for Rank Service."""
|
1366
|
+
|
1367
|
+
model_name: Optional[str]
|
1368
|
+
"""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`"""
|
1369
|
+
|
1370
|
+
|
1371
|
+
RagRetrievalConfigRankingRankServiceOrDict = Union[
|
1372
|
+
RagRetrievalConfigRankingRankService,
|
1373
|
+
RagRetrievalConfigRankingRankServiceDict,
|
1374
|
+
]
|
1375
|
+
|
1376
|
+
|
1377
|
+
class RagRetrievalConfigRanking(_common.BaseModel):
|
1378
|
+
"""Config for ranking and reranking."""
|
1379
|
+
|
1380
|
+
llm_ranker: Optional[RagRetrievalConfigRankingLlmRanker] = Field(
|
1381
|
+
default=None, description="""Optional. Config for LlmRanker."""
|
1104
1382
|
)
|
1105
|
-
|
1106
|
-
default=None,
|
1107
|
-
description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
|
1383
|
+
rank_service: Optional[RagRetrievalConfigRankingRankService] = Field(
|
1384
|
+
default=None, description="""Optional. Config for Rank Service."""
|
1108
1385
|
)
|
1109
|
-
nullable: Optional[bool] = Field(
|
1110
|
-
default=None,
|
1111
|
-
description="""Optional. Indicates if the value may be null.""",
|
1112
|
-
)
|
1113
|
-
properties: Optional[dict[str, 'Schema']] = Field(
|
1114
|
-
default=None,
|
1115
|
-
description="""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.""",
|
1116
|
-
)
|
1117
|
-
property_ordering: Optional[list[str]] = Field(
|
1118
|
-
default=None,
|
1119
|
-
description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
|
1120
|
-
)
|
1121
|
-
required: Optional[list[str]] = Field(
|
1122
|
-
default=None,
|
1123
|
-
description="""Optional. Required properties of Type.OBJECT.""",
|
1124
|
-
)
|
1125
|
-
title: Optional[str] = Field(
|
1126
|
-
default=None, description="""Optional. The title of the Schema."""
|
1127
|
-
)
|
1128
|
-
type: Optional[Type] = Field(
|
1129
|
-
default=None, description="""Optional. The type of the data."""
|
1130
|
-
)
|
1131
|
-
|
1132
|
-
@property
|
1133
|
-
def json_schema(self) -> JSONSchema:
|
1134
|
-
"""Converts the Schema object to a JSONSchema object, that is compatible with 2020-12 JSON Schema draft.
|
1135
|
-
|
1136
|
-
If a Schema field is not supported by JSONSchema, it will be ignored.
|
1137
|
-
"""
|
1138
|
-
json_schema_field_names: set[str] = set(JSONSchema.model_fields.keys())
|
1139
|
-
schema_field_names: tuple[str] = (
|
1140
|
-
'items',
|
1141
|
-
) # 'additional_properties' to come
|
1142
|
-
list_schema_field_names: tuple[str] = (
|
1143
|
-
'any_of', # 'one_of', 'all_of', 'not' to come
|
1144
|
-
)
|
1145
|
-
dict_schema_field_names: tuple[str] = ('properties',) # 'defs' to come
|
1146
|
-
|
1147
|
-
def convert_schema(schema: Union['Schema', dict[str, Any]]) -> JSONSchema:
|
1148
|
-
if isinstance(schema, pydantic.BaseModel):
|
1149
|
-
schema_dict = schema.model_dump()
|
1150
|
-
else:
|
1151
|
-
schema_dict = schema
|
1152
|
-
json_schema = JSONSchema()
|
1153
|
-
for field_name, field_value in schema_dict.items():
|
1154
|
-
if field_value is None:
|
1155
|
-
continue
|
1156
|
-
elif field_name == 'nullable':
|
1157
|
-
json_schema.type = JSONSchemaType.NULL
|
1158
|
-
elif field_name not in json_schema_field_names:
|
1159
|
-
continue
|
1160
|
-
elif field_name == 'type':
|
1161
|
-
if field_value == Type.TYPE_UNSPECIFIED:
|
1162
|
-
continue
|
1163
|
-
json_schema_type = JSONSchemaType(field_value.lower())
|
1164
|
-
if json_schema.type is None:
|
1165
|
-
json_schema.type = json_schema_type
|
1166
|
-
elif isinstance(json_schema.type, JSONSchemaType):
|
1167
|
-
existing_type: JSONSchemaType = json_schema.type
|
1168
|
-
json_schema.type = [existing_type, json_schema_type]
|
1169
|
-
elif isinstance(json_schema.type, list):
|
1170
|
-
json_schema.type.append(json_schema_type)
|
1171
|
-
elif field_name in schema_field_names:
|
1172
|
-
schema_field_value: 'JSONSchema' = convert_schema(field_value)
|
1173
|
-
setattr(json_schema, field_name, schema_field_value)
|
1174
|
-
elif field_name in list_schema_field_names:
|
1175
|
-
list_schema_field_value: list['JSONSchema'] = [
|
1176
|
-
convert_schema(this_field_value)
|
1177
|
-
for this_field_value in field_value
|
1178
|
-
]
|
1179
|
-
setattr(json_schema, field_name, list_schema_field_value)
|
1180
|
-
elif field_name in dict_schema_field_names:
|
1181
|
-
dict_schema_field_value: dict[str, 'JSONSchema'] = {
|
1182
|
-
key: convert_schema(value) for key, value in field_value.items()
|
1183
|
-
}
|
1184
|
-
setattr(json_schema, field_name, dict_schema_field_value)
|
1185
|
-
else:
|
1186
|
-
setattr(json_schema, field_name, field_value)
|
1187
|
-
|
1188
|
-
return json_schema
|
1189
|
-
|
1190
|
-
return convert_schema(self)
|
1191
|
-
|
1192
|
-
@classmethod
|
1193
|
-
def from_json_schema(
|
1194
|
-
cls,
|
1195
|
-
*,
|
1196
|
-
json_schema: JSONSchema,
|
1197
|
-
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
1198
|
-
raise_error_on_unsupported_field: bool = False,
|
1199
|
-
) -> 'Schema':
|
1200
|
-
"""Converts a JSONSchema object to a Schema object.
|
1201
|
-
|
1202
|
-
The JSONSchema is compatible with 2020-12 JSON Schema draft, specified by
|
1203
|
-
OpenAPI 3.1.
|
1204
|
-
|
1205
|
-
Args:
|
1206
|
-
json_schema: JSONSchema object to be converted.
|
1207
|
-
api_option: API option to be used. If set to 'VERTEX_AI', the JSONSchema
|
1208
|
-
will be converted to a Schema object that is compatible with Vertex AI
|
1209
|
-
API. If set to 'GEMINI_API', the JSONSchema will be converted to a
|
1210
|
-
Schema object that is compatible with Gemini API. Default is
|
1211
|
-
'GEMINI_API'.
|
1212
|
-
raise_error_on_unsupported_field: If set to True, an error will be
|
1213
|
-
raised if the JSONSchema contains any unsupported fields. Default is
|
1214
|
-
False.
|
1215
|
-
|
1216
|
-
Returns:
|
1217
|
-
Schema object that is compatible with the specified API option.
|
1218
|
-
Raises:
|
1219
|
-
ValueError: If the JSONSchema contains any unsupported fields and
|
1220
|
-
raise_error_on_unsupported_field is set to True. Or if the JSONSchema
|
1221
|
-
is not compatible with the specified API option.
|
1222
|
-
"""
|
1223
|
-
google_schema_field_names: set[str] = set(cls.model_fields.keys())
|
1224
|
-
schema_field_names: tuple[str, ...] = (
|
1225
|
-
'items',
|
1226
|
-
) # 'additional_properties' to come
|
1227
|
-
list_schema_field_names: tuple[str, ...] = (
|
1228
|
-
'any_of', # 'one_of', 'all_of', 'not' to come
|
1229
|
-
)
|
1230
|
-
dict_schema_field_names: tuple[str, ...] = ('properties',) # 'defs' to come
|
1231
|
-
|
1232
|
-
number_integer_related_field_names: tuple[str, ...] = (
|
1233
|
-
'description',
|
1234
|
-
'enum',
|
1235
|
-
'format',
|
1236
|
-
'maximum',
|
1237
|
-
'minimum',
|
1238
|
-
'title',
|
1239
|
-
)
|
1240
|
-
string_related_field_names: tuple[str, ...] = (
|
1241
|
-
'description',
|
1242
|
-
'enum',
|
1243
|
-
'format',
|
1244
|
-
'max_length',
|
1245
|
-
'min_length',
|
1246
|
-
'pattern',
|
1247
|
-
'title',
|
1248
|
-
)
|
1249
|
-
object_related_field_names: tuple[str, ...] = (
|
1250
|
-
'any_of',
|
1251
|
-
'description',
|
1252
|
-
'max_properties',
|
1253
|
-
'min_properties',
|
1254
|
-
'properties',
|
1255
|
-
'required',
|
1256
|
-
'title',
|
1257
|
-
)
|
1258
|
-
array_related_field_names: tuple[str, ...] = (
|
1259
|
-
'description',
|
1260
|
-
'items',
|
1261
|
-
'max_items',
|
1262
|
-
'min_items',
|
1263
|
-
'title',
|
1264
|
-
)
|
1265
|
-
boolean_related_field_names: tuple[str, ...] = (
|
1266
|
-
'description',
|
1267
|
-
'title',
|
1268
|
-
)
|
1269
|
-
# placeholder for potential gemini api unsupported fields
|
1270
|
-
gemini_api_unsupported_field_names: tuple[str, ...] = ()
|
1271
|
-
|
1272
|
-
def normalize_json_schema_type(
|
1273
|
-
json_schema_type: Optional[
|
1274
|
-
Union[JSONSchemaType, Sequence[JSONSchemaType], str, Sequence[str]]
|
1275
|
-
],
|
1276
|
-
) -> tuple[list[str], bool]:
|
1277
|
-
"""Returns (non_null_types, nullable)"""
|
1278
|
-
if json_schema_type is None:
|
1279
|
-
return [], False
|
1280
|
-
if isinstance(json_schema_type, str):
|
1281
|
-
if json_schema_type == JSONSchemaType.NULL.value:
|
1282
|
-
return [], True
|
1283
|
-
return [json_schema_type], False
|
1284
|
-
if isinstance(json_schema_type, JSONSchemaType):
|
1285
|
-
if json_schema_type == JSONSchemaType.NULL:
|
1286
|
-
return [], True
|
1287
|
-
return [json_schema_type.value], False
|
1288
|
-
non_null_types = []
|
1289
|
-
nullable = False
|
1290
|
-
for type_value in json_schema_type:
|
1291
|
-
if isinstance(type_value, JSONSchemaType):
|
1292
|
-
type_value = type_value.value
|
1293
|
-
if type_value == JSONSchemaType.NULL.value:
|
1294
|
-
nullable = True
|
1295
|
-
else:
|
1296
|
-
non_null_types.append(type_value)
|
1297
|
-
return non_null_types, nullable
|
1298
|
-
|
1299
|
-
def raise_error_if_cannot_convert(
|
1300
|
-
json_schema_dict: dict[str, Any],
|
1301
|
-
api_option: Literal['VERTEX_AI', 'GEMINI_API'],
|
1302
|
-
raise_error_on_unsupported_field: bool,
|
1303
|
-
) -> None:
|
1304
|
-
"""Raises an error if the JSONSchema cannot be converted to the specified Schema object."""
|
1305
|
-
if not raise_error_on_unsupported_field:
|
1306
|
-
return
|
1307
|
-
for field_name, field_value in json_schema_dict.items():
|
1308
|
-
if field_value is None:
|
1309
|
-
continue
|
1310
|
-
if field_name not in google_schema_field_names:
|
1311
|
-
raise ValueError((
|
1312
|
-
f'JSONSchema field "{field_name}" is not supported by the '
|
1313
|
-
'Schema object. And the "raise_error_on_unsupported_field" '
|
1314
|
-
'argument is set to True. If you still want to convert '
|
1315
|
-
'it into the Schema object, please either remove the field '
|
1316
|
-
f'"{field_name}" from the JSONSchema object, or leave the '
|
1317
|
-
'"raise_error_on_unsupported_field" unset.'
|
1318
|
-
))
|
1319
|
-
if (
|
1320
|
-
field_name in gemini_api_unsupported_field_names
|
1321
|
-
and api_option == 'GEMINI_API'
|
1322
|
-
):
|
1323
|
-
raise ValueError((
|
1324
|
-
f'The "{field_name}" field is not supported by the Schema '
|
1325
|
-
'object for GEMINI_API.'
|
1326
|
-
))
|
1327
|
-
|
1328
|
-
def copy_schema_fields(
|
1329
|
-
json_schema_dict: dict[str, Any],
|
1330
|
-
related_fields_to_copy: tuple[str, ...],
|
1331
|
-
sub_schema_in_any_of: dict[str, Any],
|
1332
|
-
) -> None:
|
1333
|
-
"""Copies the fields from json_schema_dict to sub_schema_in_any_of."""
|
1334
|
-
for field_name in related_fields_to_copy:
|
1335
|
-
sub_schema_in_any_of[field_name] = json_schema_dict.get(
|
1336
|
-
field_name, None
|
1337
|
-
)
|
1338
|
-
|
1339
|
-
def convert_json_schema(
|
1340
|
-
json_schema: JSONSchema,
|
1341
|
-
api_option: Literal['VERTEX_AI', 'GEMINI_API'],
|
1342
|
-
raise_error_on_unsupported_field: bool,
|
1343
|
-
) -> 'Schema':
|
1344
|
-
schema = Schema()
|
1345
|
-
json_schema_dict = json_schema.model_dump()
|
1346
|
-
raise_error_if_cannot_convert(
|
1347
|
-
json_schema_dict=json_schema_dict,
|
1348
|
-
api_option=api_option,
|
1349
|
-
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
1350
|
-
)
|
1351
|
-
|
1352
|
-
# At the highest level of the logic, there are two passes:
|
1353
|
-
# Pass 1: the JSONSchema.type is union-like,
|
1354
|
-
# e.g. ['null', 'string', 'array'].
|
1355
|
-
# for this case, we need to split the JSONSchema into multiple
|
1356
|
-
# sub-schemas, and copy them into the any_of field of the Schema.
|
1357
|
-
# And when we copy the non-type fields into any_of field,
|
1358
|
-
# we only copy the fields related to the specific type.
|
1359
|
-
# Detailed logic is commented below with `Pass 1` keyword tag.
|
1360
|
-
# Pass 2: the JSONSchema.type is not union-like,
|
1361
|
-
# e.g. 'string', ['string'], ['null', 'string'].
|
1362
|
-
# for this case, no splitting is needed. Detailed
|
1363
|
-
# logic is commented below with `Pass 2` keyword tag.
|
1364
|
-
#
|
1365
|
-
#
|
1366
|
-
# Pass 1: the JSONSchema.type is union-like
|
1367
|
-
# e.g. ['null', 'string', 'array'].
|
1368
|
-
non_null_types, nullable = normalize_json_schema_type(
|
1369
|
-
json_schema_dict.get('type', None)
|
1370
|
-
)
|
1371
|
-
if len(non_null_types) > 1:
|
1372
|
-
logger.warning(
|
1373
|
-
'JSONSchema type is union-like, e.g. ["null", "string", "array"]. '
|
1374
|
-
'Converting it into multiple sub-schemas, and copying them into '
|
1375
|
-
'the any_of field of the Schema. The value of `default` field is '
|
1376
|
-
'ignored because it is ambiguous to tell which sub-schema it '
|
1377
|
-
'belongs to.'
|
1378
|
-
)
|
1379
|
-
reformed_json_schema = JSONSchema()
|
1380
|
-
# start splitting the JSONSchema into multiple sub-schemas
|
1381
|
-
any_of = []
|
1382
|
-
if nullable:
|
1383
|
-
schema.nullable = True
|
1384
|
-
for normalized_type in non_null_types:
|
1385
|
-
sub_schema_in_any_of = {'type': normalized_type}
|
1386
|
-
if normalized_type == JSONSchemaType.BOOLEAN.value:
|
1387
|
-
copy_schema_fields(
|
1388
|
-
json_schema_dict=json_schema_dict,
|
1389
|
-
related_fields_to_copy=boolean_related_field_names,
|
1390
|
-
sub_schema_in_any_of=sub_schema_in_any_of,
|
1391
|
-
)
|
1392
|
-
elif normalized_type in (
|
1393
|
-
JSONSchemaType.NUMBER.value,
|
1394
|
-
JSONSchemaType.INTEGER.value,
|
1395
|
-
):
|
1396
|
-
copy_schema_fields(
|
1397
|
-
json_schema_dict=json_schema_dict,
|
1398
|
-
related_fields_to_copy=number_integer_related_field_names,
|
1399
|
-
sub_schema_in_any_of=sub_schema_in_any_of,
|
1400
|
-
)
|
1401
|
-
elif normalized_type == JSONSchemaType.STRING.value:
|
1402
|
-
copy_schema_fields(
|
1403
|
-
json_schema_dict=json_schema_dict,
|
1404
|
-
related_fields_to_copy=string_related_field_names,
|
1405
|
-
sub_schema_in_any_of=sub_schema_in_any_of,
|
1406
|
-
)
|
1407
|
-
elif normalized_type == JSONSchemaType.ARRAY.value:
|
1408
|
-
copy_schema_fields(
|
1409
|
-
json_schema_dict=json_schema_dict,
|
1410
|
-
related_fields_to_copy=array_related_field_names,
|
1411
|
-
sub_schema_in_any_of=sub_schema_in_any_of,
|
1412
|
-
)
|
1413
|
-
elif normalized_type == JSONSchemaType.OBJECT.value:
|
1414
|
-
copy_schema_fields(
|
1415
|
-
json_schema_dict=json_schema_dict,
|
1416
|
-
related_fields_to_copy=object_related_field_names,
|
1417
|
-
sub_schema_in_any_of=sub_schema_in_any_of,
|
1418
|
-
)
|
1419
|
-
any_of.append(JSONSchema(**sub_schema_in_any_of))
|
1420
|
-
reformed_json_schema.any_of = any_of
|
1421
|
-
json_schema_dict = reformed_json_schema.model_dump()
|
1422
|
-
|
1423
|
-
# Pass 2: the JSONSchema.type is not union-like,
|
1424
|
-
# e.g. 'string', ['string'], ['null', 'string'].
|
1425
|
-
for field_name, field_value in json_schema_dict.items():
|
1426
|
-
if field_value is None:
|
1427
|
-
continue
|
1428
|
-
if field_name in schema_field_names:
|
1429
|
-
schema_field_value: 'Schema' = convert_json_schema(
|
1430
|
-
json_schema=JSONSchema(**field_value),
|
1431
|
-
api_option=api_option,
|
1432
|
-
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
1433
|
-
)
|
1434
|
-
setattr(schema, field_name, schema_field_value)
|
1435
|
-
elif field_name in list_schema_field_names:
|
1436
|
-
list_schema_field_value: list['Schema'] = [
|
1437
|
-
convert_json_schema(
|
1438
|
-
json_schema=JSONSchema(**this_field_value),
|
1439
|
-
api_option=api_option,
|
1440
|
-
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
1441
|
-
)
|
1442
|
-
for this_field_value in field_value
|
1443
|
-
]
|
1444
|
-
setattr(schema, field_name, list_schema_field_value)
|
1445
|
-
elif field_name in dict_schema_field_names:
|
1446
|
-
dict_schema_field_value: dict[str, 'Schema'] = {
|
1447
|
-
key: convert_json_schema(
|
1448
|
-
json_schema=JSONSchema(**value),
|
1449
|
-
api_option=api_option,
|
1450
|
-
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
1451
|
-
)
|
1452
|
-
for key, value in field_value.items()
|
1453
|
-
}
|
1454
|
-
setattr(schema, field_name, dict_schema_field_value)
|
1455
|
-
elif field_name == 'type':
|
1456
|
-
# non_null_types can only be empty or have one element.
|
1457
|
-
# because already handled union-like case above.
|
1458
|
-
non_null_types, nullable = normalize_json_schema_type(field_value)
|
1459
|
-
if nullable:
|
1460
|
-
schema.nullable = True
|
1461
|
-
if non_null_types:
|
1462
|
-
schema.type = Type(non_null_types[0])
|
1463
|
-
else:
|
1464
|
-
setattr(schema, field_name, field_value)
|
1465
|
-
|
1466
|
-
return schema
|
1467
|
-
|
1468
|
-
return convert_json_schema(
|
1469
|
-
json_schema=json_schema,
|
1470
|
-
api_option=api_option,
|
1471
|
-
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
1472
|
-
)
|
1473
|
-
|
1474
|
-
|
1475
|
-
class SchemaDict(TypedDict, total=False):
|
1476
|
-
"""Schema that defines the format of input and output data.
|
1477
|
-
|
1478
|
-
Represents a select subset of an OpenAPI 3.0 schema object.
|
1479
|
-
"""
|
1480
|
-
|
1481
|
-
example: Optional[Any]
|
1482
|
-
"""Optional. Example of the object. Will only populated when the object is the root."""
|
1483
|
-
|
1484
|
-
pattern: Optional[str]
|
1485
|
-
"""Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
|
1486
|
-
|
1487
|
-
default: Optional[Any]
|
1488
|
-
"""Optional. Default value of the data."""
|
1489
|
-
|
1490
|
-
max_length: Optional[int]
|
1491
|
-
"""Optional. Maximum length of the Type.STRING"""
|
1492
|
-
|
1493
|
-
min_length: Optional[int]
|
1494
|
-
"""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING"""
|
1495
|
-
|
1496
|
-
min_properties: Optional[int]
|
1497
|
-
"""Optional. Minimum number of the properties for Type.OBJECT."""
|
1498
|
-
|
1499
|
-
max_properties: Optional[int]
|
1500
|
-
"""Optional. Maximum number of the properties for Type.OBJECT."""
|
1501
|
-
|
1502
|
-
any_of: Optional[list['SchemaDict']]
|
1503
|
-
"""Optional. The value should be validated against any (one or more) of the subschemas in the list."""
|
1504
|
-
|
1505
|
-
description: Optional[str]
|
1506
|
-
"""Optional. The description of the data."""
|
1507
|
-
|
1508
|
-
enum: Optional[list[str]]
|
1509
|
-
"""Optional. Possible values of the element of primitive type with enum format. Examples: 1. We can define direction as : {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]} 2. We can define apartment number as : {type:INTEGER, format:enum, enum:["101", "201", "301"]}"""
|
1510
|
-
|
1511
|
-
format: Optional[str]
|
1512
|
-
"""Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc"""
|
1513
|
-
|
1514
|
-
items: Optional['SchemaDict']
|
1515
|
-
"""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY."""
|
1516
|
-
|
1517
|
-
max_items: Optional[int]
|
1518
|
-
"""Optional. Maximum number of the elements for Type.ARRAY."""
|
1519
|
-
|
1520
|
-
maximum: Optional[float]
|
1521
|
-
"""Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
|
1522
|
-
|
1523
|
-
min_items: Optional[int]
|
1524
|
-
"""Optional. Minimum number of the elements for Type.ARRAY."""
|
1525
|
-
|
1526
|
-
minimum: Optional[float]
|
1527
|
-
"""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
|
1528
|
-
|
1529
|
-
nullable: Optional[bool]
|
1530
|
-
"""Optional. Indicates if the value may be null."""
|
1531
|
-
|
1532
|
-
properties: Optional[dict[str, 'SchemaDict']]
|
1533
|
-
"""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT."""
|
1534
|
-
|
1535
|
-
property_ordering: Optional[list[str]]
|
1536
|
-
"""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
|
1537
|
-
|
1538
|
-
required: Optional[list[str]]
|
1539
|
-
"""Optional. Required properties of Type.OBJECT."""
|
1540
|
-
|
1541
|
-
title: Optional[str]
|
1542
|
-
"""Optional. The title of the Schema."""
|
1543
|
-
|
1544
|
-
type: Optional[Type]
|
1545
|
-
"""Optional. The type of the data."""
|
1546
1386
|
|
1547
1387
|
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
class ModelSelectionConfig(_common.BaseModel):
|
1552
|
-
"""Config for model selection."""
|
1553
|
-
|
1554
|
-
feature_selection_preference: Optional[FeatureSelectionPreference] = Field(
|
1555
|
-
default=None, description="""Options for feature selection preference."""
|
1556
|
-
)
|
1557
|
-
|
1388
|
+
class RagRetrievalConfigRankingDict(TypedDict, total=False):
|
1389
|
+
"""Config for ranking and reranking."""
|
1558
1390
|
|
1559
|
-
|
1560
|
-
"""Config for
|
1391
|
+
llm_ranker: Optional[RagRetrievalConfigRankingLlmRankerDict]
|
1392
|
+
"""Optional. Config for LlmRanker."""
|
1561
1393
|
|
1562
|
-
|
1563
|
-
"""
|
1394
|
+
rank_service: Optional[RagRetrievalConfigRankingRankServiceDict]
|
1395
|
+
"""Optional. Config for Rank Service."""
|
1564
1396
|
|
1565
1397
|
|
1566
|
-
|
1567
|
-
|
1398
|
+
RagRetrievalConfigRankingOrDict = Union[
|
1399
|
+
RagRetrievalConfigRanking, RagRetrievalConfigRankingDict
|
1568
1400
|
]
|
1569
1401
|
|
1570
1402
|
|
1571
|
-
class
|
1572
|
-
"""
|
1403
|
+
class RagRetrievalConfig(_common.BaseModel):
|
1404
|
+
"""Specifies the context retrieval config."""
|
1573
1405
|
|
1574
|
-
|
1575
|
-
default=None,
|
1576
|
-
description="""Determines if the harm block method uses probability or probability
|
1577
|
-
and severity scores.""",
|
1406
|
+
filter: Optional[RagRetrievalConfigFilter] = Field(
|
1407
|
+
default=None, description="""Optional. Config for filters."""
|
1578
1408
|
)
|
1579
|
-
|
1580
|
-
default=None, description="""
|
1409
|
+
hybrid_search: Optional[RagRetrievalConfigHybridSearch] = Field(
|
1410
|
+
default=None, description="""Optional. Config for Hybrid Search."""
|
1581
1411
|
)
|
1582
|
-
|
1583
|
-
default=None,
|
1412
|
+
ranking: Optional[RagRetrievalConfigRanking] = Field(
|
1413
|
+
default=None,
|
1414
|
+
description="""Optional. Config for ranking and reranking.""",
|
1415
|
+
)
|
1416
|
+
top_k: Optional[int] = Field(
|
1417
|
+
default=None,
|
1418
|
+
description="""Optional. The number of contexts to retrieve.""",
|
1584
1419
|
)
|
1585
1420
|
|
1586
1421
|
|
1587
|
-
class
|
1588
|
-
"""
|
1422
|
+
class RagRetrievalConfigDict(TypedDict, total=False):
|
1423
|
+
"""Specifies the context retrieval config."""
|
1589
1424
|
|
1590
|
-
|
1591
|
-
"""
|
1592
|
-
and severity scores."""
|
1425
|
+
filter: Optional[RagRetrievalConfigFilterDict]
|
1426
|
+
"""Optional. Config for filters."""
|
1593
1427
|
|
1594
|
-
|
1595
|
-
"""
|
1428
|
+
hybrid_search: Optional[RagRetrievalConfigHybridSearchDict]
|
1429
|
+
"""Optional. Config for Hybrid Search."""
|
1596
1430
|
|
1597
|
-
|
1598
|
-
"""
|
1431
|
+
ranking: Optional[RagRetrievalConfigRankingDict]
|
1432
|
+
"""Optional. Config for ranking and reranking."""
|
1599
1433
|
|
1434
|
+
top_k: Optional[int]
|
1435
|
+
"""Optional. The number of contexts to retrieve."""
|
1600
1436
|
|
1601
|
-
SafetySettingOrDict = Union[SafetySetting, SafetySettingDict]
|
1602
1437
|
|
1438
|
+
RagRetrievalConfigOrDict = Union[RagRetrievalConfig, RagRetrievalConfigDict]
|
1603
1439
|
|
1604
|
-
class FunctionDeclaration(_common.BaseModel):
|
1605
|
-
"""Defines a function that the model can generate JSON inputs for.
|
1606
1440
|
|
1607
|
-
|
1608
|
-
|
1609
|
-
"""
|
1441
|
+
class VertexRagStore(_common.BaseModel):
|
1442
|
+
"""Retrieve from Vertex RAG Store for grounding."""
|
1610
1443
|
|
1611
|
-
|
1444
|
+
rag_corpora: Optional[list[str]] = Field(
|
1612
1445
|
default=None,
|
1613
|
-
description="""
|
1614
|
-
Object format.""",
|
1446
|
+
description="""Optional. Deprecated. Please use rag_resources instead.""",
|
1615
1447
|
)
|
1616
|
-
|
1448
|
+
rag_resources: Optional[list[VertexRagStoreRagResource]] = Field(
|
1617
1449
|
default=None,
|
1618
|
-
description="""Optional.
|
1450
|
+
description="""Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support.""",
|
1619
1451
|
)
|
1620
|
-
|
1452
|
+
rag_retrieval_config: Optional[RagRetrievalConfig] = Field(
|
1621
1453
|
default=None,
|
1622
|
-
description="""
|
1454
|
+
description="""Optional. The retrieval config for the Rag query.""",
|
1623
1455
|
)
|
1624
|
-
|
1456
|
+
similarity_top_k: Optional[int] = Field(
|
1625
1457
|
default=None,
|
1626
|
-
description="""Optional.
|
1458
|
+
description="""Optional. Number of top k results to return from the selected corpora.""",
|
1459
|
+
)
|
1460
|
+
vector_distance_threshold: Optional[float] = Field(
|
1461
|
+
default=None,
|
1462
|
+
description="""Optional. Only return results with vector distance smaller than the threshold.""",
|
1627
1463
|
)
|
1628
1464
|
|
1629
|
-
@classmethod
|
1630
|
-
def from_callable_with_api_option(
|
1631
|
-
cls,
|
1632
|
-
*,
|
1633
|
-
callable: Callable[..., Any],
|
1634
|
-
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
1635
|
-
) -> 'FunctionDeclaration':
|
1636
|
-
"""Converts a Callable to a FunctionDeclaration based on the API option.
|
1637
1465
|
|
1638
|
-
|
1639
|
-
|
1640
|
-
will raise ValueError.
|
1641
|
-
"""
|
1642
|
-
supported_api_options = ['VERTEX_AI', 'GEMINI_API']
|
1643
|
-
if api_option not in supported_api_options:
|
1644
|
-
raise ValueError(
|
1645
|
-
f'Unsupported api_option value: {api_option}. Supported api_option'
|
1646
|
-
f' value is one of: {supported_api_options}.'
|
1647
|
-
)
|
1648
|
-
from . import _automatic_function_calling_util
|
1466
|
+
class VertexRagStoreDict(TypedDict, total=False):
|
1467
|
+
"""Retrieve from Vertex RAG Store for grounding."""
|
1649
1468
|
|
1650
|
-
|
1651
|
-
|
1652
|
-
if param.kind in (
|
1653
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
1654
|
-
inspect.Parameter.KEYWORD_ONLY,
|
1655
|
-
inspect.Parameter.POSITIONAL_ONLY,
|
1656
|
-
):
|
1657
|
-
schema = _automatic_function_calling_util._parse_schema_from_parameter(
|
1658
|
-
api_option, param, callable.__name__
|
1659
|
-
)
|
1660
|
-
parameters_properties[name] = schema
|
1661
|
-
declaration = FunctionDeclaration(
|
1662
|
-
name=callable.__name__,
|
1663
|
-
description=callable.__doc__,
|
1664
|
-
)
|
1665
|
-
if parameters_properties:
|
1666
|
-
declaration.parameters = Schema(
|
1667
|
-
type='OBJECT',
|
1668
|
-
properties=parameters_properties,
|
1669
|
-
)
|
1670
|
-
declaration.parameters.required = (
|
1671
|
-
_automatic_function_calling_util._get_required_fields(
|
1672
|
-
declaration.parameters
|
1673
|
-
)
|
1674
|
-
)
|
1675
|
-
if api_option == 'GEMINI_API':
|
1676
|
-
return declaration
|
1469
|
+
rag_corpora: Optional[list[str]]
|
1470
|
+
"""Optional. Deprecated. Please use rag_resources instead."""
|
1677
1471
|
|
1678
|
-
|
1679
|
-
|
1680
|
-
return declaration
|
1472
|
+
rag_resources: Optional[list[VertexRagStoreRagResourceDict]]
|
1473
|
+
"""Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support."""
|
1681
1474
|
|
1682
|
-
|
1683
|
-
|
1684
|
-
api_option,
|
1685
|
-
inspect.Parameter(
|
1686
|
-
'return_value',
|
1687
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
1688
|
-
annotation=return_annotation,
|
1689
|
-
),
|
1690
|
-
callable.__name__,
|
1691
|
-
)
|
1692
|
-
)
|
1693
|
-
return declaration
|
1475
|
+
rag_retrieval_config: Optional[RagRetrievalConfigDict]
|
1476
|
+
"""Optional. The retrieval config for the Rag query."""
|
1694
1477
|
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
if client.vertexai:
|
1704
|
-
return cls.from_callable_with_api_option(
|
1705
|
-
callable=callable, api_option='VERTEX_AI'
|
1706
|
-
)
|
1707
|
-
else:
|
1708
|
-
return cls.from_callable_with_api_option(
|
1709
|
-
callable=callable, api_option='GEMINI_API'
|
1710
|
-
)
|
1478
|
+
similarity_top_k: Optional[int]
|
1479
|
+
"""Optional. Number of top k results to return from the selected corpora."""
|
1480
|
+
|
1481
|
+
vector_distance_threshold: Optional[float]
|
1482
|
+
"""Optional. Only return results with vector distance smaller than the threshold."""
|
1483
|
+
|
1484
|
+
|
1485
|
+
VertexRagStoreOrDict = Union[VertexRagStore, VertexRagStoreDict]
|
1711
1486
|
|
1712
1487
|
|
1713
|
-
class
|
1714
|
-
"""Defines a
|
1488
|
+
class Retrieval(_common.BaseModel):
|
1489
|
+
"""Defines a retrieval tool that model can call to access external knowledge."""
|
1490
|
+
|
1491
|
+
disable_attribution: Optional[bool] = Field(
|
1492
|
+
default=None,
|
1493
|
+
description="""Optional. Deprecated. This option is no longer supported.""",
|
1494
|
+
)
|
1495
|
+
vertex_ai_search: Optional[VertexAISearch] = Field(
|
1496
|
+
default=None,
|
1497
|
+
description="""Set to use data source powered by Vertex AI Search.""",
|
1498
|
+
)
|
1499
|
+
vertex_rag_store: Optional[VertexRagStore] = Field(
|
1500
|
+
default=None,
|
1501
|
+
description="""Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService.""",
|
1502
|
+
)
|
1503
|
+
|
1715
1504
|
|
1716
|
-
|
1717
|
-
|
1718
|
-
"""
|
1505
|
+
class RetrievalDict(TypedDict, total=False):
|
1506
|
+
"""Defines a retrieval tool that model can call to access external knowledge."""
|
1719
1507
|
|
1720
|
-
|
1721
|
-
"""
|
1722
|
-
Object format."""
|
1508
|
+
disable_attribution: Optional[bool]
|
1509
|
+
"""Optional. Deprecated. This option is no longer supported."""
|
1723
1510
|
|
1724
|
-
|
1725
|
-
"""
|
1511
|
+
vertex_ai_search: Optional[VertexAISearchDict]
|
1512
|
+
"""Set to use data source powered by Vertex AI Search."""
|
1726
1513
|
|
1727
|
-
|
1728
|
-
"""
|
1514
|
+
vertex_rag_store: Optional[VertexRagStoreDict]
|
1515
|
+
"""Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService."""
|
1729
1516
|
|
1730
|
-
parameters: Optional[SchemaDict]
|
1731
|
-
"""Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1"""
|
1732
1517
|
|
1518
|
+
RetrievalOrDict = Union[Retrieval, RetrievalDict]
|
1733
1519
|
|
1734
|
-
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
|
1735
1520
|
|
1521
|
+
class ToolCodeExecution(_common.BaseModel):
|
1522
|
+
"""Tool that executes code generated by the model, and automatically returns the result to the model.
|
1736
1523
|
|
1737
|
-
|
1738
|
-
|
1524
|
+
See also [ExecutableCode]and [CodeExecutionResult] which are input and output
|
1525
|
+
to this tool.
|
1526
|
+
"""
|
1739
1527
|
|
1740
1528
|
pass
|
1741
1529
|
|
1742
1530
|
|
1743
|
-
class
|
1744
|
-
"""Tool
|
1531
|
+
class ToolCodeExecutionDict(TypedDict, total=False):
|
1532
|
+
"""Tool that executes code generated by the model, and automatically returns the result to the model.
|
1533
|
+
|
1534
|
+
See also [ExecutableCode]and [CodeExecutionResult] which are input and output
|
1535
|
+
to this tool.
|
1536
|
+
"""
|
1745
1537
|
|
1746
1538
|
pass
|
1747
1539
|
|
1748
1540
|
|
1749
|
-
|
1541
|
+
ToolCodeExecutionOrDict = Union[ToolCodeExecution, ToolCodeExecutionDict]
|
1750
1542
|
|
1751
1543
|
|
1752
|
-
class
|
1753
|
-
"""
|
1544
|
+
class JSONSchemaType(Enum):
|
1545
|
+
"""The type of the data supported by JSON Schema.
|
1754
1546
|
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
)
|
1759
|
-
dynamic_threshold: Optional[float] = Field(
|
1760
|
-
default=None,
|
1761
|
-
description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
|
1762
|
-
)
|
1547
|
+
The values of the enums are lower case strings, while the values of the enums
|
1548
|
+
for the Type class are upper case strings.
|
1549
|
+
"""
|
1763
1550
|
|
1551
|
+
NULL = 'null'
|
1552
|
+
BOOLEAN = 'boolean'
|
1553
|
+
OBJECT = 'object'
|
1554
|
+
ARRAY = 'array'
|
1555
|
+
NUMBER = 'number'
|
1556
|
+
INTEGER = 'integer'
|
1557
|
+
STRING = 'string'
|
1764
1558
|
|
1765
|
-
class DynamicRetrievalConfigDict(TypedDict, total=False):
|
1766
|
-
"""Describes the options to customize dynamic retrieval."""
|
1767
1559
|
|
1768
|
-
|
1769
|
-
"""
|
1560
|
+
class JSONSchema(pydantic.BaseModel):
|
1561
|
+
"""A subset of JSON Schema according to 2020-12 JSON Schema draft.
|
1770
1562
|
|
1771
|
-
|
1772
|
-
|
1563
|
+
Represents a subset of a JSON Schema object that is used by the Gemini model.
|
1564
|
+
The difference between this class and the Schema class is that this class is
|
1565
|
+
compatible with OpenAPI 3.1 schema objects. And the Schema class is used to
|
1566
|
+
make API call to Gemini model.
|
1567
|
+
"""
|
1773
1568
|
|
1569
|
+
type: Optional[Union[JSONSchemaType, list[JSONSchemaType]]] = Field(
|
1570
|
+
default=None,
|
1571
|
+
description="""Validation succeeds if the type of the instance matches the type represented by the given type, or matches at least one of the given types.""",
|
1572
|
+
)
|
1573
|
+
format: Optional[str] = Field(
|
1574
|
+
default=None,
|
1575
|
+
description='Define semantic information about a string instance.',
|
1576
|
+
)
|
1577
|
+
title: Optional[str] = Field(
|
1578
|
+
default=None,
|
1579
|
+
description=(
|
1580
|
+
'A preferably short description about the purpose of the instance'
|
1581
|
+
' described by the schema.'
|
1582
|
+
),
|
1583
|
+
)
|
1584
|
+
description: Optional[str] = Field(
|
1585
|
+
default=None,
|
1586
|
+
description=(
|
1587
|
+
'An explanation about the purpose of the instance described by the'
|
1588
|
+
' schema.'
|
1589
|
+
),
|
1590
|
+
)
|
1591
|
+
default: Optional[Any] = Field(
|
1592
|
+
default=None,
|
1593
|
+
description=(
|
1594
|
+
'This keyword can be used to supply a default JSON value associated'
|
1595
|
+
' with a particular schema.'
|
1596
|
+
),
|
1597
|
+
)
|
1598
|
+
items: Optional['JSONSchema'] = Field(
|
1599
|
+
default=None,
|
1600
|
+
description=(
|
1601
|
+
'Validation succeeds if each element of the instance not covered by'
|
1602
|
+
' prefixItems validates against this schema.'
|
1603
|
+
),
|
1604
|
+
)
|
1605
|
+
min_items: Optional[int] = Field(
|
1606
|
+
default=None,
|
1607
|
+
description=(
|
1608
|
+
'An array instance is valid if its size is greater than, or equal to,'
|
1609
|
+
' the value of this keyword.'
|
1610
|
+
),
|
1611
|
+
)
|
1612
|
+
max_items: Optional[int] = Field(
|
1613
|
+
default=None,
|
1614
|
+
description=(
|
1615
|
+
'An array instance is valid if its size is less than, or equal to,'
|
1616
|
+
' the value of this keyword.'
|
1617
|
+
),
|
1618
|
+
)
|
1619
|
+
enum: Optional[list[Any]] = Field(
|
1620
|
+
default=None,
|
1621
|
+
description=(
|
1622
|
+
'Validation succeeds if the instance is equal to one of the elements'
|
1623
|
+
' in this keyword’s array value.'
|
1624
|
+
),
|
1625
|
+
)
|
1626
|
+
properties: Optional[dict[str, 'JSONSchema']] = Field(
|
1627
|
+
default=None,
|
1628
|
+
description=(
|
1629
|
+
'Validation succeeds if, for each name that appears in both the'
|
1630
|
+
' instance and as a name within this keyword’s value, the child'
|
1631
|
+
' instance for that name successfully validates against the'
|
1632
|
+
' corresponding schema.'
|
1633
|
+
),
|
1634
|
+
)
|
1635
|
+
required: Optional[list[str]] = Field(
|
1636
|
+
default=None,
|
1637
|
+
description=(
|
1638
|
+
'An object instance is valid against this keyword if every item in'
|
1639
|
+
' the array is the name of a property in the instance.'
|
1640
|
+
),
|
1641
|
+
)
|
1642
|
+
min_properties: Optional[int] = Field(
|
1643
|
+
default=None,
|
1644
|
+
description=(
|
1645
|
+
'An object instance is valid if its number of properties is greater'
|
1646
|
+
' than, or equal to, the value of this keyword.'
|
1647
|
+
),
|
1648
|
+
)
|
1649
|
+
max_properties: Optional[int] = Field(
|
1650
|
+
default=None,
|
1651
|
+
description=(
|
1652
|
+
'An object instance is valid if its number of properties is less'
|
1653
|
+
' than, or equal to, the value of this keyword.'
|
1654
|
+
),
|
1655
|
+
)
|
1656
|
+
minimum: Optional[float] = Field(
|
1657
|
+
default=None,
|
1658
|
+
description=(
|
1659
|
+
'Validation succeeds if the numeric instance is greater than or equal'
|
1660
|
+
' to the given number.'
|
1661
|
+
),
|
1662
|
+
)
|
1663
|
+
maximum: Optional[float] = Field(
|
1664
|
+
default=None,
|
1665
|
+
description=(
|
1666
|
+
'Validation succeeds if the numeric instance is less than or equal to'
|
1667
|
+
' the given number.'
|
1668
|
+
),
|
1669
|
+
)
|
1670
|
+
min_length: Optional[int] = Field(
|
1671
|
+
default=None,
|
1672
|
+
description=(
|
1673
|
+
'A string instance is valid against this keyword if its length is'
|
1674
|
+
' greater than, or equal to, the value of this keyword.'
|
1675
|
+
),
|
1676
|
+
)
|
1677
|
+
max_length: Optional[int] = Field(
|
1678
|
+
default=None,
|
1679
|
+
description=(
|
1680
|
+
'A string instance is valid against this keyword if its length is'
|
1681
|
+
' less than, or equal to, the value of this keyword.'
|
1682
|
+
),
|
1683
|
+
)
|
1684
|
+
pattern: Optional[str] = Field(
|
1685
|
+
default=None,
|
1686
|
+
description=(
|
1687
|
+
'A string instance is considered valid if the regular expression'
|
1688
|
+
' matches the instance successfully.'
|
1689
|
+
),
|
1690
|
+
)
|
1691
|
+
any_of: Optional[list['JSONSchema']] = Field(
|
1692
|
+
default=None,
|
1693
|
+
description=(
|
1694
|
+
'An instance validates successfully against this keyword if it'
|
1695
|
+
' validates successfully against at least one schema defined by this'
|
1696
|
+
' keyword’s value.'
|
1697
|
+
),
|
1698
|
+
)
|
1774
1699
|
|
1775
|
-
DynamicRetrievalConfigOrDict = Union[
|
1776
|
-
DynamicRetrievalConfig, DynamicRetrievalConfigDict
|
1777
|
-
]
|
1778
1700
|
|
1701
|
+
class Schema(_common.BaseModel):
|
1702
|
+
"""Schema is used to define the format of input/output data.
|
1779
1703
|
|
1780
|
-
|
1781
|
-
|
1704
|
+
Represents a select subset of an [OpenAPI 3.0 schema
|
1705
|
+
object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
|
1706
|
+
be added in the future as needed.
|
1707
|
+
"""
|
1782
1708
|
|
1783
|
-
|
1709
|
+
any_of: Optional[list['Schema']] = Field(
|
1710
|
+
default=None,
|
1711
|
+
description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
|
1712
|
+
)
|
1713
|
+
default: Optional[Any] = Field(
|
1714
|
+
default=None, description="""Optional. Default value of the data."""
|
1715
|
+
)
|
1716
|
+
description: Optional[str] = Field(
|
1717
|
+
default=None, description="""Optional. The description of the data."""
|
1718
|
+
)
|
1719
|
+
enum: Optional[list[str]] = Field(
|
1720
|
+
default=None,
|
1721
|
+
description="""Optional. Possible values of the element of primitive type with enum format. Examples: 1. We can define direction as : {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]} 2. We can define apartment number as : {type:INTEGER, format:enum, enum:["101", "201", "301"]}""",
|
1722
|
+
)
|
1723
|
+
example: Optional[Any] = Field(
|
1724
|
+
default=None,
|
1725
|
+
description="""Optional. Example of the object. Will only populated when the object is the root.""",
|
1726
|
+
)
|
1727
|
+
format: Optional[str] = Field(
|
1728
|
+
default=None,
|
1729
|
+
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""",
|
1730
|
+
)
|
1731
|
+
items: Optional['Schema'] = Field(
|
1732
|
+
default=None,
|
1733
|
+
description="""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY.""",
|
1734
|
+
)
|
1735
|
+
max_items: Optional[int] = Field(
|
1736
|
+
default=None,
|
1737
|
+
description="""Optional. Maximum number of the elements for Type.ARRAY.""",
|
1738
|
+
)
|
1739
|
+
max_length: Optional[int] = Field(
|
1740
|
+
default=None,
|
1741
|
+
description="""Optional. Maximum length of the Type.STRING""",
|
1742
|
+
)
|
1743
|
+
max_properties: Optional[int] = Field(
|
1744
|
+
default=None,
|
1745
|
+
description="""Optional. Maximum number of the properties for Type.OBJECT.""",
|
1746
|
+
)
|
1747
|
+
maximum: Optional[float] = Field(
|
1784
1748
|
default=None,
|
1785
|
-
description="""
|
1749
|
+
description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
|
1786
1750
|
)
|
1787
|
-
|
1788
|
-
|
1789
|
-
class GoogleSearchRetrievalDict(TypedDict, total=False):
|
1790
|
-
"""Tool to retrieve public web data for grounding, powered by Google."""
|
1791
|
-
|
1792
|
-
dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
|
1793
|
-
"""Specifies the dynamic retrieval configuration for the given source."""
|
1794
|
-
|
1795
|
-
|
1796
|
-
GoogleSearchRetrievalOrDict = Union[
|
1797
|
-
GoogleSearchRetrieval, GoogleSearchRetrievalDict
|
1798
|
-
]
|
1799
|
-
|
1800
|
-
|
1801
|
-
class VertexAISearch(_common.BaseModel):
|
1802
|
-
"""Retrieve from Vertex AI Search datastore or engine for grounding.
|
1803
|
-
|
1804
|
-
datastore and engine are mutually exclusive. See
|
1805
|
-
https://cloud.google.com/products/agent-builder
|
1806
|
-
"""
|
1807
|
-
|
1808
|
-
datastore: Optional[str] = Field(
|
1751
|
+
min_items: Optional[int] = Field(
|
1809
1752
|
default=None,
|
1810
|
-
description="""Optional.
|
1753
|
+
description="""Optional. Minimum number of the elements for Type.ARRAY.""",
|
1811
1754
|
)
|
1812
|
-
|
1755
|
+
min_length: Optional[int] = Field(
|
1813
1756
|
default=None,
|
1814
|
-
description="""Optional.
|
1757
|
+
description="""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING""",
|
1815
1758
|
)
|
1816
|
-
|
1817
|
-
|
1818
|
-
class VertexAISearchDict(TypedDict, total=False):
|
1819
|
-
"""Retrieve from Vertex AI Search datastore or engine for grounding.
|
1820
|
-
|
1821
|
-
datastore and engine are mutually exclusive. See
|
1822
|
-
https://cloud.google.com/products/agent-builder
|
1823
|
-
"""
|
1824
|
-
|
1825
|
-
datastore: Optional[str]
|
1826
|
-
"""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
|
1827
|
-
|
1828
|
-
engine: Optional[str]
|
1829
|
-
"""Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`"""
|
1830
|
-
|
1831
|
-
|
1832
|
-
VertexAISearchOrDict = Union[VertexAISearch, VertexAISearchDict]
|
1833
|
-
|
1834
|
-
|
1835
|
-
class VertexRagStoreRagResource(_common.BaseModel):
|
1836
|
-
"""The definition of the Rag resource."""
|
1837
|
-
|
1838
|
-
rag_corpus: Optional[str] = Field(
|
1759
|
+
min_properties: Optional[int] = Field(
|
1839
1760
|
default=None,
|
1840
|
-
description="""Optional.
|
1761
|
+
description="""Optional. Minimum number of the properties for Type.OBJECT.""",
|
1841
1762
|
)
|
1842
|
-
|
1763
|
+
minimum: Optional[float] = Field(
|
1843
1764
|
default=None,
|
1844
|
-
description="""Optional.
|
1765
|
+
description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
|
1845
1766
|
)
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
"""The definition of the Rag resource."""
|
1850
|
-
|
1851
|
-
rag_corpus: Optional[str]
|
1852
|
-
"""Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`"""
|
1853
|
-
|
1854
|
-
rag_file_ids: Optional[list[str]]
|
1855
|
-
"""Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field."""
|
1856
|
-
|
1857
|
-
|
1858
|
-
VertexRagStoreRagResourceOrDict = Union[
|
1859
|
-
VertexRagStoreRagResource, VertexRagStoreRagResourceDict
|
1860
|
-
]
|
1861
|
-
|
1862
|
-
|
1863
|
-
class RagRetrievalConfigFilter(_common.BaseModel):
|
1864
|
-
"""Config for filters."""
|
1865
|
-
|
1866
|
-
metadata_filter: Optional[str] = Field(
|
1867
|
-
default=None, description="""Optional. String for metadata filtering."""
|
1767
|
+
nullable: Optional[bool] = Field(
|
1768
|
+
default=None,
|
1769
|
+
description="""Optional. Indicates if the value may be null.""",
|
1868
1770
|
)
|
1869
|
-
|
1771
|
+
pattern: Optional[str] = Field(
|
1870
1772
|
default=None,
|
1871
|
-
description="""Optional.
|
1773
|
+
description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
|
1872
1774
|
)
|
1873
|
-
|
1775
|
+
properties: Optional[dict[str, 'Schema']] = Field(
|
1874
1776
|
default=None,
|
1875
|
-
description="""Optional.
|
1777
|
+
description="""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.""",
|
1876
1778
|
)
|
1877
|
-
|
1878
|
-
|
1879
|
-
class RagRetrievalConfigFilterDict(TypedDict, total=False):
|
1880
|
-
"""Config for filters."""
|
1881
|
-
|
1882
|
-
metadata_filter: Optional[str]
|
1883
|
-
"""Optional. String for metadata filtering."""
|
1884
|
-
|
1885
|
-
vector_distance_threshold: Optional[float]
|
1886
|
-
"""Optional. Only returns contexts with vector distance smaller than the threshold."""
|
1887
|
-
|
1888
|
-
vector_similarity_threshold: Optional[float]
|
1889
|
-
"""Optional. Only returns contexts with vector similarity larger than the threshold."""
|
1890
|
-
|
1891
|
-
|
1892
|
-
RagRetrievalConfigFilterOrDict = Union[
|
1893
|
-
RagRetrievalConfigFilter, RagRetrievalConfigFilterDict
|
1894
|
-
]
|
1895
|
-
|
1896
|
-
|
1897
|
-
class RagRetrievalConfigHybridSearch(_common.BaseModel):
|
1898
|
-
"""Config for Hybrid Search."""
|
1899
|
-
|
1900
|
-
alpha: Optional[float] = Field(
|
1779
|
+
property_ordering: Optional[list[str]] = Field(
|
1901
1780
|
default=None,
|
1902
|
-
description="""Optional.
|
1781
|
+
description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
|
1903
1782
|
)
|
1904
|
-
|
1905
|
-
|
1906
|
-
class RagRetrievalConfigHybridSearchDict(TypedDict, total=False):
|
1907
|
-
"""Config for Hybrid Search."""
|
1908
|
-
|
1909
|
-
alpha: Optional[float]
|
1910
|
-
"""Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally."""
|
1911
|
-
|
1912
|
-
|
1913
|
-
RagRetrievalConfigHybridSearchOrDict = Union[
|
1914
|
-
RagRetrievalConfigHybridSearch, RagRetrievalConfigHybridSearchDict
|
1915
|
-
]
|
1916
|
-
|
1917
|
-
|
1918
|
-
class RagRetrievalConfigRankingLlmRanker(_common.BaseModel):
|
1919
|
-
"""Config for LlmRanker."""
|
1920
|
-
|
1921
|
-
model_name: Optional[str] = Field(
|
1783
|
+
required: Optional[list[str]] = Field(
|
1922
1784
|
default=None,
|
1923
|
-
description="""Optional.
|
1785
|
+
description="""Optional. Required properties of Type.OBJECT.""",
|
1786
|
+
)
|
1787
|
+
title: Optional[str] = Field(
|
1788
|
+
default=None, description="""Optional. The title of the Schema."""
|
1789
|
+
)
|
1790
|
+
type: Optional[Type] = Field(
|
1791
|
+
default=None, description="""Optional. The type of the data."""
|
1924
1792
|
)
|
1925
1793
|
|
1794
|
+
@property
|
1795
|
+
def json_schema(self) -> JSONSchema:
|
1796
|
+
"""Converts the Schema object to a JSONSchema object, that is compatible with 2020-12 JSON Schema draft.
|
1926
1797
|
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
]
|
1798
|
+
If a Schema field is not supported by JSONSchema, it will be ignored.
|
1799
|
+
"""
|
1800
|
+
json_schema_field_names: set[str] = set(JSONSchema.model_fields.keys())
|
1801
|
+
schema_field_names: tuple[str] = (
|
1802
|
+
'items',
|
1803
|
+
) # 'additional_properties' to come
|
1804
|
+
list_schema_field_names: tuple[str] = (
|
1805
|
+
'any_of', # 'one_of', 'all_of', 'not' to come
|
1806
|
+
)
|
1807
|
+
dict_schema_field_names: tuple[str] = ('properties',) # 'defs' to come
|
1937
1808
|
|
1809
|
+
def convert_schema(schema: Union['Schema', dict[str, Any]]) -> JSONSchema:
|
1810
|
+
if isinstance(schema, pydantic.BaseModel):
|
1811
|
+
schema_dict = schema.model_dump()
|
1812
|
+
else:
|
1813
|
+
schema_dict = schema
|
1814
|
+
json_schema = JSONSchema()
|
1815
|
+
for field_name, field_value in schema_dict.items():
|
1816
|
+
if field_value is None:
|
1817
|
+
continue
|
1818
|
+
elif field_name == 'nullable':
|
1819
|
+
json_schema.type = JSONSchemaType.NULL
|
1820
|
+
elif field_name not in json_schema_field_names:
|
1821
|
+
continue
|
1822
|
+
elif field_name == 'type':
|
1823
|
+
if field_value == Type.TYPE_UNSPECIFIED:
|
1824
|
+
continue
|
1825
|
+
json_schema_type = JSONSchemaType(field_value.lower())
|
1826
|
+
if json_schema.type is None:
|
1827
|
+
json_schema.type = json_schema_type
|
1828
|
+
elif isinstance(json_schema.type, JSONSchemaType):
|
1829
|
+
existing_type: JSONSchemaType = json_schema.type
|
1830
|
+
json_schema.type = [existing_type, json_schema_type]
|
1831
|
+
elif isinstance(json_schema.type, list):
|
1832
|
+
json_schema.type.append(json_schema_type)
|
1833
|
+
elif field_name in schema_field_names:
|
1834
|
+
schema_field_value: 'JSONSchema' = convert_schema(field_value)
|
1835
|
+
setattr(json_schema, field_name, schema_field_value)
|
1836
|
+
elif field_name in list_schema_field_names:
|
1837
|
+
list_schema_field_value: list['JSONSchema'] = [
|
1838
|
+
convert_schema(this_field_value)
|
1839
|
+
for this_field_value in field_value
|
1840
|
+
]
|
1841
|
+
setattr(json_schema, field_name, list_schema_field_value)
|
1842
|
+
elif field_name in dict_schema_field_names:
|
1843
|
+
dict_schema_field_value: dict[str, 'JSONSchema'] = {
|
1844
|
+
key: convert_schema(value) for key, value in field_value.items()
|
1845
|
+
}
|
1846
|
+
setattr(json_schema, field_name, dict_schema_field_value)
|
1847
|
+
else:
|
1848
|
+
setattr(json_schema, field_name, field_value)
|
1938
1849
|
|
1939
|
-
|
1940
|
-
"""Config for Rank Service."""
|
1850
|
+
return json_schema
|
1941
1851
|
|
1942
|
-
|
1943
|
-
default=None,
|
1944
|
-
description="""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`""",
|
1945
|
-
)
|
1852
|
+
return convert_schema(self)
|
1946
1853
|
|
1854
|
+
@classmethod
|
1855
|
+
def from_json_schema(
|
1856
|
+
cls,
|
1857
|
+
*,
|
1858
|
+
json_schema: JSONSchema,
|
1859
|
+
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
1860
|
+
raise_error_on_unsupported_field: bool = False,
|
1861
|
+
) -> 'Schema':
|
1862
|
+
"""Converts a JSONSchema object to a Schema object.
|
1947
1863
|
|
1948
|
-
|
1949
|
-
|
1864
|
+
The JSONSchema is compatible with 2020-12 JSON Schema draft, specified by
|
1865
|
+
OpenAPI 3.1.
|
1950
1866
|
|
1951
|
-
|
1952
|
-
|
1867
|
+
Args:
|
1868
|
+
json_schema: JSONSchema object to be converted.
|
1869
|
+
api_option: API option to be used. If set to 'VERTEX_AI', the JSONSchema
|
1870
|
+
will be converted to a Schema object that is compatible with Vertex AI
|
1871
|
+
API. If set to 'GEMINI_API', the JSONSchema will be converted to a
|
1872
|
+
Schema object that is compatible with Gemini API. Default is
|
1873
|
+
'GEMINI_API'.
|
1874
|
+
raise_error_on_unsupported_field: If set to True, an error will be
|
1875
|
+
raised if the JSONSchema contains any unsupported fields. Default is
|
1876
|
+
False.
|
1953
1877
|
|
1878
|
+
Returns:
|
1879
|
+
Schema object that is compatible with the specified API option.
|
1880
|
+
Raises:
|
1881
|
+
ValueError: If the JSONSchema contains any unsupported fields and
|
1882
|
+
raise_error_on_unsupported_field is set to True. Or if the JSONSchema
|
1883
|
+
is not compatible with the specified API option.
|
1884
|
+
"""
|
1885
|
+
google_schema_field_names: set[str] = set(cls.model_fields.keys())
|
1886
|
+
schema_field_names: tuple[str, ...] = (
|
1887
|
+
'items',
|
1888
|
+
) # 'additional_properties' to come
|
1889
|
+
list_schema_field_names: tuple[str, ...] = (
|
1890
|
+
'any_of', # 'one_of', 'all_of', 'not' to come
|
1891
|
+
)
|
1892
|
+
dict_schema_field_names: tuple[str, ...] = ('properties',) # 'defs' to come
|
1954
1893
|
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1894
|
+
related_field_names_by_type: dict[str, tuple[str, ...]] = {
|
1895
|
+
JSONSchemaType.NUMBER.value: (
|
1896
|
+
'description',
|
1897
|
+
'enum',
|
1898
|
+
'format',
|
1899
|
+
'maximum',
|
1900
|
+
'minimum',
|
1901
|
+
'title',
|
1902
|
+
),
|
1903
|
+
JSONSchemaType.STRING.value: (
|
1904
|
+
'description',
|
1905
|
+
'enum',
|
1906
|
+
'format',
|
1907
|
+
'max_length',
|
1908
|
+
'min_length',
|
1909
|
+
'pattern',
|
1910
|
+
'title',
|
1911
|
+
),
|
1912
|
+
JSONSchemaType.OBJECT.value: (
|
1913
|
+
'any_of',
|
1914
|
+
'description',
|
1915
|
+
'max_properties',
|
1916
|
+
'min_properties',
|
1917
|
+
'properties',
|
1918
|
+
'required',
|
1919
|
+
'title',
|
1920
|
+
),
|
1921
|
+
JSONSchemaType.ARRAY.value: (
|
1922
|
+
'description',
|
1923
|
+
'items',
|
1924
|
+
'max_items',
|
1925
|
+
'min_items',
|
1926
|
+
'title',
|
1927
|
+
),
|
1928
|
+
JSONSchemaType.BOOLEAN.value: (
|
1929
|
+
'description',
|
1930
|
+
'title',
|
1931
|
+
),
|
1932
|
+
}
|
1933
|
+
# Treat `INTEGER` like `NUMBER`.
|
1934
|
+
related_field_names_by_type[JSONSchemaType.INTEGER.value] = (
|
1935
|
+
related_field_names_by_type[JSONSchemaType.NUMBER.value]
|
1936
|
+
)
|
1959
1937
|
|
1938
|
+
# placeholder for potential gemini api unsupported fields
|
1939
|
+
gemini_api_unsupported_field_names: tuple[str, ...] = ()
|
1960
1940
|
|
1961
|
-
|
1962
|
-
|
1941
|
+
def normalize_json_schema_type(
|
1942
|
+
json_schema_type: Optional[
|
1943
|
+
Union[JSONSchemaType, Sequence[JSONSchemaType], str, Sequence[str]]
|
1944
|
+
],
|
1945
|
+
) -> tuple[list[str], bool]:
|
1946
|
+
"""Returns (non_null_types, nullable)"""
|
1947
|
+
if json_schema_type is None:
|
1948
|
+
return [], False
|
1949
|
+
if not isinstance(json_schema_type, Sequence):
|
1950
|
+
json_schema_type = [json_schema_type]
|
1951
|
+
non_null_types = []
|
1952
|
+
nullable = False
|
1953
|
+
for type_value in json_schema_type:
|
1954
|
+
if isinstance(type_value, JSONSchemaType):
|
1955
|
+
type_value = type_value.value
|
1956
|
+
if type_value == JSONSchemaType.NULL.value:
|
1957
|
+
nullable = True
|
1958
|
+
else:
|
1959
|
+
non_null_types.append(type_value)
|
1960
|
+
return non_null_types, nullable
|
1963
1961
|
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1962
|
+
def raise_error_if_cannot_convert(
|
1963
|
+
json_schema_dict: dict[str, Any],
|
1964
|
+
api_option: Literal['VERTEX_AI', 'GEMINI_API'],
|
1965
|
+
raise_error_on_unsupported_field: bool,
|
1966
|
+
) -> None:
|
1967
|
+
"""Raises an error if the JSONSchema cannot be converted to the specified Schema object."""
|
1968
|
+
if not raise_error_on_unsupported_field:
|
1969
|
+
return
|
1970
|
+
for field_name, field_value in json_schema_dict.items():
|
1971
|
+
if field_value is None:
|
1972
|
+
continue
|
1973
|
+
if field_name not in google_schema_field_names:
|
1974
|
+
raise ValueError((
|
1975
|
+
f'JSONSchema field "{field_name}" is not supported by the '
|
1976
|
+
'Schema object. And the "raise_error_on_unsupported_field" '
|
1977
|
+
'argument is set to True. If you still want to convert '
|
1978
|
+
'it into the Schema object, please either remove the field '
|
1979
|
+
f'"{field_name}" from the JSONSchema object, or leave the '
|
1980
|
+
'"raise_error_on_unsupported_field" unset.'
|
1981
|
+
))
|
1982
|
+
if (
|
1983
|
+
field_name in gemini_api_unsupported_field_names
|
1984
|
+
and api_option == 'GEMINI_API'
|
1985
|
+
):
|
1986
|
+
raise ValueError((
|
1987
|
+
f'The "{field_name}" field is not supported by the Schema '
|
1988
|
+
'object for GEMINI_API.'
|
1989
|
+
))
|
1970
1990
|
|
1991
|
+
def copy_schema_fields(
|
1992
|
+
json_schema_dict: dict[str, Any],
|
1993
|
+
related_fields_to_copy: tuple[str, ...],
|
1994
|
+
sub_schema_in_any_of: dict[str, Any],
|
1995
|
+
) -> None:
|
1996
|
+
"""Copies the fields from json_schema_dict to sub_schema_in_any_of."""
|
1997
|
+
for field_name in related_fields_to_copy:
|
1998
|
+
sub_schema_in_any_of[field_name] = json_schema_dict.get(
|
1999
|
+
field_name, None
|
2000
|
+
)
|
1971
2001
|
|
1972
|
-
|
1973
|
-
|
2002
|
+
def convert_json_schema(
|
2003
|
+
json_schema: JSONSchema,
|
2004
|
+
api_option: Literal['VERTEX_AI', 'GEMINI_API'],
|
2005
|
+
raise_error_on_unsupported_field: bool,
|
2006
|
+
) -> 'Schema':
|
2007
|
+
schema = Schema()
|
2008
|
+
json_schema_dict = json_schema.model_dump()
|
2009
|
+
raise_error_if_cannot_convert(
|
2010
|
+
json_schema_dict=json_schema_dict,
|
2011
|
+
api_option=api_option,
|
2012
|
+
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
2013
|
+
)
|
1974
2014
|
|
1975
|
-
|
1976
|
-
|
2015
|
+
# At the highest level of the logic, there are two passes:
|
2016
|
+
# Pass 1: the JSONSchema.type is union-like,
|
2017
|
+
# e.g. ['null', 'string', 'array'].
|
2018
|
+
# for this case, we need to split the JSONSchema into multiple
|
2019
|
+
# sub-schemas, and copy them into the any_of field of the Schema.
|
2020
|
+
# And when we copy the non-type fields into any_of field,
|
2021
|
+
# we only copy the fields related to the specific type.
|
2022
|
+
# Detailed logic is commented below with `Pass 1` keyword tag.
|
2023
|
+
# Pass 2: the JSONSchema.type is not union-like,
|
2024
|
+
# e.g. 'string', ['string'], ['null', 'string'].
|
2025
|
+
# for this case, no splitting is needed. Detailed
|
2026
|
+
# logic is commented below with `Pass 2` keyword tag.
|
2027
|
+
#
|
2028
|
+
#
|
2029
|
+
# Pass 1: the JSONSchema.type is union-like
|
2030
|
+
# e.g. ['null', 'string', 'array'].
|
2031
|
+
non_null_types, nullable = normalize_json_schema_type(
|
2032
|
+
json_schema_dict.get('type', None)
|
2033
|
+
)
|
2034
|
+
if len(non_null_types) > 1:
|
2035
|
+
logger.warning(
|
2036
|
+
'JSONSchema type is union-like, e.g. ["null", "string", "array"]. '
|
2037
|
+
'Converting it into multiple sub-schemas, and copying them into '
|
2038
|
+
'the any_of field of the Schema. The value of `default` field is '
|
2039
|
+
'ignored because it is ambiguous to tell which sub-schema it '
|
2040
|
+
'belongs to.'
|
2041
|
+
)
|
2042
|
+
reformed_json_schema = JSONSchema()
|
2043
|
+
# start splitting the JSONSchema into multiple sub-schemas
|
2044
|
+
any_of = []
|
2045
|
+
if nullable:
|
2046
|
+
schema.nullable = True
|
2047
|
+
for normalized_type in non_null_types:
|
2048
|
+
sub_schema_in_any_of = {'type': normalized_type}
|
2049
|
+
related_field_names = related_field_names_by_type.get(normalized_type)
|
2050
|
+
if related_field_names is not None:
|
2051
|
+
copy_schema_fields(
|
2052
|
+
json_schema_dict=json_schema_dict,
|
2053
|
+
related_fields_to_copy=related_field_names,
|
2054
|
+
sub_schema_in_any_of=sub_schema_in_any_of,
|
2055
|
+
)
|
2056
|
+
any_of.append(JSONSchema(**sub_schema_in_any_of))
|
2057
|
+
reformed_json_schema.any_of = any_of
|
2058
|
+
json_schema_dict = reformed_json_schema.model_dump()
|
1977
2059
|
|
1978
|
-
|
1979
|
-
|
2060
|
+
# Pass 2: the JSONSchema.type is not union-like,
|
2061
|
+
# e.g. 'string', ['string'], ['null', 'string'].
|
2062
|
+
for field_name, field_value in json_schema_dict.items():
|
2063
|
+
if field_value is None:
|
2064
|
+
continue
|
2065
|
+
if field_name in schema_field_names:
|
2066
|
+
schema_field_value: 'Schema' = convert_json_schema(
|
2067
|
+
json_schema=JSONSchema(**field_value),
|
2068
|
+
api_option=api_option,
|
2069
|
+
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
2070
|
+
)
|
2071
|
+
setattr(schema, field_name, schema_field_value)
|
2072
|
+
elif field_name in list_schema_field_names:
|
2073
|
+
list_schema_field_value: list['Schema'] = [
|
2074
|
+
convert_json_schema(
|
2075
|
+
json_schema=JSONSchema(**this_field_value),
|
2076
|
+
api_option=api_option,
|
2077
|
+
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
2078
|
+
)
|
2079
|
+
for this_field_value in field_value
|
2080
|
+
]
|
2081
|
+
setattr(schema, field_name, list_schema_field_value)
|
2082
|
+
elif field_name in dict_schema_field_names:
|
2083
|
+
dict_schema_field_value: dict[str, 'Schema'] = {
|
2084
|
+
key: convert_json_schema(
|
2085
|
+
json_schema=JSONSchema(**value),
|
2086
|
+
api_option=api_option,
|
2087
|
+
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
2088
|
+
)
|
2089
|
+
for key, value in field_value.items()
|
2090
|
+
}
|
2091
|
+
setattr(schema, field_name, dict_schema_field_value)
|
2092
|
+
elif field_name == 'type':
|
2093
|
+
# non_null_types can only be empty or have one element.
|
2094
|
+
# because already handled union-like case above.
|
2095
|
+
non_null_types, nullable = normalize_json_schema_type(field_value)
|
2096
|
+
if nullable:
|
2097
|
+
schema.nullable = True
|
2098
|
+
if non_null_types:
|
2099
|
+
schema.type = Type(non_null_types[0])
|
2100
|
+
else:
|
2101
|
+
setattr(schema, field_name, field_value)
|
1980
2102
|
|
2103
|
+
return schema
|
1981
2104
|
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
2105
|
+
return convert_json_schema(
|
2106
|
+
json_schema=json_schema,
|
2107
|
+
api_option=api_option,
|
2108
|
+
raise_error_on_unsupported_field=raise_error_on_unsupported_field,
|
2109
|
+
)
|
1985
2110
|
|
1986
2111
|
|
1987
|
-
class
|
1988
|
-
"""
|
2112
|
+
class SchemaDict(TypedDict, total=False):
|
2113
|
+
"""Schema is used to define the format of input/output data.
|
1989
2114
|
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
default=None, description="""Optional. Config for Hybrid Search."""
|
1995
|
-
)
|
1996
|
-
ranking: Optional[RagRetrievalConfigRanking] = Field(
|
1997
|
-
default=None,
|
1998
|
-
description="""Optional. Config for ranking and reranking.""",
|
1999
|
-
)
|
2000
|
-
top_k: Optional[int] = Field(
|
2001
|
-
default=None,
|
2002
|
-
description="""Optional. The number of contexts to retrieve.""",
|
2003
|
-
)
|
2115
|
+
Represents a select subset of an [OpenAPI 3.0 schema
|
2116
|
+
object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
|
2117
|
+
be added in the future as needed.
|
2118
|
+
"""
|
2004
2119
|
|
2120
|
+
any_of: Optional[list['SchemaDict']]
|
2121
|
+
"""Optional. The value should be validated against any (one or more) of the subschemas in the list."""
|
2005
2122
|
|
2006
|
-
|
2007
|
-
"""
|
2123
|
+
default: Optional[Any]
|
2124
|
+
"""Optional. Default value of the data."""
|
2008
2125
|
|
2009
|
-
|
2010
|
-
"""Optional.
|
2126
|
+
description: Optional[str]
|
2127
|
+
"""Optional. The description of the data."""
|
2011
2128
|
|
2012
|
-
|
2013
|
-
"""Optional.
|
2129
|
+
enum: Optional[list[str]]
|
2130
|
+
"""Optional. Possible values of the element of primitive type with enum format. Examples: 1. We can define direction as : {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]} 2. We can define apartment number as : {type:INTEGER, format:enum, enum:["101", "201", "301"]}"""
|
2014
2131
|
|
2015
|
-
|
2016
|
-
"""Optional.
|
2132
|
+
example: Optional[Any]
|
2133
|
+
"""Optional. Example of the object. Will only populated when the object is the root."""
|
2017
2134
|
|
2018
|
-
|
2019
|
-
"""Optional. The
|
2135
|
+
format: Optional[str]
|
2136
|
+
"""Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc"""
|
2020
2137
|
|
2138
|
+
items: Optional['SchemaDict']
|
2139
|
+
"""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY."""
|
2021
2140
|
|
2022
|
-
|
2141
|
+
max_items: Optional[int]
|
2142
|
+
"""Optional. Maximum number of the elements for Type.ARRAY."""
|
2023
2143
|
|
2144
|
+
max_length: Optional[int]
|
2145
|
+
"""Optional. Maximum length of the Type.STRING"""
|
2024
2146
|
|
2025
|
-
|
2026
|
-
"""
|
2147
|
+
max_properties: Optional[int]
|
2148
|
+
"""Optional. Maximum number of the properties for Type.OBJECT."""
|
2027
2149
|
|
2028
|
-
|
2029
|
-
|
2030
|
-
description="""Optional. Deprecated. Please use rag_resources instead.""",
|
2031
|
-
)
|
2032
|
-
rag_resources: Optional[list[VertexRagStoreRagResource]] = Field(
|
2033
|
-
default=None,
|
2034
|
-
description="""Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support.""",
|
2035
|
-
)
|
2036
|
-
rag_retrieval_config: Optional[RagRetrievalConfig] = Field(
|
2037
|
-
default=None,
|
2038
|
-
description="""Optional. The retrieval config for the Rag query.""",
|
2039
|
-
)
|
2040
|
-
similarity_top_k: Optional[int] = Field(
|
2041
|
-
default=None,
|
2042
|
-
description="""Optional. Number of top k results to return from the selected corpora.""",
|
2043
|
-
)
|
2044
|
-
vector_distance_threshold: Optional[float] = Field(
|
2045
|
-
default=None,
|
2046
|
-
description="""Optional. Only return results with vector distance smaller than the threshold.""",
|
2047
|
-
)
|
2150
|
+
maximum: Optional[float]
|
2151
|
+
"""Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
|
2048
2152
|
|
2153
|
+
min_items: Optional[int]
|
2154
|
+
"""Optional. Minimum number of the elements for Type.ARRAY."""
|
2049
2155
|
|
2050
|
-
|
2051
|
-
"""
|
2156
|
+
min_length: Optional[int]
|
2157
|
+
"""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING"""
|
2052
2158
|
|
2053
|
-
|
2054
|
-
"""Optional.
|
2159
|
+
min_properties: Optional[int]
|
2160
|
+
"""Optional. Minimum number of the properties for Type.OBJECT."""
|
2055
2161
|
|
2056
|
-
|
2057
|
-
"""Optional.
|
2162
|
+
minimum: Optional[float]
|
2163
|
+
"""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
|
2058
2164
|
|
2059
|
-
|
2060
|
-
"""Optional.
|
2165
|
+
nullable: Optional[bool]
|
2166
|
+
"""Optional. Indicates if the value may be null."""
|
2061
2167
|
|
2062
|
-
|
2063
|
-
"""Optional.
|
2168
|
+
pattern: Optional[str]
|
2169
|
+
"""Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
|
2064
2170
|
|
2065
|
-
|
2066
|
-
"""Optional.
|
2171
|
+
properties: Optional[dict[str, 'SchemaDict']]
|
2172
|
+
"""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT."""
|
2067
2173
|
|
2174
|
+
property_ordering: Optional[list[str]]
|
2175
|
+
"""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
|
2068
2176
|
|
2069
|
-
|
2177
|
+
required: Optional[list[str]]
|
2178
|
+
"""Optional. Required properties of Type.OBJECT."""
|
2070
2179
|
|
2180
|
+
title: Optional[str]
|
2181
|
+
"""Optional. The title of the Schema."""
|
2071
2182
|
|
2072
|
-
|
2073
|
-
"""
|
2183
|
+
type: Optional[Type]
|
2184
|
+
"""Optional. The type of the data."""
|
2074
2185
|
|
2075
|
-
|
2186
|
+
|
2187
|
+
SchemaOrDict = Union[Schema, SchemaDict]
|
2188
|
+
|
2189
|
+
|
2190
|
+
class FunctionDeclaration(_common.BaseModel):
|
2191
|
+
"""Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
|
2192
|
+
|
2193
|
+
Included in this declaration are the function name, description, parameters
|
2194
|
+
and response type. This FunctionDeclaration is a representation of a block of
|
2195
|
+
code that can be used as a `Tool` by the model and executed by the client.
|
2196
|
+
"""
|
2197
|
+
|
2198
|
+
description: Optional[str] = Field(
|
2076
2199
|
default=None,
|
2077
|
-
description="""Optional.
|
2200
|
+
description="""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.""",
|
2078
2201
|
)
|
2079
|
-
|
2202
|
+
name: Optional[str] = Field(
|
2080
2203
|
default=None,
|
2081
|
-
description="""
|
2204
|
+
description="""Required. The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores, dots and dashes, with a maximum length of 64.""",
|
2082
2205
|
)
|
2083
|
-
|
2206
|
+
parameters: Optional[Schema] = Field(
|
2084
2207
|
default=None,
|
2085
|
-
description="""
|
2208
|
+
description="""Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1""",
|
2209
|
+
)
|
2210
|
+
response: Optional[Schema] = Field(
|
2211
|
+
default=None,
|
2212
|
+
description="""Optional. Describes the output from this function in JSON Schema format. Reflects the Open API 3.03 Response Object. The Schema defines the type used for the response value of the function.""",
|
2086
2213
|
)
|
2087
2214
|
|
2215
|
+
@classmethod
|
2216
|
+
def from_callable_with_api_option(
|
2217
|
+
cls,
|
2218
|
+
*,
|
2219
|
+
callable: Callable[..., Any],
|
2220
|
+
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
2221
|
+
) -> 'FunctionDeclaration':
|
2222
|
+
"""Converts a Callable to a FunctionDeclaration based on the API option.
|
2088
2223
|
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2224
|
+
Supported API option is 'VERTEX_AI' or 'GEMINI_API'. If api_option is unset,
|
2225
|
+
it will default to 'GEMINI_API'. If unsupported api_option is provided, it
|
2226
|
+
will raise ValueError.
|
2227
|
+
"""
|
2228
|
+
supported_api_options = ['VERTEX_AI', 'GEMINI_API']
|
2229
|
+
if api_option not in supported_api_options:
|
2230
|
+
raise ValueError(
|
2231
|
+
f'Unsupported api_option value: {api_option}. Supported api_option'
|
2232
|
+
f' value is one of: {supported_api_options}.'
|
2233
|
+
)
|
2234
|
+
from . import _automatic_function_calling_util
|
2094
2235
|
|
2095
|
-
|
2096
|
-
|
2236
|
+
parameters_properties = {}
|
2237
|
+
for name, param in inspect.signature(callable).parameters.items():
|
2238
|
+
if param.kind in (
|
2239
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
2240
|
+
inspect.Parameter.KEYWORD_ONLY,
|
2241
|
+
inspect.Parameter.POSITIONAL_ONLY,
|
2242
|
+
):
|
2243
|
+
schema = _automatic_function_calling_util._parse_schema_from_parameter(
|
2244
|
+
api_option, param, callable.__name__
|
2245
|
+
)
|
2246
|
+
parameters_properties[name] = schema
|
2247
|
+
declaration = FunctionDeclaration(
|
2248
|
+
name=callable.__name__,
|
2249
|
+
description=callable.__doc__,
|
2250
|
+
)
|
2251
|
+
if parameters_properties:
|
2252
|
+
declaration.parameters = Schema(
|
2253
|
+
type='OBJECT',
|
2254
|
+
properties=parameters_properties,
|
2255
|
+
)
|
2256
|
+
declaration.parameters.required = (
|
2257
|
+
_automatic_function_calling_util._get_required_fields(
|
2258
|
+
declaration.parameters
|
2259
|
+
)
|
2260
|
+
)
|
2261
|
+
if api_option == 'GEMINI_API':
|
2262
|
+
return declaration
|
2097
2263
|
|
2098
|
-
|
2099
|
-
|
2264
|
+
return_annotation = inspect.signature(callable).return_annotation
|
2265
|
+
if return_annotation is inspect._empty:
|
2266
|
+
return declaration
|
2100
2267
|
|
2268
|
+
declaration.response = (
|
2269
|
+
_automatic_function_calling_util._parse_schema_from_parameter(
|
2270
|
+
api_option,
|
2271
|
+
inspect.Parameter(
|
2272
|
+
'return_value',
|
2273
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
2274
|
+
annotation=return_annotation,
|
2275
|
+
),
|
2276
|
+
callable.__name__,
|
2277
|
+
)
|
2278
|
+
)
|
2279
|
+
return declaration
|
2101
2280
|
|
2102
|
-
|
2281
|
+
@classmethod
|
2282
|
+
def from_callable(
|
2283
|
+
cls,
|
2284
|
+
*,
|
2285
|
+
client: 'BaseApiClient',
|
2286
|
+
callable: Callable[..., Any],
|
2287
|
+
) -> 'FunctionDeclaration':
|
2288
|
+
"""Converts a Callable to a FunctionDeclaration based on the client."""
|
2289
|
+
if client.vertexai:
|
2290
|
+
return cls.from_callable_with_api_option(
|
2291
|
+
callable=callable, api_option='VERTEX_AI'
|
2292
|
+
)
|
2293
|
+
else:
|
2294
|
+
return cls.from_callable_with_api_option(
|
2295
|
+
callable=callable, api_option='GEMINI_API'
|
2296
|
+
)
|
2103
2297
|
|
2104
2298
|
|
2105
|
-
class
|
2106
|
-
"""
|
2299
|
+
class FunctionDeclarationDict(TypedDict, total=False):
|
2300
|
+
"""Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
|
2107
2301
|
|
2108
|
-
|
2109
|
-
|
2302
|
+
Included in this declaration are the function name, description, parameters
|
2303
|
+
and response type. This FunctionDeclaration is a representation of a block of
|
2304
|
+
code that can be used as a `Tool` by the model and executed by the client.
|
2110
2305
|
"""
|
2111
2306
|
|
2112
|
-
|
2113
|
-
|
2307
|
+
description: Optional[str]
|
2308
|
+
"""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function."""
|
2114
2309
|
|
2115
|
-
|
2116
|
-
"""
|
2310
|
+
name: Optional[str]
|
2311
|
+
"""Required. The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores, dots and dashes, with a maximum length of 64."""
|
2117
2312
|
|
2118
|
-
|
2119
|
-
to this
|
2120
|
-
"""
|
2313
|
+
parameters: Optional[SchemaDict]
|
2314
|
+
"""Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1"""
|
2121
2315
|
|
2122
|
-
|
2316
|
+
response: Optional[SchemaDict]
|
2317
|
+
"""Optional. Describes the output from this function in JSON Schema format. Reflects the Open API 3.03 Response Object. The Schema defines the type used for the response value of the function."""
|
2123
2318
|
|
2124
2319
|
|
2125
|
-
|
2320
|
+
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
|
2126
2321
|
|
2127
2322
|
|
2128
2323
|
class Tool(_common.BaseModel):
|
2129
2324
|
"""Tool details of a tool that the model may use to generate a response."""
|
2130
2325
|
|
2131
|
-
function_declarations: Optional[list[FunctionDeclaration]] = Field(
|
2132
|
-
default=None,
|
2133
|
-
description="""List of function declarations that the tool supports.""",
|
2134
|
-
)
|
2135
2326
|
retrieval: Optional[Retrieval] = Field(
|
2136
2327
|
default=None,
|
2137
2328
|
description="""Optional. Retrieval tool type. System will always execute the provided retrieval tool(s) to get external knowledge to answer the prompt. Retrieval results are presented to the model for generation.""",
|
@@ -2145,18 +2336,29 @@ class Tool(_common.BaseModel):
|
|
2145
2336
|
default=None,
|
2146
2337
|
description="""Optional. GoogleSearchRetrieval tool type. Specialized retrieval tool that is powered by Google search.""",
|
2147
2338
|
)
|
2339
|
+
enterprise_web_search: Optional[EnterpriseWebSearch] = Field(
|
2340
|
+
default=None,
|
2341
|
+
description="""Optional. Enterprise web search tool type. Specialized retrieval
|
2342
|
+
tool that is powered by Vertex AI Search and Sec4 compliance.""",
|
2343
|
+
)
|
2344
|
+
google_maps: Optional[GoogleMaps] = Field(
|
2345
|
+
default=None,
|
2346
|
+
description="""Optional. Google Maps tool type. Specialized retrieval tool
|
2347
|
+
that is powered by Google Maps.""",
|
2348
|
+
)
|
2148
2349
|
code_execution: Optional[ToolCodeExecution] = Field(
|
2149
2350
|
default=None,
|
2150
2351
|
description="""Optional. CodeExecution tool type. Enables the model to execute code as part of generation. This field is only used by the Gemini Developer API services.""",
|
2151
2352
|
)
|
2353
|
+
function_declarations: Optional[list[FunctionDeclaration]] = Field(
|
2354
|
+
default=None,
|
2355
|
+
description="""Optional. Function tool type. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating FunctionCall in the response. User should provide a FunctionResponse for each function call in the next turn. Based on the function responses, Model will generate the final response back to the user. Maximum 128 function declarations can be provided.""",
|
2356
|
+
)
|
2152
2357
|
|
2153
2358
|
|
2154
2359
|
class ToolDict(TypedDict, total=False):
|
2155
2360
|
"""Tool details of a tool that the model may use to generate a response."""
|
2156
2361
|
|
2157
|
-
function_declarations: Optional[list[FunctionDeclarationDict]]
|
2158
|
-
"""List of function declarations that the tool supports."""
|
2159
|
-
|
2160
2362
|
retrieval: Optional[RetrievalDict]
|
2161
2363
|
"""Optional. Retrieval tool type. System will always execute the provided retrieval tool(s) to get external knowledge to answer the prompt. Retrieval results are presented to the model for generation."""
|
2162
2364
|
|
@@ -2167,9 +2369,20 @@ class ToolDict(TypedDict, total=False):
|
|
2167
2369
|
google_search_retrieval: Optional[GoogleSearchRetrievalDict]
|
2168
2370
|
"""Optional. GoogleSearchRetrieval tool type. Specialized retrieval tool that is powered by Google search."""
|
2169
2371
|
|
2372
|
+
enterprise_web_search: Optional[EnterpriseWebSearchDict]
|
2373
|
+
"""Optional. Enterprise web search tool type. Specialized retrieval
|
2374
|
+
tool that is powered by Vertex AI Search and Sec4 compliance."""
|
2375
|
+
|
2376
|
+
google_maps: Optional[GoogleMapsDict]
|
2377
|
+
"""Optional. Google Maps tool type. Specialized retrieval tool
|
2378
|
+
that is powered by Google Maps."""
|
2379
|
+
|
2170
2380
|
code_execution: Optional[ToolCodeExecutionDict]
|
2171
2381
|
"""Optional. CodeExecution tool type. Enables the model to execute code as part of generation. This field is only used by the Gemini Developer API services."""
|
2172
2382
|
|
2383
|
+
function_declarations: Optional[list[FunctionDeclarationDict]]
|
2384
|
+
"""Optional. Function tool type. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating FunctionCall in the response. User should provide a FunctionResponse for each function call in the next turn. Based on the function responses, Model will generate the final response back to the user. Maximum 128 function declarations can be provided."""
|
2385
|
+
|
2173
2386
|
|
2174
2387
|
ToolOrDict = Union[Tool, ToolDict]
|
2175
2388
|
ToolListUnion = list[Union[Tool, Callable[..., Any]]]
|
@@ -2208,6 +2421,62 @@ FunctionCallingConfigOrDict = Union[
|
|
2208
2421
|
]
|
2209
2422
|
|
2210
2423
|
|
2424
|
+
class LatLng(_common.BaseModel):
|
2425
|
+
"""An object that represents a latitude/longitude pair.
|
2426
|
+
|
2427
|
+
This is expressed as a pair of doubles to represent degrees latitude and
|
2428
|
+
degrees longitude. Unless specified otherwise, this object must conform to the
|
2429
|
+
<a href="https://en.wikipedia.org/wiki/World_Geodetic_System#1984_version">
|
2430
|
+
WGS84 standard</a>. Values must be within normalized ranges.
|
2431
|
+
"""
|
2432
|
+
|
2433
|
+
latitude: Optional[float] = Field(
|
2434
|
+
default=None,
|
2435
|
+
description="""The latitude in degrees. It must be in the range [-90.0, +90.0].""",
|
2436
|
+
)
|
2437
|
+
longitude: Optional[float] = Field(
|
2438
|
+
default=None,
|
2439
|
+
description="""The longitude in degrees. It must be in the range [-180.0, +180.0]""",
|
2440
|
+
)
|
2441
|
+
|
2442
|
+
|
2443
|
+
class LatLngDict(TypedDict, total=False):
|
2444
|
+
"""An object that represents a latitude/longitude pair.
|
2445
|
+
|
2446
|
+
This is expressed as a pair of doubles to represent degrees latitude and
|
2447
|
+
degrees longitude. Unless specified otherwise, this object must conform to the
|
2448
|
+
<a href="https://en.wikipedia.org/wiki/World_Geodetic_System#1984_version">
|
2449
|
+
WGS84 standard</a>. Values must be within normalized ranges.
|
2450
|
+
"""
|
2451
|
+
|
2452
|
+
latitude: Optional[float]
|
2453
|
+
"""The latitude in degrees. It must be in the range [-90.0, +90.0]."""
|
2454
|
+
|
2455
|
+
longitude: Optional[float]
|
2456
|
+
"""The longitude in degrees. It must be in the range [-180.0, +180.0]"""
|
2457
|
+
|
2458
|
+
|
2459
|
+
LatLngOrDict = Union[LatLng, LatLngDict]
|
2460
|
+
|
2461
|
+
|
2462
|
+
class RetrievalConfig(_common.BaseModel):
|
2463
|
+
"""Retrieval config."""
|
2464
|
+
|
2465
|
+
lat_lng: Optional[LatLng] = Field(
|
2466
|
+
default=None, description="""Optional. The location of the user."""
|
2467
|
+
)
|
2468
|
+
|
2469
|
+
|
2470
|
+
class RetrievalConfigDict(TypedDict, total=False):
|
2471
|
+
"""Retrieval config."""
|
2472
|
+
|
2473
|
+
lat_lng: Optional[LatLngDict]
|
2474
|
+
"""Optional. The location of the user."""
|
2475
|
+
|
2476
|
+
|
2477
|
+
RetrievalConfigOrDict = Union[RetrievalConfig, RetrievalConfigDict]
|
2478
|
+
|
2479
|
+
|
2211
2480
|
class ToolConfig(_common.BaseModel):
|
2212
2481
|
"""Tool config.
|
2213
2482
|
|
@@ -2217,6 +2486,9 @@ class ToolConfig(_common.BaseModel):
|
|
2217
2486
|
function_calling_config: Optional[FunctionCallingConfig] = Field(
|
2218
2487
|
default=None, description="""Optional. Function calling config."""
|
2219
2488
|
)
|
2489
|
+
retrieval_config: Optional[RetrievalConfig] = Field(
|
2490
|
+
default=None, description="""Optional. Retrieval config."""
|
2491
|
+
)
|
2220
2492
|
|
2221
2493
|
|
2222
2494
|
class ToolConfigDict(TypedDict, total=False):
|
@@ -2228,6 +2500,9 @@ class ToolConfigDict(TypedDict, total=False):
|
|
2228
2500
|
function_calling_config: Optional[FunctionCallingConfigDict]
|
2229
2501
|
"""Optional. Function calling config."""
|
2230
2502
|
|
2503
|
+
retrieval_config: Optional[RetrievalConfigDict]
|
2504
|
+
"""Optional. Retrieval config."""
|
2505
|
+
|
2231
2506
|
|
2232
2507
|
ToolConfigOrDict = Union[ToolConfig, ToolConfigDict]
|
2233
2508
|
|
@@ -5544,6 +5819,7 @@ ListModelsResponseOrDict = Union[ListModelsResponse, ListModelsResponseDict]
|
|
5544
5819
|
|
5545
5820
|
|
5546
5821
|
class UpdateModelConfig(_common.BaseModel):
|
5822
|
+
"""Configuration for updating a tuned model."""
|
5547
5823
|
|
5548
5824
|
http_options: Optional[HttpOptions] = Field(
|
5549
5825
|
default=None, description="""Used to override HTTP request options."""
|
@@ -5553,6 +5829,7 @@ class UpdateModelConfig(_common.BaseModel):
|
|
5553
5829
|
|
5554
5830
|
|
5555
5831
|
class UpdateModelConfigDict(TypedDict, total=False):
|
5832
|
+
"""Configuration for updating a tuned model."""
|
5556
5833
|
|
5557
5834
|
http_options: Optional[HttpOptionsDict]
|
5558
5835
|
"""Used to override HTTP request options."""
|
@@ -5568,12 +5845,14 @@ UpdateModelConfigOrDict = Union[UpdateModelConfig, UpdateModelConfigDict]
|
|
5568
5845
|
|
5569
5846
|
|
5570
5847
|
class _UpdateModelParameters(_common.BaseModel):
|
5848
|
+
"""Configuration for updating a tuned model."""
|
5571
5849
|
|
5572
5850
|
model: Optional[str] = Field(default=None, description="""""")
|
5573
5851
|
config: Optional[UpdateModelConfig] = Field(default=None, description="""""")
|
5574
5852
|
|
5575
5853
|
|
5576
5854
|
class _UpdateModelParametersDict(TypedDict, total=False):
|
5855
|
+
"""Configuration for updating a tuned model."""
|
5577
5856
|
|
5578
5857
|
model: Optional[str]
|
5579
5858
|
""""""
|
@@ -5588,6 +5867,7 @@ _UpdateModelParametersOrDict = Union[
|
|
5588
5867
|
|
5589
5868
|
|
5590
5869
|
class DeleteModelConfig(_common.BaseModel):
|
5870
|
+
"""Configuration for deleting a tuned model."""
|
5591
5871
|
|
5592
5872
|
http_options: Optional[HttpOptions] = Field(
|
5593
5873
|
default=None, description="""Used to override HTTP request options."""
|
@@ -5595,6 +5875,7 @@ class DeleteModelConfig(_common.BaseModel):
|
|
5595
5875
|
|
5596
5876
|
|
5597
5877
|
class DeleteModelConfigDict(TypedDict, total=False):
|
5878
|
+
"""Configuration for deleting a tuned model."""
|
5598
5879
|
|
5599
5880
|
http_options: Optional[HttpOptionsDict]
|
5600
5881
|
"""Used to override HTTP request options."""
|
@@ -5604,6 +5885,7 @@ DeleteModelConfigOrDict = Union[DeleteModelConfig, DeleteModelConfigDict]
|
|
5604
5885
|
|
5605
5886
|
|
5606
5887
|
class _DeleteModelParameters(_common.BaseModel):
|
5888
|
+
"""Parameters for deleting a tuned model."""
|
5607
5889
|
|
5608
5890
|
model: Optional[str] = Field(default=None, description="""""")
|
5609
5891
|
config: Optional[DeleteModelConfig] = Field(
|
@@ -5612,6 +5894,7 @@ class _DeleteModelParameters(_common.BaseModel):
|
|
5612
5894
|
|
5613
5895
|
|
5614
5896
|
class _DeleteModelParametersDict(TypedDict, total=False):
|
5897
|
+
"""Parameters for deleting a tuned model."""
|
5615
5898
|
|
5616
5899
|
model: Optional[str]
|
5617
5900
|
""""""
|
@@ -7585,7 +7868,7 @@ class _CreateCachedContentParameters(_common.BaseModel):
|
|
7585
7868
|
|
7586
7869
|
model: Optional[str] = Field(
|
7587
7870
|
default=None,
|
7588
|
-
description="""ID of the model to use. Example: gemini-
|
7871
|
+
description="""ID of the model to use. Example: gemini-2.0-flash""",
|
7589
7872
|
)
|
7590
7873
|
config: Optional[CreateCachedContentConfig] = Field(
|
7591
7874
|
default=None,
|
@@ -7598,7 +7881,7 @@ class _CreateCachedContentParametersDict(TypedDict, total=False):
|
|
7598
7881
|
"""Parameters for caches.create method."""
|
7599
7882
|
|
7600
7883
|
model: Optional[str]
|
7601
|
-
"""ID of the model to use. Example: gemini-
|
7884
|
+
"""ID of the model to use. Example: gemini-2.0-flash"""
|
7602
7885
|
|
7603
7886
|
config: Optional[CreateCachedContentConfigDict]
|
7604
7887
|
"""Configuration that contains optional parameters.
|
@@ -9603,6 +9886,10 @@ class LiveServerContent(_common.BaseModel):
|
|
9603
9886
|
default=None,
|
9604
9887
|
description="""If true, indicates that a client message has interrupted current model generation. If the client is playing out the content in realtime, this is a good signal to stop and empty the current queue.""",
|
9605
9888
|
)
|
9889
|
+
grounding_metadata: Optional[GroundingMetadata] = Field(
|
9890
|
+
default=None,
|
9891
|
+
description="""Metadata returned to client when grounding is enabled.""",
|
9892
|
+
)
|
9606
9893
|
generation_complete: Optional[bool] = Field(
|
9607
9894
|
default=None,
|
9608
9895
|
description="""If true, indicates that the model is done generating. When model is
|
@@ -9645,6 +9932,9 @@ class LiveServerContentDict(TypedDict, total=False):
|
|
9645
9932
|
interrupted: Optional[bool]
|
9646
9933
|
"""If true, indicates that a client message has interrupted current model generation. If the client is playing out the content in realtime, this is a good signal to stop and empty the current queue."""
|
9647
9934
|
|
9935
|
+
grounding_metadata: Optional[GroundingMetadataDict]
|
9936
|
+
"""Metadata returned to client when grounding is enabled."""
|
9937
|
+
|
9648
9938
|
generation_complete: Optional[bool]
|
9649
9939
|
"""If true, indicates that the model is done generating. When model is
|
9650
9940
|
interrupted while generating there will be no generation_complete message
|
@@ -9920,11 +10210,23 @@ class LiveServerMessage(_common.BaseModel):
|
|
9920
10210
|
):
|
9921
10211
|
return None
|
9922
10212
|
text = ''
|
10213
|
+
non_text_parts = []
|
9923
10214
|
for part in self.server_content.model_turn.parts:
|
10215
|
+
for field_name, field_value in part.model_dump(
|
10216
|
+
exclude={'text', 'thought'}
|
10217
|
+
).items():
|
10218
|
+
if field_value is not None:
|
10219
|
+
non_text_parts.append(field_name)
|
9924
10220
|
if isinstance(part.text, str):
|
9925
10221
|
if isinstance(part.thought, bool) and part.thought:
|
9926
10222
|
continue
|
9927
10223
|
text += part.text
|
10224
|
+
if non_text_parts:
|
10225
|
+
logger.warning(
|
10226
|
+
'Warning: there are non-text parts in the response:'
|
10227
|
+
f' {non_text_parts}, returning concatenated text result from text'
|
10228
|
+
' parts, check out the non text parts for full response from model.'
|
10229
|
+
)
|
9928
10230
|
return text if text else None
|
9929
10231
|
|
9930
10232
|
@property
|
@@ -9938,9 +10240,21 @@ class LiveServerMessage(_common.BaseModel):
|
|
9938
10240
|
):
|
9939
10241
|
return None
|
9940
10242
|
concatenated_data = b''
|
10243
|
+
non_data_parts = []
|
9941
10244
|
for part in self.server_content.model_turn.parts:
|
10245
|
+
for field_name, field_value in part.model_dump(
|
10246
|
+
exclude={'inline_data'}
|
10247
|
+
).items():
|
10248
|
+
if field_value is not None:
|
10249
|
+
non_data_parts.append(field_name)
|
9942
10250
|
if part.inline_data and isinstance(part.inline_data.data, bytes):
|
9943
10251
|
concatenated_data += part.inline_data.data
|
10252
|
+
if non_data_parts:
|
10253
|
+
logger.warning(
|
10254
|
+
'Warning: there are non-data parts in the response:'
|
10255
|
+
f' {non_data_parts}, returning concatenated data result from data'
|
10256
|
+
' parts, check out the non data parts for full response from model.'
|
10257
|
+
)
|
9944
10258
|
return concatenated_data if len(concatenated_data) > 0 else None
|
9945
10259
|
|
9946
10260
|
|
@@ -10218,6 +10532,17 @@ class LiveClientSetup(_common.BaseModel):
|
|
10218
10532
|
|
10219
10533
|
If included, server will compress context window to fit into given length.""",
|
10220
10534
|
)
|
10535
|
+
input_audio_transcription: Optional[AudioTranscriptionConfig] = Field(
|
10536
|
+
default=None,
|
10537
|
+
description="""The transcription of the input aligns with the input audio language.
|
10538
|
+
""",
|
10539
|
+
)
|
10540
|
+
output_audio_transcription: Optional[AudioTranscriptionConfig] = Field(
|
10541
|
+
default=None,
|
10542
|
+
description="""The transcription of the output aligns with the language code
|
10543
|
+
specified for the output audio.
|
10544
|
+
""",
|
10545
|
+
)
|
10221
10546
|
|
10222
10547
|
|
10223
10548
|
class LiveClientSetupDict(TypedDict, total=False):
|
@@ -10256,6 +10581,15 @@ class LiveClientSetupDict(TypedDict, total=False):
|
|
10256
10581
|
|
10257
10582
|
If included, server will compress context window to fit into given length."""
|
10258
10583
|
|
10584
|
+
input_audio_transcription: Optional[AudioTranscriptionConfigDict]
|
10585
|
+
"""The transcription of the input aligns with the input audio language.
|
10586
|
+
"""
|
10587
|
+
|
10588
|
+
output_audio_transcription: Optional[AudioTranscriptionConfigDict]
|
10589
|
+
"""The transcription of the output aligns with the language code
|
10590
|
+
specified for the output audio.
|
10591
|
+
"""
|
10592
|
+
|
10259
10593
|
|
10260
10594
|
LiveClientSetupOrDict = Union[LiveClientSetup, LiveClientSetupDict]
|
10261
10595
|
|
@@ -10762,6 +11096,7 @@ if _is_pillow_image_imported:
|
|
10762
11096
|
else:
|
10763
11097
|
BlobImageUnion = Blob # type: ignore[misc]
|
10764
11098
|
|
11099
|
+
|
10765
11100
|
BlobImageUnionDict = Union[BlobImageUnion, BlobDict]
|
10766
11101
|
|
10767
11102
|
|