google-genai 1.55.0__py3-none-any.whl → 1.57.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 +37 -18
- google/genai/_interactions/_base_client.py +8 -2
- google/genai/_interactions/resources/interactions.py +6 -6
- google/genai/_interactions/types/__init__.py +4 -0
- google/genai/_interactions/types/audio_content.py +0 -1
- google/genai/_interactions/types/audio_content_param.py +0 -1
- google/genai/_interactions/types/code_execution_call_content.py +0 -1
- google/genai/_interactions/types/code_execution_call_content_param.py +0 -1
- google/genai/_interactions/types/code_execution_result_content.py +0 -1
- google/genai/_interactions/types/code_execution_result_content_param.py +0 -1
- google/genai/_interactions/types/content.py +63 -0
- google/genai/_interactions/types/content_delta.py +7 -23
- google/genai/_interactions/types/content_param.py +61 -0
- google/genai/_interactions/types/content_start.py +4 -44
- google/genai/_interactions/types/deep_research_agent_config.py +0 -1
- google/genai/_interactions/types/deep_research_agent_config_param.py +0 -1
- google/genai/_interactions/types/document_content.py +3 -2
- google/genai/_interactions/types/document_content_param.py +3 -2
- google/genai/_interactions/types/document_mime_type.py +23 -0
- google/genai/_interactions/types/document_mime_type_param.py +25 -0
- google/genai/_interactions/types/dynamic_agent_config.py +0 -1
- google/genai/_interactions/types/dynamic_agent_config_param.py +0 -1
- google/genai/_interactions/types/file_search_result_content.py +0 -1
- google/genai/_interactions/types/file_search_result_content_param.py +0 -1
- google/genai/_interactions/types/function_call_content.py +0 -1
- google/genai/_interactions/types/function_call_content_param.py +0 -1
- google/genai/_interactions/types/function_result_content.py +1 -2
- google/genai/_interactions/types/function_result_content_param.py +1 -2
- google/genai/_interactions/types/google_search_call_content.py +0 -1
- google/genai/_interactions/types/google_search_call_content_param.py +0 -1
- google/genai/_interactions/types/google_search_result_content.py +0 -1
- google/genai/_interactions/types/google_search_result_content_param.py +0 -1
- google/genai/_interactions/types/image_content.py +1 -2
- google/genai/_interactions/types/image_content_param.py +1 -2
- google/genai/_interactions/types/interaction.py +4 -52
- google/genai/_interactions/types/interaction_create_params.py +2 -22
- google/genai/_interactions/types/mcp_server_tool_call_content.py +0 -1
- google/genai/_interactions/types/mcp_server_tool_call_content_param.py +0 -1
- google/genai/_interactions/types/mcp_server_tool_result_content.py +1 -2
- google/genai/_interactions/types/mcp_server_tool_result_content_param.py +1 -2
- google/genai/_interactions/types/model.py +1 -0
- google/genai/_interactions/types/model_param.py +1 -0
- google/genai/_interactions/types/text_content.py +0 -1
- google/genai/_interactions/types/text_content_param.py +0 -1
- google/genai/_interactions/types/thinking_level.py +1 -1
- google/genai/_interactions/types/thought_content.py +0 -1
- google/genai/_interactions/types/thought_content_param.py +0 -1
- google/genai/_interactions/types/turn.py +3 -44
- google/genai/_interactions/types/turn_param.py +4 -40
- google/genai/_interactions/types/url_context_call_content.py +0 -1
- google/genai/_interactions/types/url_context_call_content_param.py +0 -1
- google/genai/_interactions/types/url_context_result_content.py +0 -1
- google/genai/_interactions/types/url_context_result_content_param.py +0 -1
- google/genai/_interactions/types/usage.py +1 -1
- google/genai/_interactions/types/usage_param.py +1 -1
- google/genai/_interactions/types/video_content.py +1 -2
- google/genai/_interactions/types/video_content_param.py +1 -2
- google/genai/_live_converters.py +36 -64
- google/genai/_local_tokenizer_loader.py +1 -0
- google/genai/_tokens_converters.py +14 -14
- google/genai/batches.py +27 -22
- google/genai/caches.py +42 -42
- google/genai/chats.py +0 -2
- google/genai/client.py +3 -1
- google/genai/files.py +224 -0
- google/genai/models.py +57 -72
- google/genai/tests/chats/test_get_history.py +9 -8
- google/genai/tests/chats/test_validate_response.py +1 -1
- google/genai/tests/client/test_client_requests.py +1 -135
- google/genai/tests/files/test_register.py +272 -0
- google/genai/tests/files/test_register_table.py +70 -0
- google/genai/tests/interactions/test_auth.py +479 -0
- google/genai/tests/interactions/test_integration.py +2 -0
- google/genai/tests/interactions/test_paths.py +105 -0
- google/genai/tests/live/test_live.py +2 -36
- google/genai/tests/local_tokenizer/test_local_tokenizer.py +1 -1
- google/genai/tests/models/test_function_call_streaming.py +90 -90
- google/genai/tests/models/test_generate_content.py +1 -2
- google/genai/tests/models/test_recontext_image.py +1 -1
- google/genai/tests/pytest_helper.py +17 -0
- google/genai/tunings.py +1 -27
- google/genai/types.py +603 -518
- google/genai/version.py +1 -1
- {google_genai-1.55.0.dist-info → google_genai-1.57.0.dist-info}/METADATA +224 -22
- {google_genai-1.55.0.dist-info → google_genai-1.57.0.dist-info}/RECORD +88 -80
- {google_genai-1.55.0.dist-info → google_genai-1.57.0.dist-info}/WHEEL +0 -0
- {google_genai-1.55.0.dist-info → google_genai-1.57.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.55.0.dist-info → google_genai-1.57.0.dist-info}/top_level.txt +0 -0
google/genai/types.py
CHANGED
|
@@ -86,11 +86,6 @@ else:
|
|
|
86
86
|
|
|
87
87
|
if typing.TYPE_CHECKING:
|
|
88
88
|
import yaml
|
|
89
|
-
else:
|
|
90
|
-
try:
|
|
91
|
-
import yaml
|
|
92
|
-
except ImportError:
|
|
93
|
-
yaml = None
|
|
94
89
|
|
|
95
90
|
_is_httpx_imported = False
|
|
96
91
|
if typing.TYPE_CHECKING:
|
|
@@ -187,15 +182,6 @@ class Type(_common.CaseInSensitiveEnum):
|
|
|
187
182
|
"""Null type"""
|
|
188
183
|
|
|
189
184
|
|
|
190
|
-
class Mode(_common.CaseInSensitiveEnum):
|
|
191
|
-
"""The mode of the predictor to be used in dynamic retrieval."""
|
|
192
|
-
|
|
193
|
-
MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
|
|
194
|
-
"""Always trigger retrieval."""
|
|
195
|
-
MODE_DYNAMIC = 'MODE_DYNAMIC'
|
|
196
|
-
"""Run retrieval only when system decides it is necessary."""
|
|
197
|
-
|
|
198
|
-
|
|
199
185
|
class ApiSpec(_common.CaseInSensitiveEnum):
|
|
200
186
|
"""The API spec that the external API implements.
|
|
201
187
|
|
|
@@ -266,15 +252,58 @@ class PhishBlockThreshold(_common.CaseInSensitiveEnum):
|
|
|
266
252
|
"""Blocks Extremely high confidence URL that is risky."""
|
|
267
253
|
|
|
268
254
|
|
|
255
|
+
class Behavior(_common.CaseInSensitiveEnum):
|
|
256
|
+
"""Specifies the function Behavior.
|
|
257
|
+
|
|
258
|
+
Currently only supported by the BidiGenerateContent method. This enum is not
|
|
259
|
+
supported in Vertex AI.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
UNSPECIFIED = 'UNSPECIFIED'
|
|
263
|
+
"""This value is unused."""
|
|
264
|
+
BLOCKING = 'BLOCKING'
|
|
265
|
+
"""If set, the system will wait to receive the function response before continuing the conversation."""
|
|
266
|
+
NON_BLOCKING = 'NON_BLOCKING'
|
|
267
|
+
"""If set, the system will not wait to receive the function response. Instead, it will attempt to handle function responses as they become available while maintaining the conversation between the user and the model."""
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class DynamicRetrievalConfigMode(_common.CaseInSensitiveEnum):
|
|
271
|
+
"""The mode of the predictor to be used in dynamic retrieval."""
|
|
272
|
+
|
|
273
|
+
MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
|
|
274
|
+
"""Always trigger retrieval."""
|
|
275
|
+
MODE_DYNAMIC = 'MODE_DYNAMIC'
|
|
276
|
+
"""Run retrieval only when system decides it is necessary."""
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class FunctionCallingConfigMode(_common.CaseInSensitiveEnum):
|
|
280
|
+
"""Function calling mode."""
|
|
281
|
+
|
|
282
|
+
MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
|
|
283
|
+
"""Unspecified function calling mode. This value should not be used."""
|
|
284
|
+
AUTO = 'AUTO'
|
|
285
|
+
"""Default model behavior, model decides to predict either function calls or natural language response."""
|
|
286
|
+
ANY = 'ANY'
|
|
287
|
+
"""Model is constrained to always predicting function calls only. If "allowed_function_names" are set, the predicted function calls will be limited to any one of "allowed_function_names", else the predicted function calls will be any one of the provided "function_declarations"."""
|
|
288
|
+
NONE = 'NONE'
|
|
289
|
+
"""Model will not predict any function calls. Model behavior is same as when not passing any function declarations."""
|
|
290
|
+
VALIDATED = 'VALIDATED'
|
|
291
|
+
"""Model is constrained to predict either function calls or natural language response. If "allowed_function_names" are set, the predicted function calls will be limited to any one of "allowed_function_names", else the predicted function calls will be any one of the provided "function_declarations"."""
|
|
292
|
+
|
|
293
|
+
|
|
269
294
|
class ThinkingLevel(_common.CaseInSensitiveEnum):
|
|
270
|
-
"""The
|
|
295
|
+
"""The number of thoughts tokens that the model should generate."""
|
|
271
296
|
|
|
272
297
|
THINKING_LEVEL_UNSPECIFIED = 'THINKING_LEVEL_UNSPECIFIED'
|
|
273
|
-
"""
|
|
298
|
+
"""Unspecified thinking level."""
|
|
274
299
|
LOW = 'LOW'
|
|
275
300
|
"""Low thinking level."""
|
|
301
|
+
MEDIUM = 'MEDIUM'
|
|
302
|
+
"""Medium thinking level."""
|
|
276
303
|
HIGH = 'HIGH'
|
|
277
304
|
"""High thinking level."""
|
|
305
|
+
MINIMAL = 'MINIMAL'
|
|
306
|
+
"""MINIMAL thinking level."""
|
|
278
307
|
|
|
279
308
|
|
|
280
309
|
class HarmCategory(_common.CaseInSensitiveEnum):
|
|
@@ -577,6 +606,8 @@ class PartMediaResolutionLevel(_common.CaseInSensitiveEnum):
|
|
|
577
606
|
"""Media resolution set to medium."""
|
|
578
607
|
MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH'
|
|
579
608
|
"""Media resolution set to high."""
|
|
609
|
+
MEDIA_RESOLUTION_ULTRA_HIGH = 'MEDIA_RESOLUTION_ULTRA_HIGH'
|
|
610
|
+
"""Media resolution set to ultra high."""
|
|
580
611
|
|
|
581
612
|
|
|
582
613
|
class ResourceScope(_common.CaseInSensitiveEnum):
|
|
@@ -617,26 +648,6 @@ class FeatureSelectionPreference(_common.CaseInSensitiveEnum):
|
|
|
617
648
|
PRIORITIZE_COST = 'PRIORITIZE_COST'
|
|
618
649
|
|
|
619
650
|
|
|
620
|
-
class Behavior(_common.CaseInSensitiveEnum):
|
|
621
|
-
"""Defines the function behavior. Defaults to `BLOCKING`."""
|
|
622
|
-
|
|
623
|
-
UNSPECIFIED = 'UNSPECIFIED'
|
|
624
|
-
"""This value is unused."""
|
|
625
|
-
BLOCKING = 'BLOCKING'
|
|
626
|
-
"""If set, the system will wait to receive the function response before continuing the conversation."""
|
|
627
|
-
NON_BLOCKING = 'NON_BLOCKING'
|
|
628
|
-
"""If set, the system will not wait to receive the function response. Instead, it will attempt to handle function responses as they become available while maintaining the conversation between the user and the model."""
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
class DynamicRetrievalConfigMode(_common.CaseInSensitiveEnum):
|
|
632
|
-
"""Config for the dynamic retrieval config mode."""
|
|
633
|
-
|
|
634
|
-
MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
|
|
635
|
-
"""Always trigger retrieval."""
|
|
636
|
-
MODE_DYNAMIC = 'MODE_DYNAMIC'
|
|
637
|
-
"""Run retrieval only when system decides it is necessary."""
|
|
638
|
-
|
|
639
|
-
|
|
640
651
|
class Environment(_common.CaseInSensitiveEnum):
|
|
641
652
|
"""The environment being operated."""
|
|
642
653
|
|
|
@@ -646,21 +657,6 @@ class Environment(_common.CaseInSensitiveEnum):
|
|
|
646
657
|
"""Operates in a web browser."""
|
|
647
658
|
|
|
648
659
|
|
|
649
|
-
class FunctionCallingConfigMode(_common.CaseInSensitiveEnum):
|
|
650
|
-
"""Config for the function calling config mode."""
|
|
651
|
-
|
|
652
|
-
MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
|
|
653
|
-
"""The function calling config mode is unspecified. Should not be used."""
|
|
654
|
-
AUTO = 'AUTO'
|
|
655
|
-
"""Default model behavior, model decides to predict either function calls or natural language response."""
|
|
656
|
-
ANY = 'ANY'
|
|
657
|
-
"""Model is constrained to always predicting function calls only. If "allowed_function_names" are set, the predicted function calls will be limited to any one of "allowed_function_names", else the predicted function calls will be any one of the provided "function_declarations"."""
|
|
658
|
-
NONE = 'NONE'
|
|
659
|
-
"""Model will not predict any function calls. Model behavior is same as when not passing any function declarations."""
|
|
660
|
-
VALIDATED = 'VALIDATED'
|
|
661
|
-
"""Model decides to predict either a function call or a natural language response, but will validate function calls with constrained decoding. If "allowed_function_names" are set, the predicted function call will be limited to any one of "allowed_function_names", else the predicted function call will be any one of the provided "function_declarations"."""
|
|
662
|
-
|
|
663
|
-
|
|
664
660
|
class SafetyFilterLevel(_common.CaseInSensitiveEnum):
|
|
665
661
|
"""Enum that controls the safety filter level for objectionable content."""
|
|
666
662
|
|
|
@@ -829,6 +825,7 @@ class FileSource(_common.CaseInSensitiveEnum):
|
|
|
829
825
|
SOURCE_UNSPECIFIED = 'SOURCE_UNSPECIFIED'
|
|
830
826
|
UPLOADED = 'UPLOADED'
|
|
831
827
|
GENERATED = 'GENERATED'
|
|
828
|
+
REGISTERED = 'REGISTERED'
|
|
832
829
|
|
|
833
830
|
|
|
834
831
|
class TurnCompleteReason(_common.CaseInSensitiveEnum):
|
|
@@ -2804,404 +2801,95 @@ ModelSelectionConfigOrDict = Union[
|
|
|
2804
2801
|
]
|
|
2805
2802
|
|
|
2806
2803
|
|
|
2807
|
-
class
|
|
2808
|
-
"""
|
|
2809
|
-
|
|
2810
|
-
The inputs are based on `OpenAPI 3.0 specifications
|
|
2811
|
-
<https://spec.openapis.org/oas/v3.0.3>`_.
|
|
2812
|
-
"""
|
|
2804
|
+
class ComputerUse(_common.BaseModel):
|
|
2805
|
+
"""Tool to support computer use."""
|
|
2813
2806
|
|
|
2814
|
-
|
|
2815
|
-
default=None, description="""
|
|
2807
|
+
environment: Optional[Environment] = Field(
|
|
2808
|
+
default=None, description="""Required. The environment being operated."""
|
|
2816
2809
|
)
|
|
2817
|
-
|
|
2810
|
+
excluded_predefined_functions: Optional[list[str]] = Field(
|
|
2818
2811
|
default=None,
|
|
2819
|
-
description="""
|
|
2812
|
+
description="""By default, predefined functions are included in the final model call.
|
|
2813
|
+
Some of them can be explicitly excluded from being automatically included.
|
|
2814
|
+
This can serve two purposes:
|
|
2815
|
+
1. Using a more restricted / different action space.
|
|
2816
|
+
2. Improving the definitions / instructions of predefined functions.""",
|
|
2820
2817
|
)
|
|
2821
|
-
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
class ComputerUseDict(TypedDict, total=False):
|
|
2821
|
+
"""Tool to support computer use."""
|
|
2822
|
+
|
|
2823
|
+
environment: Optional[Environment]
|
|
2824
|
+
"""Required. The environment being operated."""
|
|
2825
|
+
|
|
2826
|
+
excluded_predefined_functions: Optional[list[str]]
|
|
2827
|
+
"""By default, predefined functions are included in the final model call.
|
|
2828
|
+
Some of them can be explicitly excluded from being automatically included.
|
|
2829
|
+
This can serve two purposes:
|
|
2830
|
+
1. Using a more restricted / different action space.
|
|
2831
|
+
2. Improving the definitions / instructions of predefined functions."""
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]
|
|
2835
|
+
|
|
2836
|
+
|
|
2837
|
+
class FileSearch(_common.BaseModel):
|
|
2838
|
+
"""Tool to retrieve knowledge from the File Search Stores."""
|
|
2839
|
+
|
|
2840
|
+
file_search_store_names: Optional[list[str]] = Field(
|
|
2822
2841
|
default=None,
|
|
2823
|
-
description="""
|
|
2842
|
+
description="""The names of the file_search_stores to retrieve from.
|
|
2843
|
+
Example: `fileSearchStores/my-file-search-store-123`""",
|
|
2824
2844
|
)
|
|
2825
|
-
|
|
2845
|
+
top_k: Optional[int] = Field(
|
|
2826
2846
|
default=None,
|
|
2827
|
-
description="""
|
|
2847
|
+
description="""The number of file search retrieval chunks to retrieve.""",
|
|
2828
2848
|
)
|
|
2829
|
-
|
|
2849
|
+
metadata_filter: Optional[str] = Field(
|
|
2830
2850
|
default=None,
|
|
2831
|
-
description="""
|
|
2851
|
+
description="""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.""",
|
|
2832
2852
|
)
|
|
2833
|
-
|
|
2853
|
+
|
|
2854
|
+
|
|
2855
|
+
class FileSearchDict(TypedDict, total=False):
|
|
2856
|
+
"""Tool to retrieve knowledge from the File Search Stores."""
|
|
2857
|
+
|
|
2858
|
+
file_search_store_names: Optional[list[str]]
|
|
2859
|
+
"""The names of the file_search_stores to retrieve from.
|
|
2860
|
+
Example: `fileSearchStores/my-file-search-store-123`"""
|
|
2861
|
+
|
|
2862
|
+
top_k: Optional[int]
|
|
2863
|
+
"""The number of file search retrieval chunks to retrieve."""
|
|
2864
|
+
|
|
2865
|
+
metadata_filter: Optional[str]
|
|
2866
|
+
"""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."""
|
|
2867
|
+
|
|
2868
|
+
|
|
2869
|
+
FileSearchOrDict = Union[FileSearch, FileSearchDict]
|
|
2870
|
+
|
|
2871
|
+
|
|
2872
|
+
class ApiAuthApiKeyConfig(_common.BaseModel):
|
|
2873
|
+
"""The API secret. This data type is not supported in Gemini API."""
|
|
2874
|
+
|
|
2875
|
+
api_key_secret_version: Optional[str] = Field(
|
|
2834
2876
|
default=None,
|
|
2835
|
-
description="""
|
|
2877
|
+
description="""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}""",
|
|
2836
2878
|
)
|
|
2837
|
-
|
|
2879
|
+
api_key_string: Optional[str] = Field(
|
|
2838
2880
|
default=None,
|
|
2839
|
-
description="""
|
|
2881
|
+
description="""The API key string. Either this or `api_key_secret_version` must be set.""",
|
|
2840
2882
|
)
|
|
2841
2883
|
|
|
2842
|
-
@classmethod
|
|
2843
|
-
def from_callable_with_api_option(
|
|
2844
|
-
cls,
|
|
2845
|
-
*,
|
|
2846
|
-
callable: Callable[..., Any],
|
|
2847
|
-
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
|
2848
|
-
behavior: Optional[Behavior] = None,
|
|
2849
|
-
) -> 'FunctionDeclaration':
|
|
2850
|
-
"""Converts a Callable to a FunctionDeclaration based on the API option.
|
|
2851
2884
|
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
will raise ValueError.
|
|
2855
|
-
"""
|
|
2856
|
-
supported_api_options = ['VERTEX_AI', 'GEMINI_API']
|
|
2857
|
-
if api_option not in supported_api_options:
|
|
2858
|
-
raise ValueError(
|
|
2859
|
-
f'Unsupported api_option value: {api_option}. Supported api_option'
|
|
2860
|
-
f' value is one of: {supported_api_options}.'
|
|
2861
|
-
)
|
|
2862
|
-
from . import _automatic_function_calling_util
|
|
2885
|
+
class ApiAuthApiKeyConfigDict(TypedDict, total=False):
|
|
2886
|
+
"""The API secret. This data type is not supported in Gemini API."""
|
|
2863
2887
|
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
annotation_under_future = typing.get_type_hints(callable)
|
|
2867
|
-
try:
|
|
2868
|
-
for name, param in inspect.signature(callable).parameters.items():
|
|
2869
|
-
if param.kind in (
|
|
2870
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
2871
|
-
inspect.Parameter.KEYWORD_ONLY,
|
|
2872
|
-
inspect.Parameter.POSITIONAL_ONLY,
|
|
2873
|
-
):
|
|
2874
|
-
param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
|
|
2875
|
-
param, annotation_under_future, name
|
|
2876
|
-
)
|
|
2877
|
-
schema = (
|
|
2878
|
-
_automatic_function_calling_util._parse_schema_from_parameter(
|
|
2879
|
-
api_option, param, callable.__name__
|
|
2880
|
-
)
|
|
2881
|
-
)
|
|
2882
|
-
parameters_properties[name] = schema
|
|
2883
|
-
except ValueError:
|
|
2884
|
-
parameters_properties = {}
|
|
2885
|
-
for name, param in inspect.signature(callable).parameters.items():
|
|
2886
|
-
if param.kind in (
|
|
2887
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
2888
|
-
inspect.Parameter.KEYWORD_ONLY,
|
|
2889
|
-
inspect.Parameter.POSITIONAL_ONLY,
|
|
2890
|
-
):
|
|
2891
|
-
try:
|
|
2892
|
-
param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
|
|
2893
|
-
param, annotation_under_future, name
|
|
2894
|
-
)
|
|
2895
|
-
param_schema_adapter = pydantic.TypeAdapter(
|
|
2896
|
-
param.annotation,
|
|
2897
|
-
config=pydantic.ConfigDict(arbitrary_types_allowed=True),
|
|
2898
|
-
)
|
|
2899
|
-
json_schema_dict = param_schema_adapter.json_schema()
|
|
2900
|
-
json_schema_dict = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
|
|
2901
|
-
json_schema_dict
|
|
2902
|
-
)
|
|
2903
|
-
if 'prefixItems' in json_schema_dict:
|
|
2904
|
-
parameters_json_schema[name] = json_schema_dict
|
|
2905
|
-
continue
|
|
2888
|
+
api_key_secret_version: Optional[str]
|
|
2889
|
+
"""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}"""
|
|
2906
2890
|
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
_automatic_function_calling_util._is_builtin_primitive_or_compound(
|
|
2910
|
-
arg
|
|
2911
|
-
)
|
|
2912
|
-
for arg in union_args
|
|
2913
|
-
)
|
|
2914
|
-
if (
|
|
2915
|
-
'$ref' in json_schema_dict or '$defs' in json_schema_dict
|
|
2916
|
-
) and has_primitive:
|
|
2917
|
-
# This is a complex schema with a primitive (e.g., str | MyModel)
|
|
2918
|
-
# that is better represented by raw JSON schema.
|
|
2919
|
-
parameters_json_schema[name] = json_schema_dict
|
|
2920
|
-
continue
|
|
2921
|
-
|
|
2922
|
-
schema = Schema.from_json_schema(
|
|
2923
|
-
json_schema=JSONSchema(**json_schema_dict),
|
|
2924
|
-
api_option=api_option,
|
|
2925
|
-
)
|
|
2926
|
-
if param.default is not inspect.Parameter.empty:
|
|
2927
|
-
schema.default = param.default
|
|
2928
|
-
parameters_properties[name] = schema
|
|
2929
|
-
except Exception as e:
|
|
2930
|
-
_automatic_function_calling_util._raise_for_unsupported_param(
|
|
2931
|
-
param, callable.__name__, e
|
|
2932
|
-
)
|
|
2933
|
-
|
|
2934
|
-
declaration = FunctionDeclaration(
|
|
2935
|
-
name=callable.__name__,
|
|
2936
|
-
description=inspect.cleandoc(callable.__doc__)
|
|
2937
|
-
if callable.__doc__
|
|
2938
|
-
else callable.__doc__,
|
|
2939
|
-
behavior=behavior,
|
|
2940
|
-
)
|
|
2941
|
-
if parameters_properties:
|
|
2942
|
-
declaration.parameters = Schema(
|
|
2943
|
-
type='OBJECT',
|
|
2944
|
-
properties=parameters_properties,
|
|
2945
|
-
)
|
|
2946
|
-
declaration.parameters.required = (
|
|
2947
|
-
_automatic_function_calling_util._get_required_fields(
|
|
2948
|
-
declaration.parameters
|
|
2949
|
-
)
|
|
2950
|
-
)
|
|
2951
|
-
elif parameters_json_schema:
|
|
2952
|
-
declaration.parameters_json_schema = parameters_json_schema
|
|
2953
|
-
# TODO: b/421991354 - Remove this check once the bug is fixed.
|
|
2954
|
-
if api_option == 'GEMINI_API':
|
|
2955
|
-
return declaration
|
|
2956
|
-
|
|
2957
|
-
return_annotation = inspect.signature(callable).return_annotation
|
|
2958
|
-
if return_annotation is inspect._empty:
|
|
2959
|
-
return declaration
|
|
2960
|
-
|
|
2961
|
-
return_value = inspect.Parameter(
|
|
2962
|
-
'return_value',
|
|
2963
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
2964
|
-
annotation=return_annotation,
|
|
2965
|
-
)
|
|
2966
|
-
|
|
2967
|
-
# This snippet catches the case when type hints are stored as strings
|
|
2968
|
-
if isinstance(return_value.annotation, str):
|
|
2969
|
-
return_value = return_value.replace(
|
|
2970
|
-
annotation=annotation_under_future['return']
|
|
2971
|
-
)
|
|
2972
|
-
response_schema: Optional[Schema] = None
|
|
2973
|
-
response_json_schema: Optional[Union[dict[str, Any], Schema]] = {}
|
|
2974
|
-
try:
|
|
2975
|
-
response_schema = (
|
|
2976
|
-
_automatic_function_calling_util._parse_schema_from_parameter(
|
|
2977
|
-
api_option,
|
|
2978
|
-
return_value,
|
|
2979
|
-
callable.__name__,
|
|
2980
|
-
)
|
|
2981
|
-
)
|
|
2982
|
-
if response_schema.any_of is not None:
|
|
2983
|
-
# To handle any_of, we need to use responseJsonSchema
|
|
2984
|
-
response_json_schema = response_schema
|
|
2985
|
-
response_schema = None
|
|
2986
|
-
except ValueError:
|
|
2987
|
-
try:
|
|
2988
|
-
return_value_schema_adapter = pydantic.TypeAdapter(
|
|
2989
|
-
return_value.annotation,
|
|
2990
|
-
config=pydantic.ConfigDict(arbitrary_types_allowed=True),
|
|
2991
|
-
)
|
|
2992
|
-
response_json_schema = return_value_schema_adapter.json_schema()
|
|
2993
|
-
response_json_schema = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
|
|
2994
|
-
response_json_schema
|
|
2995
|
-
)
|
|
2996
|
-
except Exception as e:
|
|
2997
|
-
_automatic_function_calling_util._raise_for_unsupported_param(
|
|
2998
|
-
return_value, callable.__name__, e
|
|
2999
|
-
)
|
|
3000
|
-
|
|
3001
|
-
if response_schema:
|
|
3002
|
-
declaration.response = response_schema
|
|
3003
|
-
elif response_json_schema:
|
|
3004
|
-
declaration.response_json_schema = response_json_schema
|
|
3005
|
-
return declaration
|
|
3006
|
-
|
|
3007
|
-
@classmethod
|
|
3008
|
-
def from_callable(
|
|
3009
|
-
cls,
|
|
3010
|
-
*,
|
|
3011
|
-
client: 'BaseApiClient',
|
|
3012
|
-
callable: Callable[..., Any],
|
|
3013
|
-
behavior: Optional[Behavior] = None,
|
|
3014
|
-
) -> 'FunctionDeclaration':
|
|
3015
|
-
"""Converts a Callable to a FunctionDeclaration based on the client.
|
|
3016
|
-
|
|
3017
|
-
Note: For best results prefer
|
|
3018
|
-
[Google-style
|
|
3019
|
-
docstring](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods)
|
|
3020
|
-
when describing arguments. This function does **not** parse argument
|
|
3021
|
-
descriptions into the property description slots of the resulting structure.
|
|
3022
|
-
Instead it sends the whole docstring in the top-level function description.
|
|
3023
|
-
Google-style docstring are closest to what the model is trained on.
|
|
3024
|
-
"""
|
|
3025
|
-
if client.vertexai:
|
|
3026
|
-
return cls.from_callable_with_api_option(
|
|
3027
|
-
callable=callable, api_option='VERTEX_AI', behavior=behavior
|
|
3028
|
-
)
|
|
3029
|
-
else:
|
|
3030
|
-
return cls.from_callable_with_api_option(
|
|
3031
|
-
callable=callable, api_option='GEMINI_API', behavior=behavior
|
|
3032
|
-
)
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
class FunctionDeclarationDict(TypedDict, total=False):
|
|
3036
|
-
"""Defines a function that the model can generate JSON inputs for.
|
|
3037
|
-
|
|
3038
|
-
The inputs are based on `OpenAPI 3.0 specifications
|
|
3039
|
-
<https://spec.openapis.org/oas/v3.0.3>`_.
|
|
3040
|
-
"""
|
|
3041
|
-
|
|
3042
|
-
behavior: Optional[Behavior]
|
|
3043
|
-
"""Defines the function behavior."""
|
|
3044
|
-
|
|
3045
|
-
description: Optional[str]
|
|
3046
|
-
"""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function."""
|
|
3047
|
-
|
|
3048
|
-
name: Optional[str]
|
|
3049
|
-
"""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."""
|
|
3050
|
-
|
|
3051
|
-
parameters: Optional[SchemaDict]
|
|
3052
|
-
"""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"""
|
|
3053
|
-
|
|
3054
|
-
parameters_json_schema: Optional[Any]
|
|
3055
|
-
"""Optional. Describes the parameters to the function in JSON Schema format. The schema must describe an object where the properties are the parameters to the function. For example: ``` { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": ["name", "age"], "propertyOrdering": ["name", "age"] } ``` This field is mutually exclusive with `parameters`."""
|
|
3056
|
-
|
|
3057
|
-
response: Optional[SchemaDict]
|
|
3058
|
-
"""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."""
|
|
3059
|
-
|
|
3060
|
-
response_json_schema: Optional[Any]
|
|
3061
|
-
"""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`."""
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
class DynamicRetrievalConfig(_common.BaseModel):
|
|
3068
|
-
"""Describes the options to customize dynamic retrieval."""
|
|
3069
|
-
|
|
3070
|
-
mode: Optional[DynamicRetrievalConfigMode] = Field(
|
|
3071
|
-
default=None,
|
|
3072
|
-
description="""The mode of the predictor to be used in dynamic retrieval.""",
|
|
3073
|
-
)
|
|
3074
|
-
dynamic_threshold: Optional[float] = Field(
|
|
3075
|
-
default=None,
|
|
3076
|
-
description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
|
|
3077
|
-
)
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
class DynamicRetrievalConfigDict(TypedDict, total=False):
|
|
3081
|
-
"""Describes the options to customize dynamic retrieval."""
|
|
3082
|
-
|
|
3083
|
-
mode: Optional[DynamicRetrievalConfigMode]
|
|
3084
|
-
"""The mode of the predictor to be used in dynamic retrieval."""
|
|
3085
|
-
|
|
3086
|
-
dynamic_threshold: Optional[float]
|
|
3087
|
-
"""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used."""
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
DynamicRetrievalConfigOrDict = Union[
|
|
3091
|
-
DynamicRetrievalConfig, DynamicRetrievalConfigDict
|
|
3092
|
-
]
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
class GoogleSearchRetrieval(_common.BaseModel):
|
|
3096
|
-
"""Tool to retrieve public web data for grounding, powered by Google."""
|
|
3097
|
-
|
|
3098
|
-
dynamic_retrieval_config: Optional[DynamicRetrievalConfig] = Field(
|
|
3099
|
-
default=None,
|
|
3100
|
-
description="""Specifies the dynamic retrieval configuration for the given source.""",
|
|
3101
|
-
)
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
class GoogleSearchRetrievalDict(TypedDict, total=False):
|
|
3105
|
-
"""Tool to retrieve public web data for grounding, powered by Google."""
|
|
3106
|
-
|
|
3107
|
-
dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
|
|
3108
|
-
"""Specifies the dynamic retrieval configuration for the given source."""
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
GoogleSearchRetrievalOrDict = Union[
|
|
3112
|
-
GoogleSearchRetrieval, GoogleSearchRetrievalDict
|
|
3113
|
-
]
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
class ComputerUse(_common.BaseModel):
|
|
3117
|
-
"""Tool to support computer use."""
|
|
3118
|
-
|
|
3119
|
-
environment: Optional[Environment] = Field(
|
|
3120
|
-
default=None, description="""Required. The environment being operated."""
|
|
3121
|
-
)
|
|
3122
|
-
excluded_predefined_functions: Optional[list[str]] = Field(
|
|
3123
|
-
default=None,
|
|
3124
|
-
description="""By default, predefined functions are included in the final model call.
|
|
3125
|
-
Some of them can be explicitly excluded from being automatically included.
|
|
3126
|
-
This can serve two purposes:
|
|
3127
|
-
1. Using a more restricted / different action space.
|
|
3128
|
-
2. Improving the definitions / instructions of predefined functions.""",
|
|
3129
|
-
)
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
class ComputerUseDict(TypedDict, total=False):
|
|
3133
|
-
"""Tool to support computer use."""
|
|
3134
|
-
|
|
3135
|
-
environment: Optional[Environment]
|
|
3136
|
-
"""Required. The environment being operated."""
|
|
3137
|
-
|
|
3138
|
-
excluded_predefined_functions: Optional[list[str]]
|
|
3139
|
-
"""By default, predefined functions are included in the final model call.
|
|
3140
|
-
Some of them can be explicitly excluded from being automatically included.
|
|
3141
|
-
This can serve two purposes:
|
|
3142
|
-
1. Using a more restricted / different action space.
|
|
3143
|
-
2. Improving the definitions / instructions of predefined functions."""
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
class FileSearch(_common.BaseModel):
|
|
3150
|
-
"""Tool to retrieve knowledge from the File Search Stores."""
|
|
3151
|
-
|
|
3152
|
-
file_search_store_names: Optional[list[str]] = Field(
|
|
3153
|
-
default=None,
|
|
3154
|
-
description="""The names of the file_search_stores to retrieve from.
|
|
3155
|
-
Example: `fileSearchStores/my-file-search-store-123`""",
|
|
3156
|
-
)
|
|
3157
|
-
top_k: Optional[int] = Field(
|
|
3158
|
-
default=None,
|
|
3159
|
-
description="""The number of file search retrieval chunks to retrieve.""",
|
|
3160
|
-
)
|
|
3161
|
-
metadata_filter: Optional[str] = Field(
|
|
3162
|
-
default=None,
|
|
3163
|
-
description="""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.""",
|
|
3164
|
-
)
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
class FileSearchDict(TypedDict, total=False):
|
|
3168
|
-
"""Tool to retrieve knowledge from the File Search Stores."""
|
|
3169
|
-
|
|
3170
|
-
file_search_store_names: Optional[list[str]]
|
|
3171
|
-
"""The names of the file_search_stores to retrieve from.
|
|
3172
|
-
Example: `fileSearchStores/my-file-search-store-123`"""
|
|
3173
|
-
|
|
3174
|
-
top_k: Optional[int]
|
|
3175
|
-
"""The number of file search retrieval chunks to retrieve."""
|
|
3176
|
-
|
|
3177
|
-
metadata_filter: Optional[str]
|
|
3178
|
-
"""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."""
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
FileSearchOrDict = Union[FileSearch, FileSearchDict]
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
class ApiAuthApiKeyConfig(_common.BaseModel):
|
|
3185
|
-
"""The API secret. This data type is not supported in Gemini API."""
|
|
3186
|
-
|
|
3187
|
-
api_key_secret_version: Optional[str] = Field(
|
|
3188
|
-
default=None,
|
|
3189
|
-
description="""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}""",
|
|
3190
|
-
)
|
|
3191
|
-
api_key_string: Optional[str] = Field(
|
|
3192
|
-
default=None,
|
|
3193
|
-
description="""The API key string. Either this or `api_key_secret_version` must be set.""",
|
|
3194
|
-
)
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
class ApiAuthApiKeyConfigDict(TypedDict, total=False):
|
|
3198
|
-
"""The API secret. This data type is not supported in Gemini API."""
|
|
3199
|
-
|
|
3200
|
-
api_key_secret_version: Optional[str]
|
|
3201
|
-
"""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}"""
|
|
3202
|
-
|
|
3203
|
-
api_key_string: Optional[str]
|
|
3204
|
-
"""The API key string. Either this or `api_key_secret_version` must be set."""
|
|
2891
|
+
api_key_string: Optional[str]
|
|
2892
|
+
"""The API key string. Either this or `api_key_secret_version` must be set."""
|
|
3205
2893
|
|
|
3206
2894
|
|
|
3207
2895
|
ApiAuthApiKeyConfigOrDict = Union[ApiAuthApiKeyConfig, ApiAuthApiKeyConfigDict]
|
|
@@ -4010,33 +3698,296 @@ ToolCodeExecutionOrDict = Union[ToolCodeExecution, ToolCodeExecutionDict]
|
|
|
4010
3698
|
class EnterpriseWebSearch(_common.BaseModel):
|
|
4011
3699
|
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
|
|
4012
3700
|
|
|
4013
|
-
This data type is not supported in Gemini API.
|
|
3701
|
+
This data type is not supported in Gemini API.
|
|
3702
|
+
"""
|
|
3703
|
+
|
|
3704
|
+
exclude_domains: Optional[list[str]] = Field(
|
|
3705
|
+
default=None,
|
|
3706
|
+
description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains.""",
|
|
3707
|
+
)
|
|
3708
|
+
blocking_confidence: Optional[PhishBlockThreshold] = Field(
|
|
3709
|
+
default=None,
|
|
3710
|
+
description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results.""",
|
|
3711
|
+
)
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
class EnterpriseWebSearchDict(TypedDict, total=False):
|
|
3715
|
+
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
|
|
3716
|
+
|
|
3717
|
+
This data type is not supported in Gemini API.
|
|
3718
|
+
"""
|
|
3719
|
+
|
|
3720
|
+
exclude_domains: Optional[list[str]]
|
|
3721
|
+
"""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains."""
|
|
3722
|
+
|
|
3723
|
+
blocking_confidence: Optional[PhishBlockThreshold]
|
|
3724
|
+
"""Optional. Sites with confidence level chosen & above this value will be blocked from the search results."""
|
|
3725
|
+
|
|
3726
|
+
|
|
3727
|
+
EnterpriseWebSearchOrDict = Union[EnterpriseWebSearch, EnterpriseWebSearchDict]
|
|
3728
|
+
|
|
3729
|
+
|
|
3730
|
+
class FunctionDeclaration(_common.BaseModel):
|
|
3731
|
+
"""Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
|
|
3732
|
+
|
|
3733
|
+
Included in this declaration are the function name, description, parameters
|
|
3734
|
+
and response type. This FunctionDeclaration is a representation of a block of
|
|
3735
|
+
code that can be used as a `Tool` by the model and executed by the client.
|
|
3736
|
+
"""
|
|
3737
|
+
|
|
3738
|
+
description: Optional[str] = Field(
|
|
3739
|
+
default=None,
|
|
3740
|
+
description="""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.""",
|
|
3741
|
+
)
|
|
3742
|
+
name: Optional[str] = Field(
|
|
3743
|
+
default=None,
|
|
3744
|
+
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.""",
|
|
3745
|
+
)
|
|
3746
|
+
parameters: Optional[Schema] = Field(
|
|
3747
|
+
default=None,
|
|
3748
|
+
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""",
|
|
3749
|
+
)
|
|
3750
|
+
parameters_json_schema: Optional[Any] = Field(
|
|
3751
|
+
default=None,
|
|
3752
|
+
description="""Optional. Describes the parameters to the function in JSON Schema format. The schema must describe an object where the properties are the parameters to the function. For example: ``` { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": ["name", "age"], "propertyOrdering": ["name", "age"] } ``` This field is mutually exclusive with `parameters`.""",
|
|
3753
|
+
)
|
|
3754
|
+
response: Optional[Schema] = Field(
|
|
3755
|
+
default=None,
|
|
3756
|
+
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.""",
|
|
3757
|
+
)
|
|
3758
|
+
response_json_schema: Optional[Any] = Field(
|
|
3759
|
+
default=None,
|
|
3760
|
+
description="""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`.""",
|
|
3761
|
+
)
|
|
3762
|
+
behavior: Optional[Behavior] = Field(
|
|
3763
|
+
default=None,
|
|
3764
|
+
description="""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""",
|
|
3765
|
+
)
|
|
3766
|
+
|
|
3767
|
+
@classmethod
|
|
3768
|
+
def from_callable_with_api_option(
|
|
3769
|
+
cls,
|
|
3770
|
+
*,
|
|
3771
|
+
callable: Callable[..., Any],
|
|
3772
|
+
api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
|
|
3773
|
+
behavior: Optional[Behavior] = None,
|
|
3774
|
+
) -> 'FunctionDeclaration':
|
|
3775
|
+
"""Converts a Callable to a FunctionDeclaration based on the API option.
|
|
3776
|
+
|
|
3777
|
+
Supported API option is 'VERTEX_AI' or 'GEMINI_API'. If api_option is unset,
|
|
3778
|
+
it will default to 'GEMINI_API'. If unsupported api_option is provided, it
|
|
3779
|
+
will raise ValueError.
|
|
3780
|
+
"""
|
|
3781
|
+
supported_api_options = ['VERTEX_AI', 'GEMINI_API']
|
|
3782
|
+
if api_option not in supported_api_options:
|
|
3783
|
+
raise ValueError(
|
|
3784
|
+
f'Unsupported api_option value: {api_option}. Supported api_option'
|
|
3785
|
+
f' value is one of: {supported_api_options}.'
|
|
3786
|
+
)
|
|
3787
|
+
from . import _automatic_function_calling_util
|
|
3788
|
+
|
|
3789
|
+
parameters_properties = {}
|
|
3790
|
+
parameters_json_schema = {}
|
|
3791
|
+
annotation_under_future = typing.get_type_hints(callable)
|
|
3792
|
+
try:
|
|
3793
|
+
for name, param in inspect.signature(callable).parameters.items():
|
|
3794
|
+
if param.kind in (
|
|
3795
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
3796
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
3797
|
+
inspect.Parameter.POSITIONAL_ONLY,
|
|
3798
|
+
):
|
|
3799
|
+
param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
|
|
3800
|
+
param, annotation_under_future, name
|
|
3801
|
+
)
|
|
3802
|
+
schema = (
|
|
3803
|
+
_automatic_function_calling_util._parse_schema_from_parameter(
|
|
3804
|
+
api_option, param, callable.__name__
|
|
3805
|
+
)
|
|
3806
|
+
)
|
|
3807
|
+
parameters_properties[name] = schema
|
|
3808
|
+
except ValueError:
|
|
3809
|
+
parameters_properties = {}
|
|
3810
|
+
for name, param in inspect.signature(callable).parameters.items():
|
|
3811
|
+
if param.kind in (
|
|
3812
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
3813
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
3814
|
+
inspect.Parameter.POSITIONAL_ONLY,
|
|
3815
|
+
):
|
|
3816
|
+
try:
|
|
3817
|
+
param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
|
|
3818
|
+
param, annotation_under_future, name
|
|
3819
|
+
)
|
|
3820
|
+
param_schema_adapter = pydantic.TypeAdapter(
|
|
3821
|
+
param.annotation,
|
|
3822
|
+
config=pydantic.ConfigDict(arbitrary_types_allowed=True),
|
|
3823
|
+
)
|
|
3824
|
+
json_schema_dict = param_schema_adapter.json_schema()
|
|
3825
|
+
json_schema_dict = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
|
|
3826
|
+
json_schema_dict
|
|
3827
|
+
)
|
|
3828
|
+
if 'prefixItems' in json_schema_dict:
|
|
3829
|
+
parameters_json_schema[name] = json_schema_dict
|
|
3830
|
+
continue
|
|
3831
|
+
|
|
3832
|
+
union_args = typing.get_args(param.annotation)
|
|
3833
|
+
has_primitive = any(
|
|
3834
|
+
_automatic_function_calling_util._is_builtin_primitive_or_compound(
|
|
3835
|
+
arg
|
|
3836
|
+
)
|
|
3837
|
+
for arg in union_args
|
|
3838
|
+
)
|
|
3839
|
+
if (
|
|
3840
|
+
'$ref' in json_schema_dict or '$defs' in json_schema_dict
|
|
3841
|
+
) and has_primitive:
|
|
3842
|
+
# This is a complex schema with a primitive (e.g., str | MyModel)
|
|
3843
|
+
# that is better represented by raw JSON schema.
|
|
3844
|
+
parameters_json_schema[name] = json_schema_dict
|
|
3845
|
+
continue
|
|
3846
|
+
|
|
3847
|
+
schema = Schema.from_json_schema(
|
|
3848
|
+
json_schema=JSONSchema(**json_schema_dict),
|
|
3849
|
+
api_option=api_option,
|
|
3850
|
+
)
|
|
3851
|
+
if param.default is not inspect.Parameter.empty:
|
|
3852
|
+
schema.default = param.default
|
|
3853
|
+
parameters_properties[name] = schema
|
|
3854
|
+
except Exception as e:
|
|
3855
|
+
_automatic_function_calling_util._raise_for_unsupported_param(
|
|
3856
|
+
param, callable.__name__, e
|
|
3857
|
+
)
|
|
3858
|
+
|
|
3859
|
+
declaration = FunctionDeclaration(
|
|
3860
|
+
name=callable.__name__,
|
|
3861
|
+
description=inspect.cleandoc(callable.__doc__)
|
|
3862
|
+
if callable.__doc__
|
|
3863
|
+
else callable.__doc__,
|
|
3864
|
+
behavior=behavior,
|
|
3865
|
+
)
|
|
3866
|
+
if parameters_properties:
|
|
3867
|
+
declaration.parameters = Schema(
|
|
3868
|
+
type='OBJECT',
|
|
3869
|
+
properties=parameters_properties,
|
|
3870
|
+
)
|
|
3871
|
+
declaration.parameters.required = (
|
|
3872
|
+
_automatic_function_calling_util._get_required_fields(
|
|
3873
|
+
declaration.parameters
|
|
3874
|
+
)
|
|
3875
|
+
)
|
|
3876
|
+
elif parameters_json_schema:
|
|
3877
|
+
declaration.parameters_json_schema = parameters_json_schema
|
|
3878
|
+
# TODO: b/421991354 - Remove this check once the bug is fixed.
|
|
3879
|
+
if api_option == 'GEMINI_API':
|
|
3880
|
+
return declaration
|
|
3881
|
+
|
|
3882
|
+
return_annotation = inspect.signature(callable).return_annotation
|
|
3883
|
+
if return_annotation is inspect._empty:
|
|
3884
|
+
return declaration
|
|
3885
|
+
|
|
3886
|
+
return_value = inspect.Parameter(
|
|
3887
|
+
'return_value',
|
|
3888
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
3889
|
+
annotation=return_annotation,
|
|
3890
|
+
)
|
|
3891
|
+
|
|
3892
|
+
# This snippet catches the case when type hints are stored as strings
|
|
3893
|
+
if isinstance(return_value.annotation, str):
|
|
3894
|
+
return_value = return_value.replace(
|
|
3895
|
+
annotation=annotation_under_future['return']
|
|
3896
|
+
)
|
|
3897
|
+
response_schema: Optional[Schema] = None
|
|
3898
|
+
response_json_schema: Optional[Union[dict[str, Any], Schema]] = {}
|
|
3899
|
+
try:
|
|
3900
|
+
response_schema = (
|
|
3901
|
+
_automatic_function_calling_util._parse_schema_from_parameter(
|
|
3902
|
+
api_option,
|
|
3903
|
+
return_value,
|
|
3904
|
+
callable.__name__,
|
|
3905
|
+
)
|
|
3906
|
+
)
|
|
3907
|
+
if response_schema.any_of is not None:
|
|
3908
|
+
# To handle any_of, we need to use responseJsonSchema
|
|
3909
|
+
response_json_schema = response_schema
|
|
3910
|
+
response_schema = None
|
|
3911
|
+
except ValueError:
|
|
3912
|
+
try:
|
|
3913
|
+
return_value_schema_adapter = pydantic.TypeAdapter(
|
|
3914
|
+
return_value.annotation,
|
|
3915
|
+
config=pydantic.ConfigDict(arbitrary_types_allowed=True),
|
|
3916
|
+
)
|
|
3917
|
+
response_json_schema = return_value_schema_adapter.json_schema()
|
|
3918
|
+
response_json_schema = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
|
|
3919
|
+
response_json_schema
|
|
3920
|
+
)
|
|
3921
|
+
except Exception as e:
|
|
3922
|
+
_automatic_function_calling_util._raise_for_unsupported_param(
|
|
3923
|
+
return_value, callable.__name__, e
|
|
3924
|
+
)
|
|
3925
|
+
|
|
3926
|
+
if response_schema:
|
|
3927
|
+
declaration.response = response_schema
|
|
3928
|
+
elif response_json_schema:
|
|
3929
|
+
declaration.response_json_schema = response_json_schema
|
|
3930
|
+
return declaration
|
|
3931
|
+
|
|
3932
|
+
@classmethod
|
|
3933
|
+
def from_callable(
|
|
3934
|
+
cls,
|
|
3935
|
+
*,
|
|
3936
|
+
client: 'BaseApiClient',
|
|
3937
|
+
callable: Callable[..., Any],
|
|
3938
|
+
behavior: Optional[Behavior] = None,
|
|
3939
|
+
) -> 'FunctionDeclaration':
|
|
3940
|
+
"""Converts a Callable to a FunctionDeclaration based on the client.
|
|
3941
|
+
|
|
3942
|
+
Note: For best results prefer
|
|
3943
|
+
[Google-style
|
|
3944
|
+
docstring](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods)
|
|
3945
|
+
when describing arguments. This function does **not** parse argument
|
|
3946
|
+
descriptions into the property description slots of the resulting structure.
|
|
3947
|
+
Instead it sends the whole docstring in the top-level function description.
|
|
3948
|
+
Google-style docstring are closest to what the model is trained on.
|
|
3949
|
+
"""
|
|
3950
|
+
if client.vertexai:
|
|
3951
|
+
return cls.from_callable_with_api_option(
|
|
3952
|
+
callable=callable, api_option='VERTEX_AI', behavior=behavior
|
|
3953
|
+
)
|
|
3954
|
+
else:
|
|
3955
|
+
return cls.from_callable_with_api_option(
|
|
3956
|
+
callable=callable, api_option='GEMINI_API', behavior=behavior
|
|
3957
|
+
)
|
|
3958
|
+
|
|
3959
|
+
|
|
3960
|
+
class FunctionDeclarationDict(TypedDict, total=False):
|
|
3961
|
+
"""Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
|
|
3962
|
+
|
|
3963
|
+
Included in this declaration are the function name, description, parameters
|
|
3964
|
+
and response type. This FunctionDeclaration is a representation of a block of
|
|
3965
|
+
code that can be used as a `Tool` by the model and executed by the client.
|
|
4014
3966
|
"""
|
|
4015
3967
|
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains.""",
|
|
4019
|
-
)
|
|
4020
|
-
blocking_confidence: Optional[PhishBlockThreshold] = Field(
|
|
4021
|
-
default=None,
|
|
4022
|
-
description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results.""",
|
|
4023
|
-
)
|
|
3968
|
+
description: Optional[str]
|
|
3969
|
+
"""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function."""
|
|
4024
3970
|
|
|
3971
|
+
name: Optional[str]
|
|
3972
|
+
"""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."""
|
|
4025
3973
|
|
|
4026
|
-
|
|
4027
|
-
"""
|
|
3974
|
+
parameters: Optional[SchemaDict]
|
|
3975
|
+
"""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"""
|
|
4028
3976
|
|
|
4029
|
-
|
|
4030
|
-
"""
|
|
3977
|
+
parameters_json_schema: Optional[Any]
|
|
3978
|
+
"""Optional. Describes the parameters to the function in JSON Schema format. The schema must describe an object where the properties are the parameters to the function. For example: ``` { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": ["name", "age"], "propertyOrdering": ["name", "age"] } ``` This field is mutually exclusive with `parameters`."""
|
|
4031
3979
|
|
|
4032
|
-
|
|
4033
|
-
"""Optional.
|
|
3980
|
+
response: Optional[SchemaDict]
|
|
3981
|
+
"""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."""
|
|
4034
3982
|
|
|
4035
|
-
|
|
4036
|
-
"""Optional.
|
|
3983
|
+
response_json_schema: Optional[Any]
|
|
3984
|
+
"""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`."""
|
|
3985
|
+
|
|
3986
|
+
behavior: Optional[Behavior]
|
|
3987
|
+
"""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI."""
|
|
4037
3988
|
|
|
4038
3989
|
|
|
4039
|
-
|
|
3990
|
+
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
|
|
4040
3991
|
|
|
4041
3992
|
|
|
4042
3993
|
class GoogleMaps(_common.BaseModel):
|
|
@@ -4140,6 +4091,55 @@ class GoogleSearchDict(TypedDict, total=False):
|
|
|
4140
4091
|
GoogleSearchOrDict = Union[GoogleSearch, GoogleSearchDict]
|
|
4141
4092
|
|
|
4142
4093
|
|
|
4094
|
+
class DynamicRetrievalConfig(_common.BaseModel):
|
|
4095
|
+
"""Describes the options to customize dynamic retrieval."""
|
|
4096
|
+
|
|
4097
|
+
dynamic_threshold: Optional[float] = Field(
|
|
4098
|
+
default=None,
|
|
4099
|
+
description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
|
|
4100
|
+
)
|
|
4101
|
+
mode: Optional[DynamicRetrievalConfigMode] = Field(
|
|
4102
|
+
default=None,
|
|
4103
|
+
description="""The mode of the predictor to be used in dynamic retrieval.""",
|
|
4104
|
+
)
|
|
4105
|
+
|
|
4106
|
+
|
|
4107
|
+
class DynamicRetrievalConfigDict(TypedDict, total=False):
|
|
4108
|
+
"""Describes the options to customize dynamic retrieval."""
|
|
4109
|
+
|
|
4110
|
+
dynamic_threshold: Optional[float]
|
|
4111
|
+
"""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used."""
|
|
4112
|
+
|
|
4113
|
+
mode: Optional[DynamicRetrievalConfigMode]
|
|
4114
|
+
"""The mode of the predictor to be used in dynamic retrieval."""
|
|
4115
|
+
|
|
4116
|
+
|
|
4117
|
+
DynamicRetrievalConfigOrDict = Union[
|
|
4118
|
+
DynamicRetrievalConfig, DynamicRetrievalConfigDict
|
|
4119
|
+
]
|
|
4120
|
+
|
|
4121
|
+
|
|
4122
|
+
class GoogleSearchRetrieval(_common.BaseModel):
|
|
4123
|
+
"""Tool to retrieve public web data for grounding, powered by Google."""
|
|
4124
|
+
|
|
4125
|
+
dynamic_retrieval_config: Optional[DynamicRetrievalConfig] = Field(
|
|
4126
|
+
default=None,
|
|
4127
|
+
description="""Specifies the dynamic retrieval configuration for the given source.""",
|
|
4128
|
+
)
|
|
4129
|
+
|
|
4130
|
+
|
|
4131
|
+
class GoogleSearchRetrievalDict(TypedDict, total=False):
|
|
4132
|
+
"""Tool to retrieve public web data for grounding, powered by Google."""
|
|
4133
|
+
|
|
4134
|
+
dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
|
|
4135
|
+
"""Specifies the dynamic retrieval configuration for the given source."""
|
|
4136
|
+
|
|
4137
|
+
|
|
4138
|
+
GoogleSearchRetrievalOrDict = Union[
|
|
4139
|
+
GoogleSearchRetrieval, GoogleSearchRetrievalDict
|
|
4140
|
+
]
|
|
4141
|
+
|
|
4142
|
+
|
|
4143
4143
|
class UrlContext(_common.BaseModel):
|
|
4144
4144
|
"""Tool to support URL context."""
|
|
4145
4145
|
|
|
@@ -4158,18 +4158,10 @@ UrlContextOrDict = Union[UrlContext, UrlContextDict]
|
|
|
4158
4158
|
class Tool(_common.BaseModel):
|
|
4159
4159
|
"""Tool details of a tool that the model may use to generate a response."""
|
|
4160
4160
|
|
|
4161
|
-
function_declarations: Optional[list[FunctionDeclaration]] = Field(
|
|
4162
|
-
default=None,
|
|
4163
|
-
description="""List of function declarations that the tool supports.""",
|
|
4164
|
-
)
|
|
4165
4161
|
retrieval: Optional[Retrieval] = Field(
|
|
4166
4162
|
default=None,
|
|
4167
4163
|
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. This field is not supported in Gemini API.""",
|
|
4168
4164
|
)
|
|
4169
|
-
google_search_retrieval: Optional[GoogleSearchRetrieval] = Field(
|
|
4170
|
-
default=None,
|
|
4171
|
-
description="""Optional. Specialized retrieval tool that is powered by Google Search.""",
|
|
4172
|
-
)
|
|
4173
4165
|
computer_use: Optional[ComputerUse] = Field(
|
|
4174
4166
|
default=None,
|
|
4175
4167
|
description="""Optional. Tool to support the model interacting directly with the
|
|
@@ -4188,6 +4180,10 @@ class Tool(_common.BaseModel):
|
|
|
4188
4180
|
default=None,
|
|
4189
4181
|
description="""Optional. Tool to support searching public web data, powered by Vertex AI Search and Sec4 compliance. This field is not supported in Gemini API.""",
|
|
4190
4182
|
)
|
|
4183
|
+
function_declarations: Optional[list[FunctionDeclaration]] = Field(
|
|
4184
|
+
default=None,
|
|
4185
|
+
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 512 function declarations can be provided.""",
|
|
4186
|
+
)
|
|
4191
4187
|
google_maps: Optional[GoogleMaps] = Field(
|
|
4192
4188
|
default=None,
|
|
4193
4189
|
description="""Optional. GoogleMaps tool type. Tool to support Google Maps in Model.""",
|
|
@@ -4196,6 +4192,10 @@ class Tool(_common.BaseModel):
|
|
|
4196
4192
|
default=None,
|
|
4197
4193
|
description="""Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google.""",
|
|
4198
4194
|
)
|
|
4195
|
+
google_search_retrieval: Optional[GoogleSearchRetrieval] = Field(
|
|
4196
|
+
default=None,
|
|
4197
|
+
description="""Optional. Specialized retrieval tool that is powered by Google Search.""",
|
|
4198
|
+
)
|
|
4199
4199
|
url_context: Optional[UrlContext] = Field(
|
|
4200
4200
|
default=None,
|
|
4201
4201
|
description="""Optional. Tool to support URL context retrieval.""",
|
|
@@ -4205,15 +4205,9 @@ class Tool(_common.BaseModel):
|
|
|
4205
4205
|
class ToolDict(TypedDict, total=False):
|
|
4206
4206
|
"""Tool details of a tool that the model may use to generate a response."""
|
|
4207
4207
|
|
|
4208
|
-
function_declarations: Optional[list[FunctionDeclarationDict]]
|
|
4209
|
-
"""List of function declarations that the tool supports."""
|
|
4210
|
-
|
|
4211
4208
|
retrieval: Optional[RetrievalDict]
|
|
4212
4209
|
"""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. This field is not supported in Gemini API."""
|
|
4213
4210
|
|
|
4214
|
-
google_search_retrieval: Optional[GoogleSearchRetrievalDict]
|
|
4215
|
-
"""Optional. Specialized retrieval tool that is powered by Google Search."""
|
|
4216
|
-
|
|
4217
4211
|
computer_use: Optional[ComputerUseDict]
|
|
4218
4212
|
"""Optional. Tool to support the model interacting directly with the
|
|
4219
4213
|
computer. If enabled, it automatically populates computer-use specific
|
|
@@ -4228,12 +4222,18 @@ class ToolDict(TypedDict, total=False):
|
|
|
4228
4222
|
enterprise_web_search: Optional[EnterpriseWebSearchDict]
|
|
4229
4223
|
"""Optional. Tool to support searching public web data, powered by Vertex AI Search and Sec4 compliance. This field is not supported in Gemini API."""
|
|
4230
4224
|
|
|
4225
|
+
function_declarations: Optional[list[FunctionDeclarationDict]]
|
|
4226
|
+
"""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 512 function declarations can be provided."""
|
|
4227
|
+
|
|
4231
4228
|
google_maps: Optional[GoogleMapsDict]
|
|
4232
4229
|
"""Optional. GoogleMaps tool type. Tool to support Google Maps in Model."""
|
|
4233
4230
|
|
|
4234
4231
|
google_search: Optional[GoogleSearchDict]
|
|
4235
4232
|
"""Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google."""
|
|
4236
4233
|
|
|
4234
|
+
google_search_retrieval: Optional[GoogleSearchRetrievalDict]
|
|
4235
|
+
"""Optional. Specialized retrieval tool that is powered by Google Search."""
|
|
4236
|
+
|
|
4237
4237
|
url_context: Optional[UrlContextDict]
|
|
4238
4238
|
"""Optional. Tool to support URL context retrieval."""
|
|
4239
4239
|
|
|
@@ -4257,40 +4257,6 @@ SchemaUnion = Union[
|
|
|
4257
4257
|
SchemaUnionDict = Union[SchemaUnion, SchemaDict]
|
|
4258
4258
|
|
|
4259
4259
|
|
|
4260
|
-
class FunctionCallingConfig(_common.BaseModel):
|
|
4261
|
-
"""Function calling config."""
|
|
4262
|
-
|
|
4263
|
-
mode: Optional[FunctionCallingConfigMode] = Field(
|
|
4264
|
-
default=None, description="""Optional. Function calling mode."""
|
|
4265
|
-
)
|
|
4266
|
-
allowed_function_names: Optional[list[str]] = Field(
|
|
4267
|
-
default=None,
|
|
4268
|
-
description="""Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided.""",
|
|
4269
|
-
)
|
|
4270
|
-
stream_function_call_arguments: Optional[bool] = Field(
|
|
4271
|
-
default=None,
|
|
4272
|
-
description="""Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API.""",
|
|
4273
|
-
)
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
class FunctionCallingConfigDict(TypedDict, total=False):
|
|
4277
|
-
"""Function calling config."""
|
|
4278
|
-
|
|
4279
|
-
mode: Optional[FunctionCallingConfigMode]
|
|
4280
|
-
"""Optional. Function calling mode."""
|
|
4281
|
-
|
|
4282
|
-
allowed_function_names: Optional[list[str]]
|
|
4283
|
-
"""Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided."""
|
|
4284
|
-
|
|
4285
|
-
stream_function_call_arguments: Optional[bool]
|
|
4286
|
-
"""Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API."""
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
FunctionCallingConfigOrDict = Union[
|
|
4290
|
-
FunctionCallingConfig, FunctionCallingConfigDict
|
|
4291
|
-
]
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
4260
|
class LatLng(_common.BaseModel):
|
|
4295
4261
|
"""An object that represents a latitude/longitude pair.
|
|
4296
4262
|
|
|
@@ -4353,18 +4319,52 @@ class RetrievalConfigDict(TypedDict, total=False):
|
|
|
4353
4319
|
RetrievalConfigOrDict = Union[RetrievalConfig, RetrievalConfigDict]
|
|
4354
4320
|
|
|
4355
4321
|
|
|
4322
|
+
class FunctionCallingConfig(_common.BaseModel):
|
|
4323
|
+
"""Function calling config."""
|
|
4324
|
+
|
|
4325
|
+
allowed_function_names: Optional[list[str]] = Field(
|
|
4326
|
+
default=None,
|
|
4327
|
+
description="""Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided.""",
|
|
4328
|
+
)
|
|
4329
|
+
mode: Optional[FunctionCallingConfigMode] = Field(
|
|
4330
|
+
default=None, description="""Optional. Function calling mode."""
|
|
4331
|
+
)
|
|
4332
|
+
stream_function_call_arguments: Optional[bool] = Field(
|
|
4333
|
+
default=None,
|
|
4334
|
+
description="""Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API.""",
|
|
4335
|
+
)
|
|
4336
|
+
|
|
4337
|
+
|
|
4338
|
+
class FunctionCallingConfigDict(TypedDict, total=False):
|
|
4339
|
+
"""Function calling config."""
|
|
4340
|
+
|
|
4341
|
+
allowed_function_names: Optional[list[str]]
|
|
4342
|
+
"""Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided."""
|
|
4343
|
+
|
|
4344
|
+
mode: Optional[FunctionCallingConfigMode]
|
|
4345
|
+
"""Optional. Function calling mode."""
|
|
4346
|
+
|
|
4347
|
+
stream_function_call_arguments: Optional[bool]
|
|
4348
|
+
"""Optional. When set to true, arguments of a single function call will be streamed out in multiple parts/contents/responses. Partial parameter results will be returned in the [FunctionCall.partial_args] field. This field is not supported in Gemini API."""
|
|
4349
|
+
|
|
4350
|
+
|
|
4351
|
+
FunctionCallingConfigOrDict = Union[
|
|
4352
|
+
FunctionCallingConfig, FunctionCallingConfigDict
|
|
4353
|
+
]
|
|
4354
|
+
|
|
4355
|
+
|
|
4356
4356
|
class ToolConfig(_common.BaseModel):
|
|
4357
4357
|
"""Tool config.
|
|
4358
4358
|
|
|
4359
4359
|
This config is shared for all tools provided in the request.
|
|
4360
4360
|
"""
|
|
4361
4361
|
|
|
4362
|
-
function_calling_config: Optional[FunctionCallingConfig] = Field(
|
|
4363
|
-
default=None, description="""Optional. Function calling config."""
|
|
4364
|
-
)
|
|
4365
4362
|
retrieval_config: Optional[RetrievalConfig] = Field(
|
|
4366
4363
|
default=None, description="""Optional. Retrieval config."""
|
|
4367
4364
|
)
|
|
4365
|
+
function_calling_config: Optional[FunctionCallingConfig] = Field(
|
|
4366
|
+
default=None, description="""Optional. Function calling config."""
|
|
4367
|
+
)
|
|
4368
4368
|
|
|
4369
4369
|
|
|
4370
4370
|
class ToolConfigDict(TypedDict, total=False):
|
|
@@ -4373,12 +4373,12 @@ class ToolConfigDict(TypedDict, total=False):
|
|
|
4373
4373
|
This config is shared for all tools provided in the request.
|
|
4374
4374
|
"""
|
|
4375
4375
|
|
|
4376
|
-
function_calling_config: Optional[FunctionCallingConfigDict]
|
|
4377
|
-
"""Optional. Function calling config."""
|
|
4378
|
-
|
|
4379
4376
|
retrieval_config: Optional[RetrievalConfigDict]
|
|
4380
4377
|
"""Optional. Retrieval config."""
|
|
4381
4378
|
|
|
4379
|
+
function_calling_config: Optional[FunctionCallingConfigDict]
|
|
4380
|
+
"""Optional. Function calling config."""
|
|
4381
|
+
|
|
4382
4382
|
|
|
4383
4383
|
ToolConfigOrDict = Union[ToolConfig, ToolConfigDict]
|
|
4384
4384
|
|
|
@@ -4484,24 +4484,19 @@ SpeakerVoiceConfigOrDict = Union[SpeakerVoiceConfig, SpeakerVoiceConfigDict]
|
|
|
4484
4484
|
|
|
4485
4485
|
|
|
4486
4486
|
class MultiSpeakerVoiceConfig(_common.BaseModel):
|
|
4487
|
-
"""
|
|
4488
|
-
|
|
4489
|
-
This data type is not supported in Vertex AI.
|
|
4490
|
-
"""
|
|
4487
|
+
"""Configuration for a multi-speaker text-to-speech request."""
|
|
4491
4488
|
|
|
4492
4489
|
speaker_voice_configs: Optional[list[SpeakerVoiceConfig]] = Field(
|
|
4493
|
-
default=None,
|
|
4490
|
+
default=None,
|
|
4491
|
+
description="""Required. A list of configurations for the voices of the speakers. Exactly two speaker voice configurations must be provided.""",
|
|
4494
4492
|
)
|
|
4495
4493
|
|
|
4496
4494
|
|
|
4497
4495
|
class MultiSpeakerVoiceConfigDict(TypedDict, total=False):
|
|
4498
|
-
"""
|
|
4499
|
-
|
|
4500
|
-
This data type is not supported in Vertex AI.
|
|
4501
|
-
"""
|
|
4496
|
+
"""Configuration for a multi-speaker text-to-speech request."""
|
|
4502
4497
|
|
|
4503
4498
|
speaker_voice_configs: Optional[list[SpeakerVoiceConfigDict]]
|
|
4504
|
-
"""Required.
|
|
4499
|
+
"""Required. A list of configurations for the voices of the speakers. Exactly two speaker voice configurations must be provided."""
|
|
4505
4500
|
|
|
4506
4501
|
|
|
4507
4502
|
MultiSpeakerVoiceConfigOrDict = Union[
|
|
@@ -4521,7 +4516,7 @@ class SpeechConfig(_common.BaseModel):
|
|
|
4521
4516
|
)
|
|
4522
4517
|
multi_speaker_voice_config: Optional[MultiSpeakerVoiceConfig] = Field(
|
|
4523
4518
|
default=None,
|
|
4524
|
-
description="""
|
|
4519
|
+
description="""The configuration for a multi-speaker text-to-speech request. This field is mutually exclusive with `voice_config`.""",
|
|
4525
4520
|
)
|
|
4526
4521
|
|
|
4527
4522
|
|
|
@@ -4534,7 +4529,7 @@ class SpeechConfigDict(TypedDict, total=False):
|
|
|
4534
4529
|
"""Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization."""
|
|
4535
4530
|
|
|
4536
4531
|
multi_speaker_voice_config: Optional[MultiSpeakerVoiceConfigDict]
|
|
4537
|
-
"""
|
|
4532
|
+
"""The configuration for a multi-speaker text-to-speech request. This field is mutually exclusive with `voice_config`."""
|
|
4538
4533
|
|
|
4539
4534
|
|
|
4540
4535
|
SpeechConfigOrDict = Union[SpeechConfig, SpeechConfigDict]
|
|
@@ -4614,7 +4609,7 @@ class ThinkingConfig(_common.BaseModel):
|
|
|
4614
4609
|
)
|
|
4615
4610
|
thinking_level: Optional[ThinkingLevel] = Field(
|
|
4616
4611
|
default=None,
|
|
4617
|
-
description="""Optional. The
|
|
4612
|
+
description="""Optional. The number of thoughts tokens that the model should generate.""",
|
|
4618
4613
|
)
|
|
4619
4614
|
|
|
4620
4615
|
|
|
@@ -4630,7 +4625,7 @@ class ThinkingConfigDict(TypedDict, total=False):
|
|
|
4630
4625
|
"""
|
|
4631
4626
|
|
|
4632
4627
|
thinking_level: Optional[ThinkingLevel]
|
|
4633
|
-
"""Optional. The
|
|
4628
|
+
"""Optional. The number of thoughts tokens that the model should generate."""
|
|
4634
4629
|
|
|
4635
4630
|
|
|
4636
4631
|
ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
|
|
@@ -4650,6 +4645,11 @@ class ImageConfig(_common.BaseModel):
|
|
|
4650
4645
|
values are `1K`, `2K`, `4K`. If not specified, the model will use default
|
|
4651
4646
|
value `1K`.""",
|
|
4652
4647
|
)
|
|
4648
|
+
person_generation: Optional[str] = Field(
|
|
4649
|
+
default=None,
|
|
4650
|
+
description="""Controls the generation of people. Supported values are:
|
|
4651
|
+
ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE.""",
|
|
4652
|
+
)
|
|
4653
4653
|
output_mime_type: Optional[str] = Field(
|
|
4654
4654
|
default=None,
|
|
4655
4655
|
description="""MIME type of the generated image. This field is not
|
|
@@ -4674,6 +4674,10 @@ class ImageConfigDict(TypedDict, total=False):
|
|
|
4674
4674
|
values are `1K`, `2K`, `4K`. If not specified, the model will use default
|
|
4675
4675
|
value `1K`."""
|
|
4676
4676
|
|
|
4677
|
+
person_generation: Optional[str]
|
|
4678
|
+
"""Controls the generation of people. Supported values are:
|
|
4679
|
+
ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE."""
|
|
4680
|
+
|
|
4677
4681
|
output_mime_type: Optional[str]
|
|
4678
4682
|
"""MIME type of the generated image. This field is not
|
|
4679
4683
|
supported in Gemini API."""
|
|
@@ -10645,7 +10649,9 @@ class Metric(_common.BaseModel):
|
|
|
10645
10649
|
Raises:
|
|
10646
10650
|
ImportError: If the pyyaml library is not installed.
|
|
10647
10651
|
"""
|
|
10648
|
-
|
|
10652
|
+
try:
|
|
10653
|
+
import yaml
|
|
10654
|
+
except ImportError:
|
|
10649
10655
|
raise ImportError(
|
|
10650
10656
|
'YAML serialization requires the pyyaml library. Please install'
|
|
10651
10657
|
" it using 'pip install google-cloud-aiplatform[evaluation]'."
|
|
@@ -13923,6 +13929,85 @@ class DeleteFileResponseDict(TypedDict, total=False):
|
|
|
13923
13929
|
DeleteFileResponseOrDict = Union[DeleteFileResponse, DeleteFileResponseDict]
|
|
13924
13930
|
|
|
13925
13931
|
|
|
13932
|
+
class RegisterFilesConfig(_common.BaseModel):
|
|
13933
|
+
"""Used to override the default configuration."""
|
|
13934
|
+
|
|
13935
|
+
http_options: Optional[HttpOptions] = Field(
|
|
13936
|
+
default=None, description="""Used to override HTTP request options."""
|
|
13937
|
+
)
|
|
13938
|
+
should_return_http_response: Optional[bool] = Field(
|
|
13939
|
+
default=None,
|
|
13940
|
+
description=""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field.""",
|
|
13941
|
+
)
|
|
13942
|
+
|
|
13943
|
+
|
|
13944
|
+
class RegisterFilesConfigDict(TypedDict, total=False):
|
|
13945
|
+
"""Used to override the default configuration."""
|
|
13946
|
+
|
|
13947
|
+
http_options: Optional[HttpOptionsDict]
|
|
13948
|
+
"""Used to override HTTP request options."""
|
|
13949
|
+
|
|
13950
|
+
should_return_http_response: Optional[bool]
|
|
13951
|
+
""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field."""
|
|
13952
|
+
|
|
13953
|
+
|
|
13954
|
+
RegisterFilesConfigOrDict = Union[RegisterFilesConfig, RegisterFilesConfigDict]
|
|
13955
|
+
|
|
13956
|
+
|
|
13957
|
+
class _RegisterFilesParameters(_common.BaseModel):
|
|
13958
|
+
"""Generates the parameters for the private _Register method."""
|
|
13959
|
+
|
|
13960
|
+
uris: Optional[list[str]] = Field(
|
|
13961
|
+
default=None,
|
|
13962
|
+
description="""The Google Cloud Storage URIs to register. Example: `gs://bucket/object`.""",
|
|
13963
|
+
)
|
|
13964
|
+
config: Optional[RegisterFilesConfig] = Field(
|
|
13965
|
+
default=None,
|
|
13966
|
+
description="""Used to override the default configuration.""",
|
|
13967
|
+
)
|
|
13968
|
+
|
|
13969
|
+
|
|
13970
|
+
class _RegisterFilesParametersDict(TypedDict, total=False):
|
|
13971
|
+
"""Generates the parameters for the private _Register method."""
|
|
13972
|
+
|
|
13973
|
+
uris: Optional[list[str]]
|
|
13974
|
+
"""The Google Cloud Storage URIs to register. Example: `gs://bucket/object`."""
|
|
13975
|
+
|
|
13976
|
+
config: Optional[RegisterFilesConfigDict]
|
|
13977
|
+
"""Used to override the default configuration."""
|
|
13978
|
+
|
|
13979
|
+
|
|
13980
|
+
_RegisterFilesParametersOrDict = Union[
|
|
13981
|
+
_RegisterFilesParameters, _RegisterFilesParametersDict
|
|
13982
|
+
]
|
|
13983
|
+
|
|
13984
|
+
|
|
13985
|
+
class RegisterFilesResponse(_common.BaseModel):
|
|
13986
|
+
"""Response for the _register file method."""
|
|
13987
|
+
|
|
13988
|
+
sdk_http_response: Optional[HttpResponse] = Field(
|
|
13989
|
+
default=None, description="""Used to retain the full HTTP response."""
|
|
13990
|
+
)
|
|
13991
|
+
files: Optional[list[File]] = Field(
|
|
13992
|
+
default=None, description="""The registered files."""
|
|
13993
|
+
)
|
|
13994
|
+
|
|
13995
|
+
|
|
13996
|
+
class RegisterFilesResponseDict(TypedDict, total=False):
|
|
13997
|
+
"""Response for the _register file method."""
|
|
13998
|
+
|
|
13999
|
+
sdk_http_response: Optional[HttpResponseDict]
|
|
14000
|
+
"""Used to retain the full HTTP response."""
|
|
14001
|
+
|
|
14002
|
+
files: Optional[list[FileDict]]
|
|
14003
|
+
"""The registered files."""
|
|
14004
|
+
|
|
14005
|
+
|
|
14006
|
+
RegisterFilesResponseOrDict = Union[
|
|
14007
|
+
RegisterFilesResponse, RegisterFilesResponseDict
|
|
14008
|
+
]
|
|
14009
|
+
|
|
14010
|
+
|
|
13926
14011
|
class InlinedRequest(_common.BaseModel):
|
|
13927
14012
|
"""Config for inlined request."""
|
|
13928
14013
|
|