diff --git a/google/genai/_live_converters.py b/google/genai/_live_converters.py
index fb7ee19db..c048a7011 100644
--- a/google/genai/_live_converters.py
+++ b/google/genai/_live_converters.py
@@ -150,13 +150,6 @@ def _GenerationConfig_to_vertex(
getv(from_object, ['model_selection_config']),
)
- if getv(from_object, ['response_json_schema']) is not None:
- setv(
- to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
- )
-
if getv(from_object, ['audio_timestamp']) is not None:
setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
@@ -195,6 +188,13 @@ def _GenerationConfig_to_vertex(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
+ if getv(from_object, ['response_json_schema']) is not None:
+ setv(
+ to_object,
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
+ )
+
if getv(from_object, ['response_logprobs']) is not None:
setv(
to_object,
diff --git a/google/genai/batches.py b/google/genai/batches.py
index 57ae78c49..f8d9f6919 100644
--- a/google/genai/batches.py
+++ b/google/genai/batches.py
@@ -849,60 +849,62 @@ def _GenerateContentConfig_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
-
- if getv(from_object, ['system_instruction']) is not None:
- setv(
- parent_object,
- ['systemInstruction'],
- _Content_to_mldev(
- t.t_content(getv(from_object, ['system_instruction'])), to_object
- ),
+ if getv(from_object, ['model_selection_config']) is not None:
+ raise ValueError(
+ 'model_selection_config parameter is not supported in Gemini API.'
)
- if getv(from_object, ['temperature']) is not None:
- setv(to_object, ['temperature'], getv(from_object, ['temperature']))
-
- if getv(from_object, ['top_p']) is not None:
- setv(to_object, ['topP'], getv(from_object, ['top_p']))
-
- if getv(from_object, ['top_k']) is not None:
- setv(to_object, ['topK'], getv(from_object, ['top_k']))
+ if getv(from_object, ['audio_timestamp']) is not None:
+ raise ValueError(
+ 'audio_timestamp parameter is not supported in Gemini API.'
+ )
if getv(from_object, ['candidate_count']) is not None:
setv(to_object, ['candidateCount'], getv(from_object, ['candidate_count']))
- if getv(from_object, ['max_output_tokens']) is not None:
- setv(
- to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ if getv(from_object, ['enable_affective_dialog']) is not None:
+ raise ValueError(
+ 'enable_affective_dialog parameter is not supported in Gemini API.'
)
- if getv(from_object, ['stop_sequences']) is not None:
- setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
-
- if getv(from_object, ['response_logprobs']) is not None:
+ if getv(from_object, ['frequency_penalty']) is not None:
setv(
to_object,
- ['responseLogprobs'],
- getv(from_object, ['response_logprobs']),
+ ['frequencyPenalty'],
+ getv(from_object, ['frequency_penalty']),
)
if getv(from_object, ['logprobs']) is not None:
setv(to_object, ['logprobs'], getv(from_object, ['logprobs']))
+ if getv(from_object, ['max_output_tokens']) is not None:
+ setv(
+ to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ )
+
+ if getv(from_object, ['media_resolution']) is not None:
+ setv(
+ to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
+ )
+
if getv(from_object, ['presence_penalty']) is not None:
setv(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
- if getv(from_object, ['frequency_penalty']) is not None:
+ if getv(from_object, ['response_json_schema']) is not None:
setv(
to_object,
- ['frequencyPenalty'],
- getv(from_object, ['frequency_penalty']),
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
)
- if getv(from_object, ['seed']) is not None:
- setv(to_object, ['seed'], getv(from_object, ['seed']))
+ if getv(from_object, ['response_logprobs']) is not None:
+ setv(
+ to_object,
+ ['responseLogprobs'],
+ getv(from_object, ['response_logprobs']),
+ )
if getv(from_object, ['response_mime_type']) is not None:
setv(
@@ -911,6 +913,13 @@ def _GenerateContentConfig_to_mldev(
getv(from_object, ['response_mime_type']),
)
+ if getv(from_object, ['response_modalities']) is not None:
+ setv(
+ to_object,
+ ['responseModalities'],
+ getv(from_object, ['response_modalities']),
+ )
+
if getv(from_object, ['response_schema']) is not None:
setv(
to_object,
@@ -918,19 +927,48 @@ def _GenerateContentConfig_to_mldev(
t.t_schema(api_client, getv(from_object, ['response_schema'])),
)
- if getv(from_object, ['response_json_schema']) is not None:
+ if getv(from_object, ['routing_config']) is not None:
+ raise ValueError('routing_config parameter is not supported in Gemini API.')
+
+ if getv(from_object, ['seed']) is not None:
+ setv(to_object, ['seed'], getv(from_object, ['seed']))
+
+ if getv(from_object, ['speech_config']) is not None:
setv(
to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
+ ['speechConfig'],
+ t.t_speech_config(getv(from_object, ['speech_config'])),
)
- if getv(from_object, ['routing_config']) is not None:
- raise ValueError('routing_config parameter is not supported in Gemini API.')
+ if getv(from_object, ['stop_sequences']) is not None:
+ setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
- if getv(from_object, ['model_selection_config']) is not None:
- raise ValueError(
- 'model_selection_config parameter is not supported in Gemini API.'
+ if getv(from_object, ['temperature']) is not None:
+ setv(to_object, ['temperature'], getv(from_object, ['temperature']))
+
+ if getv(from_object, ['thinking_config']) is not None:
+ setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
+
+ if getv(from_object, ['top_k']) is not None:
+ setv(to_object, ['topK'], getv(from_object, ['top_k']))
+
+ if getv(from_object, ['top_p']) is not None:
+ setv(to_object, ['topP'], getv(from_object, ['top_p']))
+
+ if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
+ setv(
+ to_object,
+ ['enableEnhancedCivicAnswers'],
+ getv(from_object, ['enable_enhanced_civic_answers']),
+ )
+
+ if getv(from_object, ['system_instruction']) is not None:
+ setv(
+ parent_object,
+ ['systemInstruction'],
+ _Content_to_mldev(
+ t.t_content(getv(from_object, ['system_instruction'])), to_object
+ ),
)
if getv(from_object, ['safety_settings']) is not None:
@@ -972,33 +1010,6 @@ def _GenerateContentConfig_to_mldev(
),
)
- if getv(from_object, ['response_modalities']) is not None:
- setv(
- to_object,
- ['responseModalities'],
- getv(from_object, ['response_modalities']),
- )
-
- if getv(from_object, ['media_resolution']) is not None:
- setv(
- to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
- )
-
- if getv(from_object, ['speech_config']) is not None:
- setv(
- to_object,
- ['speechConfig'],
- t.t_speech_config(getv(from_object, ['speech_config'])),
- )
-
- if getv(from_object, ['audio_timestamp']) is not None:
- raise ValueError(
- 'audio_timestamp parameter is not supported in Gemini API.'
- )
-
- if getv(from_object, ['thinking_config']) is not None:
- setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
-
if getv(from_object, ['image_config']) is not None:
setv(
to_object,
@@ -1006,13 +1017,6 @@ def _GenerateContentConfig_to_mldev(
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
)
- if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
- setv(
- to_object,
- ['enableEnhancedCivicAnswers'],
- getv(from_object, ['enable_enhanced_civic_answers']),
- )
-
return to_object
diff --git a/google/genai/models.py b/google/genai/models.py
index e81925fa0..1b31e374e 100644
--- a/google/genai/models.py
+++ b/google/genai/models.py
@@ -953,60 +953,62 @@ def _GenerateContentConfig_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
-
- if getv(from_object, ['system_instruction']) is not None:
- setv(
- parent_object,
- ['systemInstruction'],
- _Content_to_mldev(
- t.t_content(getv(from_object, ['system_instruction'])), to_object
- ),
+ if getv(from_object, ['model_selection_config']) is not None:
+ raise ValueError(
+ 'model_selection_config parameter is not supported in Gemini API.'
)
- if getv(from_object, ['temperature']) is not None:
- setv(to_object, ['temperature'], getv(from_object, ['temperature']))
-
- if getv(from_object, ['top_p']) is not None:
- setv(to_object, ['topP'], getv(from_object, ['top_p']))
-
- if getv(from_object, ['top_k']) is not None:
- setv(to_object, ['topK'], getv(from_object, ['top_k']))
+ if getv(from_object, ['audio_timestamp']) is not None:
+ raise ValueError(
+ 'audio_timestamp parameter is not supported in Gemini API.'
+ )
if getv(from_object, ['candidate_count']) is not None:
setv(to_object, ['candidateCount'], getv(from_object, ['candidate_count']))
- if getv(from_object, ['max_output_tokens']) is not None:
- setv(
- to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ if getv(from_object, ['enable_affective_dialog']) is not None:
+ raise ValueError(
+ 'enable_affective_dialog parameter is not supported in Gemini API.'
)
- if getv(from_object, ['stop_sequences']) is not None:
- setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
-
- if getv(from_object, ['response_logprobs']) is not None:
+ if getv(from_object, ['frequency_penalty']) is not None:
setv(
to_object,
- ['responseLogprobs'],
- getv(from_object, ['response_logprobs']),
+ ['frequencyPenalty'],
+ getv(from_object, ['frequency_penalty']),
)
if getv(from_object, ['logprobs']) is not None:
setv(to_object, ['logprobs'], getv(from_object, ['logprobs']))
+ if getv(from_object, ['max_output_tokens']) is not None:
+ setv(
+ to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ )
+
+ if getv(from_object, ['media_resolution']) is not None:
+ setv(
+ to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
+ )
+
if getv(from_object, ['presence_penalty']) is not None:
setv(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
- if getv(from_object, ['frequency_penalty']) is not None:
+ if getv(from_object, ['response_json_schema']) is not None:
setv(
to_object,
- ['frequencyPenalty'],
- getv(from_object, ['frequency_penalty']),
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
)
- if getv(from_object, ['seed']) is not None:
- setv(to_object, ['seed'], getv(from_object, ['seed']))
+ if getv(from_object, ['response_logprobs']) is not None:
+ setv(
+ to_object,
+ ['responseLogprobs'],
+ getv(from_object, ['response_logprobs']),
+ )
if getv(from_object, ['response_mime_type']) is not None:
setv(
@@ -1015,6 +1017,13 @@ def _GenerateContentConfig_to_mldev(
getv(from_object, ['response_mime_type']),
)
+ if getv(from_object, ['response_modalities']) is not None:
+ setv(
+ to_object,
+ ['responseModalities'],
+ getv(from_object, ['response_modalities']),
+ )
+
if getv(from_object, ['response_schema']) is not None:
setv(
to_object,
@@ -1022,19 +1031,48 @@ def _GenerateContentConfig_to_mldev(
t.t_schema(api_client, getv(from_object, ['response_schema'])),
)
- if getv(from_object, ['response_json_schema']) is not None:
+ if getv(from_object, ['routing_config']) is not None:
+ raise ValueError('routing_config parameter is not supported in Gemini API.')
+
+ if getv(from_object, ['seed']) is not None:
+ setv(to_object, ['seed'], getv(from_object, ['seed']))
+
+ if getv(from_object, ['speech_config']) is not None:
setv(
to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
+ ['speechConfig'],
+ t.t_speech_config(getv(from_object, ['speech_config'])),
)
- if getv(from_object, ['routing_config']) is not None:
- raise ValueError('routing_config parameter is not supported in Gemini API.')
+ if getv(from_object, ['stop_sequences']) is not None:
+ setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
- if getv(from_object, ['model_selection_config']) is not None:
- raise ValueError(
- 'model_selection_config parameter is not supported in Gemini API.'
+ if getv(from_object, ['temperature']) is not None:
+ setv(to_object, ['temperature'], getv(from_object, ['temperature']))
+
+ if getv(from_object, ['thinking_config']) is not None:
+ setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
+
+ if getv(from_object, ['top_k']) is not None:
+ setv(to_object, ['topK'], getv(from_object, ['top_k']))
+
+ if getv(from_object, ['top_p']) is not None:
+ setv(to_object, ['topP'], getv(from_object, ['top_p']))
+
+ if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
+ setv(
+ to_object,
+ ['enableEnhancedCivicAnswers'],
+ getv(from_object, ['enable_enhanced_civic_answers']),
+ )
+
+ if getv(from_object, ['system_instruction']) is not None:
+ setv(
+ parent_object,
+ ['systemInstruction'],
+ _Content_to_mldev(
+ t.t_content(getv(from_object, ['system_instruction'])), to_object
+ ),
)
if getv(from_object, ['safety_settings']) is not None:
@@ -1076,33 +1114,6 @@ def _GenerateContentConfig_to_mldev(
),
)
- if getv(from_object, ['response_modalities']) is not None:
- setv(
- to_object,
- ['responseModalities'],
- getv(from_object, ['response_modalities']),
- )
-
- if getv(from_object, ['media_resolution']) is not None:
- setv(
- to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
- )
-
- if getv(from_object, ['speech_config']) is not None:
- setv(
- to_object,
- ['speechConfig'],
- t.t_speech_config(getv(from_object, ['speech_config'])),
- )
-
- if getv(from_object, ['audio_timestamp']) is not None:
- raise ValueError(
- 'audio_timestamp parameter is not supported in Gemini API.'
- )
-
- if getv(from_object, ['thinking_config']) is not None:
- setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
-
if getv(from_object, ['image_config']) is not None:
setv(
to_object,
@@ -1110,13 +1121,6 @@ def _GenerateContentConfig_to_mldev(
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
)
- if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
- setv(
- to_object,
- ['enableEnhancedCivicAnswers'],
- getv(from_object, ['enable_enhanced_civic_answers']),
- )
-
return to_object
@@ -1126,58 +1130,64 @@ def _GenerateContentConfig_to_vertex(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
-
- if getv(from_object, ['system_instruction']) is not None:
+ if getv(from_object, ['model_selection_config']) is not None:
setv(
- parent_object,
- ['systemInstruction'],
- t.t_content(getv(from_object, ['system_instruction'])),
+ to_object,
+ ['modelConfig'],
+ getv(from_object, ['model_selection_config']),
)
- if getv(from_object, ['temperature']) is not None:
- setv(to_object, ['temperature'], getv(from_object, ['temperature']))
-
- if getv(from_object, ['top_p']) is not None:
- setv(to_object, ['topP'], getv(from_object, ['top_p']))
-
- if getv(from_object, ['top_k']) is not None:
- setv(to_object, ['topK'], getv(from_object, ['top_k']))
+ if getv(from_object, ['audio_timestamp']) is not None:
+ setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
if getv(from_object, ['candidate_count']) is not None:
setv(to_object, ['candidateCount'], getv(from_object, ['candidate_count']))
- if getv(from_object, ['max_output_tokens']) is not None:
+ if getv(from_object, ['enable_affective_dialog']) is not None:
setv(
- to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ to_object,
+ ['enableAffectiveDialog'],
+ getv(from_object, ['enable_affective_dialog']),
)
- if getv(from_object, ['stop_sequences']) is not None:
- setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
-
- if getv(from_object, ['response_logprobs']) is not None:
+ if getv(from_object, ['frequency_penalty']) is not None:
setv(
to_object,
- ['responseLogprobs'],
- getv(from_object, ['response_logprobs']),
+ ['frequencyPenalty'],
+ getv(from_object, ['frequency_penalty']),
)
if getv(from_object, ['logprobs']) is not None:
setv(to_object, ['logprobs'], getv(from_object, ['logprobs']))
+ if getv(from_object, ['max_output_tokens']) is not None:
+ setv(
+ to_object, ['maxOutputTokens'], getv(from_object, ['max_output_tokens'])
+ )
+
+ if getv(from_object, ['media_resolution']) is not None:
+ setv(
+ to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
+ )
+
if getv(from_object, ['presence_penalty']) is not None:
setv(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
- if getv(from_object, ['frequency_penalty']) is not None:
+ if getv(from_object, ['response_json_schema']) is not None:
setv(
to_object,
- ['frequencyPenalty'],
- getv(from_object, ['frequency_penalty']),
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
)
- if getv(from_object, ['seed']) is not None:
- setv(to_object, ['seed'], getv(from_object, ['seed']))
+ if getv(from_object, ['response_logprobs']) is not None:
+ setv(
+ to_object,
+ ['responseLogprobs'],
+ getv(from_object, ['response_logprobs']),
+ )
if getv(from_object, ['response_mime_type']) is not None:
setv(
@@ -1186,28 +1196,58 @@ def _GenerateContentConfig_to_vertex(
getv(from_object, ['response_mime_type']),
)
- if getv(from_object, ['response_schema']) is not None:
+ if getv(from_object, ['response_modalities']) is not None:
setv(
to_object,
- ['responseSchema'],
- t.t_schema(api_client, getv(from_object, ['response_schema'])),
+ ['responseModalities'],
+ getv(from_object, ['response_modalities']),
)
- if getv(from_object, ['response_json_schema']) is not None:
+ if getv(from_object, ['response_schema']) is not None:
setv(
to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
+ ['responseSchema'],
+ t.t_schema(api_client, getv(from_object, ['response_schema'])),
)
if getv(from_object, ['routing_config']) is not None:
setv(to_object, ['routingConfig'], getv(from_object, ['routing_config']))
- if getv(from_object, ['model_selection_config']) is not None:
+ if getv(from_object, ['seed']) is not None:
+ setv(to_object, ['seed'], getv(from_object, ['seed']))
+
+ if getv(from_object, ['speech_config']) is not None:
setv(
to_object,
- ['modelConfig'],
- getv(from_object, ['model_selection_config']),
+ ['speechConfig'],
+ t.t_speech_config(getv(from_object, ['speech_config'])),
+ )
+
+ if getv(from_object, ['stop_sequences']) is not None:
+ setv(to_object, ['stopSequences'], getv(from_object, ['stop_sequences']))
+
+ if getv(from_object, ['temperature']) is not None:
+ setv(to_object, ['temperature'], getv(from_object, ['temperature']))
+
+ if getv(from_object, ['thinking_config']) is not None:
+ setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
+
+ if getv(from_object, ['top_k']) is not None:
+ setv(to_object, ['topK'], getv(from_object, ['top_k']))
+
+ if getv(from_object, ['top_p']) is not None:
+ setv(to_object, ['topP'], getv(from_object, ['top_p']))
+
+ if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
+ raise ValueError(
+ 'enable_enhanced_civic_answers parameter is not supported in Vertex AI.'
+ )
+
+ if getv(from_object, ['system_instruction']) is not None:
+ setv(
+ parent_object,
+ ['systemInstruction'],
+ t.t_content(getv(from_object, ['system_instruction'])),
)
if getv(from_object, ['safety_settings']) is not None:
@@ -1242,31 +1282,6 @@ def _GenerateContentConfig_to_vertex(
),
)
- if getv(from_object, ['response_modalities']) is not None:
- setv(
- to_object,
- ['responseModalities'],
- getv(from_object, ['response_modalities']),
- )
-
- if getv(from_object, ['media_resolution']) is not None:
- setv(
- to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
- )
-
- if getv(from_object, ['speech_config']) is not None:
- setv(
- to_object,
- ['speechConfig'],
- t.t_speech_config(getv(from_object, ['speech_config'])),
- )
-
- if getv(from_object, ['audio_timestamp']) is not None:
- setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
-
- if getv(from_object, ['thinking_config']) is not None:
- setv(to_object, ['thinkingConfig'], getv(from_object, ['thinking_config']))
-
if getv(from_object, ['image_config']) is not None:
setv(
to_object,
@@ -1274,11 +1289,6 @@ def _GenerateContentConfig_to_vertex(
_ImageConfig_to_vertex(getv(from_object, ['image_config']), to_object),
)
- if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
- raise ValueError(
- 'enable_enhanced_civic_answers parameter is not supported in Vertex AI.'
- )
-
return to_object
@@ -2368,13 +2378,6 @@ def _GenerationConfig_to_vertex(
getv(from_object, ['model_selection_config']),
)
- if getv(from_object, ['response_json_schema']) is not None:
- setv(
- to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
- )
-
if getv(from_object, ['audio_timestamp']) is not None:
setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
@@ -2413,6 +2416,13 @@ def _GenerationConfig_to_vertex(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
+ if getv(from_object, ['response_json_schema']) is not None:
+ setv(
+ to_object,
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
+ )
+
if getv(from_object, ['response_logprobs']) is not None:
setv(
to_object,
diff --git a/google/genai/tunings.py b/google/genai/tunings.py
index f84cc455d..632f9c51d 100644
--- a/google/genai/tunings.py
+++ b/google/genai/tunings.py
@@ -489,13 +489,6 @@ def _GenerationConfig_from_vertex(
getv(from_object, ['modelConfig']),
)
- if getv(from_object, ['responseJsonSchema']) is not None:
- setv(
- to_object,
- ['response_json_schema'],
- getv(from_object, ['responseJsonSchema']),
- )
-
if getv(from_object, ['audioTimestamp']) is not None:
setv(to_object, ['audio_timestamp'], getv(from_object, ['audioTimestamp']))
@@ -534,6 +527,13 @@ def _GenerationConfig_from_vertex(
to_object, ['presence_penalty'], getv(from_object, ['presencePenalty'])
)
+ if getv(from_object, ['responseJsonSchema']) is not None:
+ setv(
+ to_object,
+ ['response_json_schema'],
+ getv(from_object, ['responseJsonSchema']),
+ )
+
if getv(from_object, ['responseLogprobs']) is not None:
setv(
to_object,
@@ -598,13 +598,6 @@ def _GenerationConfig_to_vertex(
getv(from_object, ['model_selection_config']),
)
- if getv(from_object, ['response_json_schema']) is not None:
- setv(
- to_object,
- ['responseJsonSchema'],
- getv(from_object, ['response_json_schema']),
- )
-
if getv(from_object, ['audio_timestamp']) is not None:
setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
@@ -643,6 +636,13 @@ def _GenerationConfig_to_vertex(
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
)
+ if getv(from_object, ['response_json_schema']) is not None:
+ setv(
+ to_object,
+ ['responseJsonSchema'],
+ getv(from_object, ['response_json_schema']),
+ )
+
if getv(from_object, ['response_logprobs']) is not None:
setv(
to_object,
diff --git a/google/genai/types.py b/google/genai/types.py
index fc2c51692..091b87b27 100644
--- a/google/genai/types.py
+++ b/google/genai/types.py
@@ -161,27 +161,6 @@ class FunctionResponseScheduling(_common.CaseInSensitiveEnum):
"""Add the result to the conversation context, interrupt ongoing generation and prompt to generate output."""
-class Type(_common.CaseInSensitiveEnum):
- """The type of the data."""
-
- TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED'
- """Not specified, should not be used."""
- STRING = 'STRING'
- """OpenAPI string type"""
- NUMBER = 'NUMBER'
- """OpenAPI number type"""
- INTEGER = 'INTEGER'
- """OpenAPI integer type"""
- BOOLEAN = 'BOOLEAN'
- """OpenAPI boolean type"""
- ARRAY = 'ARRAY'
- """OpenAPI array type"""
- OBJECT = 'OBJECT'
- """OpenAPI object type"""
- NULL = 'NULL'
- """Null type"""
-
-
class ApiSpec(_common.CaseInSensitiveEnum):
"""The API spec that the external API implements.
@@ -267,6 +246,27 @@ class Behavior(_common.CaseInSensitiveEnum):
"""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."""
+class Type(_common.CaseInSensitiveEnum):
+ """The type of the data."""
+
+ TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED'
+ """Not specified, should not be used."""
+ STRING = 'STRING'
+ """OpenAPI string type"""
+ NUMBER = 'NUMBER'
+ """OpenAPI number type"""
+ INTEGER = 'INTEGER'
+ """OpenAPI integer type"""
+ BOOLEAN = 'BOOLEAN'
+ """OpenAPI boolean type"""
+ ARRAY = 'ARRAY'
+ """OpenAPI array type"""
+ OBJECT = 'OBJECT'
+ """OpenAPI object type"""
+ NULL = 'NULL'
+ """Null type"""
+
+
class DynamicRetrievalConfigMode(_common.CaseInSensitiveEnum):
"""The mode of the predictor to be used in dynamic retrieval."""
@@ -291,6 +291,32 @@ class FunctionCallingConfigMode(_common.CaseInSensitiveEnum):
"""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"."""
+class MediaResolution(_common.CaseInSensitiveEnum):
+ """If specified, the media resolution specified will be used."""
+
+ MEDIA_RESOLUTION_UNSPECIFIED = 'MEDIA_RESOLUTION_UNSPECIFIED'
+ """Media resolution has not been set."""
+ MEDIA_RESOLUTION_LOW = 'MEDIA_RESOLUTION_LOW'
+ """Media resolution set to low (64 tokens)."""
+ MEDIA_RESOLUTION_MEDIUM = 'MEDIA_RESOLUTION_MEDIUM'
+ """Media resolution set to medium (256 tokens)."""
+ MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH'
+ """Media resolution set to high (zoomed reframing with 256 tokens)."""
+
+
+class Modality(_common.CaseInSensitiveEnum):
+ """Server content modalities."""
+
+ MODALITY_UNSPECIFIED = 'MODALITY_UNSPECIFIED'
+ """The modality is unspecified."""
+ TEXT = 'TEXT'
+ """Indicates the model should return text"""
+ IMAGE = 'IMAGE'
+ """Indicates the model should return images."""
+ AUDIO = 'AUDIO'
+ """Indicates the model should return audio."""
+
+
class ThinkingLevel(_common.CaseInSensitiveEnum):
"""The number of thoughts tokens that the model should generate."""
@@ -494,32 +520,6 @@ class TrafficType(_common.CaseInSensitiveEnum):
"""Type for Provisioned Throughput traffic."""
-class Modality(_common.CaseInSensitiveEnum):
- """Server content modalities."""
-
- MODALITY_UNSPECIFIED = 'MODALITY_UNSPECIFIED'
- """The modality is unspecified."""
- TEXT = 'TEXT'
- """Indicates the model should return text"""
- IMAGE = 'IMAGE'
- """Indicates the model should return images."""
- AUDIO = 'AUDIO'
- """Indicates the model should return audio."""
-
-
-class MediaResolution(_common.CaseInSensitiveEnum):
- """The media resolution to use."""
-
- MEDIA_RESOLUTION_UNSPECIFIED = 'MEDIA_RESOLUTION_UNSPECIFIED'
- """Media resolution has not been set"""
- MEDIA_RESOLUTION_LOW = 'MEDIA_RESOLUTION_LOW'
- """Media resolution set to low (64 tokens)."""
- MEDIA_RESOLUTION_MEDIUM = 'MEDIA_RESOLUTION_MEDIUM'
- """Media resolution set to medium (256 tokens)."""
- MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH'
- """Media resolution set to high (zoomed reframing with 256 tokens)."""
-
-
class TuningMode(_common.CaseInSensitiveEnum):
"""Tuning mode. This enum is not supported in Gemini API."""
@@ -621,6 +621,15 @@ class ResourceScope(_common.CaseInSensitiveEnum):
"https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview"""
+class Environment(_common.CaseInSensitiveEnum):
+ """The environment being operated."""
+
+ ENVIRONMENT_UNSPECIFIED = 'ENVIRONMENT_UNSPECIFIED'
+ """Defaults to browser."""
+ ENVIRONMENT_BROWSER = 'ENVIRONMENT_BROWSER'
+ """Operates in a web browser."""
+
+
class JSONSchemaType(Enum):
"""The type of the data supported by JSON Schema.
@@ -637,26 +646,6 @@ class JSONSchemaType(Enum):
STRING = 'string'
-class FeatureSelectionPreference(_common.CaseInSensitiveEnum):
- """Options for feature selection preference."""
-
- FEATURE_SELECTION_PREFERENCE_UNSPECIFIED = (
- 'FEATURE_SELECTION_PREFERENCE_UNSPECIFIED'
- )
- PRIORITIZE_QUALITY = 'PRIORITIZE_QUALITY'
- BALANCED = 'BALANCED'
- PRIORITIZE_COST = 'PRIORITIZE_COST'
-
-
-class Environment(_common.CaseInSensitiveEnum):
- """The environment being operated."""
-
- ENVIRONMENT_UNSPECIFIED = 'ENVIRONMENT_UNSPECIFIED'
- """Defaults to browser."""
- ENVIRONMENT_BROWSER = 'ENVIRONMENT_BROWSER'
- """Operates in a web browser."""
-
-
class SafetyFilterLevel(_common.CaseInSensitiveEnum):
"""Enum that controls the safety filter level for objectionable content."""
@@ -792,6 +781,17 @@ class VideoCompressionQuality(_common.CaseInSensitiveEnum):
with a larger file size."""
+class FeatureSelectionPreference(_common.CaseInSensitiveEnum):
+ """Options for feature selection preference."""
+
+ FEATURE_SELECTION_PREFERENCE_UNSPECIFIED = (
+ 'FEATURE_SELECTION_PREFERENCE_UNSPECIFIED'
+ )
+ PRIORITIZE_QUALITY = 'PRIORITIZE_QUALITY'
+ BALANCED = 'BALANCED'
+ PRIORITIZE_COST = 'PRIORITIZE_COST'
+
+
class TuningMethod(_common.CaseInSensitiveEnum):
"""Enum representing the tuning method."""
@@ -1964,2423 +1964,2632 @@ class HttpOptionsDict(TypedDict, total=False):
HttpOptionsOrDict = Union[HttpOptions, HttpOptionsDict]
-class JSONSchema(_common.BaseModel):
- """A subset of JSON Schema according to 2020-12 JSON Schema draft.
-
- Represents a subset of a JSON Schema object that is used by the Gemini model.
- The difference between this class and the Schema class is that this class is
- compatible with OpenAPI 3.1 schema objects. And the Schema class is used to
- make API call to Gemini model.
- """
+class ComputerUse(_common.BaseModel):
+ """Tool to support computer use."""
- type: Optional[Union[JSONSchemaType, list[JSONSchemaType]]] = Field(
- default=None,
- 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.""",
- )
- format: Optional[str] = Field(
- default=None,
- description='Define semantic information about a string instance.',
- )
- title: Optional[str] = Field(
- default=None,
- description=(
- 'A preferably short description about the purpose of the instance'
- ' described by the schema.'
- ),
+ environment: Optional[Environment] = Field(
+ default=None, description="""Required. The environment being operated."""
)
- description: Optional[str] = Field(
+ excluded_predefined_functions: Optional[list[str]] = Field(
default=None,
- description=(
- 'An explanation about the purpose of the instance described by the'
- ' schema.'
- ),
+ description="""By default, predefined functions are included in the final model call.
+ Some of them can be explicitly excluded from being automatically included.
+ This can serve two purposes:
+ 1. Using a more restricted / different action space.
+ 2. Improving the definitions / instructions of predefined functions.""",
)
- default: Optional[Any] = Field(
+
+
+class ComputerUseDict(TypedDict, total=False):
+ """Tool to support computer use."""
+
+ environment: Optional[Environment]
+ """Required. The environment being operated."""
+
+ excluded_predefined_functions: Optional[list[str]]
+ """By default, predefined functions are included in the final model call.
+ Some of them can be explicitly excluded from being automatically included.
+ This can serve two purposes:
+ 1. Using a more restricted / different action space.
+ 2. Improving the definitions / instructions of predefined functions."""
+
+
+ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]
+
+
+class FileSearch(_common.BaseModel):
+ """Tool to retrieve knowledge from the File Search Stores."""
+
+ file_search_store_names: Optional[list[str]] = Field(
default=None,
- description=(
- 'This keyword can be used to supply a default JSON value associated'
- ' with a particular schema.'
- ),
+ description="""The names of the file_search_stores to retrieve from.
+ Example: `fileSearchStores/my-file-search-store-123`""",
)
- items: Optional['JSONSchema'] = Field(
+ top_k: Optional[int] = Field(
default=None,
- description=(
- 'Validation succeeds if each element of the instance not covered by'
- ' prefixItems validates against this schema.'
- ),
+ description="""The number of file search retrieval chunks to retrieve.""",
)
- min_items: Optional[int] = Field(
+ metadata_filter: Optional[str] = Field(
default=None,
- description=(
- 'An array instance is valid if its size is greater than, or equal to,'
- ' the value of this keyword.'
- ),
+ description="""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.""",
)
- max_items: Optional[int] = Field(
+
+
+class FileSearchDict(TypedDict, total=False):
+ """Tool to retrieve knowledge from the File Search Stores."""
+
+ file_search_store_names: Optional[list[str]]
+ """The names of the file_search_stores to retrieve from.
+ Example: `fileSearchStores/my-file-search-store-123`"""
+
+ top_k: Optional[int]
+ """The number of file search retrieval chunks to retrieve."""
+
+ metadata_filter: Optional[str]
+ """Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."""
+
+
+FileSearchOrDict = Union[FileSearch, FileSearchDict]
+
+
+class ApiAuthApiKeyConfig(_common.BaseModel):
+ """The API secret. This data type is not supported in Gemini API."""
+
+ api_key_secret_version: Optional[str] = Field(
default=None,
- description=(
- 'An array instance is valid if its size is less than, or equal to,'
- ' the value of this keyword.'
- ),
+ description="""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}""",
)
- enum: Optional[list[Any]] = Field(
+ api_key_string: Optional[str] = Field(
default=None,
- description=(
- 'Validation succeeds if the instance is equal to one of the elements'
- ' in this keyword’s array value.'
- ),
+ description="""The API key string. Either this or `api_key_secret_version` must be set.""",
)
- properties: Optional[dict[str, 'JSONSchema']] = Field(
- default=None,
- description=(
- 'Validation succeeds if, for each name that appears in both the'
- ' instance and as a name within this keyword’s value, the child'
- ' instance for that name successfully validates against the'
- ' corresponding schema.'
- ),
- )
- required: Optional[list[str]] = Field(
- default=None,
- description=(
- 'An object instance is valid against this keyword if every item in'
- ' the array is the name of a property in the instance.'
- ),
- )
- min_properties: Optional[int] = Field(
- default=None,
- description=(
- 'An object instance is valid if its number of properties is greater'
- ' than, or equal to, the value of this keyword.'
- ),
- )
- max_properties: Optional[int] = Field(
- default=None,
- description=(
- 'An object instance is valid if its number of properties is less'
- ' than, or equal to, the value of this keyword.'
- ),
- )
- minimum: Optional[float] = Field(
- default=None,
- description=(
- 'Validation succeeds if the numeric instance is greater than or equal'
- ' to the given number.'
- ),
- )
- maximum: Optional[float] = Field(
- default=None,
- description=(
- 'Validation succeeds if the numeric instance is less than or equal to'
- ' the given number.'
- ),
- )
- min_length: Optional[int] = Field(
- default=None,
- description=(
- 'A string instance is valid against this keyword if its length is'
- ' greater than, or equal to, the value of this keyword.'
- ),
- )
- max_length: Optional[int] = Field(
- default=None,
- description=(
- 'A string instance is valid against this keyword if its length is'
- ' less than, or equal to, the value of this keyword.'
- ),
- )
- pattern: Optional[str] = Field(
- default=None,
- description=(
- 'A string instance is considered valid if the regular expression'
- ' matches the instance successfully.'
- ),
- )
- additional_properties: Optional[Any] = Field(
- default=None,
- description="""Can either be a boolean or an object; controls the presence of additional properties.""",
+
+
+class ApiAuthApiKeyConfigDict(TypedDict, total=False):
+ """The API secret. This data type is not supported in Gemini API."""
+
+ api_key_secret_version: Optional[str]
+ """Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}"""
+
+ api_key_string: Optional[str]
+ """The API key string. Either this or `api_key_secret_version` must be set."""
+
+
+ApiAuthApiKeyConfigOrDict = Union[ApiAuthApiKeyConfig, ApiAuthApiKeyConfigDict]
+
+
+class ApiAuth(_common.BaseModel):
+ """The generic reusable api auth config.
+
+ Deprecated. Please use AuthConfig (google/cloud/aiplatform/master/auth.proto)
+ instead. This data type is not supported in Gemini API.
+ """
+
+ api_key_config: Optional[ApiAuthApiKeyConfig] = Field(
+ default=None, description="""The API secret."""
)
- any_of: Optional[list['JSONSchema']] = Field(
+
+
+class ApiAuthDict(TypedDict, total=False):
+ """The generic reusable api auth config.
+
+ Deprecated. Please use AuthConfig (google/cloud/aiplatform/master/auth.proto)
+ instead. This data type is not supported in Gemini API.
+ """
+
+ api_key_config: Optional[ApiAuthApiKeyConfigDict]
+ """The API secret."""
+
+
+ApiAuthOrDict = Union[ApiAuth, ApiAuthDict]
+
+
+class ApiKeyConfig(_common.BaseModel):
+ """Config for authentication with API key.
+
+ This data type is not supported in Gemini API.
+ """
+
+ api_key_secret: Optional[str] = Field(
default=None,
- description=(
- 'An instance validates successfully against this keyword if it'
- ' validates successfully against at least one schema defined by this'
- ' keyword’s value.'
- ),
+ description="""Optional. The name of the SecretManager secret version resource storing the API key. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If both `api_key_secret` and `api_key_string` are specified, this field takes precedence over `api_key_string`. - 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.""",
)
- unique_items: Optional[bool] = Field(
+ api_key_string: Optional[str] = Field(
default=None,
- description="""Boolean value that indicates whether the items in an array are unique.""",
+ description="""Optional. The API key to be used in the request directly.""",
)
- ref: Optional[str] = Field(
- default=None,
- alias='$ref',
- description="""Allows indirect references between schema nodes.""",
+ http_element_location: Optional[HttpElementLocation] = Field(
+ default=None, description="""Optional. The location of the API key."""
)
- defs: Optional[dict[str, 'JSONSchema']] = Field(
+ name: Optional[str] = Field(
default=None,
- alias='$defs',
- description="""Schema definitions to be used with $ref.""",
+ description="""Optional. The parameter name of the API key. E.g. If the API request is "https://example.com/act?api_key=", "api_key" would be the parameter name.""",
)
-class Schema(_common.BaseModel):
- """Schema is used to define the format of input/output data.
+class ApiKeyConfigDict(TypedDict, total=False):
+ """Config for authentication with API key.
- Represents a select subset of an [OpenAPI 3.0 schema
- object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
- be added in the future as needed.
+ This data type is not supported in Gemini API.
"""
- additional_properties: Optional[Any] = Field(
+ api_key_secret: Optional[str]
+ """Optional. The name of the SecretManager secret version resource storing the API key. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If both `api_key_secret` and `api_key_string` are specified, this field takes precedence over `api_key_string`. - 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."""
+
+ api_key_string: Optional[str]
+ """Optional. The API key to be used in the request directly."""
+
+ http_element_location: Optional[HttpElementLocation]
+ """Optional. The location of the API key."""
+
+ name: Optional[str]
+ """Optional. The parameter name of the API key. E.g. If the API request is "https://example.com/act?api_key=", "api_key" would be the parameter name."""
+
+
+ApiKeyConfigOrDict = Union[ApiKeyConfig, ApiKeyConfigDict]
+
+
+class AuthConfigGoogleServiceAccountConfig(_common.BaseModel):
+ """Config for Google Service Account Authentication.
+
+ This data type is not supported in Gemini API.
+ """
+
+ service_account: Optional[str] = Field(
default=None,
- description="""Optional. Can either be a boolean or an object; controls the presence of additional properties.""",
+ 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.""",
)
- defs: Optional[dict[str, 'Schema']] = Field(
+
+
+class AuthConfigGoogleServiceAccountConfigDict(TypedDict, total=False):
+ """Config for Google Service Account Authentication.
+
+ This data type is not supported in Gemini API.
+ """
+
+ service_account: Optional[str]
+ """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."""
+
+
+AuthConfigGoogleServiceAccountConfigOrDict = Union[
+ AuthConfigGoogleServiceAccountConfig,
+ AuthConfigGoogleServiceAccountConfigDict,
+]
+
+
+class AuthConfigHttpBasicAuthConfig(_common.BaseModel):
+ """Config for HTTP Basic Authentication.
+
+ This data type is not supported in Gemini API.
+ """
+
+ credential_secret: Optional[str] = Field(
default=None,
- description="""Optional. A map of definitions for use by `ref` Only allowed at the root of the schema.""",
+ 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.""",
)
- ref: Optional[str] = Field(
+
+
+class AuthConfigHttpBasicAuthConfigDict(TypedDict, total=False):
+ """Config for HTTP Basic Authentication.
+
+ This data type is not supported in Gemini API.
+ """
+
+ credential_secret: Optional[str]
+ """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."""
+
+
+AuthConfigHttpBasicAuthConfigOrDict = Union[
+ AuthConfigHttpBasicAuthConfig, AuthConfigHttpBasicAuthConfigDict
+]
+
+
+class AuthConfigOauthConfig(_common.BaseModel):
+ """Config for user oauth. This data type is not supported in Gemini API."""
+
+ access_token: Optional[str] = Field(
default=None,
- description="""Optional. Allows indirect references between schema nodes. The value should be a valid reference to a child of the root `defs`. For example, the following schema defines a reference to a schema node named "Pet": type: object properties: pet: ref: #/defs/Pet defs: Pet: type: object properties: name: type: string The value of the "pet" property is a reference to the schema node named "Pet". See details in https://json-schema.org/understanding-json-schema/structuring""",
+ description="""Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
)
- any_of: Optional[list['Schema']] = Field(
+ service_account: Optional[str] = Field(
default=None,
- description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
- )
- default: Optional[Any] = Field(
- default=None, description="""Optional. Default value of the data."""
- )
- description: Optional[str] = Field(
- default=None, description="""Optional. The description of the data."""
+ 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.""",
)
- enum: Optional[list[str]] = Field(
+
+
+class AuthConfigOauthConfigDict(TypedDict, total=False):
+ """Config for user oauth. This data type is not supported in Gemini API."""
+
+ access_token: Optional[str]
+ """Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
+
+ service_account: Optional[str]
+ """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."""
+
+
+AuthConfigOauthConfigOrDict = Union[
+ AuthConfigOauthConfig, AuthConfigOauthConfigDict
+]
+
+
+class AuthConfigOidcConfig(_common.BaseModel):
+ """Config for user OIDC auth.
+
+ This data type is not supported in Gemini API.
+ """
+
+ id_token: Optional[str] = Field(
default=None,
- 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"]}""",
+ description="""OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
)
- example: Optional[Any] = Field(
+ service_account: Optional[str] = Field(
default=None,
- description="""Optional. Example of the object. Will only populated when the object is the root.""",
+ 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).""",
)
- format: Optional[str] = Field(
- default=None,
- 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""",
- )
- items: Optional['Schema'] = Field(
- default=None,
- description="""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY.""",
+
+
+class AuthConfigOidcConfigDict(TypedDict, total=False):
+ """Config for user OIDC auth.
+
+ This data type is not supported in Gemini API.
+ """
+
+ id_token: Optional[str]
+ """OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
+
+ service_account: Optional[str]
+ """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)."""
+
+
+AuthConfigOidcConfigOrDict = Union[
+ AuthConfigOidcConfig, AuthConfigOidcConfigDict
+]
+
+
+class AuthConfig(_common.BaseModel):
+ """Auth configuration to run the extension.
+
+ This data type is not supported in Gemini API.
+ """
+
+ api_key_config: Optional[ApiKeyConfig] = Field(
+ default=None, description="""Config for API key auth."""
)
- max_items: Optional[int] = Field(
- default=None,
- description="""Optional. Maximum number of the elements for Type.ARRAY.""",
+ auth_type: Optional[AuthType] = Field(
+ default=None, description="""Type of auth scheme."""
)
- max_length: Optional[int] = Field(
- default=None,
- description="""Optional. Maximum length of the Type.STRING""",
+ google_service_account_config: Optional[
+ AuthConfigGoogleServiceAccountConfig
+ ] = Field(
+ default=None, description="""Config for Google Service Account auth."""
)
- max_properties: Optional[int] = Field(
- default=None,
- description="""Optional. Maximum number of the properties for Type.OBJECT.""",
+ http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfig] = Field(
+ default=None, description="""Config for HTTP Basic auth."""
)
- maximum: Optional[float] = Field(
- default=None,
- description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
+ oauth_config: Optional[AuthConfigOauthConfig] = Field(
+ default=None, description="""Config for user oauth."""
)
- min_items: Optional[int] = Field(
- default=None,
- description="""Optional. Minimum number of the elements for Type.ARRAY.""",
+ oidc_config: Optional[AuthConfigOidcConfig] = Field(
+ default=None, description="""Config for user OIDC auth."""
)
- min_length: Optional[int] = Field(
- default=None,
- description="""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING""",
+
+
+class AuthConfigDict(TypedDict, total=False):
+ """Auth configuration to run the extension.
+
+ This data type is not supported in Gemini API.
+ """
+
+ api_key_config: Optional[ApiKeyConfigDict]
+ """Config for API key auth."""
+
+ auth_type: Optional[AuthType]
+ """Type of auth scheme."""
+
+ google_service_account_config: Optional[
+ AuthConfigGoogleServiceAccountConfigDict
+ ]
+ """Config for Google Service Account auth."""
+
+ http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfigDict]
+ """Config for HTTP Basic auth."""
+
+ oauth_config: Optional[AuthConfigOauthConfigDict]
+ """Config for user oauth."""
+
+ oidc_config: Optional[AuthConfigOidcConfigDict]
+ """Config for user OIDC auth."""
+
+
+AuthConfigOrDict = Union[AuthConfig, AuthConfigDict]
+
+
+class ExternalApiElasticSearchParams(_common.BaseModel):
+ """The search parameters to use for the ELASTIC_SEARCH spec.
+
+ This data type is not supported in Gemini API.
+ """
+
+ index: Optional[str] = Field(
+ default=None, description="""The ElasticSearch index to use."""
)
- min_properties: Optional[int] = Field(
+ num_hits: Optional[int] = Field(
default=None,
- description="""Optional. Minimum number of the properties for Type.OBJECT.""",
+ description="""Optional. Number of hits (chunks) to request. When specified, it is passed to Elasticsearch as the `num_hits` param.""",
)
- minimum: Optional[float] = Field(
- default=None,
- description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
+ search_template: Optional[str] = Field(
+ default=None, description="""The ElasticSearch search template to use."""
)
- nullable: Optional[bool] = Field(
+
+
+class ExternalApiElasticSearchParamsDict(TypedDict, total=False):
+ """The search parameters to use for the ELASTIC_SEARCH spec.
+
+ This data type is not supported in Gemini API.
+ """
+
+ index: Optional[str]
+ """The ElasticSearch index to use."""
+
+ num_hits: Optional[int]
+ """Optional. Number of hits (chunks) to request. When specified, it is passed to Elasticsearch as the `num_hits` param."""
+
+ search_template: Optional[str]
+ """The ElasticSearch search template to use."""
+
+
+ExternalApiElasticSearchParamsOrDict = Union[
+ ExternalApiElasticSearchParams, ExternalApiElasticSearchParamsDict
+]
+
+
+class ExternalApiSimpleSearchParams(_common.BaseModel):
+ """The search parameters to use for SIMPLE_SEARCH spec.
+
+ This data type is not supported in Gemini API.
+ """
+
+ pass
+
+
+class ExternalApiSimpleSearchParamsDict(TypedDict, total=False):
+ """The search parameters to use for SIMPLE_SEARCH spec.
+
+ This data type is not supported in Gemini API.
+ """
+
+ pass
+
+
+ExternalApiSimpleSearchParamsOrDict = Union[
+ ExternalApiSimpleSearchParams, ExternalApiSimpleSearchParamsDict
+]
+
+
+class ExternalApi(_common.BaseModel):
+ """Retrieve from data source powered by external API for grounding.
+
+ The external API is not owned by Google, but need to follow the pre-defined
+ API spec. This data type is not supported in Gemini API.
+ """
+
+ api_auth: Optional[ApiAuth] = Field(
default=None,
- description="""Optional. Indicates if the value may be null.""",
+ description="""The authentication config to access the API. Deprecated. Please use auth_config instead.""",
)
- pattern: Optional[str] = Field(
+ api_spec: Optional[ApiSpec] = Field(
default=None,
- description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
+ description="""The API spec that the external API implements.""",
)
- properties: Optional[dict[str, 'Schema']] = Field(
+ auth_config: Optional[AuthConfig] = Field(
default=None,
- description="""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.""",
+ description="""The authentication config to access the API.""",
)
- property_ordering: Optional[list[str]] = Field(
- default=None,
- description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
+ elastic_search_params: Optional[ExternalApiElasticSearchParams] = Field(
+ default=None, description="""Parameters for the elastic search API."""
)
- required: Optional[list[str]] = Field(
+ endpoint: Optional[str] = Field(
default=None,
- description="""Optional. Required properties of Type.OBJECT.""",
- )
- title: Optional[str] = Field(
- default=None, description="""Optional. The title of the Schema."""
+ description="""The endpoint of the external API. The system will call the API at this endpoint to retrieve the data for grounding. Example: https://acme.com:443/search""",
)
- type: Optional[Type] = Field(
- default=None, description="""Optional. The type of the data."""
+ simple_search_params: Optional[ExternalApiSimpleSearchParams] = Field(
+ default=None, description="""Parameters for the simple search API."""
)
- @property
- def json_schema(self) -> JSONSchema:
- """Converts the Schema object to a JSONSchema object, that is compatible with 2020-12 JSON Schema draft.
- Note: Conversion of fields that are not included in the JSONSchema class
- are ignored.
- Json Schema is now supported natively by both Vertex AI and Gemini API.
- Users
- are recommended to pass/receive Json Schema directly to/from the API. For
- example:
- 1. the counter part of GenerateContentConfig.response_schema is
- GenerateContentConfig.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- 2. the counter part of FunctionDeclaration.parameters is
- FunctionDeclaration.parameters_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- 3. the counter part of FunctionDeclaration.response is
- FunctionDeclaration.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- """
+class ExternalApiDict(TypedDict, total=False):
+ """Retrieve from data source powered by external API for grounding.
- global _json_schema_warning_logged
- if not _json_schema_warning_logged:
- info_message = """
-Note: Conversion of fields that are not included in the JSONSchema class are
-ignored.
-Json Schema is now supported natively by both Vertex AI and Gemini API. Users
-are recommended to pass/receive Json Schema directly to/from the API. For example:
-1. the counter part of GenerateContentConfig.response_schema is
- GenerateContentConfig.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-2. the counter part of FunctionDeclaration.parameters is
- FunctionDeclaration.parameters_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-3. the counter part of FunctionDeclaration.response is
- FunctionDeclaration.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-"""
- logger.info(info_message)
- _json_schema_warning_logged = True
+ The external API is not owned by Google, but need to follow the pre-defined
+ API spec. This data type is not supported in Gemini API.
+ """
- json_schema_field_names: set[str] = set(JSONSchema.model_fields.keys())
- schema_field_names: tuple[str] = (
- 'items',
- ) # 'additional_properties' to come
- list_schema_field_names: tuple[str] = (
- 'any_of', # 'one_of', 'all_of', 'not' to come
- )
- dict_schema_field_names: tuple[str] = ('properties',) # 'defs' to come
+ api_auth: Optional[ApiAuthDict]
+ """The authentication config to access the API. Deprecated. Please use auth_config instead."""
- def convert_schema(schema: Union['Schema', dict[str, Any]]) -> JSONSchema:
- if isinstance(schema, pydantic.BaseModel):
- schema_dict = schema.model_dump(exclude_none=True)
- else:
- schema_dict = schema
- json_schema = JSONSchema()
- for field_name, field_value in schema_dict.items():
- if field_value is None:
- continue
- elif field_name == 'nullable':
- if json_schema.type is None:
- json_schema.type = JSONSchemaType.NULL
- elif isinstance(json_schema.type, JSONSchemaType):
- current_type: JSONSchemaType = json_schema.type
- json_schema.type = [current_type, JSONSchemaType.NULL]
- elif isinstance(json_schema.type, list):
- json_schema.type.append(JSONSchemaType.NULL)
- elif field_name not in json_schema_field_names:
- continue
- elif field_name == 'type':
- if field_value == Type.TYPE_UNSPECIFIED:
- continue
- json_schema_type = JSONSchemaType(field_value.lower())
- if json_schema.type is None:
- json_schema.type = json_schema_type
- elif isinstance(json_schema.type, JSONSchemaType):
- existing_type: JSONSchemaType = json_schema.type
- json_schema.type = [existing_type, json_schema_type]
- elif isinstance(json_schema.type, list):
- json_schema.type.append(json_schema_type)
- elif field_name in schema_field_names:
- schema_field_value: 'JSONSchema' = convert_schema(field_value)
- setattr(json_schema, field_name, schema_field_value)
- elif field_name in list_schema_field_names:
- list_schema_field_value: list['JSONSchema'] = [
- convert_schema(this_field_value)
- for this_field_value in field_value
- ]
- setattr(json_schema, field_name, list_schema_field_value)
- elif field_name in dict_schema_field_names:
- dict_schema_field_value: dict[str, 'JSONSchema'] = {
- key: convert_schema(value) for key, value in field_value.items()
- }
- setattr(json_schema, field_name, dict_schema_field_value)
- else:
- setattr(json_schema, field_name, field_value)
-
- return json_schema
-
- return convert_schema(self)
-
- @classmethod
- def from_json_schema(
- cls,
- *,
- json_schema: JSONSchema,
- api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
- raise_error_on_unsupported_field: bool = False,
- ) -> 'Schema':
- """Converts a JSONSchema object to a Schema object.
-
- Note: Conversion of fields that are not included in the JSONSchema class
- are ignored.
- Json Schema is now supported natively by both Vertex AI and Gemini API.
- Users
- are recommended to pass/receive Json Schema directly to/from the API. For
- example:
- 1. the counter part of GenerateContentConfig.response_schema is
- GenerateContentConfig.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- 2. the counter part of FunctionDeclaration.parameters is
- FunctionDeclaration.parameters_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- 3. the counter part of FunctionDeclaration.response is
- FunctionDeclaration.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
- The JSONSchema is compatible with 2020-12 JSON Schema draft, specified by
- OpenAPI 3.1.
-
- Args:
- json_schema: JSONSchema object to be converted.
- api_option: API option to be used. If set to 'VERTEX_AI', the
- JSONSchema will be converted to a Schema object that is compatible
- with Vertex AI API. If set to 'GEMINI_API', the JSONSchema will be
- converted to a Schema object that is compatible with Gemini API.
- Default is 'GEMINI_API'.
- raise_error_on_unsupported_field: If set to True, an error will be
- raised if the JSONSchema contains any unsupported fields. Default is
- False.
-
- Returns:
- Schema object that is compatible with the specified API option.
- Raises:
- ValueError: If the JSONSchema contains any unsupported fields and
- raise_error_on_unsupported_field is set to True. Or if the JSONSchema
- is not compatible with the specified API option.
- """
- global _from_json_schema_warning_logged
- if not _from_json_schema_warning_logged:
- info_message = """
-Note: Conversion of fields that are not included in the JSONSchema class are ignored.
-Json Schema is now supported natively by both Vertex AI and Gemini API. Users
-are recommended to pass/receive Json Schema directly to/from the API. For example:
-1. the counter part of GenerateContentConfig.response_schema is
- GenerateContentConfig.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-2. the counter part of FunctionDeclaration.parameters is
- FunctionDeclaration.parameters_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-3. the counter part of FunctionDeclaration.response is
- FunctionDeclaration.response_json_schema, which accepts [JSON
- Schema](https://json-schema.org/)
-"""
- logger.info(info_message)
- _from_json_schema_warning_logged = True
-
- google_schema_field_names: set[str] = set(cls.model_fields.keys())
- schema_field_names: tuple[str, ...] = (
- 'items',
- ) # 'additional_properties' to come
- list_schema_field_names: tuple[str, ...] = (
- 'any_of', # 'one_of', 'all_of', 'not' to come
- )
- dict_schema_field_names: tuple[str, ...] = ('properties',)
-
- related_field_names_by_type: dict[str, tuple[str, ...]] = {
- JSONSchemaType.NUMBER.value: (
- 'description',
- 'enum',
- 'format',
- 'maximum',
- 'minimum',
- 'title',
- ),
- JSONSchemaType.STRING.value: (
- 'description',
- 'enum',
- 'format',
- 'max_length',
- 'min_length',
- 'pattern',
- 'title',
- ),
- JSONSchemaType.OBJECT.value: (
- 'any_of',
- 'description',
- 'max_properties',
- 'min_properties',
- 'properties',
- 'required',
- 'title',
- ),
- JSONSchemaType.ARRAY.value: (
- 'description',
- 'items',
- 'max_items',
- 'min_items',
- 'title',
- ),
- JSONSchemaType.BOOLEAN.value: (
- 'description',
- 'title',
- ),
- }
- # Treat `INTEGER` like `NUMBER`.
- related_field_names_by_type[JSONSchemaType.INTEGER.value] = (
- related_field_names_by_type[JSONSchemaType.NUMBER.value]
- )
-
- # placeholder for potential gemini api unsupported fields
- gemini_api_unsupported_field_names: tuple[str, ...] = ()
-
- def _resolve_ref(
- ref_path: str, root_schema_dict: dict[str, Any]
- ) -> dict[str, Any]:
- """Helper to resolve a $ref path."""
- current = root_schema_dict
- for part in ref_path.lstrip('#/').split('/'):
- if part == '$defs':
- part = 'defs'
- current = current[part]
- current.pop('title', None)
- if 'properties' in current and current['properties'] is not None:
- for prop_schema in current['properties'].values():
- if isinstance(prop_schema, dict):
- prop_schema.pop('title', None)
-
- return current
-
- def normalize_json_schema_type(
- json_schema_type: Optional[
- Union[JSONSchemaType, Sequence[JSONSchemaType], str, Sequence[str]]
- ],
- ) -> tuple[list[str], bool]:
- """Returns (non_null_types, nullable)"""
- if json_schema_type is None:
- return [], False
- type_sequence: Sequence[Union[JSONSchemaType, str]]
- if isinstance(json_schema_type, str) or not isinstance(
- json_schema_type, Sequence
- ):
- type_sequence = [json_schema_type]
- else:
- type_sequence = json_schema_type
- non_null_types = []
- nullable = False
- for type_value in type_sequence:
- if isinstance(type_value, JSONSchemaType):
- type_value = type_value.value
- if type_value == JSONSchemaType.NULL.value:
- nullable = True
- else:
- non_null_types.append(type_value)
- return non_null_types, nullable
-
- def raise_error_if_cannot_convert(
- json_schema_dict: dict[str, Any],
- api_option: Literal['VERTEX_AI', 'GEMINI_API'],
- raise_error_on_unsupported_field: bool,
- ) -> None:
- """Raises an error if the JSONSchema cannot be converted to the specified Schema object."""
- if not raise_error_on_unsupported_field:
- return
- for field_name, field_value in json_schema_dict.items():
- if field_value is None:
- continue
- if field_name not in google_schema_field_names and field_name not in [
- 'ref',
- 'defs',
- ]:
- raise ValueError(
- f'JSONSchema field "{field_name}" is not supported by the Schema'
- ' object. And the "raise_error_on_unsupported_field" argument is'
- ' set to True. If you still want to convert it into the Schema'
- f' object, please either remove the field "{field_name}" from the'
- ' JSONSchema object, leave the'
- ' "raise_error_on_unsupported_field" unset, or try using'
- ' response_json_schema instead.'
- )
- if (
- field_name in gemini_api_unsupported_field_names
- and api_option == 'GEMINI_API'
- ):
- raise ValueError(
- f'The "{field_name}" field is not supported by the Schema '
- 'object for GEMINI_API.'
- )
-
- def copy_schema_fields(
- json_schema_dict: dict[str, Any],
- related_fields_to_copy: tuple[str, ...],
- sub_schema_in_any_of: dict[str, Any],
- ) -> None:
- """Copies the fields from json_schema_dict to sub_schema_in_any_of."""
- for field_name in related_fields_to_copy:
- sub_schema_in_any_of[field_name] = json_schema_dict.get(
- field_name, None
- )
-
- def convert_json_schema(
- current_json_schema: JSONSchema,
- root_json_schema_dict: dict[str, Any],
- api_option: Literal['VERTEX_AI', 'GEMINI_API'],
- raise_error_on_unsupported_field: bool,
- ) -> 'Schema':
- schema = Schema()
- json_schema_dict = current_json_schema.model_dump()
-
- if json_schema_dict.get('ref'):
- json_schema_dict = _resolve_ref(
- json_schema_dict['ref'], root_json_schema_dict
- )
-
- raise_error_if_cannot_convert(
- json_schema_dict=json_schema_dict,
- api_option=api_option,
- raise_error_on_unsupported_field=raise_error_on_unsupported_field,
- )
-
- # At the highest level of the logic, there are two passes:
- # Pass 1: the JSONSchema.type is union-like,
- # e.g. ['null', 'string', 'array'].
- # for this case, we need to split the JSONSchema into multiple
- # sub-schemas, and copy them into the any_of field of the Schema.
- # And when we copy the non-type fields into any_of field,
- # we only copy the fields related to the specific type.
- # Detailed logic is commented below with `Pass 1` keyword tag.
- # Pass 2: the JSONSchema.type is not union-like,
- # e.g. 'string', ['string'], ['null', 'string'].
- # for this case, no splitting is needed. Detailed
- # logic is commented below with `Pass 2` keyword tag.
- #
- #
- # Pass 1: the JSONSchema.type is union-like
- # e.g. ['null', 'string', 'array'].
- non_null_types, nullable = normalize_json_schema_type(
- json_schema_dict.get('type', None)
- )
- is_union_like_type = len(non_null_types) > 1
- if len(non_null_types) > 1:
- logger.warning(
- 'JSONSchema type is union-like, e.g. ["null", "string", "array"]. '
- 'Converting it into multiple sub-schemas, and copying them into '
- 'the any_of field of the Schema. The value of `default` field is '
- 'ignored because it is ambiguous to tell which sub-schema it '
- 'belongs to.'
- )
- reformed_json_schema = JSONSchema()
- # start splitting the JSONSchema into multiple sub-schemas
- any_of = []
- if nullable:
- schema.nullable = True
- for normalized_type in non_null_types:
- sub_schema_in_any_of = {'type': normalized_type}
- related_field_names = related_field_names_by_type.get(normalized_type)
- if related_field_names is not None:
- copy_schema_fields(
- json_schema_dict=json_schema_dict,
- related_fields_to_copy=related_field_names,
- sub_schema_in_any_of=sub_schema_in_any_of,
- )
- any_of.append(JSONSchema(**sub_schema_in_any_of))
- reformed_json_schema.any_of = any_of
- json_schema_dict = reformed_json_schema.model_dump()
-
- # Pass 2: the JSONSchema.type is not union-like,
- # e.g. 'string', ['string'], ['null', 'string'].
- for field_name, field_value in json_schema_dict.items():
- if field_value is None or field_name == 'defs':
- continue
- if field_name in schema_field_names:
- if field_name == 'items' and not field_value:
- continue
- schema_field_value: 'Schema' = convert_json_schema(
- current_json_schema=JSONSchema(**field_value),
- root_json_schema_dict=root_json_schema_dict,
- api_option=api_option,
- raise_error_on_unsupported_field=raise_error_on_unsupported_field,
- )
- setattr(schema, field_name, schema_field_value)
- elif field_name in list_schema_field_names:
- list_schema_field_value: list['Schema'] = [
- convert_json_schema(
- current_json_schema=JSONSchema(**this_field_value),
- root_json_schema_dict=root_json_schema_dict,
- api_option=api_option,
- raise_error_on_unsupported_field=raise_error_on_unsupported_field,
- )
- for this_field_value in field_value
- ]
- setattr(schema, field_name, list_schema_field_value)
- if not schema.type and not is_union_like_type and not schema.any_of:
- schema.type = Type('OBJECT')
- elif field_name in dict_schema_field_names:
- dict_schema_field_value: dict[str, 'Schema'] = {
- key: convert_json_schema(
- current_json_schema=JSONSchema(**value),
- root_json_schema_dict=root_json_schema_dict,
- api_option=api_option,
- raise_error_on_unsupported_field=raise_error_on_unsupported_field,
- )
- for key, value in field_value.items()
- }
- setattr(schema, field_name, dict_schema_field_value)
- elif field_name == 'type':
- non_null_types, nullable = normalize_json_schema_type(field_value)
- if nullable:
- schema.nullable = True
- if non_null_types:
- schema.type = Type(non_null_types[0])
- else:
- if (
- hasattr(schema, field_name)
- and field_name != 'additional_properties'
- ):
- setattr(schema, field_name, field_value)
-
- if (
- schema.type == 'ARRAY'
- and schema.items
- and not schema.items.model_dump(exclude_unset=True)
- ):
- schema.items = None
-
- if schema.any_of and len(schema.any_of) == 2:
- nullable_part = None
- type_part = None
- for part in schema.any_of:
- # A schema representing `None` will either be of type NULL or just be nullable.
- part_dict = part.model_dump(exclude_unset=True)
- if part_dict == {'nullable': True} or part_dict == {'type': 'NULL'}:
- nullable_part = part
- else:
- type_part = part
-
- # If we found both parts, unwrap them into a single schema.
- if nullable_part and type_part:
- default_value = schema.default
- schema = type_part
- schema.nullable = True
- # Carry the default value over to the unwrapped schema
- if default_value is not None:
- schema.default = default_value
-
- return schema
-
- # This is the initial call to the recursive function.
- root_schema_dict = json_schema.model_dump()
- return convert_json_schema(
- current_json_schema=json_schema,
- root_json_schema_dict=root_schema_dict,
- api_option=api_option,
- raise_error_on_unsupported_field=raise_error_on_unsupported_field,
- )
-
-
-class SchemaDict(TypedDict, total=False):
- """Schema is used to define the format of input/output data.
-
- Represents a select subset of an [OpenAPI 3.0 schema
- object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
- be added in the future as needed.
- """
-
- additional_properties: Optional[Any]
- """Optional. Can either be a boolean or an object; controls the presence of additional properties."""
-
- defs: Optional[dict[str, 'SchemaDict']]
- """Optional. A map of definitions for use by `ref` Only allowed at the root of the schema."""
-
- ref: Optional[str]
- """Optional. Allows indirect references between schema nodes. The value should be a valid reference to a child of the root `defs`. For example, the following schema defines a reference to a schema node named "Pet": type: object properties: pet: ref: #/defs/Pet defs: Pet: type: object properties: name: type: string The value of the "pet" property is a reference to the schema node named "Pet". See details in https://json-schema.org/understanding-json-schema/structuring"""
-
- any_of: Optional[list['SchemaDict']]
- """Optional. The value should be validated against any (one or more) of the subschemas in the list."""
-
- default: Optional[Any]
- """Optional. Default value of the data."""
-
- description: Optional[str]
- """Optional. The description of the data."""
-
- enum: Optional[list[str]]
- """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"]}"""
-
- example: Optional[Any]
- """Optional. Example of the object. Will only populated when the object is the root."""
-
- format: Optional[str]
- """Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc"""
-
- items: Optional['SchemaDict']
- """Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY."""
-
- max_items: Optional[int]
- """Optional. Maximum number of the elements for Type.ARRAY."""
-
- max_length: Optional[int]
- """Optional. Maximum length of the Type.STRING"""
-
- max_properties: Optional[int]
- """Optional. Maximum number of the properties for Type.OBJECT."""
-
- maximum: Optional[float]
- """Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
-
- min_items: Optional[int]
- """Optional. Minimum number of the elements for Type.ARRAY."""
-
- min_length: Optional[int]
- """Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING"""
-
- min_properties: Optional[int]
- """Optional. Minimum number of the properties for Type.OBJECT."""
-
- minimum: Optional[float]
- """Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
-
- nullable: Optional[bool]
- """Optional. Indicates if the value may be null."""
-
- pattern: Optional[str]
- """Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
-
- properties: Optional[dict[str, 'SchemaDict']]
- """Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT."""
-
- property_ordering: Optional[list[str]]
- """Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
-
- required: Optional[list[str]]
- """Optional. Required properties of Type.OBJECT."""
-
- title: Optional[str]
- """Optional. The title of the Schema."""
-
- type: Optional[Type]
- """Optional. The type of the data."""
-
-
-SchemaOrDict = Union[Schema, SchemaDict]
-
-
-class ModelSelectionConfig(_common.BaseModel):
- """Config for model selection."""
-
- feature_selection_preference: Optional[FeatureSelectionPreference] = Field(
- default=None, description="""Options for feature selection preference."""
- )
-
-
-class ModelSelectionConfigDict(TypedDict, total=False):
- """Config for model selection."""
-
- feature_selection_preference: Optional[FeatureSelectionPreference]
- """Options for feature selection preference."""
-
-
-ModelSelectionConfigOrDict = Union[
- ModelSelectionConfig, ModelSelectionConfigDict
-]
-
-
-class ComputerUse(_common.BaseModel):
- """Tool to support computer use."""
+ api_spec: Optional[ApiSpec]
+ """The API spec that the external API implements."""
- environment: Optional[Environment] = Field(
- default=None, description="""Required. The environment being operated."""
- )
- excluded_predefined_functions: Optional[list[str]] = Field(
- default=None,
- description="""By default, predefined functions are included in the final model call.
- Some of them can be explicitly excluded from being automatically included.
- This can serve two purposes:
- 1. Using a more restricted / different action space.
- 2. Improving the definitions / instructions of predefined functions.""",
- )
+ auth_config: Optional[AuthConfigDict]
+ """The authentication config to access the API."""
+ elastic_search_params: Optional[ExternalApiElasticSearchParamsDict]
+ """Parameters for the elastic search API."""
-class ComputerUseDict(TypedDict, total=False):
- """Tool to support computer use."""
+ endpoint: Optional[str]
+ """The endpoint of the external API. The system will call the API at this endpoint to retrieve the data for grounding. Example: https://acme.com:443/search"""
- environment: Optional[Environment]
- """Required. The environment being operated."""
+ simple_search_params: Optional[ExternalApiSimpleSearchParamsDict]
+ """Parameters for the simple search API."""
- excluded_predefined_functions: Optional[list[str]]
- """By default, predefined functions are included in the final model call.
- Some of them can be explicitly excluded from being automatically included.
- This can serve two purposes:
- 1. Using a more restricted / different action space.
- 2. Improving the definitions / instructions of predefined functions."""
+ExternalApiOrDict = Union[ExternalApi, ExternalApiDict]
-ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]
+class VertexAISearchDataStoreSpec(_common.BaseModel):
+ """Define data stores within engine to filter on in a search call and configurations for those data stores.
-class FileSearch(_common.BaseModel):
- """Tool to retrieve knowledge from the File Search Stores."""
+ For more information, see
+ https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec.
+ This data type is not supported in Gemini API.
+ """
- file_search_store_names: Optional[list[str]] = Field(
- default=None,
- description="""The names of the file_search_stores to retrieve from.
- Example: `fileSearchStores/my-file-search-store-123`""",
- )
- top_k: Optional[int] = Field(
+ data_store: Optional[str] = Field(
default=None,
- description="""The number of file search retrieval chunks to retrieve.""",
+ description="""Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
)
- metadata_filter: Optional[str] = Field(
+ filter: Optional[str] = Field(
default=None,
- description="""Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.""",
+ description="""Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)""",
)
-class FileSearchDict(TypedDict, total=False):
- """Tool to retrieve knowledge from the File Search Stores."""
+class VertexAISearchDataStoreSpecDict(TypedDict, total=False):
+ """Define data stores within engine to filter on in a search call and configurations for those data stores.
- file_search_store_names: Optional[list[str]]
- """The names of the file_search_stores to retrieve from.
- Example: `fileSearchStores/my-file-search-store-123`"""
+ For more information, see
+ https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec.
+ This data type is not supported in Gemini API.
+ """
- top_k: Optional[int]
- """The number of file search retrieval chunks to retrieve."""
+ data_store: Optional[str]
+ """Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
- metadata_filter: Optional[str]
- """Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."""
+ filter: Optional[str]
+ """Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)"""
-FileSearchOrDict = Union[FileSearch, FileSearchDict]
+VertexAISearchDataStoreSpecOrDict = Union[
+ VertexAISearchDataStoreSpec, VertexAISearchDataStoreSpecDict
+]
-class ApiAuthApiKeyConfig(_common.BaseModel):
- """The API secret. This data type is not supported in Gemini API."""
+class VertexAISearch(_common.BaseModel):
+ """Retrieve from Vertex AI Search datastore or engine for grounding.
- api_key_secret_version: Optional[str] = Field(
+ datastore and engine are mutually exclusive. See
+ https://cloud.google.com/products/agent-builder. This data type is not
+ supported in Gemini API.
+ """
+
+ data_store_specs: Optional[list[VertexAISearchDataStoreSpec]] = Field(
default=None,
- description="""Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}""",
+ description="""Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used.""",
)
- api_key_string: Optional[str] = Field(
+ datastore: Optional[str] = Field(
default=None,
- description="""The API key string. Either this or `api_key_secret_version` must be set.""",
+ description="""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
+ )
+ engine: Optional[str] = Field(
+ default=None,
+ description="""Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`""",
+ )
+ filter: Optional[str] = Field(
+ default=None,
+ description="""Optional. Filter strings to be passed to the search API.""",
+ )
+ max_results: Optional[int] = Field(
+ default=None,
+ description="""Optional. Number of search results to return per query. The default value is 10. The maximumm allowed value is 10.""",
)
-class ApiAuthApiKeyConfigDict(TypedDict, total=False):
- """The API secret. This data type is not supported in Gemini API."""
+class VertexAISearchDict(TypedDict, total=False):
+ """Retrieve from Vertex AI Search datastore or engine for grounding.
- api_key_secret_version: Optional[str]
- """Required. The SecretManager secret version resource name storing API key. e.g. projects/{project}/secrets/{secret}/versions/{version}"""
+ datastore and engine are mutually exclusive. See
+ https://cloud.google.com/products/agent-builder. This data type is not
+ supported in Gemini API.
+ """
- api_key_string: Optional[str]
- """The API key string. Either this or `api_key_secret_version` must be set."""
+ data_store_specs: Optional[list[VertexAISearchDataStoreSpecDict]]
+ """Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used."""
+ datastore: Optional[str]
+ """Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
-ApiAuthApiKeyConfigOrDict = Union[ApiAuthApiKeyConfig, ApiAuthApiKeyConfigDict]
+ engine: Optional[str]
+ """Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`"""
+ filter: Optional[str]
+ """Optional. Filter strings to be passed to the search API."""
-class ApiAuth(_common.BaseModel):
- """The generic reusable api auth config.
+ max_results: Optional[int]
+ """Optional. Number of search results to return per query. The default value is 10. The maximumm allowed value is 10."""
- Deprecated. Please use AuthConfig (google/cloud/aiplatform/master/auth.proto)
- instead. This data type is not supported in Gemini API.
+
+VertexAISearchOrDict = Union[VertexAISearch, VertexAISearchDict]
+
+
+class VertexRagStoreRagResource(_common.BaseModel):
+ """The definition of the Rag resource.
+
+ This data type is not supported in Gemini API.
"""
- api_key_config: Optional[ApiAuthApiKeyConfig] = Field(
- default=None, description="""The API secret."""
+ rag_corpus: Optional[str] = Field(
+ default=None,
+ description="""Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`""",
+ )
+ rag_file_ids: Optional[list[str]] = Field(
+ default=None,
+ description="""Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.""",
)
-class ApiAuthDict(TypedDict, total=False):
- """The generic reusable api auth config.
+class VertexRagStoreRagResourceDict(TypedDict, total=False):
+ """The definition of the Rag resource.
- Deprecated. Please use AuthConfig (google/cloud/aiplatform/master/auth.proto)
- instead. This data type is not supported in Gemini API.
+ This data type is not supported in Gemini API.
"""
- api_key_config: Optional[ApiAuthApiKeyConfigDict]
- """The API secret."""
+ rag_corpus: Optional[str]
+ """Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`"""
+ rag_file_ids: Optional[list[str]]
+ """Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field."""
-ApiAuthOrDict = Union[ApiAuth, ApiAuthDict]
+VertexRagStoreRagResourceOrDict = Union[
+ VertexRagStoreRagResource, VertexRagStoreRagResourceDict
+]
-class ApiKeyConfig(_common.BaseModel):
- """Config for authentication with API key.
- This data type is not supported in Gemini API.
- """
+class RagRetrievalConfigFilter(_common.BaseModel):
+ """Config for filters. This data type is not supported in Gemini API."""
- api_key_secret: Optional[str] = Field(
- default=None,
- description="""Optional. The name of the SecretManager secret version resource storing the API key. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If both `api_key_secret` and `api_key_string` are specified, this field takes precedence over `api_key_string`. - 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.""",
+ metadata_filter: Optional[str] = Field(
+ default=None, description="""Optional. String for metadata filtering."""
)
- api_key_string: Optional[str] = Field(
+ vector_distance_threshold: Optional[float] = Field(
default=None,
- description="""Optional. The API key to be used in the request directly.""",
- )
- http_element_location: Optional[HttpElementLocation] = Field(
- default=None, description="""Optional. The location of the API key."""
+ description="""Optional. Only returns contexts with vector distance smaller than the threshold.""",
)
- name: Optional[str] = Field(
+ vector_similarity_threshold: Optional[float] = Field(
default=None,
- description="""Optional. The parameter name of the API key. E.g. If the API request is "https://example.com/act?api_key=", "api_key" would be the parameter name.""",
+ description="""Optional. Only returns contexts with vector similarity larger than the threshold.""",
)
-class ApiKeyConfigDict(TypedDict, total=False):
- """Config for authentication with API key.
+class RagRetrievalConfigFilterDict(TypedDict, total=False):
+ """Config for filters. This data type is not supported in Gemini API."""
- This data type is not supported in Gemini API.
- """
+ metadata_filter: Optional[str]
+ """Optional. String for metadata filtering."""
- api_key_secret: Optional[str]
- """Optional. The name of the SecretManager secret version resource storing the API key. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If both `api_key_secret` and `api_key_string` are specified, this field takes precedence over `api_key_string`. - 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."""
+ vector_distance_threshold: Optional[float]
+ """Optional. Only returns contexts with vector distance smaller than the threshold."""
- api_key_string: Optional[str]
- """Optional. The API key to be used in the request directly."""
+ vector_similarity_threshold: Optional[float]
+ """Optional. Only returns contexts with vector similarity larger than the threshold."""
- http_element_location: Optional[HttpElementLocation]
- """Optional. The location of the API key."""
- name: Optional[str]
- """Optional. The parameter name of the API key. E.g. If the API request is "https://example.com/act?api_key=", "api_key" would be the parameter name."""
+RagRetrievalConfigFilterOrDict = Union[
+ RagRetrievalConfigFilter, RagRetrievalConfigFilterDict
+]
-ApiKeyConfigOrDict = Union[ApiKeyConfig, ApiKeyConfigDict]
+class RagRetrievalConfigHybridSearch(_common.BaseModel):
+ """Config for Hybrid Search. This data type is not supported in Gemini API."""
+ alpha: Optional[float] = Field(
+ default=None,
+ 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.""",
+ )
-class AuthConfigGoogleServiceAccountConfig(_common.BaseModel):
- """Config for Google Service Account Authentication.
- This data type is not supported in Gemini API.
- """
+class RagRetrievalConfigHybridSearchDict(TypedDict, total=False):
+ """Config for Hybrid Search. This data type is not supported in Gemini API."""
- service_account: Optional[str] = Field(
+ alpha: Optional[float]
+ """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."""
+
+
+RagRetrievalConfigHybridSearchOrDict = Union[
+ RagRetrievalConfigHybridSearch, RagRetrievalConfigHybridSearchDict
+]
+
+
+class RagRetrievalConfigRankingLlmRanker(_common.BaseModel):
+ """Config for LlmRanker. This data type is not supported in Gemini API."""
+
+ model_name: Optional[str] = Field(
default=None,
- 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.""",
+ description="""Optional. The model name used for ranking. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models).""",
)
-class AuthConfigGoogleServiceAccountConfigDict(TypedDict, total=False):
- """Config for Google Service Account Authentication.
-
- This data type is not supported in Gemini API.
- """
+class RagRetrievalConfigRankingLlmRankerDict(TypedDict, total=False):
+ """Config for LlmRanker. This data type is not supported in Gemini API."""
- service_account: Optional[str]
- """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."""
+ model_name: Optional[str]
+ """Optional. The model name used for ranking. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models)."""
-AuthConfigGoogleServiceAccountConfigOrDict = Union[
- AuthConfigGoogleServiceAccountConfig,
- AuthConfigGoogleServiceAccountConfigDict,
+RagRetrievalConfigRankingLlmRankerOrDict = Union[
+ RagRetrievalConfigRankingLlmRanker, RagRetrievalConfigRankingLlmRankerDict
]
-class AuthConfigHttpBasicAuthConfig(_common.BaseModel):
- """Config for HTTP Basic Authentication.
-
- This data type is not supported in Gemini API.
- """
+class RagRetrievalConfigRankingRankService(_common.BaseModel):
+ """Config for Rank Service. This data type is not supported in Gemini API."""
- credential_secret: Optional[str] = Field(
+ model_name: Optional[str] = Field(
default=None,
- 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.""",
+ description="""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`""",
)
-class AuthConfigHttpBasicAuthConfigDict(TypedDict, total=False):
- """Config for HTTP Basic Authentication.
-
- This data type is not supported in Gemini API.
- """
+class RagRetrievalConfigRankingRankServiceDict(TypedDict, total=False):
+ """Config for Rank Service. This data type is not supported in Gemini API."""
- credential_secret: Optional[str]
- """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."""
+ model_name: Optional[str]
+ """Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`"""
-AuthConfigHttpBasicAuthConfigOrDict = Union[
- AuthConfigHttpBasicAuthConfig, AuthConfigHttpBasicAuthConfigDict
+RagRetrievalConfigRankingRankServiceOrDict = Union[
+ RagRetrievalConfigRankingRankService,
+ RagRetrievalConfigRankingRankServiceDict,
]
-class AuthConfigOauthConfig(_common.BaseModel):
- """Config for user oauth. This data type is not supported in Gemini API."""
+class RagRetrievalConfigRanking(_common.BaseModel):
+ """Config for ranking and reranking.
- access_token: Optional[str] = Field(
- default=None,
- description="""Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
+ This data type is not supported in Gemini API.
+ """
+
+ llm_ranker: Optional[RagRetrievalConfigRankingLlmRanker] = Field(
+ default=None, description="""Optional. Config for LlmRanker."""
)
- service_account: Optional[str] = Field(
- default=None,
- 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.""",
+ rank_service: Optional[RagRetrievalConfigRankingRankService] = Field(
+ default=None, description="""Optional. Config for Rank Service."""
)
-class AuthConfigOauthConfigDict(TypedDict, total=False):
- """Config for user oauth. This data type is not supported in Gemini API."""
+class RagRetrievalConfigRankingDict(TypedDict, total=False):
+ """Config for ranking and reranking.
- access_token: Optional[str]
- """Access token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
+ This data type is not supported in Gemini API.
+ """
- service_account: Optional[str]
- """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."""
+ llm_ranker: Optional[RagRetrievalConfigRankingLlmRankerDict]
+ """Optional. Config for LlmRanker."""
+
+ rank_service: Optional[RagRetrievalConfigRankingRankServiceDict]
+ """Optional. Config for Rank Service."""
-AuthConfigOauthConfigOrDict = Union[
- AuthConfigOauthConfig, AuthConfigOauthConfigDict
+RagRetrievalConfigRankingOrDict = Union[
+ RagRetrievalConfigRanking, RagRetrievalConfigRankingDict
]
-class AuthConfigOidcConfig(_common.BaseModel):
- """Config for user OIDC auth.
+class RagRetrievalConfig(_common.BaseModel):
+ """Specifies the context retrieval config.
This data type is not supported in Gemini API.
"""
- id_token: Optional[str] = Field(
+ filter: Optional[RagRetrievalConfigFilter] = Field(
+ default=None, description="""Optional. Config for filters."""
+ )
+ hybrid_search: Optional[RagRetrievalConfigHybridSearch] = Field(
+ default=None, description="""Optional. Config for Hybrid Search."""
+ )
+ ranking: Optional[RagRetrievalConfigRanking] = Field(
default=None,
- description="""OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time.""",
+ description="""Optional. Config for ranking and reranking.""",
)
- service_account: Optional[str] = Field(
+ top_k: Optional[int] = Field(
default=None,
- 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).""",
+ description="""Optional. The number of contexts to retrieve.""",
)
-class AuthConfigOidcConfigDict(TypedDict, total=False):
- """Config for user OIDC auth.
+class RagRetrievalConfigDict(TypedDict, total=False):
+ """Specifies the context retrieval config.
This data type is not supported in Gemini API.
"""
- id_token: Optional[str]
- """OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from [[ExecuteExtensionRequest.runtime_auth_config]] at request time."""
+ filter: Optional[RagRetrievalConfigFilterDict]
+ """Optional. Config for filters."""
- service_account: Optional[str]
- """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)."""
+ hybrid_search: Optional[RagRetrievalConfigHybridSearchDict]
+ """Optional. Config for Hybrid Search."""
+ ranking: Optional[RagRetrievalConfigRankingDict]
+ """Optional. Config for ranking and reranking."""
-AuthConfigOidcConfigOrDict = Union[
- AuthConfigOidcConfig, AuthConfigOidcConfigDict
-]
+ top_k: Optional[int]
+ """Optional. The number of contexts to retrieve."""
-class AuthConfig(_common.BaseModel):
- """Auth configuration to run the extension.
+RagRetrievalConfigOrDict = Union[RagRetrievalConfig, RagRetrievalConfigDict]
+
+
+class VertexRagStore(_common.BaseModel):
+ """Retrieve from Vertex RAG Store for grounding.
This data type is not supported in Gemini API.
"""
- api_key_config: Optional[ApiKeyConfig] = Field(
- default=None, description="""Config for API key auth."""
+ rag_corpora: Optional[list[str]] = Field(
+ default=None,
+ description="""Optional. Deprecated. Please use rag_resources instead.""",
)
- auth_type: Optional[AuthType] = Field(
- default=None, description="""Type of auth scheme."""
+ rag_resources: Optional[list[VertexRagStoreRagResource]] = Field(
+ default=None,
+ 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.""",
)
- google_service_account_config: Optional[
- AuthConfigGoogleServiceAccountConfig
- ] = Field(
- default=None, description="""Config for Google Service Account auth."""
+ rag_retrieval_config: Optional[RagRetrievalConfig] = Field(
+ default=None,
+ description="""Optional. The retrieval config for the Rag query.""",
)
- http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfig] = Field(
- default=None, description="""Config for HTTP Basic auth."""
+ similarity_top_k: Optional[int] = Field(
+ default=None,
+ description="""Optional. Number of top k results to return from the selected corpora.""",
)
- oauth_config: Optional[AuthConfigOauthConfig] = Field(
- default=None, description="""Config for user oauth."""
+ store_context: Optional[bool] = Field(
+ default=None,
+ description="""Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions.""",
)
- oidc_config: Optional[AuthConfigOidcConfig] = Field(
- default=None, description="""Config for user OIDC auth."""
+ vector_distance_threshold: Optional[float] = Field(
+ default=None,
+ description="""Optional. Only return results with vector distance smaller than the threshold.""",
)
-class AuthConfigDict(TypedDict, total=False):
- """Auth configuration to run the extension.
+class VertexRagStoreDict(TypedDict, total=False):
+ """Retrieve from Vertex RAG Store for grounding.
This data type is not supported in Gemini API.
"""
- api_key_config: Optional[ApiKeyConfigDict]
- """Config for API key auth."""
+ rag_corpora: Optional[list[str]]
+ """Optional. Deprecated. Please use rag_resources instead."""
- auth_type: Optional[AuthType]
- """Type of auth scheme."""
+ rag_resources: Optional[list[VertexRagStoreRagResourceDict]]
+ """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."""
- google_service_account_config: Optional[
- AuthConfigGoogleServiceAccountConfigDict
- ]
- """Config for Google Service Account auth."""
+ rag_retrieval_config: Optional[RagRetrievalConfigDict]
+ """Optional. The retrieval config for the Rag query."""
- http_basic_auth_config: Optional[AuthConfigHttpBasicAuthConfigDict]
- """Config for HTTP Basic auth."""
+ similarity_top_k: Optional[int]
+ """Optional. Number of top k results to return from the selected corpora."""
- oauth_config: Optional[AuthConfigOauthConfigDict]
- """Config for user oauth."""
+ store_context: Optional[bool]
+ """Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions."""
- oidc_config: Optional[AuthConfigOidcConfigDict]
- """Config for user OIDC auth."""
+ vector_distance_threshold: Optional[float]
+ """Optional. Only return results with vector distance smaller than the threshold."""
-AuthConfigOrDict = Union[AuthConfig, AuthConfigDict]
+VertexRagStoreOrDict = Union[VertexRagStore, VertexRagStoreDict]
-class ExternalApiElasticSearchParams(_common.BaseModel):
- """The search parameters to use for the ELASTIC_SEARCH spec.
+class Retrieval(_common.BaseModel):
+ """Defines a retrieval tool that model can call to access external knowledge.
This data type is not supported in Gemini API.
"""
- index: Optional[str] = Field(
- default=None, description="""The ElasticSearch index to use."""
+ disable_attribution: Optional[bool] = Field(
+ default=None,
+ description="""Optional. Deprecated. This option is no longer supported.""",
)
- num_hits: Optional[int] = Field(
+ external_api: Optional[ExternalApi] = Field(
default=None,
- description="""Optional. Number of hits (chunks) to request. When specified, it is passed to Elasticsearch as the `num_hits` param.""",
+ description="""Use data source powered by external API for grounding.""",
)
- search_template: Optional[str] = Field(
- default=None, description="""The ElasticSearch search template to use."""
+ vertex_ai_search: Optional[VertexAISearch] = Field(
+ default=None,
+ description="""Set to use data source powered by Vertex AI Search.""",
+ )
+ vertex_rag_store: Optional[VertexRagStore] = Field(
+ default=None,
+ description="""Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService.""",
)
-class ExternalApiElasticSearchParamsDict(TypedDict, total=False):
- """The search parameters to use for the ELASTIC_SEARCH spec.
+class RetrievalDict(TypedDict, total=False):
+ """Defines a retrieval tool that model can call to access external knowledge.
This data type is not supported in Gemini API.
"""
- index: Optional[str]
- """The ElasticSearch index to use."""
+ disable_attribution: Optional[bool]
+ """Optional. Deprecated. This option is no longer supported."""
- num_hits: Optional[int]
- """Optional. Number of hits (chunks) to request. When specified, it is passed to Elasticsearch as the `num_hits` param."""
+ external_api: Optional[ExternalApiDict]
+ """Use data source powered by external API for grounding."""
- search_template: Optional[str]
- """The ElasticSearch search template to use."""
+ vertex_ai_search: Optional[VertexAISearchDict]
+ """Set to use data source powered by Vertex AI Search."""
+ vertex_rag_store: Optional[VertexRagStoreDict]
+ """Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService."""
-ExternalApiElasticSearchParamsOrDict = Union[
- ExternalApiElasticSearchParams, ExternalApiElasticSearchParamsDict
-]
+RetrievalOrDict = Union[Retrieval, RetrievalDict]
-class ExternalApiSimpleSearchParams(_common.BaseModel):
- """The search parameters to use for SIMPLE_SEARCH spec.
- This data type is not supported in Gemini API.
+class ToolCodeExecution(_common.BaseModel):
+ """Tool that executes code generated by the model, and automatically returns the result to the model.
+
+ See also [ExecutableCode]and [CodeExecutionResult] which are input and output
+ to this tool. This data type is not supported in Gemini API.
"""
pass
-class ExternalApiSimpleSearchParamsDict(TypedDict, total=False):
- """The search parameters to use for SIMPLE_SEARCH spec.
+class ToolCodeExecutionDict(TypedDict, total=False):
+ """Tool that executes code generated by the model, and automatically returns the result to the model.
+
+ See also [ExecutableCode]and [CodeExecutionResult] which are input and output
+ to this tool. This data type is not supported in Gemini API.
+ """
+
+ pass
+
+
+ToolCodeExecutionOrDict = Union[ToolCodeExecution, ToolCodeExecutionDict]
+
+
+class EnterpriseWebSearch(_common.BaseModel):
+ """Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
+
+ This data type is not supported in Gemini API.
+ """
+
+ exclude_domains: Optional[list[str]] = Field(
+ default=None,
+ description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains.""",
+ )
+ blocking_confidence: Optional[PhishBlockThreshold] = Field(
+ default=None,
+ description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results.""",
+ )
+
+
+class EnterpriseWebSearchDict(TypedDict, total=False):
+ """Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
This data type is not supported in Gemini API.
"""
- pass
+ exclude_domains: Optional[list[str]]
+ """Optional. List of domains to be excluded from the search results. The default limit is 2000 domains."""
+
+ blocking_confidence: Optional[PhishBlockThreshold]
+ """Optional. Sites with confidence level chosen & above this value will be blocked from the search results."""
-ExternalApiSimpleSearchParamsOrDict = Union[
- ExternalApiSimpleSearchParams, ExternalApiSimpleSearchParamsDict
-]
+EnterpriseWebSearchOrDict = Union[EnterpriseWebSearch, EnterpriseWebSearchDict]
-class ExternalApi(_common.BaseModel):
- """Retrieve from data source powered by external API for grounding.
+class Schema(_common.BaseModel):
+ """Schema is used to define the format of input/output data.
- The external API is not owned by Google, but need to follow the pre-defined
- API spec. This data type is not supported in Gemini API.
+ Represents a select subset of an [OpenAPI 3.0 schema
+ object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
+ be added in the future as needed.
"""
- api_auth: Optional[ApiAuth] = Field(
+ additional_properties: Optional[Any] = Field(
default=None,
- description="""The authentication config to access the API. Deprecated. Please use auth_config instead.""",
+ description="""Optional. Can either be a boolean or an object; controls the presence of additional properties.""",
)
- api_spec: Optional[ApiSpec] = Field(
+ defs: Optional[dict[str, 'Schema']] = Field(
default=None,
- description="""The API spec that the external API implements.""",
+ description="""Optional. A map of definitions for use by `ref` Only allowed at the root of the schema.""",
)
- auth_config: Optional[AuthConfig] = Field(
+ ref: Optional[str] = Field(
default=None,
- description="""The authentication config to access the API.""",
+ description="""Optional. Allows indirect references between schema nodes. The value should be a valid reference to a child of the root `defs`. For example, the following schema defines a reference to a schema node named "Pet": type: object properties: pet: ref: #/defs/Pet defs: Pet: type: object properties: name: type: string The value of the "pet" property is a reference to the schema node named "Pet". See details in https://json-schema.org/understanding-json-schema/structuring""",
)
- elastic_search_params: Optional[ExternalApiElasticSearchParams] = Field(
- default=None, description="""Parameters for the elastic search API."""
+ any_of: Optional[list['Schema']] = Field(
+ default=None,
+ description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
)
- endpoint: Optional[str] = Field(
+ default: Optional[Any] = Field(
+ default=None, description="""Optional. Default value of the data."""
+ )
+ description: Optional[str] = Field(
+ default=None, description="""Optional. The description of the data."""
+ )
+ enum: Optional[list[str]] = Field(
default=None,
- description="""The endpoint of the external API. The system will call the API at this endpoint to retrieve the data for grounding. Example: https://acme.com:443/search""",
+ 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"]}""",
)
- simple_search_params: Optional[ExternalApiSimpleSearchParams] = Field(
- default=None, description="""Parameters for the simple search API."""
+ example: Optional[Any] = Field(
+ default=None,
+ description="""Optional. Example of the object. Will only populated when the object is the root.""",
+ )
+ format: Optional[str] = Field(
+ default=None,
+ 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""",
+ )
+ items: Optional['Schema'] = Field(
+ default=None,
+ description="""Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY.""",
+ )
+ max_items: Optional[int] = Field(
+ default=None,
+ description="""Optional. Maximum number of the elements for Type.ARRAY.""",
+ )
+ max_length: Optional[int] = Field(
+ default=None,
+ description="""Optional. Maximum length of the Type.STRING""",
+ )
+ max_properties: Optional[int] = Field(
+ default=None,
+ description="""Optional. Maximum number of the properties for Type.OBJECT.""",
+ )
+ maximum: Optional[float] = Field(
+ default=None,
+ description="""Optional. Maximum value of the Type.INTEGER and Type.NUMBER""",
+ )
+ min_items: Optional[int] = Field(
+ default=None,
+ description="""Optional. Minimum number of the elements for Type.ARRAY.""",
+ )
+ min_length: Optional[int] = Field(
+ default=None,
+ description="""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING""",
+ )
+ min_properties: Optional[int] = Field(
+ default=None,
+ description="""Optional. Minimum number of the properties for Type.OBJECT.""",
+ )
+ minimum: Optional[float] = Field(
+ default=None,
+ description="""Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER""",
+ )
+ nullable: Optional[bool] = Field(
+ default=None,
+ description="""Optional. Indicates if the value may be null.""",
+ )
+ pattern: Optional[str] = Field(
+ default=None,
+ description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
+ )
+ properties: Optional[dict[str, 'Schema']] = Field(
+ default=None,
+ description="""Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.""",
+ )
+ property_ordering: Optional[list[str]] = Field(
+ default=None,
+ description="""Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.""",
+ )
+ required: Optional[list[str]] = Field(
+ default=None,
+ description="""Optional. Required properties of Type.OBJECT.""",
+ )
+ title: Optional[str] = Field(
+ default=None, description="""Optional. The title of the Schema."""
+ )
+ type: Optional[Type] = Field(
+ default=None, description="""Optional. The type of the data."""
)
+ @property
+ def json_schema(self) -> JSONSchema:
+ """Converts the Schema object to a JSONSchema object, that is compatible with 2020-12 JSON Schema draft.
-class ExternalApiDict(TypedDict, total=False):
- """Retrieve from data source powered by external API for grounding.
+ Note: Conversion of fields that are not included in the JSONSchema class
+ are ignored.
+ Json Schema is now supported natively by both Vertex AI and Gemini API.
+ Users
+ are recommended to pass/receive Json Schema directly to/from the API. For
+ example:
+ 1. the counter part of GenerateContentConfig.response_schema is
+ GenerateContentConfig.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ 2. the counter part of FunctionDeclaration.parameters is
+ FunctionDeclaration.parameters_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ 3. the counter part of FunctionDeclaration.response is
+ FunctionDeclaration.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ """
- The external API is not owned by Google, but need to follow the pre-defined
- API spec. This data type is not supported in Gemini API.
- """
+ global _json_schema_warning_logged
+ if not _json_schema_warning_logged:
+ info_message = """
+Note: Conversion of fields that are not included in the JSONSchema class are
+ignored.
+Json Schema is now supported natively by both Vertex AI and Gemini API. Users
+are recommended to pass/receive Json Schema directly to/from the API. For example:
+1. the counter part of GenerateContentConfig.response_schema is
+ GenerateContentConfig.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+2. the counter part of FunctionDeclaration.parameters is
+ FunctionDeclaration.parameters_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+3. the counter part of FunctionDeclaration.response is
+ FunctionDeclaration.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+"""
+ logger.info(info_message)
+ _json_schema_warning_logged = True
- api_auth: Optional[ApiAuthDict]
- """The authentication config to access the API. Deprecated. Please use auth_config instead."""
+ json_schema_field_names: set[str] = set(JSONSchema.model_fields.keys())
+ schema_field_names: tuple[str] = (
+ 'items',
+ ) # 'additional_properties' to come
+ list_schema_field_names: tuple[str] = (
+ 'any_of', # 'one_of', 'all_of', 'not' to come
+ )
+ dict_schema_field_names: tuple[str] = ('properties',) # 'defs' to come
- api_spec: Optional[ApiSpec]
- """The API spec that the external API implements."""
+ def convert_schema(schema: Union['Schema', dict[str, Any]]) -> JSONSchema:
+ if isinstance(schema, pydantic.BaseModel):
+ schema_dict = schema.model_dump(exclude_none=True)
+ else:
+ schema_dict = schema
+ json_schema = JSONSchema()
+ for field_name, field_value in schema_dict.items():
+ if field_value is None:
+ continue
+ elif field_name == 'nullable':
+ if json_schema.type is None:
+ json_schema.type = JSONSchemaType.NULL
+ elif isinstance(json_schema.type, JSONSchemaType):
+ current_type: JSONSchemaType = json_schema.type
+ json_schema.type = [current_type, JSONSchemaType.NULL]
+ elif isinstance(json_schema.type, list):
+ json_schema.type.append(JSONSchemaType.NULL)
+ elif field_name not in json_schema_field_names:
+ continue
+ elif field_name == 'type':
+ if field_value == Type.TYPE_UNSPECIFIED:
+ continue
+ json_schema_type = JSONSchemaType(field_value.lower())
+ if json_schema.type is None:
+ json_schema.type = json_schema_type
+ elif isinstance(json_schema.type, JSONSchemaType):
+ existing_type: JSONSchemaType = json_schema.type
+ json_schema.type = [existing_type, json_schema_type]
+ elif isinstance(json_schema.type, list):
+ json_schema.type.append(json_schema_type)
+ elif field_name in schema_field_names:
+ schema_field_value: 'JSONSchema' = convert_schema(field_value)
+ setattr(json_schema, field_name, schema_field_value)
+ elif field_name in list_schema_field_names:
+ list_schema_field_value: list['JSONSchema'] = [
+ convert_schema(this_field_value)
+ for this_field_value in field_value
+ ]
+ setattr(json_schema, field_name, list_schema_field_value)
+ elif field_name in dict_schema_field_names:
+ dict_schema_field_value: dict[str, 'JSONSchema'] = {
+ key: convert_schema(value) for key, value in field_value.items()
+ }
+ setattr(json_schema, field_name, dict_schema_field_value)
+ else:
+ setattr(json_schema, field_name, field_value)
- auth_config: Optional[AuthConfigDict]
- """The authentication config to access the API."""
+ return json_schema
- elastic_search_params: Optional[ExternalApiElasticSearchParamsDict]
- """Parameters for the elastic search API."""
+ return convert_schema(self)
+
+ @classmethod
+ def from_json_schema(
+ cls,
+ *,
+ json_schema: JSONSchema,
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
+ raise_error_on_unsupported_field: bool = False,
+ ) -> 'Schema':
+ """Converts a JSONSchema object to a Schema object.
+
+ Note: Conversion of fields that are not included in the JSONSchema class
+ are ignored.
+ Json Schema is now supported natively by both Vertex AI and Gemini API.
+ Users
+ are recommended to pass/receive Json Schema directly to/from the API. For
+ example:
+ 1. the counter part of GenerateContentConfig.response_schema is
+ GenerateContentConfig.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ 2. the counter part of FunctionDeclaration.parameters is
+ FunctionDeclaration.parameters_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ 3. the counter part of FunctionDeclaration.response is
+ FunctionDeclaration.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+ The JSONSchema is compatible with 2020-12 JSON Schema draft, specified by
+ OpenAPI 3.1.
+
+ Args:
+ json_schema: JSONSchema object to be converted.
+ api_option: API option to be used. If set to 'VERTEX_AI', the
+ JSONSchema will be converted to a Schema object that is compatible
+ with Vertex AI API. If set to 'GEMINI_API', the JSONSchema will be
+ converted to a Schema object that is compatible with Gemini API.
+ Default is 'GEMINI_API'.
+ raise_error_on_unsupported_field: If set to True, an error will be
+ raised if the JSONSchema contains any unsupported fields. Default is
+ False.
- endpoint: Optional[str]
- """The endpoint of the external API. The system will call the API at this endpoint to retrieve the data for grounding. Example: https://acme.com:443/search"""
+ Returns:
+ Schema object that is compatible with the specified API option.
+ Raises:
+ ValueError: If the JSONSchema contains any unsupported fields and
+ raise_error_on_unsupported_field is set to True. Or if the JSONSchema
+ is not compatible with the specified API option.
+ """
+ global _from_json_schema_warning_logged
+ if not _from_json_schema_warning_logged:
+ info_message = """
+Note: Conversion of fields that are not included in the JSONSchema class are ignored.
+Json Schema is now supported natively by both Vertex AI and Gemini API. Users
+are recommended to pass/receive Json Schema directly to/from the API. For example:
+1. the counter part of GenerateContentConfig.response_schema is
+ GenerateContentConfig.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+2. the counter part of FunctionDeclaration.parameters is
+ FunctionDeclaration.parameters_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+3. the counter part of FunctionDeclaration.response is
+ FunctionDeclaration.response_json_schema, which accepts [JSON
+ Schema](https://json-schema.org/)
+"""
+ logger.info(info_message)
+ _from_json_schema_warning_logged = True
- simple_search_params: Optional[ExternalApiSimpleSearchParamsDict]
- """Parameters for the simple search API."""
+ google_schema_field_names: set[str] = set(cls.model_fields.keys())
+ schema_field_names: tuple[str, ...] = (
+ 'items',
+ ) # 'additional_properties' to come
+ list_schema_field_names: tuple[str, ...] = (
+ 'any_of', # 'one_of', 'all_of', 'not' to come
+ )
+ dict_schema_field_names: tuple[str, ...] = ('properties',)
+ related_field_names_by_type: dict[str, tuple[str, ...]] = {
+ JSONSchemaType.NUMBER.value: (
+ 'description',
+ 'enum',
+ 'format',
+ 'maximum',
+ 'minimum',
+ 'title',
+ ),
+ JSONSchemaType.STRING.value: (
+ 'description',
+ 'enum',
+ 'format',
+ 'max_length',
+ 'min_length',
+ 'pattern',
+ 'title',
+ ),
+ JSONSchemaType.OBJECT.value: (
+ 'any_of',
+ 'description',
+ 'max_properties',
+ 'min_properties',
+ 'properties',
+ 'required',
+ 'title',
+ ),
+ JSONSchemaType.ARRAY.value: (
+ 'description',
+ 'items',
+ 'max_items',
+ 'min_items',
+ 'title',
+ ),
+ JSONSchemaType.BOOLEAN.value: (
+ 'description',
+ 'title',
+ ),
+ }
+ # Treat `INTEGER` like `NUMBER`.
+ related_field_names_by_type[JSONSchemaType.INTEGER.value] = (
+ related_field_names_by_type[JSONSchemaType.NUMBER.value]
+ )
-ExternalApiOrDict = Union[ExternalApi, ExternalApiDict]
+ # placeholder for potential gemini api unsupported fields
+ gemini_api_unsupported_field_names: tuple[str, ...] = ()
+ def _resolve_ref(
+ ref_path: str, root_schema_dict: dict[str, Any]
+ ) -> dict[str, Any]:
+ """Helper to resolve a $ref path."""
+ current = root_schema_dict
+ for part in ref_path.lstrip('#/').split('/'):
+ if part == '$defs':
+ part = 'defs'
+ current = current[part]
+ current.pop('title', None)
+ if 'properties' in current and current['properties'] is not None:
+ for prop_schema in current['properties'].values():
+ if isinstance(prop_schema, dict):
+ prop_schema.pop('title', None)
-class VertexAISearchDataStoreSpec(_common.BaseModel):
- """Define data stores within engine to filter on in a search call and configurations for those data stores.
+ return current
- For more information, see
- https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec.
- This data type is not supported in Gemini API.
- """
+ def normalize_json_schema_type(
+ json_schema_type: Optional[
+ Union[JSONSchemaType, Sequence[JSONSchemaType], str, Sequence[str]]
+ ],
+ ) -> tuple[list[str], bool]:
+ """Returns (non_null_types, nullable)"""
+ if json_schema_type is None:
+ return [], False
+ type_sequence: Sequence[Union[JSONSchemaType, str]]
+ if isinstance(json_schema_type, str) or not isinstance(
+ json_schema_type, Sequence
+ ):
+ type_sequence = [json_schema_type]
+ else:
+ type_sequence = json_schema_type
+ non_null_types = []
+ nullable = False
+ for type_value in type_sequence:
+ if isinstance(type_value, JSONSchemaType):
+ type_value = type_value.value
+ if type_value == JSONSchemaType.NULL.value:
+ nullable = True
+ else:
+ non_null_types.append(type_value)
+ return non_null_types, nullable
- data_store: Optional[str] = Field(
- default=None,
- description="""Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
- )
- filter: Optional[str] = Field(
- default=None,
- description="""Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)""",
- )
+ def raise_error_if_cannot_convert(
+ json_schema_dict: dict[str, Any],
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'],
+ raise_error_on_unsupported_field: bool,
+ ) -> None:
+ """Raises an error if the JSONSchema cannot be converted to the specified Schema object."""
+ if not raise_error_on_unsupported_field:
+ return
+ for field_name, field_value in json_schema_dict.items():
+ if field_value is None:
+ continue
+ if field_name not in google_schema_field_names and field_name not in [
+ 'ref',
+ 'defs',
+ ]:
+ raise ValueError(
+ f'JSONSchema field "{field_name}" is not supported by the Schema'
+ ' object. And the "raise_error_on_unsupported_field" argument is'
+ ' set to True. If you still want to convert it into the Schema'
+ f' object, please either remove the field "{field_name}" from the'
+ ' JSONSchema object, leave the'
+ ' "raise_error_on_unsupported_field" unset, or try using'
+ ' response_json_schema instead.'
+ )
+ if (
+ field_name in gemini_api_unsupported_field_names
+ and api_option == 'GEMINI_API'
+ ):
+ raise ValueError(
+ f'The "{field_name}" field is not supported by the Schema '
+ 'object for GEMINI_API.'
+ )
+ def copy_schema_fields(
+ json_schema_dict: dict[str, Any],
+ related_fields_to_copy: tuple[str, ...],
+ sub_schema_in_any_of: dict[str, Any],
+ ) -> None:
+ """Copies the fields from json_schema_dict to sub_schema_in_any_of."""
+ for field_name in related_fields_to_copy:
+ sub_schema_in_any_of[field_name] = json_schema_dict.get(
+ field_name, None
+ )
-class VertexAISearchDataStoreSpecDict(TypedDict, total=False):
- """Define data stores within engine to filter on in a search call and configurations for those data stores.
+ def convert_json_schema(
+ current_json_schema: JSONSchema,
+ root_json_schema_dict: dict[str, Any],
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'],
+ raise_error_on_unsupported_field: bool,
+ ) -> 'Schema':
+ schema = Schema()
+ json_schema_dict = current_json_schema.model_dump()
- For more information, see
- https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec.
- This data type is not supported in Gemini API.
- """
+ if json_schema_dict.get('ref'):
+ json_schema_dict = _resolve_ref(
+ json_schema_dict['ref'], root_json_schema_dict
+ )
- data_store: Optional[str]
- """Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
+ raise_error_if_cannot_convert(
+ json_schema_dict=json_schema_dict,
+ api_option=api_option,
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
+ )
- filter: Optional[str]
- """Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)"""
+ # At the highest level of the logic, there are two passes:
+ # Pass 1: the JSONSchema.type is union-like,
+ # e.g. ['null', 'string', 'array'].
+ # for this case, we need to split the JSONSchema into multiple
+ # sub-schemas, and copy them into the any_of field of the Schema.
+ # And when we copy the non-type fields into any_of field,
+ # we only copy the fields related to the specific type.
+ # Detailed logic is commented below with `Pass 1` keyword tag.
+ # Pass 2: the JSONSchema.type is not union-like,
+ # e.g. 'string', ['string'], ['null', 'string'].
+ # for this case, no splitting is needed. Detailed
+ # logic is commented below with `Pass 2` keyword tag.
+ #
+ #
+ # Pass 1: the JSONSchema.type is union-like
+ # e.g. ['null', 'string', 'array'].
+ non_null_types, nullable = normalize_json_schema_type(
+ json_schema_dict.get('type', None)
+ )
+ is_union_like_type = len(non_null_types) > 1
+ if len(non_null_types) > 1:
+ logger.warning(
+ 'JSONSchema type is union-like, e.g. ["null", "string", "array"]. '
+ 'Converting it into multiple sub-schemas, and copying them into '
+ 'the any_of field of the Schema. The value of `default` field is '
+ 'ignored because it is ambiguous to tell which sub-schema it '
+ 'belongs to.'
+ )
+ reformed_json_schema = JSONSchema()
+ # start splitting the JSONSchema into multiple sub-schemas
+ any_of = []
+ if nullable:
+ schema.nullable = True
+ for normalized_type in non_null_types:
+ sub_schema_in_any_of = {'type': normalized_type}
+ related_field_names = related_field_names_by_type.get(normalized_type)
+ if related_field_names is not None:
+ copy_schema_fields(
+ json_schema_dict=json_schema_dict,
+ related_fields_to_copy=related_field_names,
+ sub_schema_in_any_of=sub_schema_in_any_of,
+ )
+ any_of.append(JSONSchema(**sub_schema_in_any_of))
+ reformed_json_schema.any_of = any_of
+ json_schema_dict = reformed_json_schema.model_dump()
+ # Pass 2: the JSONSchema.type is not union-like,
+ # e.g. 'string', ['string'], ['null', 'string'].
+ for field_name, field_value in json_schema_dict.items():
+ if field_value is None or field_name == 'defs':
+ continue
+ if field_name in schema_field_names:
+ if field_name == 'items' and not field_value:
+ continue
+ schema_field_value: 'Schema' = convert_json_schema(
+ current_json_schema=JSONSchema(**field_value),
+ root_json_schema_dict=root_json_schema_dict,
+ api_option=api_option,
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
+ )
+ setattr(schema, field_name, schema_field_value)
+ elif field_name in list_schema_field_names:
+ list_schema_field_value: list['Schema'] = [
+ convert_json_schema(
+ current_json_schema=JSONSchema(**this_field_value),
+ root_json_schema_dict=root_json_schema_dict,
+ api_option=api_option,
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
+ )
+ for this_field_value in field_value
+ ]
+ setattr(schema, field_name, list_schema_field_value)
+ if not schema.type and not is_union_like_type and not schema.any_of:
+ schema.type = Type('OBJECT')
+ elif field_name in dict_schema_field_names:
+ dict_schema_field_value: dict[str, 'Schema'] = {
+ key: convert_json_schema(
+ current_json_schema=JSONSchema(**value),
+ root_json_schema_dict=root_json_schema_dict,
+ api_option=api_option,
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
+ )
+ for key, value in field_value.items()
+ }
+ setattr(schema, field_name, dict_schema_field_value)
+ elif field_name == 'type':
+ non_null_types, nullable = normalize_json_schema_type(field_value)
+ if nullable:
+ schema.nullable = True
+ if non_null_types:
+ schema.type = Type(non_null_types[0])
+ else:
+ if (
+ hasattr(schema, field_name)
+ and field_name != 'additional_properties'
+ ):
+ setattr(schema, field_name, field_value)
-VertexAISearchDataStoreSpecOrDict = Union[
- VertexAISearchDataStoreSpec, VertexAISearchDataStoreSpecDict
-]
+ if (
+ schema.type == 'ARRAY'
+ and schema.items
+ and not schema.items.model_dump(exclude_unset=True)
+ ):
+ schema.items = None
+ if schema.any_of and len(schema.any_of) == 2:
+ nullable_part = None
+ type_part = None
+ for part in schema.any_of:
+ # A schema representing `None` will either be of type NULL or just be nullable.
+ part_dict = part.model_dump(exclude_unset=True)
+ if part_dict == {'nullable': True} or part_dict == {'type': 'NULL'}:
+ nullable_part = part
+ else:
+ type_part = part
-class VertexAISearch(_common.BaseModel):
- """Retrieve from Vertex AI Search datastore or engine for grounding.
+ # If we found both parts, unwrap them into a single schema.
+ if nullable_part and type_part:
+ default_value = schema.default
+ schema = type_part
+ schema.nullable = True
+ # Carry the default value over to the unwrapped schema
+ if default_value is not None:
+ schema.default = default_value
- datastore and engine are mutually exclusive. See
- https://cloud.google.com/products/agent-builder. This data type is not
- supported in Gemini API.
- """
+ return schema
- data_store_specs: Optional[list[VertexAISearchDataStoreSpec]] = Field(
- default=None,
- description="""Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used.""",
- )
- datastore: Optional[str] = Field(
- default=None,
- description="""Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`""",
- )
- engine: Optional[str] = Field(
- default=None,
- description="""Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`""",
- )
- filter: Optional[str] = Field(
- default=None,
- description="""Optional. Filter strings to be passed to the search API.""",
- )
- max_results: Optional[int] = Field(
- default=None,
- description="""Optional. Number of search results to return per query. The default value is 10. The maximumm allowed value is 10.""",
- )
+ # This is the initial call to the recursive function.
+ root_schema_dict = json_schema.model_dump()
+ return convert_json_schema(
+ current_json_schema=json_schema,
+ root_json_schema_dict=root_schema_dict,
+ api_option=api_option,
+ raise_error_on_unsupported_field=raise_error_on_unsupported_field,
+ )
-class VertexAISearchDict(TypedDict, total=False):
- """Retrieve from Vertex AI Search datastore or engine for grounding.
+class SchemaDict(TypedDict, total=False):
+ """Schema is used to define the format of input/output data.
- datastore and engine are mutually exclusive. See
- https://cloud.google.com/products/agent-builder. This data type is not
- supported in Gemini API.
+ Represents a select subset of an [OpenAPI 3.0 schema
+ object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may
+ be added in the future as needed.
"""
- data_store_specs: Optional[list[VertexAISearchDataStoreSpecDict]]
- """Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used."""
-
- datastore: Optional[str]
- """Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`"""
-
- engine: Optional[str]
- """Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`"""
-
- filter: Optional[str]
- """Optional. Filter strings to be passed to the search API."""
-
- max_results: Optional[int]
- """Optional. Number of search results to return per query. The default value is 10. The maximumm allowed value is 10."""
-
-
-VertexAISearchOrDict = Union[VertexAISearch, VertexAISearchDict]
-
-
-class VertexRagStoreRagResource(_common.BaseModel):
- """The definition of the Rag resource.
+ additional_properties: Optional[Any]
+ """Optional. Can either be a boolean or an object; controls the presence of additional properties."""
- This data type is not supported in Gemini API.
- """
+ defs: Optional[dict[str, 'SchemaDict']]
+ """Optional. A map of definitions for use by `ref` Only allowed at the root of the schema."""
- rag_corpus: Optional[str] = Field(
- default=None,
- description="""Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`""",
- )
- rag_file_ids: Optional[list[str]] = Field(
- default=None,
- description="""Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.""",
- )
+ ref: Optional[str]
+ """Optional. Allows indirect references between schema nodes. The value should be a valid reference to a child of the root `defs`. For example, the following schema defines a reference to a schema node named "Pet": type: object properties: pet: ref: #/defs/Pet defs: Pet: type: object properties: name: type: string The value of the "pet" property is a reference to the schema node named "Pet". See details in https://json-schema.org/understanding-json-schema/structuring"""
+ any_of: Optional[list['SchemaDict']]
+ """Optional. The value should be validated against any (one or more) of the subschemas in the list."""
-class VertexRagStoreRagResourceDict(TypedDict, total=False):
- """The definition of the Rag resource.
+ default: Optional[Any]
+ """Optional. Default value of the data."""
- This data type is not supported in Gemini API.
- """
+ description: Optional[str]
+ """Optional. The description of the data."""
- rag_corpus: Optional[str]
- """Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`"""
+ enum: Optional[list[str]]
+ """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"]}"""
- rag_file_ids: Optional[list[str]]
- """Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field."""
+ example: Optional[Any]
+ """Optional. Example of the object. Will only populated when the object is the root."""
+ format: Optional[str]
+ """Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc"""
-VertexRagStoreRagResourceOrDict = Union[
- VertexRagStoreRagResource, VertexRagStoreRagResourceDict
-]
+ items: Optional['SchemaDict']
+ """Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY."""
+ max_items: Optional[int]
+ """Optional. Maximum number of the elements for Type.ARRAY."""
-class RagRetrievalConfigFilter(_common.BaseModel):
- """Config for filters. This data type is not supported in Gemini API."""
+ max_length: Optional[int]
+ """Optional. Maximum length of the Type.STRING"""
- metadata_filter: Optional[str] = Field(
- default=None, description="""Optional. String for metadata filtering."""
- )
- vector_distance_threshold: Optional[float] = Field(
- default=None,
- description="""Optional. Only returns contexts with vector distance smaller than the threshold.""",
- )
- vector_similarity_threshold: Optional[float] = Field(
- default=None,
- description="""Optional. Only returns contexts with vector similarity larger than the threshold.""",
- )
+ max_properties: Optional[int]
+ """Optional. Maximum number of the properties for Type.OBJECT."""
+ maximum: Optional[float]
+ """Optional. Maximum value of the Type.INTEGER and Type.NUMBER"""
-class RagRetrievalConfigFilterDict(TypedDict, total=False):
- """Config for filters. This data type is not supported in Gemini API."""
+ min_items: Optional[int]
+ """Optional. Minimum number of the elements for Type.ARRAY."""
- metadata_filter: Optional[str]
- """Optional. String for metadata filtering."""
+ min_length: Optional[int]
+ """Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING"""
- vector_distance_threshold: Optional[float]
- """Optional. Only returns contexts with vector distance smaller than the threshold."""
+ min_properties: Optional[int]
+ """Optional. Minimum number of the properties for Type.OBJECT."""
- vector_similarity_threshold: Optional[float]
- """Optional. Only returns contexts with vector similarity larger than the threshold."""
+ minimum: Optional[float]
+ """Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER"""
+ nullable: Optional[bool]
+ """Optional. Indicates if the value may be null."""
-RagRetrievalConfigFilterOrDict = Union[
- RagRetrievalConfigFilter, RagRetrievalConfigFilterDict
-]
+ pattern: Optional[str]
+ """Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
+ properties: Optional[dict[str, 'SchemaDict']]
+ """Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT."""
-class RagRetrievalConfigHybridSearch(_common.BaseModel):
- """Config for Hybrid Search. This data type is not supported in Gemini API."""
+ property_ordering: Optional[list[str]]
+ """Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties."""
- alpha: Optional[float] = Field(
- default=None,
- 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.""",
- )
+ required: Optional[list[str]]
+ """Optional. Required properties of Type.OBJECT."""
+ title: Optional[str]
+ """Optional. The title of the Schema."""
-class RagRetrievalConfigHybridSearchDict(TypedDict, total=False):
- """Config for Hybrid Search. This data type is not supported in Gemini API."""
+ type: Optional[Type]
+ """Optional. The type of the data."""
- alpha: Optional[float]
- """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."""
+SchemaOrDict = Union[Schema, SchemaDict]
-RagRetrievalConfigHybridSearchOrDict = Union[
- RagRetrievalConfigHybridSearch, RagRetrievalConfigHybridSearchDict
-]
+class FunctionDeclaration(_common.BaseModel):
+ """Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
-class RagRetrievalConfigRankingLlmRanker(_common.BaseModel):
- """Config for LlmRanker. This data type is not supported in Gemini API."""
+ Included in this declaration are the function name, description, parameters
+ and response type. This FunctionDeclaration is a representation of a block of
+ code that can be used as a `Tool` by the model and executed by the client.
+ """
- model_name: Optional[str] = Field(
+ description: Optional[str] = Field(
default=None,
- description="""Optional. The model name used for ranking. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models).""",
+ description="""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.""",
+ )
+ name: Optional[str] = Field(
+ default=None,
+ 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.""",
+ )
+ parameters: Optional[Schema] = Field(
+ default=None,
+ 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""",
+ )
+ parameters_json_schema: Optional[Any] = Field(
+ default=None,
+ 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`.""",
+ )
+ response: Optional[Schema] = Field(
+ default=None,
+ 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.""",
+ )
+ response_json_schema: Optional[Any] = Field(
+ default=None,
+ 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`.""",
+ )
+ behavior: Optional[Behavior] = Field(
+ default=None,
+ description="""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""",
)
+ @classmethod
+ def from_callable_with_api_option(
+ cls,
+ *,
+ callable: Callable[..., Any],
+ api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
+ behavior: Optional[Behavior] = None,
+ ) -> 'FunctionDeclaration':
+ """Converts a Callable to a FunctionDeclaration based on the API option.
-class RagRetrievalConfigRankingLlmRankerDict(TypedDict, total=False):
- """Config for LlmRanker. This data type is not supported in Gemini API."""
-
- model_name: Optional[str]
- """Optional. The model name used for ranking. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models)."""
+ Supported API option is 'VERTEX_AI' or 'GEMINI_API'. If api_option is unset,
+ it will default to 'GEMINI_API'. If unsupported api_option is provided, it
+ will raise ValueError.
+ """
+ supported_api_options = ['VERTEX_AI', 'GEMINI_API']
+ if api_option not in supported_api_options:
+ raise ValueError(
+ f'Unsupported api_option value: {api_option}. Supported api_option'
+ f' value is one of: {supported_api_options}.'
+ )
+ from . import _automatic_function_calling_util
+ parameters_properties = {}
+ parameters_json_schema = {}
+ annotation_under_future = typing.get_type_hints(callable)
+ try:
+ for name, param in inspect.signature(callable).parameters.items():
+ if param.kind in (
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
+ inspect.Parameter.KEYWORD_ONLY,
+ inspect.Parameter.POSITIONAL_ONLY,
+ ):
+ param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
+ param, annotation_under_future, name
+ )
+ schema = (
+ _automatic_function_calling_util._parse_schema_from_parameter(
+ api_option, param, callable.__name__
+ )
+ )
+ parameters_properties[name] = schema
+ except ValueError:
+ parameters_properties = {}
+ for name, param in inspect.signature(callable).parameters.items():
+ if param.kind in (
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
+ inspect.Parameter.KEYWORD_ONLY,
+ inspect.Parameter.POSITIONAL_ONLY,
+ ):
+ try:
+ param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
+ param, annotation_under_future, name
+ )
+ param_schema_adapter = pydantic.TypeAdapter(
+ param.annotation,
+ config=pydantic.ConfigDict(arbitrary_types_allowed=True),
+ )
+ json_schema_dict = param_schema_adapter.json_schema()
+ json_schema_dict = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
+ json_schema_dict
+ )
+ if 'prefixItems' in json_schema_dict:
+ parameters_json_schema[name] = json_schema_dict
+ continue
-RagRetrievalConfigRankingLlmRankerOrDict = Union[
- RagRetrievalConfigRankingLlmRanker, RagRetrievalConfigRankingLlmRankerDict
-]
+ union_args = typing.get_args(param.annotation)
+ has_primitive = any(
+ _automatic_function_calling_util._is_builtin_primitive_or_compound(
+ arg
+ )
+ for arg in union_args
+ )
+ if (
+ '$ref' in json_schema_dict or '$defs' in json_schema_dict
+ ) and has_primitive:
+ # This is a complex schema with a primitive (e.g., str | MyModel)
+ # that is better represented by raw JSON schema.
+ parameters_json_schema[name] = json_schema_dict
+ continue
+ schema = Schema.from_json_schema(
+ json_schema=JSONSchema(**json_schema_dict),
+ api_option=api_option,
+ )
+ if param.default is not inspect.Parameter.empty:
+ schema.default = param.default
+ parameters_properties[name] = schema
+ except Exception as e:
+ _automatic_function_calling_util._raise_for_unsupported_param(
+ param, callable.__name__, e
+ )
-class RagRetrievalConfigRankingRankService(_common.BaseModel):
- """Config for Rank Service. This data type is not supported in Gemini API."""
+ declaration = FunctionDeclaration(
+ name=callable.__name__,
+ description=inspect.cleandoc(callable.__doc__)
+ if callable.__doc__
+ else callable.__doc__,
+ behavior=behavior,
+ )
+ if parameters_properties:
+ declaration.parameters = Schema(
+ type='OBJECT',
+ properties=parameters_properties,
+ )
+ declaration.parameters.required = (
+ _automatic_function_calling_util._get_required_fields(
+ declaration.parameters
+ )
+ )
+ elif parameters_json_schema:
+ declaration.parameters_json_schema = parameters_json_schema
+ # TODO: b/421991354 - Remove this check once the bug is fixed.
+ if api_option == 'GEMINI_API':
+ return declaration
- model_name: Optional[str] = Field(
- default=None,
- description="""Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`""",
- )
+ return_annotation = inspect.signature(callable).return_annotation
+ if return_annotation is inspect._empty:
+ return declaration
+ return_value = inspect.Parameter(
+ 'return_value',
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
+ annotation=return_annotation,
+ )
-class RagRetrievalConfigRankingRankServiceDict(TypedDict, total=False):
- """Config for Rank Service. This data type is not supported in Gemini API."""
+ # This snippet catches the case when type hints are stored as strings
+ if isinstance(return_value.annotation, str):
+ return_value = return_value.replace(
+ annotation=annotation_under_future['return']
+ )
+ response_schema: Optional[Schema] = None
+ response_json_schema: Optional[Union[dict[str, Any], Schema]] = {}
+ try:
+ response_schema = (
+ _automatic_function_calling_util._parse_schema_from_parameter(
+ api_option,
+ return_value,
+ callable.__name__,
+ )
+ )
+ if response_schema.any_of is not None:
+ # To handle any_of, we need to use responseJsonSchema
+ response_json_schema = response_schema
+ response_schema = None
+ except ValueError:
+ try:
+ return_value_schema_adapter = pydantic.TypeAdapter(
+ return_value.annotation,
+ config=pydantic.ConfigDict(arbitrary_types_allowed=True),
+ )
+ response_json_schema = return_value_schema_adapter.json_schema()
+ response_json_schema = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
+ response_json_schema
+ )
+ except Exception as e:
+ _automatic_function_calling_util._raise_for_unsupported_param(
+ return_value, callable.__name__, e
+ )
- model_name: Optional[str]
- """Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`"""
+ if response_schema:
+ declaration.response = response_schema
+ elif response_json_schema:
+ declaration.response_json_schema = response_json_schema
+ return declaration
+ @classmethod
+ def from_callable(
+ cls,
+ *,
+ client: 'BaseApiClient',
+ callable: Callable[..., Any],
+ behavior: Optional[Behavior] = None,
+ ) -> 'FunctionDeclaration':
+ """Converts a Callable to a FunctionDeclaration based on the client.
-RagRetrievalConfigRankingRankServiceOrDict = Union[
- RagRetrievalConfigRankingRankService,
- RagRetrievalConfigRankingRankServiceDict,
-]
+ Note: For best results prefer
+ [Google-style
+ docstring](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods)
+ when describing arguments. This function does **not** parse argument
+ descriptions into the property description slots of the resulting structure.
+ Instead it sends the whole docstring in the top-level function description.
+ Google-style docstring are closest to what the model is trained on.
+ """
+ if client.vertexai:
+ return cls.from_callable_with_api_option(
+ callable=callable, api_option='VERTEX_AI', behavior=behavior
+ )
+ else:
+ return cls.from_callable_with_api_option(
+ callable=callable, api_option='GEMINI_API', behavior=behavior
+ )
-class RagRetrievalConfigRanking(_common.BaseModel):
- """Config for ranking and reranking.
+class FunctionDeclarationDict(TypedDict, total=False):
+ """Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
- This data type is not supported in Gemini API.
+ Included in this declaration are the function name, description, parameters
+ and response type. This FunctionDeclaration is a representation of a block of
+ code that can be used as a `Tool` by the model and executed by the client.
"""
- llm_ranker: Optional[RagRetrievalConfigRankingLlmRanker] = Field(
- default=None, description="""Optional. Config for LlmRanker."""
- )
- rank_service: Optional[RagRetrievalConfigRankingRankService] = Field(
- default=None, description="""Optional. Config for Rank Service."""
- )
+ description: Optional[str]
+ """Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function."""
+ name: Optional[str]
+ """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."""
-class RagRetrievalConfigRankingDict(TypedDict, total=False):
- """Config for ranking and reranking.
+ parameters: Optional[SchemaDict]
+ """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"""
- This data type is not supported in Gemini API.
- """
+ parameters_json_schema: Optional[Any]
+ """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`."""
- llm_ranker: Optional[RagRetrievalConfigRankingLlmRankerDict]
- """Optional. Config for LlmRanker."""
+ response: Optional[SchemaDict]
+ """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."""
- rank_service: Optional[RagRetrievalConfigRankingRankServiceDict]
- """Optional. Config for Rank Service."""
+ response_json_schema: Optional[Any]
+ """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`."""
+ behavior: Optional[Behavior]
+ """Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI."""
-RagRetrievalConfigRankingOrDict = Union[
- RagRetrievalConfigRanking, RagRetrievalConfigRankingDict
-]
+FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
-class RagRetrievalConfig(_common.BaseModel):
- """Specifies the context retrieval config.
- This data type is not supported in Gemini API.
- """
+class GoogleMaps(_common.BaseModel):
+ """Tool to retrieve public maps data for grounding, powered by Google."""
- filter: Optional[RagRetrievalConfigFilter] = Field(
- default=None, description="""Optional. Config for filters."""
- )
- hybrid_search: Optional[RagRetrievalConfigHybridSearch] = Field(
- default=None, description="""Optional. Config for Hybrid Search."""
- )
- ranking: Optional[RagRetrievalConfigRanking] = Field(
+ auth_config: Optional[AuthConfig] = Field(
default=None,
- description="""Optional. Config for ranking and reranking.""",
+ description="""The authentication config to access the API. Only API key is supported. This field is not supported in Gemini API.""",
)
- top_k: Optional[int] = Field(
+ enable_widget: Optional[bool] = Field(
default=None,
- description="""Optional. The number of contexts to retrieve.""",
+ description="""Optional. If true, include the widget context token in the response.""",
)
-class RagRetrievalConfigDict(TypedDict, total=False):
- """Specifies the context retrieval config.
-
- This data type is not supported in Gemini API.
- """
-
- filter: Optional[RagRetrievalConfigFilterDict]
- """Optional. Config for filters."""
-
- hybrid_search: Optional[RagRetrievalConfigHybridSearchDict]
- """Optional. Config for Hybrid Search."""
+class GoogleMapsDict(TypedDict, total=False):
+ """Tool to retrieve public maps data for grounding, powered by Google."""
- ranking: Optional[RagRetrievalConfigRankingDict]
- """Optional. Config for ranking and reranking."""
+ auth_config: Optional[AuthConfigDict]
+ """The authentication config to access the API. Only API key is supported. This field is not supported in Gemini API."""
- top_k: Optional[int]
- """Optional. The number of contexts to retrieve."""
+ enable_widget: Optional[bool]
+ """Optional. If true, include the widget context token in the response."""
-RagRetrievalConfigOrDict = Union[RagRetrievalConfig, RagRetrievalConfigDict]
+GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]
-class VertexRagStore(_common.BaseModel):
- """Retrieve from Vertex RAG Store for grounding.
+class Interval(_common.BaseModel):
+ """Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive).
- This data type is not supported in Gemini API.
+ The start must be less than or equal to the end. When the start equals the
+ end, the interval is empty (matches no time). When both start and end are
+ unspecified, the interval matches any time.
"""
- rag_corpora: Optional[list[str]] = Field(
- default=None,
- description="""Optional. Deprecated. Please use rag_resources instead.""",
- )
- rag_resources: Optional[list[VertexRagStoreRagResource]] = Field(
- default=None,
- 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.""",
- )
- rag_retrieval_config: Optional[RagRetrievalConfig] = Field(
- default=None,
- description="""Optional. The retrieval config for the Rag query.""",
- )
- similarity_top_k: Optional[int] = Field(
- default=None,
- description="""Optional. Number of top k results to return from the selected corpora.""",
- )
- store_context: Optional[bool] = Field(
+ end_time: Optional[datetime.datetime] = Field(
default=None,
- description="""Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions.""",
+ description="""Optional. Exclusive end of the interval. If specified, a Timestamp matching this interval will have to be before the end.""",
)
- vector_distance_threshold: Optional[float] = Field(
+ start_time: Optional[datetime.datetime] = Field(
default=None,
- description="""Optional. Only return results with vector distance smaller than the threshold.""",
+ description="""Optional. Inclusive start of the interval. If specified, a Timestamp matching this interval will have to be the same or after the start.""",
)
-class VertexRagStoreDict(TypedDict, total=False):
- """Retrieve from Vertex RAG Store for grounding.
+class IntervalDict(TypedDict, total=False):
+ """Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive).
- This data type is not supported in Gemini API.
+ The start must be less than or equal to the end. When the start equals the
+ end, the interval is empty (matches no time). When both start and end are
+ unspecified, the interval matches any time.
"""
- rag_corpora: Optional[list[str]]
- """Optional. Deprecated. Please use rag_resources instead."""
-
- rag_resources: Optional[list[VertexRagStoreRagResourceDict]]
- """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."""
-
- rag_retrieval_config: Optional[RagRetrievalConfigDict]
- """Optional. The retrieval config for the Rag query."""
-
- similarity_top_k: Optional[int]
- """Optional. Number of top k results to return from the selected corpora."""
-
- store_context: Optional[bool]
- """Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions."""
+ end_time: Optional[datetime.datetime]
+ """Optional. Exclusive end of the interval. If specified, a Timestamp matching this interval will have to be before the end."""
- vector_distance_threshold: Optional[float]
- """Optional. Only return results with vector distance smaller than the threshold."""
+ start_time: Optional[datetime.datetime]
+ """Optional. Inclusive start of the interval. If specified, a Timestamp matching this interval will have to be the same or after the start."""
-VertexRagStoreOrDict = Union[VertexRagStore, VertexRagStoreDict]
+IntervalOrDict = Union[Interval, IntervalDict]
-class Retrieval(_common.BaseModel):
- """Defines a retrieval tool that model can call to access external knowledge.
+class GoogleSearch(_common.BaseModel):
+ """GoogleSearch tool type.
- This data type is not supported in Gemini API.
+ Tool to support Google Search in Model. Powered by Google.
"""
- disable_attribution: Optional[bool] = Field(
- default=None,
- description="""Optional. Deprecated. This option is no longer supported.""",
- )
- external_api: Optional[ExternalApi] = Field(
+ exclude_domains: Optional[list[str]] = Field(
default=None,
- description="""Use data source powered by external API for grounding.""",
+ description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains. Example: ["amazon.com", "facebook.com"]. This field is not supported in Gemini API.""",
)
- vertex_ai_search: Optional[VertexAISearch] = Field(
+ blocking_confidence: Optional[PhishBlockThreshold] = Field(
default=None,
- description="""Set to use data source powered by Vertex AI Search.""",
+ description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results. This field is not supported in Gemini API.""",
)
- vertex_rag_store: Optional[VertexRagStore] = Field(
+ time_range_filter: Optional[Interval] = Field(
default=None,
- description="""Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService.""",
+ description="""Optional. Filter search results to a specific time range. If customers set a start time, they must set an end time (and vice versa). This field is not supported in Vertex AI.""",
)
-class RetrievalDict(TypedDict, total=False):
- """Defines a retrieval tool that model can call to access external knowledge.
+class GoogleSearchDict(TypedDict, total=False):
+ """GoogleSearch tool type.
- This data type is not supported in Gemini API.
+ Tool to support Google Search in Model. Powered by Google.
"""
- disable_attribution: Optional[bool]
- """Optional. Deprecated. This option is no longer supported."""
+ exclude_domains: Optional[list[str]]
+ """Optional. List of domains to be excluded from the search results. The default limit is 2000 domains. Example: ["amazon.com", "facebook.com"]. This field is not supported in Gemini API."""
- external_api: Optional[ExternalApiDict]
- """Use data source powered by external API for grounding."""
+ blocking_confidence: Optional[PhishBlockThreshold]
+ """Optional. Sites with confidence level chosen & above this value will be blocked from the search results. This field is not supported in Gemini API."""
- vertex_ai_search: Optional[VertexAISearchDict]
- """Set to use data source powered by Vertex AI Search."""
+ time_range_filter: Optional[IntervalDict]
+ """Optional. Filter search results to a specific time range. If customers set a start time, they must set an end time (and vice versa). This field is not supported in Vertex AI."""
- vertex_rag_store: Optional[VertexRagStoreDict]
- """Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService."""
+GoogleSearchOrDict = Union[GoogleSearch, GoogleSearchDict]
-RetrievalOrDict = Union[Retrieval, RetrievalDict]
+class DynamicRetrievalConfig(_common.BaseModel):
+ """Describes the options to customize dynamic retrieval."""
-class ToolCodeExecution(_common.BaseModel):
- """Tool that executes code generated by the model, and automatically returns the result to the model.
+ dynamic_threshold: Optional[float] = Field(
+ default=None,
+ description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
+ )
+ mode: Optional[DynamicRetrievalConfigMode] = Field(
+ default=None,
+ description="""The mode of the predictor to be used in dynamic retrieval.""",
+ )
- See also [ExecutableCode]and [CodeExecutionResult] which are input and output
- to this tool. This data type is not supported in Gemini API.
- """
- pass
+class DynamicRetrievalConfigDict(TypedDict, total=False):
+ """Describes the options to customize dynamic retrieval."""
+ dynamic_threshold: Optional[float]
+ """Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used."""
-class ToolCodeExecutionDict(TypedDict, total=False):
- """Tool that executes code generated by the model, and automatically returns the result to the model.
+ mode: Optional[DynamicRetrievalConfigMode]
+ """The mode of the predictor to be used in dynamic retrieval."""
- See also [ExecutableCode]and [CodeExecutionResult] which are input and output
- to this tool. This data type is not supported in Gemini API.
- """
- pass
+DynamicRetrievalConfigOrDict = Union[
+ DynamicRetrievalConfig, DynamicRetrievalConfigDict
+]
-ToolCodeExecutionOrDict = Union[ToolCodeExecution, ToolCodeExecutionDict]
+class GoogleSearchRetrieval(_common.BaseModel):
+ """Tool to retrieve public web data for grounding, powered by Google."""
+ dynamic_retrieval_config: Optional[DynamicRetrievalConfig] = Field(
+ default=None,
+ description="""Specifies the dynamic retrieval configuration for the given source.""",
+ )
-class EnterpriseWebSearch(_common.BaseModel):
- """Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
- This data type is not supported in Gemini API.
- """
+class GoogleSearchRetrievalDict(TypedDict, total=False):
+ """Tool to retrieve public web data for grounding, powered by Google."""
- exclude_domains: Optional[list[str]] = Field(
- default=None,
- description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains.""",
- )
- blocking_confidence: Optional[PhishBlockThreshold] = Field(
- default=None,
- description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results.""",
- )
+ dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
+ """Specifies the dynamic retrieval configuration for the given source."""
-class EnterpriseWebSearchDict(TypedDict, total=False):
- """Tool to search public web data, powered by Vertex AI Search and Sec4 compliance.
+GoogleSearchRetrievalOrDict = Union[
+ GoogleSearchRetrieval, GoogleSearchRetrievalDict
+]
- This data type is not supported in Gemini API.
- """
- exclude_domains: Optional[list[str]]
- """Optional. List of domains to be excluded from the search results. The default limit is 2000 domains."""
+class UrlContext(_common.BaseModel):
+ """Tool to support URL context."""
- blocking_confidence: Optional[PhishBlockThreshold]
- """Optional. Sites with confidence level chosen & above this value will be blocked from the search results."""
+ pass
-EnterpriseWebSearchOrDict = Union[EnterpriseWebSearch, EnterpriseWebSearchDict]
+class UrlContextDict(TypedDict, total=False):
+ """Tool to support URL context."""
+ pass
-class FunctionDeclaration(_common.BaseModel):
- """Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
- Included in this declaration are the function name, description, parameters
- and response type. This FunctionDeclaration is a representation of a block of
- code that can be used as a `Tool` by the model and executed by the client.
- """
+UrlContextOrDict = Union[UrlContext, UrlContextDict]
- description: Optional[str] = Field(
+
+class Tool(_common.BaseModel):
+ """Tool details of a tool that the model may use to generate a response."""
+
+ retrieval: Optional[Retrieval] = Field(
+ default=None,
+ 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.""",
+ )
+ computer_use: Optional[ComputerUse] = Field(
default=None,
- description="""Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.""",
+ description="""Optional. Tool to support the model interacting directly with the
+ computer. If enabled, it automatically populates computer-use specific
+ Function Declarations.""",
)
- name: Optional[str] = Field(
+ file_search: Optional[FileSearch] = Field(
default=None,
- 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.""",
+ description="""Optional. Tool to retrieve knowledge from the File Search Stores.""",
)
- parameters: Optional[Schema] = Field(
+ code_execution: Optional[ToolCodeExecution] = Field(
default=None,
- 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""",
+ description="""Optional. CodeExecution tool type. Enables the model to execute code as part of generation.""",
)
- parameters_json_schema: Optional[Any] = Field(
+ enterprise_web_search: Optional[EnterpriseWebSearch] = Field(
default=None,
- 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`.""",
+ 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.""",
)
- response: Optional[Schema] = Field(
+ function_declarations: Optional[list[FunctionDeclaration]] = Field(
default=None,
- 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.""",
+ 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.""",
)
- response_json_schema: Optional[Any] = Field(
+ google_maps: Optional[GoogleMaps] = Field(
default=None,
- 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`.""",
+ description="""Optional. GoogleMaps tool type. Tool to support Google Maps in Model.""",
)
- behavior: Optional[Behavior] = Field(
+ google_search: Optional[GoogleSearch] = Field(
default=None,
- description="""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""",
+ description="""Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google.""",
+ )
+ google_search_retrieval: Optional[GoogleSearchRetrieval] = Field(
+ default=None,
+ description="""Optional. Specialized retrieval tool that is powered by Google Search.""",
+ )
+ url_context: Optional[UrlContext] = Field(
+ default=None,
+ description="""Optional. Tool to support URL context retrieval.""",
)
- @classmethod
- def from_callable_with_api_option(
- cls,
- *,
- callable: Callable[..., Any],
- api_option: Literal['VERTEX_AI', 'GEMINI_API'] = 'GEMINI_API',
- behavior: Optional[Behavior] = None,
- ) -> 'FunctionDeclaration':
- """Converts a Callable to a FunctionDeclaration based on the API option.
- Supported API option is 'VERTEX_AI' or 'GEMINI_API'. If api_option is unset,
- it will default to 'GEMINI_API'. If unsupported api_option is provided, it
- will raise ValueError.
- """
- supported_api_options = ['VERTEX_AI', 'GEMINI_API']
- if api_option not in supported_api_options:
- raise ValueError(
- f'Unsupported api_option value: {api_option}. Supported api_option'
- f' value is one of: {supported_api_options}.'
- )
- from . import _automatic_function_calling_util
+class ToolDict(TypedDict, total=False):
+ """Tool details of a tool that the model may use to generate a response."""
- parameters_properties = {}
- parameters_json_schema = {}
- annotation_under_future = typing.get_type_hints(callable)
- try:
- for name, param in inspect.signature(callable).parameters.items():
- if param.kind in (
- inspect.Parameter.POSITIONAL_OR_KEYWORD,
- inspect.Parameter.KEYWORD_ONLY,
- inspect.Parameter.POSITIONAL_ONLY,
- ):
- param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
- param, annotation_under_future, name
- )
- schema = (
- _automatic_function_calling_util._parse_schema_from_parameter(
- api_option, param, callable.__name__
- )
- )
- parameters_properties[name] = schema
- except ValueError:
- parameters_properties = {}
- for name, param in inspect.signature(callable).parameters.items():
- if param.kind in (
- inspect.Parameter.POSITIONAL_OR_KEYWORD,
- inspect.Parameter.KEYWORD_ONLY,
- inspect.Parameter.POSITIONAL_ONLY,
- ):
- try:
- param = _automatic_function_calling_util._handle_params_as_deferred_annotations(
- param, annotation_under_future, name
- )
- param_schema_adapter = pydantic.TypeAdapter(
- param.annotation,
- config=pydantic.ConfigDict(arbitrary_types_allowed=True),
- )
- json_schema_dict = param_schema_adapter.json_schema()
- json_schema_dict = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
- json_schema_dict
- )
- if 'prefixItems' in json_schema_dict:
- parameters_json_schema[name] = json_schema_dict
- continue
+ retrieval: Optional[RetrievalDict]
+ """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."""
- union_args = typing.get_args(param.annotation)
- has_primitive = any(
- _automatic_function_calling_util._is_builtin_primitive_or_compound(
- arg
- )
- for arg in union_args
- )
- if (
- '$ref' in json_schema_dict or '$defs' in json_schema_dict
- ) and has_primitive:
- # This is a complex schema with a primitive (e.g., str | MyModel)
- # that is better represented by raw JSON schema.
- parameters_json_schema[name] = json_schema_dict
- continue
+ computer_use: Optional[ComputerUseDict]
+ """Optional. Tool to support the model interacting directly with the
+ computer. If enabled, it automatically populates computer-use specific
+ Function Declarations."""
- schema = Schema.from_json_schema(
- json_schema=JSONSchema(**json_schema_dict),
- api_option=api_option,
- )
- if param.default is not inspect.Parameter.empty:
- schema.default = param.default
- parameters_properties[name] = schema
- except Exception as e:
- _automatic_function_calling_util._raise_for_unsupported_param(
- param, callable.__name__, e
- )
+ file_search: Optional[FileSearchDict]
+ """Optional. Tool to retrieve knowledge from the File Search Stores."""
- declaration = FunctionDeclaration(
- name=callable.__name__,
- description=inspect.cleandoc(callable.__doc__)
- if callable.__doc__
- else callable.__doc__,
- behavior=behavior,
- )
- if parameters_properties:
- declaration.parameters = Schema(
- type='OBJECT',
- properties=parameters_properties,
- )
- declaration.parameters.required = (
- _automatic_function_calling_util._get_required_fields(
- declaration.parameters
- )
- )
- elif parameters_json_schema:
- declaration.parameters_json_schema = parameters_json_schema
- # TODO: b/421991354 - Remove this check once the bug is fixed.
- if api_option == 'GEMINI_API':
- return declaration
+ code_execution: Optional[ToolCodeExecutionDict]
+ """Optional. CodeExecution tool type. Enables the model to execute code as part of generation."""
- return_annotation = inspect.signature(callable).return_annotation
- if return_annotation is inspect._empty:
- return declaration
+ enterprise_web_search: Optional[EnterpriseWebSearchDict]
+ """Optional. Tool to support searching public web data, powered by Vertex AI Search and Sec4 compliance. This field is not supported in Gemini API."""
- return_value = inspect.Parameter(
- 'return_value',
- inspect.Parameter.POSITIONAL_OR_KEYWORD,
- annotation=return_annotation,
- )
+ function_declarations: Optional[list[FunctionDeclarationDict]]
+ """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."""
- # This snippet catches the case when type hints are stored as strings
- if isinstance(return_value.annotation, str):
- return_value = return_value.replace(
- annotation=annotation_under_future['return']
- )
- response_schema: Optional[Schema] = None
- response_json_schema: Optional[Union[dict[str, Any], Schema]] = {}
- try:
- response_schema = (
- _automatic_function_calling_util._parse_schema_from_parameter(
- api_option,
- return_value,
- callable.__name__,
- )
- )
- if response_schema.any_of is not None:
- # To handle any_of, we need to use responseJsonSchema
- response_json_schema = response_schema
- response_schema = None
- except ValueError:
- try:
- return_value_schema_adapter = pydantic.TypeAdapter(
- return_value.annotation,
- config=pydantic.ConfigDict(arbitrary_types_allowed=True),
- )
- response_json_schema = return_value_schema_adapter.json_schema()
- response_json_schema = _automatic_function_calling_util._add_unevaluated_items_to_fixed_len_tuple_schema(
- response_json_schema
- )
- except Exception as e:
- _automatic_function_calling_util._raise_for_unsupported_param(
- return_value, callable.__name__, e
- )
+ google_maps: Optional[GoogleMapsDict]
+ """Optional. GoogleMaps tool type. Tool to support Google Maps in Model."""
- if response_schema:
- declaration.response = response_schema
- elif response_json_schema:
- declaration.response_json_schema = response_json_schema
- return declaration
+ google_search: Optional[GoogleSearchDict]
+ """Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google."""
- @classmethod
- def from_callable(
- cls,
- *,
- client: 'BaseApiClient',
- callable: Callable[..., Any],
- behavior: Optional[Behavior] = None,
- ) -> 'FunctionDeclaration':
- """Converts a Callable to a FunctionDeclaration based on the client.
+ google_search_retrieval: Optional[GoogleSearchRetrievalDict]
+ """Optional. Specialized retrieval tool that is powered by Google Search."""
- Note: For best results prefer
- [Google-style
- docstring](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods)
- when describing arguments. This function does **not** parse argument
- descriptions into the property description slots of the resulting structure.
- Instead it sends the whole docstring in the top-level function description.
- Google-style docstring are closest to what the model is trained on.
- """
- if client.vertexai:
- return cls.from_callable_with_api_option(
- callable=callable, api_option='VERTEX_AI', behavior=behavior
- )
- else:
- return cls.from_callable_with_api_option(
- callable=callable, api_option='GEMINI_API', behavior=behavior
- )
+ url_context: Optional[UrlContextDict]
+ """Optional. Tool to support URL context retrieval."""
+
+
+ToolOrDict = Union[Tool, ToolDict]
+if _is_mcp_imported:
+ ToolUnion = Union[Tool, Callable[..., Any], mcp_types.Tool, McpClientSession]
+ ToolUnionDict = Union[
+ ToolDict, Callable[..., Any], mcp_types.Tool, McpClientSession
+ ]
+else:
+ ToolUnion = Union[Tool, Callable[..., Any]] # type: ignore[misc]
+ ToolUnionDict = Union[ToolDict, Callable[..., Any]] # type: ignore[misc]
+
+ToolListUnion = list[ToolUnion]
+ToolListUnionDict = list[ToolUnionDict]
+SchemaUnion = Union[
+ dict[Any, Any], type, Schema, builtin_types.GenericAlias, VersionedUnionType # type: ignore[valid-type]
+]
+SchemaUnionDict = Union[SchemaUnion, SchemaDict]
-class FunctionDeclarationDict(TypedDict, total=False):
- """Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3).
- Included in this declaration are the function name, description, parameters
- and response type. This FunctionDeclaration is a representation of a block of
- code that can be used as a `Tool` by the model and executed by the client.
- """
+class LatLng(_common.BaseModel):
+ """An object that represents a latitude/longitude pair.
- description: Optional[str]
- """Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function."""
+ This is expressed as a pair of doubles to represent degrees latitude and
+ degrees longitude. Unless specified otherwise, this object must conform to the
+
+ WGS84 standard. Values must be within normalized ranges.
+ """
- name: Optional[str]
- """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."""
+ latitude: Optional[float] = Field(
+ default=None,
+ description="""The latitude in degrees. It must be in the range [-90.0, +90.0].""",
+ )
+ longitude: Optional[float] = Field(
+ default=None,
+ description="""The longitude in degrees. It must be in the range [-180.0, +180.0]""",
+ )
- parameters: Optional[SchemaDict]
- """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"""
- parameters_json_schema: Optional[Any]
- """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`."""
+class LatLngDict(TypedDict, total=False):
+ """An object that represents a latitude/longitude pair.
- response: Optional[SchemaDict]
- """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."""
+ This is expressed as a pair of doubles to represent degrees latitude and
+ degrees longitude. Unless specified otherwise, this object must conform to the
+
+ WGS84 standard. Values must be within normalized ranges.
+ """
- response_json_schema: Optional[Any]
- """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`."""
+ latitude: Optional[float]
+ """The latitude in degrees. It must be in the range [-90.0, +90.0]."""
- behavior: Optional[Behavior]
- """Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI."""
+ longitude: Optional[float]
+ """The longitude in degrees. It must be in the range [-180.0, +180.0]"""
-FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]
+LatLngOrDict = Union[LatLng, LatLngDict]
-class GoogleMaps(_common.BaseModel):
- """Tool to retrieve public maps data for grounding, powered by Google."""
+class RetrievalConfig(_common.BaseModel):
+ """Retrieval config."""
- auth_config: Optional[AuthConfig] = Field(
- default=None,
- description="""The authentication config to access the API. Only API key is supported. This field is not supported in Gemini API.""",
+ lat_lng: Optional[LatLng] = Field(
+ default=None, description="""Optional. The location of the user."""
)
- enable_widget: Optional[bool] = Field(
- default=None,
- description="""Optional. If true, include the widget context token in the response.""",
+ language_code: Optional[str] = Field(
+ default=None, description="""The language code of the user."""
)
-class GoogleMapsDict(TypedDict, total=False):
- """Tool to retrieve public maps data for grounding, powered by Google."""
-
- auth_config: Optional[AuthConfigDict]
- """The authentication config to access the API. Only API key is supported. This field is not supported in Gemini API."""
+class RetrievalConfigDict(TypedDict, total=False):
+ """Retrieval config."""
- enable_widget: Optional[bool]
- """Optional. If true, include the widget context token in the response."""
+ lat_lng: Optional[LatLngDict]
+ """Optional. The location of the user."""
+ language_code: Optional[str]
+ """The language code of the user."""
-GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]
+RetrievalConfigOrDict = Union[RetrievalConfig, RetrievalConfigDict]
-class Interval(_common.BaseModel):
- """Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive).
- The start must be less than or equal to the end. When the start equals the
- end, the interval is empty (matches no time). When both start and end are
- unspecified, the interval matches any time.
- """
+class FunctionCallingConfig(_common.BaseModel):
+ """Function calling config."""
- end_time: Optional[datetime.datetime] = Field(
+ allowed_function_names: Optional[list[str]] = Field(
default=None,
- description="""Optional. Exclusive end of the interval. If specified, a Timestamp matching this interval will have to be before the end.""",
+ 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.""",
)
- start_time: Optional[datetime.datetime] = Field(
+ mode: Optional[FunctionCallingConfigMode] = Field(
+ default=None, description="""Optional. Function calling mode."""
+ )
+ stream_function_call_arguments: Optional[bool] = Field(
default=None,
- description="""Optional. Inclusive start of the interval. If specified, a Timestamp matching this interval will have to be the same or after the start.""",
+ 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.""",
)
-class IntervalDict(TypedDict, total=False):
- """Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive).
+class FunctionCallingConfigDict(TypedDict, total=False):
+ """Function calling config."""
- The start must be less than or equal to the end. When the start equals the
- end, the interval is empty (matches no time). When both start and end are
- unspecified, the interval matches any time.
- """
+ allowed_function_names: Optional[list[str]]
+ """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."""
- end_time: Optional[datetime.datetime]
- """Optional. Exclusive end of the interval. If specified, a Timestamp matching this interval will have to be before the end."""
+ mode: Optional[FunctionCallingConfigMode]
+ """Optional. Function calling mode."""
- start_time: Optional[datetime.datetime]
- """Optional. Inclusive start of the interval. If specified, a Timestamp matching this interval will have to be the same or after the start."""
+ stream_function_call_arguments: Optional[bool]
+ """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."""
-IntervalOrDict = Union[Interval, IntervalDict]
+FunctionCallingConfigOrDict = Union[
+ FunctionCallingConfig, FunctionCallingConfigDict
+]
-class GoogleSearch(_common.BaseModel):
- """GoogleSearch tool type.
+class ToolConfig(_common.BaseModel):
+ """Tool config.
- Tool to support Google Search in Model. Powered by Google.
+ This config is shared for all tools provided in the request.
"""
- exclude_domains: Optional[list[str]] = Field(
- default=None,
- description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains. Example: ["amazon.com", "facebook.com"]. This field is not supported in Gemini API.""",
- )
- blocking_confidence: Optional[PhishBlockThreshold] = Field(
- default=None,
- description="""Optional. Sites with confidence level chosen & above this value will be blocked from the search results. This field is not supported in Gemini API.""",
+ retrieval_config: Optional[RetrievalConfig] = Field(
+ default=None, description="""Optional. Retrieval config."""
)
- time_range_filter: Optional[Interval] = Field(
- default=None,
- description="""Optional. Filter search results to a specific time range. If customers set a start time, they must set an end time (and vice versa). This field is not supported in Vertex AI.""",
+ function_calling_config: Optional[FunctionCallingConfig] = Field(
+ default=None, description="""Optional. Function calling config."""
)
-class GoogleSearchDict(TypedDict, total=False):
- """GoogleSearch tool type.
+class ToolConfigDict(TypedDict, total=False):
+ """Tool config.
- Tool to support Google Search in Model. Powered by Google.
+ This config is shared for all tools provided in the request.
"""
- exclude_domains: Optional[list[str]]
- """Optional. List of domains to be excluded from the search results. The default limit is 2000 domains. Example: ["amazon.com", "facebook.com"]. This field is not supported in Gemini API."""
+ retrieval_config: Optional[RetrievalConfigDict]
+ """Optional. Retrieval config."""
- blocking_confidence: Optional[PhishBlockThreshold]
- """Optional. Sites with confidence level chosen & above this value will be blocked from the search results. This field is not supported in Gemini API."""
+ function_calling_config: Optional[FunctionCallingConfigDict]
+ """Optional. Function calling config."""
- time_range_filter: Optional[IntervalDict]
- """Optional. Filter search results to a specific time range. If customers set a start time, they must set an end time (and vice versa). This field is not supported in Vertex AI."""
+ToolConfigOrDict = Union[ToolConfig, ToolConfigDict]
-GoogleSearchOrDict = Union[GoogleSearch, GoogleSearchDict]
+class JSONSchema(_common.BaseModel):
+ """A subset of JSON Schema according to 2020-12 JSON Schema draft.
-class DynamicRetrievalConfig(_common.BaseModel):
- """Describes the options to customize dynamic retrieval."""
+ Represents a subset of a JSON Schema object that is used by the Gemini model.
+ The difference between this class and the Schema class is that this class is
+ compatible with OpenAPI 3.1 schema objects. And the Schema class is used to
+ make API call to Gemini model.
+ """
- dynamic_threshold: Optional[float] = Field(
+ type: Optional[Union[JSONSchemaType, list[JSONSchemaType]]] = Field(
+ default=None,
+ 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.""",
+ )
+ format: Optional[str] = Field(
+ default=None,
+ description='Define semantic information about a string instance.',
+ )
+ title: Optional[str] = Field(
+ default=None,
+ description=(
+ 'A preferably short description about the purpose of the instance'
+ ' described by the schema.'
+ ),
+ )
+ description: Optional[str] = Field(
+ default=None,
+ description=(
+ 'An explanation about the purpose of the instance described by the'
+ ' schema.'
+ ),
+ )
+ default: Optional[Any] = Field(
+ default=None,
+ description=(
+ 'This keyword can be used to supply a default JSON value associated'
+ ' with a particular schema.'
+ ),
+ )
+ items: Optional['JSONSchema'] = Field(
+ default=None,
+ description=(
+ 'Validation succeeds if each element of the instance not covered by'
+ ' prefixItems validates against this schema.'
+ ),
+ )
+ min_items: Optional[int] = Field(
+ default=None,
+ description=(
+ 'An array instance is valid if its size is greater than, or equal to,'
+ ' the value of this keyword.'
+ ),
+ )
+ max_items: Optional[int] = Field(
+ default=None,
+ description=(
+ 'An array instance is valid if its size is less than, or equal to,'
+ ' the value of this keyword.'
+ ),
+ )
+ enum: Optional[list[Any]] = Field(
+ default=None,
+ description=(
+ 'Validation succeeds if the instance is equal to one of the elements'
+ ' in this keyword’s array value.'
+ ),
+ )
+ properties: Optional[dict[str, 'JSONSchema']] = Field(
+ default=None,
+ description=(
+ 'Validation succeeds if, for each name that appears in both the'
+ ' instance and as a name within this keyword’s value, the child'
+ ' instance for that name successfully validates against the'
+ ' corresponding schema.'
+ ),
+ )
+ required: Optional[list[str]] = Field(
+ default=None,
+ description=(
+ 'An object instance is valid against this keyword if every item in'
+ ' the array is the name of a property in the instance.'
+ ),
+ )
+ min_properties: Optional[int] = Field(
+ default=None,
+ description=(
+ 'An object instance is valid if its number of properties is greater'
+ ' than, or equal to, the value of this keyword.'
+ ),
+ )
+ max_properties: Optional[int] = Field(
+ default=None,
+ description=(
+ 'An object instance is valid if its number of properties is less'
+ ' than, or equal to, the value of this keyword.'
+ ),
+ )
+ minimum: Optional[float] = Field(
default=None,
- description="""Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.""",
+ description=(
+ 'Validation succeeds if the numeric instance is greater than or equal'
+ ' to the given number.'
+ ),
)
- mode: Optional[DynamicRetrievalConfigMode] = Field(
+ maximum: Optional[float] = Field(
default=None,
- description="""The mode of the predictor to be used in dynamic retrieval.""",
+ description=(
+ 'Validation succeeds if the numeric instance is less than or equal to'
+ ' the given number.'
+ ),
)
-
-
-class DynamicRetrievalConfigDict(TypedDict, total=False):
- """Describes the options to customize dynamic retrieval."""
-
- dynamic_threshold: Optional[float]
- """Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used."""
-
- mode: Optional[DynamicRetrievalConfigMode]
- """The mode of the predictor to be used in dynamic retrieval."""
-
-
-DynamicRetrievalConfigOrDict = Union[
- DynamicRetrievalConfig, DynamicRetrievalConfigDict
-]
-
-
-class GoogleSearchRetrieval(_common.BaseModel):
- """Tool to retrieve public web data for grounding, powered by Google."""
-
- dynamic_retrieval_config: Optional[DynamicRetrievalConfig] = Field(
+ min_length: Optional[int] = Field(
default=None,
- description="""Specifies the dynamic retrieval configuration for the given source.""",
+ description=(
+ 'A string instance is valid against this keyword if its length is'
+ ' greater than, or equal to, the value of this keyword.'
+ ),
)
-
-
-class GoogleSearchRetrievalDict(TypedDict, total=False):
- """Tool to retrieve public web data for grounding, powered by Google."""
-
- dynamic_retrieval_config: Optional[DynamicRetrievalConfigDict]
- """Specifies the dynamic retrieval configuration for the given source."""
-
-
-GoogleSearchRetrievalOrDict = Union[
- GoogleSearchRetrieval, GoogleSearchRetrievalDict
-]
-
-
-class UrlContext(_common.BaseModel):
- """Tool to support URL context."""
-
- pass
-
-
-class UrlContextDict(TypedDict, total=False):
- """Tool to support URL context."""
-
- pass
-
-
-UrlContextOrDict = Union[UrlContext, UrlContextDict]
-
-
-class Tool(_common.BaseModel):
- """Tool details of a tool that the model may use to generate a response."""
-
- retrieval: Optional[Retrieval] = Field(
+ max_length: Optional[int] = Field(
default=None,
- 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.""",
+ description=(
+ 'A string instance is valid against this keyword if its length is'
+ ' less than, or equal to, the value of this keyword.'
+ ),
)
- computer_use: Optional[ComputerUse] = Field(
+ pattern: Optional[str] = Field(
default=None,
- description="""Optional. Tool to support the model interacting directly with the
- computer. If enabled, it automatically populates computer-use specific
- Function Declarations.""",
+ description=(
+ 'A string instance is considered valid if the regular expression'
+ ' matches the instance successfully.'
+ ),
)
- file_search: Optional[FileSearch] = Field(
+ additional_properties: Optional[Any] = Field(
default=None,
- description="""Optional. Tool to retrieve knowledge from the File Search Stores.""",
+ description="""Can either be a boolean or an object; controls the presence of additional properties.""",
)
- code_execution: Optional[ToolCodeExecution] = Field(
+ any_of: Optional[list['JSONSchema']] = Field(
default=None,
- description="""Optional. CodeExecution tool type. Enables the model to execute code as part of generation.""",
+ description=(
+ 'An instance validates successfully against this keyword if it'
+ ' validates successfully against at least one schema defined by this'
+ ' keyword’s value.'
+ ),
)
- enterprise_web_search: Optional[EnterpriseWebSearch] = Field(
+ unique_items: Optional[bool] = Field(
default=None,
- 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.""",
+ description="""Boolean value that indicates whether the items in an array are unique.""",
)
- function_declarations: Optional[list[FunctionDeclaration]] = Field(
+ ref: Optional[str] = Field(
default=None,
- 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.""",
+ alias='$ref',
+ description="""Allows indirect references between schema nodes.""",
)
- google_maps: Optional[GoogleMaps] = Field(
+ defs: Optional[dict[str, 'JSONSchema']] = Field(
default=None,
- description="""Optional. GoogleMaps tool type. Tool to support Google Maps in Model.""",
+ alias='$defs',
+ description="""Schema definitions to be used with $ref.""",
)
- google_search: Optional[GoogleSearch] = Field(
+
+
+class ImageConfig(_common.BaseModel):
+ """The image generation configuration to be used in GenerateContentConfig."""
+
+ aspect_ratio: Optional[str] = Field(
default=None,
- description="""Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google.""",
+ description="""Aspect ratio of the generated images. Supported values are
+ "1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9".""",
)
- google_search_retrieval: Optional[GoogleSearchRetrieval] = Field(
+ image_size: Optional[str] = Field(
default=None,
- description="""Optional. Specialized retrieval tool that is powered by Google Search.""",
+ description="""Optional. Specifies the size of generated images. Supported
+ values are `1K`, `2K`, `4K`. If not specified, the model will use default
+ value `1K`.""",
)
- url_context: Optional[UrlContext] = Field(
+ person_generation: Optional[str] = Field(
default=None,
- description="""Optional. Tool to support URL context retrieval.""",
+ description="""Controls the generation of people. Supported values are:
+ ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE.""",
+ )
+ output_mime_type: Optional[str] = Field(
+ default=None,
+ description="""MIME type of the generated image. This field is not
+ supported in Gemini API.""",
+ )
+ output_compression_quality: Optional[int] = Field(
+ default=None,
+ description="""Compression quality of the generated image (for
+ ``image/jpeg`` only). This field is not supported in Gemini API.""",
)
-class ToolDict(TypedDict, total=False):
- """Tool details of a tool that the model may use to generate a response."""
+class ImageConfigDict(TypedDict, total=False):
+ """The image generation configuration to be used in GenerateContentConfig."""
- retrieval: Optional[RetrievalDict]
- """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."""
+ aspect_ratio: Optional[str]
+ """Aspect ratio of the generated images. Supported values are
+ "1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9"."""
- computer_use: Optional[ComputerUseDict]
- """Optional. Tool to support the model interacting directly with the
- computer. If enabled, it automatically populates computer-use specific
- Function Declarations."""
+ image_size: Optional[str]
+ """Optional. Specifies the size of generated images. Supported
+ values are `1K`, `2K`, `4K`. If not specified, the model will use default
+ value `1K`."""
- file_search: Optional[FileSearchDict]
- """Optional. Tool to retrieve knowledge from the File Search Stores."""
+ person_generation: Optional[str]
+ """Controls the generation of people. Supported values are:
+ ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE."""
- code_execution: Optional[ToolCodeExecutionDict]
- """Optional. CodeExecution tool type. Enables the model to execute code as part of generation."""
+ output_mime_type: Optional[str]
+ """MIME type of the generated image. This field is not
+ supported in Gemini API."""
- enterprise_web_search: Optional[EnterpriseWebSearchDict]
- """Optional. Tool to support searching public web data, powered by Vertex AI Search and Sec4 compliance. This field is not supported in Gemini API."""
+ output_compression_quality: Optional[int]
+ """Compression quality of the generated image (for
+ ``image/jpeg`` only). This field is not supported in Gemini API."""
- function_declarations: Optional[list[FunctionDeclarationDict]]
- """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."""
- google_maps: Optional[GoogleMapsDict]
- """Optional. GoogleMaps tool type. Tool to support Google Maps in Model."""
+ImageConfigOrDict = Union[ImageConfig, ImageConfigDict]
- google_search: Optional[GoogleSearchDict]
- """Optional. GoogleSearch tool type. Tool to support Google Search in Model. Powered by Google."""
- google_search_retrieval: Optional[GoogleSearchRetrievalDict]
- """Optional. Specialized retrieval tool that is powered by Google Search."""
+class AutomaticFunctionCallingConfig(_common.BaseModel):
+ """The configuration for automatic function calling."""
- url_context: Optional[UrlContextDict]
- """Optional. Tool to support URL context retrieval."""
+ disable: Optional[bool] = Field(
+ default=None,
+ description="""Whether to disable automatic function calling.
+ If not set or set to False, will enable automatic function calling.
+ If set to True, will disable automatic function calling.
+ """,
+ )
+ maximum_remote_calls: Optional[int] = Field(
+ default=10,
+ description="""If automatic function calling is enabled,
+ maximum number of remote calls for automatic function calling.
+ This number should be a positive integer.
+ If not set, SDK will set maximum number of remote calls to 10.
+ """,
+ )
+ ignore_call_history: Optional[bool] = Field(
+ default=None,
+ description="""If automatic function calling is enabled,
+ whether to ignore call history to the response.
+ If not set, SDK will set ignore_call_history to false,
+ and will append the call history to
+ GenerateContentResponse.automatic_function_calling_history.
+ """,
+ )
-ToolOrDict = Union[Tool, ToolDict]
-if _is_mcp_imported:
- ToolUnion = Union[Tool, Callable[..., Any], mcp_types.Tool, McpClientSession]
- ToolUnionDict = Union[
- ToolDict, Callable[..., Any], mcp_types.Tool, McpClientSession
- ]
-else:
- ToolUnion = Union[Tool, Callable[..., Any]] # type: ignore[misc]
- ToolUnionDict = Union[ToolDict, Callable[..., Any]] # type: ignore[misc]
+class AutomaticFunctionCallingConfigDict(TypedDict, total=False):
+ """The configuration for automatic function calling."""
-ToolListUnion = list[ToolUnion]
-ToolListUnionDict = list[ToolUnionDict]
+ disable: Optional[bool]
+ """Whether to disable automatic function calling.
+ If not set or set to False, will enable automatic function calling.
+ If set to True, will disable automatic function calling.
+ """
-SchemaUnion = Union[
- dict[Any, Any], type, Schema, builtin_types.GenericAlias, VersionedUnionType # type: ignore[valid-type]
-]
-SchemaUnionDict = Union[SchemaUnion, SchemaDict]
+ maximum_remote_calls: Optional[int]
+ """If automatic function calling is enabled,
+ maximum number of remote calls for automatic function calling.
+ This number should be a positive integer.
+ If not set, SDK will set maximum number of remote calls to 10.
+ """
+
+ ignore_call_history: Optional[bool]
+ """If automatic function calling is enabled,
+ whether to ignore call history to the response.
+ If not set, SDK will set ignore_call_history to false,
+ and will append the call history to
+ GenerateContentResponse.automatic_function_calling_history.
+ """
-class LatLng(_common.BaseModel):
- """An object that represents a latitude/longitude pair.
+AutomaticFunctionCallingConfigOrDict = Union[
+ AutomaticFunctionCallingConfig, AutomaticFunctionCallingConfigDict
+]
- This is expressed as a pair of doubles to represent degrees latitude and
- degrees longitude. Unless specified otherwise, this object must conform to the
-
- WGS84 standard. Values must be within normalized ranges.
- """
- latitude: Optional[float] = Field(
- default=None,
- description="""The latitude in degrees. It must be in the range [-90.0, +90.0].""",
- )
- longitude: Optional[float] = Field(
- default=None,
- description="""The longitude in degrees. It must be in the range [-180.0, +180.0]""",
+class ModelSelectionConfig(_common.BaseModel):
+ """Config for model selection."""
+
+ feature_selection_preference: Optional[FeatureSelectionPreference] = Field(
+ default=None, description="""Options for feature selection preference."""
)
-class LatLngDict(TypedDict, total=False):
- """An object that represents a latitude/longitude pair.
+class ModelSelectionConfigDict(TypedDict, total=False):
+ """Config for model selection."""
- This is expressed as a pair of doubles to represent degrees latitude and
- degrees longitude. Unless specified otherwise, this object must conform to the
-
- WGS84 standard. Values must be within normalized ranges.
- """
+ feature_selection_preference: Optional[FeatureSelectionPreference]
+ """Options for feature selection preference."""
- latitude: Optional[float]
- """The latitude in degrees. It must be in the range [-90.0, +90.0]."""
- longitude: Optional[float]
- """The longitude in degrees. It must be in the range [-180.0, +180.0]"""
+ModelSelectionConfigOrDict = Union[
+ ModelSelectionConfig, ModelSelectionConfigDict
+]
-LatLngOrDict = Union[LatLng, LatLngDict]
+class GenerationConfigRoutingConfigAutoRoutingMode(_common.BaseModel):
+ """When automated routing is specified, the routing will be determined by the pretrained routing model and customer provided model routing preference.
+ This data type is not supported in Gemini API.
+ """
-class RetrievalConfig(_common.BaseModel):
- """Retrieval config."""
+ model_routing_preference: Optional[
+ Literal['UNKNOWN', 'PRIORITIZE_QUALITY', 'BALANCED', 'PRIORITIZE_COST']
+ ] = Field(default=None, description="""The model routing preference.""")
- lat_lng: Optional[LatLng] = Field(
- default=None, description="""Optional. The location of the user."""
- )
- language_code: Optional[str] = Field(
- default=None, description="""The language code of the user."""
- )
+class GenerationConfigRoutingConfigAutoRoutingModeDict(TypedDict, total=False):
+ """When automated routing is specified, the routing will be determined by the pretrained routing model and customer provided model routing preference.
-class RetrievalConfigDict(TypedDict, total=False):
- """Retrieval config."""
+ This data type is not supported in Gemini API.
+ """
- lat_lng: Optional[LatLngDict]
- """Optional. The location of the user."""
+ model_routing_preference: Optional[
+ Literal['UNKNOWN', 'PRIORITIZE_QUALITY', 'BALANCED', 'PRIORITIZE_COST']
+ ]
+ """The model routing preference."""
- language_code: Optional[str]
- """The language code of the user."""
+GenerationConfigRoutingConfigAutoRoutingModeOrDict = Union[
+ GenerationConfigRoutingConfigAutoRoutingMode,
+ GenerationConfigRoutingConfigAutoRoutingModeDict,
+]
-RetrievalConfigOrDict = Union[RetrievalConfig, RetrievalConfigDict]
+class GenerationConfigRoutingConfigManualRoutingMode(_common.BaseModel):
+ """When manual routing is set, the specified model will be used directly.
-class FunctionCallingConfig(_common.BaseModel):
- """Function calling config."""
+ This data type is not supported in Gemini API.
+ """
- allowed_function_names: Optional[list[str]] = Field(
- default=None,
- 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.""",
- )
- mode: Optional[FunctionCallingConfigMode] = Field(
- default=None, description="""Optional. Function calling mode."""
- )
- stream_function_call_arguments: Optional[bool] = Field(
+ model_name: Optional[str] = Field(
default=None,
- 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.""",
+ description="""The model name to use. Only the public LLM models are accepted. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models).""",
)
-class FunctionCallingConfigDict(TypedDict, total=False):
- """Function calling config."""
-
- allowed_function_names: Optional[list[str]]
- """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."""
+class GenerationConfigRoutingConfigManualRoutingModeDict(
+ TypedDict, total=False
+):
+ """When manual routing is set, the specified model will be used directly.
- mode: Optional[FunctionCallingConfigMode]
- """Optional. Function calling mode."""
+ This data type is not supported in Gemini API.
+ """
- stream_function_call_arguments: Optional[bool]
- """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."""
+ model_name: Optional[str]
+ """The model name to use. Only the public LLM models are accepted. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models)."""
-FunctionCallingConfigOrDict = Union[
- FunctionCallingConfig, FunctionCallingConfigDict
+GenerationConfigRoutingConfigManualRoutingModeOrDict = Union[
+ GenerationConfigRoutingConfigManualRoutingMode,
+ GenerationConfigRoutingConfigManualRoutingModeDict,
]
-class ToolConfig(_common.BaseModel):
- """Tool config.
+class GenerationConfigRoutingConfig(_common.BaseModel):
+ """The configuration for routing the request to a specific model.
- This config is shared for all tools provided in the request.
+ This data type is not supported in Gemini API.
"""
- retrieval_config: Optional[RetrievalConfig] = Field(
- default=None, description="""Optional. Retrieval config."""
+ auto_mode: Optional[GenerationConfigRoutingConfigAutoRoutingMode] = Field(
+ default=None, description="""Automated routing."""
)
- function_calling_config: Optional[FunctionCallingConfig] = Field(
- default=None, description="""Optional. Function calling config."""
+ manual_mode: Optional[GenerationConfigRoutingConfigManualRoutingMode] = Field(
+ default=None, description="""Manual routing."""
)
-class ToolConfigDict(TypedDict, total=False):
- """Tool config.
+class GenerationConfigRoutingConfigDict(TypedDict, total=False):
+ """The configuration for routing the request to a specific model.
- This config is shared for all tools provided in the request.
+ This data type is not supported in Gemini API.
"""
- retrieval_config: Optional[RetrievalConfigDict]
- """Optional. Retrieval config."""
+ auto_mode: Optional[GenerationConfigRoutingConfigAutoRoutingModeDict]
+ """Automated routing."""
- function_calling_config: Optional[FunctionCallingConfigDict]
- """Optional. Function calling config."""
+ manual_mode: Optional[GenerationConfigRoutingConfigManualRoutingModeDict]
+ """Manual routing."""
-ToolConfigOrDict = Union[ToolConfig, ToolConfigDict]
+GenerationConfigRoutingConfigOrDict = Union[
+ GenerationConfigRoutingConfig, GenerationConfigRoutingConfigDict
+]
class ReplicatedVoiceConfig(_common.BaseModel):
@@ -4535,159 +4744,210 @@ class SpeechConfigDict(TypedDict, total=False):
SpeechConfigOrDict = Union[SpeechConfig, SpeechConfigDict]
-class AutomaticFunctionCallingConfig(_common.BaseModel):
- """The configuration for automatic function calling."""
+class ThinkingConfig(_common.BaseModel):
+ """The thinking features configuration."""
- disable: Optional[bool] = Field(
+ include_thoughts: Optional[bool] = Field(
default=None,
- description="""Whether to disable automatic function calling.
- If not set or set to False, will enable automatic function calling.
- If set to True, will disable automatic function calling.
+ description="""Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available.
+ """,
+ )
+ thinking_budget: Optional[int] = Field(
+ default=None,
+ description="""Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
""",
)
- maximum_remote_calls: Optional[int] = Field(
- default=10,
- description="""If automatic function calling is enabled,
- maximum number of remote calls for automatic function calling.
- This number should be a positive integer.
- If not set, SDK will set maximum number of remote calls to 10.
- """,
+ thinking_level: Optional[ThinkingLevel] = Field(
+ default=None,
+ description="""Optional. The number of thoughts tokens that the model should generate.""",
+ )
+
+
+class ThinkingConfigDict(TypedDict, total=False):
+ """The thinking features configuration."""
+
+ include_thoughts: Optional[bool]
+ """Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available.
+ """
+
+ thinking_budget: Optional[int]
+ """Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
+ """
+
+ thinking_level: Optional[ThinkingLevel]
+ """Optional. The number of thoughts tokens that the model should generate."""
+
+
+ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
+
+
+class GenerationConfig(_common.BaseModel):
+ """Generation config."""
+
+ model_selection_config: Optional[ModelSelectionConfig] = Field(
+ default=None, description="""Optional. Config for model selection."""
+ )
+ audio_timestamp: Optional[bool] = Field(
+ default=None,
+ description="""Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API.""",
+ )
+ candidate_count: Optional[int] = Field(
+ default=None,
+ description="""Optional. Number of candidates to generate.""",
+ )
+ enable_affective_dialog: Optional[bool] = Field(
+ default=None,
+ description="""Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API.""",
+ )
+ frequency_penalty: Optional[float] = Field(
+ default=None, description="""Optional. Frequency penalties."""
+ )
+ logprobs: Optional[int] = Field(
+ default=None, description="""Optional. Logit probabilities."""
+ )
+ max_output_tokens: Optional[int] = Field(
+ default=None,
+ description="""Optional. The maximum number of output tokens to generate per message.""",
+ )
+ media_resolution: Optional[MediaResolution] = Field(
+ default=None,
+ description="""Optional. If specified, the media resolution specified will be used.""",
+ )
+ presence_penalty: Optional[float] = Field(
+ default=None, description="""Optional. Positive penalties."""
+ )
+ response_json_schema: Optional[Any] = Field(
+ default=None,
+ description="""Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set.""",
+ )
+ response_logprobs: Optional[bool] = Field(
+ default=None,
+ description="""Optional. If true, export the logprobs results in response.""",
+ )
+ response_mime_type: Optional[str] = Field(
+ default=None,
+ description="""Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature.""",
+ )
+ response_modalities: Optional[list[Modality]] = Field(
+ default=None, description="""Optional. The modalities of the response."""
+ )
+ response_schema: Optional[Schema] = Field(
+ default=None,
+ description="""Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response.""",
+ )
+ routing_config: Optional[GenerationConfigRoutingConfig] = Field(
+ default=None,
+ description="""Optional. Routing configuration. This field is not supported in Gemini API.""",
+ )
+ seed: Optional[int] = Field(default=None, description="""Optional. Seed.""")
+ speech_config: Optional[SpeechConfig] = Field(
+ default=None, description="""Optional. The speech generation config."""
+ )
+ stop_sequences: Optional[list[str]] = Field(
+ default=None, description="""Optional. Stop sequences."""
+ )
+ temperature: Optional[float] = Field(
+ default=None,
+ description="""Optional. Controls the randomness of predictions.""",
+ )
+ thinking_config: Optional[ThinkingConfig] = Field(
+ default=None,
+ description="""Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking.""",
+ )
+ top_k: Optional[float] = Field(
+ default=None,
+ description="""Optional. If specified, top-k sampling will be used.""",
+ )
+ top_p: Optional[float] = Field(
+ default=None,
+ description="""Optional. If specified, nucleus sampling will be used.""",
)
- ignore_call_history: Optional[bool] = Field(
+ enable_enhanced_civic_answers: Optional[bool] = Field(
default=None,
- description="""If automatic function calling is enabled,
- whether to ignore call history to the response.
- If not set, SDK will set ignore_call_history to false,
- and will append the call history to
- GenerateContentResponse.automatic_function_calling_history.
- """,
+ description="""Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI.""",
)
-class AutomaticFunctionCallingConfigDict(TypedDict, total=False):
- """The configuration for automatic function calling."""
+class GenerationConfigDict(TypedDict, total=False):
+ """Generation config."""
- disable: Optional[bool]
- """Whether to disable automatic function calling.
- If not set or set to False, will enable automatic function calling.
- If set to True, will disable automatic function calling.
- """
+ model_selection_config: Optional[ModelSelectionConfigDict]
+ """Optional. Config for model selection."""
- maximum_remote_calls: Optional[int]
- """If automatic function calling is enabled,
- maximum number of remote calls for automatic function calling.
- This number should be a positive integer.
- If not set, SDK will set maximum number of remote calls to 10.
- """
+ audio_timestamp: Optional[bool]
+ """Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API."""
- ignore_call_history: Optional[bool]
- """If automatic function calling is enabled,
- whether to ignore call history to the response.
- If not set, SDK will set ignore_call_history to false,
- and will append the call history to
- GenerateContentResponse.automatic_function_calling_history.
- """
+ candidate_count: Optional[int]
+ """Optional. Number of candidates to generate."""
+ enable_affective_dialog: Optional[bool]
+ """Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API."""
-AutomaticFunctionCallingConfigOrDict = Union[
- AutomaticFunctionCallingConfig, AutomaticFunctionCallingConfigDict
-]
+ frequency_penalty: Optional[float]
+ """Optional. Frequency penalties."""
+ logprobs: Optional[int]
+ """Optional. Logit probabilities."""
-class ThinkingConfig(_common.BaseModel):
- """The thinking features configuration."""
+ max_output_tokens: Optional[int]
+ """Optional. The maximum number of output tokens to generate per message."""
- include_thoughts: Optional[bool] = Field(
- default=None,
- description="""Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available.
- """,
- )
- thinking_budget: Optional[int] = Field(
- default=None,
- description="""Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
- """,
- )
- thinking_level: Optional[ThinkingLevel] = Field(
- default=None,
- description="""Optional. The number of thoughts tokens that the model should generate.""",
- )
+ media_resolution: Optional[MediaResolution]
+ """Optional. If specified, the media resolution specified will be used."""
+ presence_penalty: Optional[float]
+ """Optional. Positive penalties."""
-class ThinkingConfigDict(TypedDict, total=False):
- """The thinking features configuration."""
+ response_json_schema: Optional[Any]
+ """Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set."""
- include_thoughts: Optional[bool]
- """Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available.
- """
+ response_logprobs: Optional[bool]
+ """Optional. If true, export the logprobs results in response."""
- thinking_budget: Optional[int]
- """Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent.
- """
+ response_mime_type: Optional[str]
+ """Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature."""
- thinking_level: Optional[ThinkingLevel]
- """Optional. The number of thoughts tokens that the model should generate."""
+ response_modalities: Optional[list[Modality]]
+ """Optional. The modalities of the response."""
+ response_schema: Optional[SchemaDict]
+ """Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response."""
-ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
+ routing_config: Optional[GenerationConfigRoutingConfigDict]
+ """Optional. Routing configuration. This field is not supported in Gemini API."""
+ seed: Optional[int]
+ """Optional. Seed."""
-class ImageConfig(_common.BaseModel):
- """The image generation configuration to be used in GenerateContentConfig."""
+ speech_config: Optional[SpeechConfigDict]
+ """Optional. The speech generation config."""
- aspect_ratio: Optional[str] = Field(
- default=None,
- description="""Aspect ratio of the generated images. Supported values are
- "1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9".""",
- )
- image_size: Optional[str] = Field(
- default=None,
- description="""Optional. Specifies the size of generated images. Supported
- values are `1K`, `2K`, `4K`. If not specified, the model will use default
- value `1K`.""",
- )
- person_generation: Optional[str] = Field(
- default=None,
- description="""Controls the generation of people. Supported values are:
- ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE.""",
- )
- output_mime_type: Optional[str] = Field(
- default=None,
- description="""MIME type of the generated image. This field is not
- supported in Gemini API.""",
- )
- output_compression_quality: Optional[int] = Field(
- default=None,
- description="""Compression quality of the generated image (for
- ``image/jpeg`` only). This field is not supported in Gemini API.""",
- )
+ stop_sequences: Optional[list[str]]
+ """Optional. Stop sequences."""
+ temperature: Optional[float]
+ """Optional. Controls the randomness of predictions."""
-class ImageConfigDict(TypedDict, total=False):
- """The image generation configuration to be used in GenerateContentConfig."""
+ thinking_config: Optional[ThinkingConfigDict]
+ """Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking."""
- aspect_ratio: Optional[str]
- """Aspect ratio of the generated images. Supported values are
- "1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9"."""
+ top_k: Optional[float]
+ """Optional. If specified, top-k sampling will be used."""
- image_size: Optional[str]
- """Optional. Specifies the size of generated images. Supported
- values are `1K`, `2K`, `4K`. If not specified, the model will use default
- value `1K`."""
+ top_p: Optional[float]
+ """Optional. If specified, nucleus sampling will be used."""
- person_generation: Optional[str]
- """Controls the generation of people. Supported values are:
- ALLOW_ALL, ALLOW_ADULT, ALLOW_NONE."""
+ enable_enhanced_civic_answers: Optional[bool]
+ """Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI."""
- output_mime_type: Optional[str]
- """MIME type of the generated image. This field is not
- supported in Gemini API."""
- output_compression_quality: Optional[int]
- """Compression quality of the generated image (for
- ``image/jpeg`` only). This field is not supported in Gemini API."""
+GenerationConfigOrDict = Union[GenerationConfig, GenerationConfigDict]
-ImageConfigOrDict = Union[ImageConfig, ImageConfigDict]
+SpeechConfigUnion = Union[str, SpeechConfig]
+
+
+SpeechConfigUnionDict = Union[str, SpeechConfig, SpeechConfigDict]
class FileStatus(_common.BaseModel):
@@ -4798,142 +5058,51 @@ class FileDict(TypedDict, total=False):
expiration_time: Optional[datetime.datetime]
"""Output only. The timestamp of when the `File` will be deleted. Only set if the `File` is scheduled to expire."""
- update_time: Optional[datetime.datetime]
- """Output only. The timestamp of when the `File` was last updated."""
-
- sha256_hash: Optional[str]
- """Output only. SHA-256 hash of the uploaded bytes. The hash value is encoded in base64 format."""
-
- uri: Optional[str]
- """Output only. The URI of the `File`."""
-
- download_uri: Optional[str]
- """Output only. The URI of the `File`, only set for downloadable (generated) files."""
-
- state: Optional[FileState]
- """Output only. Processing state of the File."""
-
- source: Optional[FileSource]
- """Output only. The source of the `File`."""
-
- video_metadata: Optional[dict[str, Any]]
- """Output only. Metadata for a video."""
-
- error: Optional[FileStatusDict]
- """Output only. Error status if File processing failed."""
-
-
-FileOrDict = Union[File, FileDict]
-
-
-if _is_pillow_image_imported:
- PartUnion = Union[str, PIL_Image, File, Part]
-else:
- PartUnion = Union[str, File, Part] # type: ignore[misc]
-
-
-if _is_pillow_image_imported:
- PartUnionDict = Union[str, PIL_Image, File, FileDict, Part, PartDict]
-else:
- PartUnionDict = Union[str, File, FileDict, Part, PartDict] # type: ignore[misc]
-
-
-ContentUnion = Union[Content, PartUnion, list[PartUnion]]
-
-
-ContentUnionDict = Union[
- Content, ContentDict, PartUnionDict, list[PartUnionDict]
-]
-
-
-class GenerationConfigRoutingConfigAutoRoutingMode(_common.BaseModel):
- """When automated routing is specified, the routing will be determined by the pretrained routing model and customer provided model routing preference.
-
- This data type is not supported in Gemini API.
- """
-
- model_routing_preference: Optional[
- Literal['UNKNOWN', 'PRIORITIZE_QUALITY', 'BALANCED', 'PRIORITIZE_COST']
- ] = Field(default=None, description="""The model routing preference.""")
-
-
-class GenerationConfigRoutingConfigAutoRoutingModeDict(TypedDict, total=False):
- """When automated routing is specified, the routing will be determined by the pretrained routing model and customer provided model routing preference.
-
- This data type is not supported in Gemini API.
- """
-
- model_routing_preference: Optional[
- Literal['UNKNOWN', 'PRIORITIZE_QUALITY', 'BALANCED', 'PRIORITIZE_COST']
- ]
- """The model routing preference."""
-
-
-GenerationConfigRoutingConfigAutoRoutingModeOrDict = Union[
- GenerationConfigRoutingConfigAutoRoutingMode,
- GenerationConfigRoutingConfigAutoRoutingModeDict,
-]
-
-
-class GenerationConfigRoutingConfigManualRoutingMode(_common.BaseModel):
- """When manual routing is set, the specified model will be used directly.
-
- This data type is not supported in Gemini API.
- """
-
- model_name: Optional[str] = Field(
- default=None,
- description="""The model name to use. Only the public LLM models are accepted. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models).""",
- )
-
+ update_time: Optional[datetime.datetime]
+ """Output only. The timestamp of when the `File` was last updated."""
-class GenerationConfigRoutingConfigManualRoutingModeDict(
- TypedDict, total=False
-):
- """When manual routing is set, the specified model will be used directly.
+ sha256_hash: Optional[str]
+ """Output only. SHA-256 hash of the uploaded bytes. The hash value is encoded in base64 format."""
- This data type is not supported in Gemini API.
- """
+ uri: Optional[str]
+ """Output only. The URI of the `File`."""
- model_name: Optional[str]
- """The model name to use. Only the public LLM models are accepted. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models)."""
+ download_uri: Optional[str]
+ """Output only. The URI of the `File`, only set for downloadable (generated) files."""
+ state: Optional[FileState]
+ """Output only. Processing state of the File."""
-GenerationConfigRoutingConfigManualRoutingModeOrDict = Union[
- GenerationConfigRoutingConfigManualRoutingMode,
- GenerationConfigRoutingConfigManualRoutingModeDict,
-]
+ source: Optional[FileSource]
+ """Output only. The source of the `File`."""
+ video_metadata: Optional[dict[str, Any]]
+ """Output only. Metadata for a video."""
-class GenerationConfigRoutingConfig(_common.BaseModel):
- """The configuration for routing the request to a specific model.
+ error: Optional[FileStatusDict]
+ """Output only. Error status if File processing failed."""
- This data type is not supported in Gemini API.
- """
- auto_mode: Optional[GenerationConfigRoutingConfigAutoRoutingMode] = Field(
- default=None, description="""Automated routing."""
- )
- manual_mode: Optional[GenerationConfigRoutingConfigManualRoutingMode] = Field(
- default=None, description="""Manual routing."""
- )
+FileOrDict = Union[File, FileDict]
-class GenerationConfigRoutingConfigDict(TypedDict, total=False):
- """The configuration for routing the request to a specific model.
+if _is_pillow_image_imported:
+ PartUnion = Union[str, PIL_Image, File, Part]
+else:
+ PartUnion = Union[str, File, Part] # type: ignore[misc]
- This data type is not supported in Gemini API.
- """
- auto_mode: Optional[GenerationConfigRoutingConfigAutoRoutingModeDict]
- """Automated routing."""
+if _is_pillow_image_imported:
+ PartUnionDict = Union[str, PIL_Image, File, FileDict, Part, PartDict]
+else:
+ PartUnionDict = Union[str, File, FileDict, Part, PartDict] # type: ignore[misc]
- manual_mode: Optional[GenerationConfigRoutingConfigManualRoutingModeDict]
- """Manual routing."""
+
+ContentUnion = Union[Content, PartUnion, list[PartUnion]]
-GenerationConfigRoutingConfigOrDict = Union[
- GenerationConfigRoutingConfig, GenerationConfigRoutingConfigDict
+ContentUnionDict = Union[
+ Content, ContentDict, PartUnionDict, list[PartUnionDict]
]
@@ -4968,12 +5137,6 @@ class SafetySettingDict(TypedDict, total=False):
SafetySettingOrDict = Union[SafetySetting, SafetySettingDict]
-SpeechConfigUnion = Union[str, SpeechConfig]
-
-
-SpeechConfigUnionDict = Union[str, SpeechConfig, SpeechConfigDict]
-
-
class GenerateContentConfig(_common.BaseModel):
"""Optional model configuration parameters.
@@ -4981,143 +5144,100 @@ class GenerateContentConfig(_common.BaseModel):
`_.
"""
- http_options: Optional[HttpOptions] = Field(
- default=None, description="""Used to override HTTP request options."""
+ model_selection_config: Optional[ModelSelectionConfig] = Field(
+ default=None, description="""Optional. Config for model selection."""
)
- should_return_http_response: Optional[bool] = Field(
+ audio_timestamp: Optional[bool] = Field(
default=None,
- description=""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field.""",
+ description="""Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API.""",
)
- system_instruction: Optional[ContentUnion] = Field(
+ candidate_count: Optional[int] = Field(
default=None,
- description="""Instructions for the model to steer it toward better performance.
- For example, "Answer as concisely as possible" or "Don't use technical
- terms in your response".
- """,
+ description="""Optional. Number of candidates to generate.""",
)
- temperature: Optional[float] = Field(
+ enable_affective_dialog: Optional[bool] = Field(
default=None,
- description="""Value that controls the degree of randomness in token selection.
- Lower temperatures are good for prompts that require a less open-ended or
- creative response, while higher temperatures can lead to more diverse or
- creative results.
- """,
+ description="""Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API.""",
)
- top_p: Optional[float] = Field(
- default=None,
- description="""Tokens are selected from the most to least probable until the sum
- of their probabilities equals this value. Use a lower value for less
- random responses and a higher value for more random responses.
- """,
+ frequency_penalty: Optional[float] = Field(
+ default=None, description="""Optional. Frequency penalties."""
)
- top_k: Optional[float] = Field(
- default=None,
- description="""For each token selection step, the ``top_k`` tokens with the
- highest probabilities are sampled. Then tokens are further filtered based
- on ``top_p`` with the final token selected using temperature sampling. Use
- a lower number for less random responses and a higher number for more
- random responses.
- """,
+ logprobs: Optional[int] = Field(
+ default=None, description="""Optional. Logit probabilities."""
)
- candidate_count: Optional[int] = Field(
+ max_output_tokens: Optional[int] = Field(
default=None,
- description="""Number of response variations to return.
- """,
+ description="""Optional. The maximum number of output tokens to generate per message.""",
)
- max_output_tokens: Optional[int] = Field(
+ media_resolution: Optional[MediaResolution] = Field(
default=None,
- description="""Maximum number of tokens that can be generated in the response.
- """,
+ description="""Optional. If specified, the media resolution specified will be used.""",
)
- stop_sequences: Optional[list[str]] = Field(
+ presence_penalty: Optional[float] = Field(
+ default=None, description="""Optional. Positive penalties."""
+ )
+ response_json_schema: Optional[Any] = Field(
default=None,
- description="""List of strings that tells the model to stop generating text if one
- of the strings is encountered in the response.
- """,
+ description="""Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set.""",
)
response_logprobs: Optional[bool] = Field(
default=None,
- description="""Whether to return the log probabilities of the tokens that were
- chosen by the model at each step.
- """,
+ description="""Optional. If true, export the logprobs results in response.""",
)
- logprobs: Optional[int] = Field(
+ response_mime_type: Optional[str] = Field(
default=None,
- description="""Number of top candidate tokens to return the log probabilities for
- at each generation step.
- """,
+ description="""Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature.""",
)
- presence_penalty: Optional[float] = Field(
+ response_modalities: Optional[list[str]] = Field(
+ default=None, description="""Optional. The modalities of the response."""
+ )
+ response_schema: Optional[SchemaUnion] = Field(
default=None,
- description="""Positive values penalize tokens that already appear in the
- generated text, increasing the probability of generating more diverse
- content.
- """,
+ description="""Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response.""",
)
- frequency_penalty: Optional[float] = Field(
+ routing_config: Optional[GenerationConfigRoutingConfig] = Field(
default=None,
- description="""Positive values penalize tokens that repeatedly appear in the
- generated text, increasing the probability of generating more diverse
- content.
- """,
+ description="""Optional. Routing configuration. This field is not supported in Gemini API.""",
)
- seed: Optional[int] = Field(
+ seed: Optional[int] = Field(default=None, description="""Optional. Seed.""")
+ speech_config: Optional[SpeechConfigUnion] = Field(
+ default=None, description="""Optional. The speech generation config."""
+ )
+ stop_sequences: Optional[list[str]] = Field(
+ default=None, description="""Optional. Stop sequences."""
+ )
+ temperature: Optional[float] = Field(
default=None,
- description="""When ``seed`` is fixed to a specific number, the model makes a best
- effort to provide the same response for repeated requests. By default, a
- random number is used.
- """,
+ description="""Optional. Controls the randomness of predictions.""",
)
- response_mime_type: Optional[str] = Field(
+ thinking_config: Optional[ThinkingConfig] = Field(
default=None,
- description="""Output response mimetype of the generated candidate text.
- Supported mimetype:
- - `text/plain`: (default) Text output.
- - `application/json`: JSON response in the candidates.
- The model needs to be prompted to output the appropriate response type,
- otherwise the behavior is undefined.
- This is a preview feature.
- """,
+ description="""Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking.""",
)
- response_schema: Optional[SchemaUnion] = Field(
+ top_k: Optional[float] = Field(
default=None,
- description="""The `Schema` object allows the definition of input and output data types.
- These types can be objects, but also primitives and arrays.
- Represents a select subset of an [OpenAPI 3.0 schema
- object](https://spec.openapis.org/oas/v3.0.3#schema).
- If set, a compatible response_mime_type must also be set.
- Compatible mimetypes: `application/json`: Schema for JSON response.
-
- If `response_schema` doesn't process your schema correctly, try using
- `response_json_schema` instead.
- """,
+ description="""Optional. If specified, top-k sampling will be used.""",
)
- response_json_schema: Optional[Any] = Field(
+ top_p: Optional[float] = Field(
default=None,
- description="""Optional. Output schema of the generated response.
- This is an alternative to `response_schema` that accepts [JSON
- Schema](https://json-schema.org/). If set, `response_schema` must be
- omitted, but `response_mime_type` is required. While the full JSON Schema
- may be sent, not all features are supported. Specifically, only the
- following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor`
- - `type` - `format` - `title` - `description` - `enum` (for strings and
- numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` -
- `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) -
- `properties` - `additionalProperties` - `required` The non-standard
- `propertyOrdering` property may also be set. Cyclic references are
- unrolled to a limited degree and, as such, may only be used within
- non-required properties. (Nullable properties are not sufficient.) If
- `$ref` is set on a sub-schema, no other properties, except for than those
- starting as a `$`, may be set.""",
+ description="""Optional. If specified, nucleus sampling will be used.""",
)
- routing_config: Optional[GenerationConfigRoutingConfig] = Field(
+ enable_enhanced_civic_answers: Optional[bool] = Field(
default=None,
- description="""Configuration for model router requests.
- """,
+ description="""Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI.""",
)
- model_selection_config: Optional[ModelSelectionConfig] = Field(
+ http_options: Optional[HttpOptions] = Field(
+ default=None, description="""Used to override HTTP request options."""
+ )
+ should_return_http_response: Optional[bool] = Field(
+ default=None,
+ description=""" If true, the raw HTTP response will be returned in the 'sdk_http_response' field.""",
+ )
+ system_instruction: Optional[ContentUnion] = Field(
default=None,
- description="""Configuration for model selection.
+ description="""Instructions for the model to steer it toward better performance.
+ For example, "Answer as concisely as possible" or "Don't use technical
+ terms in your response".
""",
)
safety_settings: Optional[list[SafetySetting]] = Field(
@@ -5147,47 +5267,14 @@ class GenerateContentConfig(_common.BaseModel):
requests.
""",
)
- response_modalities: Optional[list[str]] = Field(
- default=None,
- description="""The requested modalities of the response. Represents the set of
- modalities that the model can return.
- """,
- )
- media_resolution: Optional[MediaResolution] = Field(
- default=None,
- description="""If specified, the media resolution specified will be used.
- """,
- )
- speech_config: Optional[SpeechConfigUnion] = Field(
- default=None,
- description="""The speech generation configuration.
- """,
- )
- audio_timestamp: Optional[bool] = Field(
- default=None,
- description="""If enabled, audio timestamp will be included in the request to the
- model.
- """,
- )
- automatic_function_calling: Optional[AutomaticFunctionCallingConfig] = Field(
- default=None,
- description="""The configuration for automatic function calling.
- """,
- )
- thinking_config: Optional[ThinkingConfig] = Field(
- default=None,
- description="""The thinking features configuration.
- """,
- )
image_config: Optional[ImageConfig] = Field(
default=None,
description="""The image generation configuration.
""",
)
- enable_enhanced_civic_answers: Optional[bool] = Field(
+ automatic_function_calling: Optional[AutomaticFunctionCallingConfig] = Field(
default=None,
- description="""Enables enhanced civic answers. It may not be available for all
- models. This field is not supported in Vertex AI.
+ description="""The configuration for automatic function calling.
""",
)
@@ -5222,125 +5309,85 @@ class GenerateContentConfigDict(TypedDict, total=False):
`_.
"""
- http_options: Optional[HttpOptionsDict]
- """Used to override HTTP request options."""
+ model_selection_config: Optional[ModelSelectionConfigDict]
+ """Optional. Config for model selection."""
- should_return_http_response: Optional[bool]
- """ If true, the raw HTTP response will be returned in the 'sdk_http_response' field."""
+ audio_timestamp: Optional[bool]
+ """Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API."""
- system_instruction: Optional[ContentUnionDict]
- """Instructions for the model to steer it toward better performance.
- For example, "Answer as concisely as possible" or "Don't use technical
- terms in your response".
- """
+ candidate_count: Optional[int]
+ """Optional. Number of candidates to generate."""
- temperature: Optional[float]
- """Value that controls the degree of randomness in token selection.
- Lower temperatures are good for prompts that require a less open-ended or
- creative response, while higher temperatures can lead to more diverse or
- creative results.
- """
+ enable_affective_dialog: Optional[bool]
+ """Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API."""
- top_p: Optional[float]
- """Tokens are selected from the most to least probable until the sum
- of their probabilities equals this value. Use a lower value for less
- random responses and a higher value for more random responses.
- """
+ frequency_penalty: Optional[float]
+ """Optional. Frequency penalties."""
- top_k: Optional[float]
- """For each token selection step, the ``top_k`` tokens with the
- highest probabilities are sampled. Then tokens are further filtered based
- on ``top_p`` with the final token selected using temperature sampling. Use
- a lower number for less random responses and a higher number for more
- random responses.
- """
+ logprobs: Optional[int]
+ """Optional. Logit probabilities."""
- candidate_count: Optional[int]
- """Number of response variations to return.
- """
+ max_output_tokens: Optional[int]
+ """Optional. The maximum number of output tokens to generate per message."""
- max_output_tokens: Optional[int]
- """Maximum number of tokens that can be generated in the response.
- """
+ media_resolution: Optional[MediaResolution]
+ """Optional. If specified, the media resolution specified will be used."""
- stop_sequences: Optional[list[str]]
- """List of strings that tells the model to stop generating text if one
- of the strings is encountered in the response.
- """
+ presence_penalty: Optional[float]
+ """Optional. Positive penalties."""
+
+ response_json_schema: Optional[Any]
+ """Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/). If set, `response_schema` must be omitted, but `response_mime_type` is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required` The non-standard `propertyOrdering` property may also be set. Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set."""
response_logprobs: Optional[bool]
- """Whether to return the log probabilities of the tokens that were
- chosen by the model at each step.
- """
+ """Optional. If true, export the logprobs results in response."""
- logprobs: Optional[int]
- """Number of top candidate tokens to return the log probabilities for
- at each generation step.
- """
+ response_mime_type: Optional[str]
+ """Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature."""
- presence_penalty: Optional[float]
- """Positive values penalize tokens that already appear in the
- generated text, increasing the probability of generating more diverse
- content.
- """
+ response_modalities: Optional[list[str]]
+ """Optional. The modalities of the response."""
- frequency_penalty: Optional[float]
- """Positive values penalize tokens that repeatedly appear in the
- generated text, increasing the probability of generating more diverse
- content.
- """
+ response_schema: Optional[SchemaUnionDict]
+ """Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response."""
+
+ routing_config: Optional[GenerationConfigRoutingConfigDict]
+ """Optional. Routing configuration. This field is not supported in Gemini API."""
seed: Optional[int]
- """When ``seed`` is fixed to a specific number, the model makes a best
- effort to provide the same response for repeated requests. By default, a
- random number is used.
- """
+ """Optional. Seed."""
- response_mime_type: Optional[str]
- """Output response mimetype of the generated candidate text.
- Supported mimetype:
- - `text/plain`: (default) Text output.
- - `application/json`: JSON response in the candidates.
- The model needs to be prompted to output the appropriate response type,
- otherwise the behavior is undefined.
- This is a preview feature.
- """
+ speech_config: Optional[SpeechConfigUnionDict]
+ """Optional. The speech generation config."""
- response_schema: Optional[SchemaUnionDict]
- """The `Schema` object allows the definition of input and output data types.
- These types can be objects, but also primitives and arrays.
- Represents a select subset of an [OpenAPI 3.0 schema
- object](https://spec.openapis.org/oas/v3.0.3#schema).
- If set, a compatible response_mime_type must also be set.
- Compatible mimetypes: `application/json`: Schema for JSON response.
-
- If `response_schema` doesn't process your schema correctly, try using
- `response_json_schema` instead.
- """
+ stop_sequences: Optional[list[str]]
+ """Optional. Stop sequences."""
- response_json_schema: Optional[Any]
- """Optional. Output schema of the generated response.
- This is an alternative to `response_schema` that accepts [JSON
- Schema](https://json-schema.org/). If set, `response_schema` must be
- omitted, but `response_mime_type` is required. While the full JSON Schema
- may be sent, not all features are supported. Specifically, only the
- following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor`
- - `type` - `format` - `title` - `description` - `enum` (for strings and
- numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` -
- `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) -
- `properties` - `additionalProperties` - `required` The non-standard
- `propertyOrdering` property may also be set. Cyclic references are
- unrolled to a limited degree and, as such, may only be used within
- non-required properties. (Nullable properties are not sufficient.) If
- `$ref` is set on a sub-schema, no other properties, except for than those
- starting as a `$`, may be set."""
+ temperature: Optional[float]
+ """Optional. Controls the randomness of predictions."""
- routing_config: Optional[GenerationConfigRoutingConfigDict]
- """Configuration for model router requests.
- """
+ thinking_config: Optional[ThinkingConfigDict]
+ """Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking."""
- model_selection_config: Optional[ModelSelectionConfigDict]
- """Configuration for model selection.
+ top_k: Optional[float]
+ """Optional. If specified, top-k sampling will be used."""
+
+ top_p: Optional[float]
+ """Optional. If specified, nucleus sampling will be used."""
+
+ enable_enhanced_civic_answers: Optional[bool]
+ """Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI."""
+
+ http_options: Optional[HttpOptionsDict]
+ """Used to override HTTP request options."""
+
+ should_return_http_response: Optional[bool]
+ """ If true, the raw HTTP response will be returned in the 'sdk_http_response' field."""
+
+ system_instruction: Optional[ContentUnionDict]
+ """Instructions for the model to steer it toward better performance.
+ For example, "Answer as concisely as possible" or "Don't use technical
+ terms in your response".
"""
safety_settings: Optional[list[SafetySettingDict]]
@@ -5365,39 +5412,12 @@ class GenerateContentConfigDict(TypedDict, total=False):
requests.
"""
- response_modalities: Optional[list[str]]
- """The requested modalities of the response. Represents the set of
- modalities that the model can return.
- """
-
- media_resolution: Optional[MediaResolution]
- """If specified, the media resolution specified will be used.
- """
-
- speech_config: Optional[SpeechConfigUnionDict]
- """The speech generation configuration.
- """
-
- audio_timestamp: Optional[bool]
- """If enabled, audio timestamp will be included in the request to the
- model.
- """
-
- automatic_function_calling: Optional[AutomaticFunctionCallingConfigDict]
- """The configuration for automatic function calling.
- """
-
- thinking_config: Optional[ThinkingConfigDict]
- """The thinking features configuration.
- """
-
image_config: Optional[ImageConfigDict]
"""The image generation configuration.
"""
- enable_enhanced_civic_answers: Optional[bool]
- """Enables enhanced civic answers. It may not be available for all
- models. This field is not supported in Vertex AI.
+ automatic_function_calling: Optional[AutomaticFunctionCallingConfigDict]
+ """The configuration for automatic function calling.
"""
@@ -9223,173 +9243,6 @@ class DeleteModelResponseDict(TypedDict, total=False):
DeleteModelResponseOrDict = Union[DeleteModelResponse, DeleteModelResponseDict]
-class GenerationConfig(_common.BaseModel):
- """Generation config."""
-
- model_selection_config: Optional[ModelSelectionConfig] = Field(
- default=None, description="""Optional. Config for model selection."""
- )
- response_json_schema: Optional[Any] = Field(
- default=None,
- description="""Output schema of the generated response. This is an alternative to
- `response_schema` that accepts [JSON Schema](https://json-schema.org/).
- """,
- )
- audio_timestamp: Optional[bool] = Field(
- default=None,
- description="""Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API.""",
- )
- candidate_count: Optional[int] = Field(
- default=None,
- description="""Optional. Number of candidates to generate.""",
- )
- enable_affective_dialog: Optional[bool] = Field(
- default=None,
- description="""Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API.""",
- )
- frequency_penalty: Optional[float] = Field(
- default=None, description="""Optional. Frequency penalties."""
- )
- logprobs: Optional[int] = Field(
- default=None, description="""Optional. Logit probabilities."""
- )
- max_output_tokens: Optional[int] = Field(
- default=None,
- description="""Optional. The maximum number of output tokens to generate per message.""",
- )
- media_resolution: Optional[MediaResolution] = Field(
- default=None,
- description="""Optional. If specified, the media resolution specified will be used.""",
- )
- presence_penalty: Optional[float] = Field(
- default=None, description="""Optional. Positive penalties."""
- )
- response_logprobs: Optional[bool] = Field(
- default=None,
- description="""Optional. If true, export the logprobs results in response.""",
- )
- response_mime_type: Optional[str] = Field(
- default=None,
- description="""Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature.""",
- )
- response_modalities: Optional[list[Modality]] = Field(
- default=None, description="""Optional. The modalities of the response."""
- )
- response_schema: Optional[Schema] = Field(
- default=None,
- description="""Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response.""",
- )
- routing_config: Optional[GenerationConfigRoutingConfig] = Field(
- default=None,
- description="""Optional. Routing configuration. This field is not supported in Gemini API.""",
- )
- seed: Optional[int] = Field(default=None, description="""Optional. Seed.""")
- speech_config: Optional[SpeechConfig] = Field(
- default=None, description="""Optional. The speech generation config."""
- )
- stop_sequences: Optional[list[str]] = Field(
- default=None, description="""Optional. Stop sequences."""
- )
- temperature: Optional[float] = Field(
- default=None,
- description="""Optional. Controls the randomness of predictions.""",
- )
- thinking_config: Optional[ThinkingConfig] = Field(
- default=None,
- description="""Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking.""",
- )
- top_k: Optional[float] = Field(
- default=None,
- description="""Optional. If specified, top-k sampling will be used.""",
- )
- top_p: Optional[float] = Field(
- default=None,
- description="""Optional. If specified, nucleus sampling will be used.""",
- )
- enable_enhanced_civic_answers: Optional[bool] = Field(
- default=None,
- description="""Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI.""",
- )
-
-
-class GenerationConfigDict(TypedDict, total=False):
- """Generation config."""
-
- model_selection_config: Optional[ModelSelectionConfigDict]
- """Optional. Config for model selection."""
-
- response_json_schema: Optional[Any]
- """Output schema of the generated response. This is an alternative to
- `response_schema` that accepts [JSON Schema](https://json-schema.org/).
- """
-
- audio_timestamp: Optional[bool]
- """Optional. If enabled, audio timestamp will be included in the request to the model. This field is not supported in Gemini API."""
-
- candidate_count: Optional[int]
- """Optional. Number of candidates to generate."""
-
- enable_affective_dialog: Optional[bool]
- """Optional. If enabled, the model will detect emotions and adapt its responses accordingly. This field is not supported in Gemini API."""
-
- frequency_penalty: Optional[float]
- """Optional. Frequency penalties."""
-
- logprobs: Optional[int]
- """Optional. Logit probabilities."""
-
- max_output_tokens: Optional[int]
- """Optional. The maximum number of output tokens to generate per message."""
-
- media_resolution: Optional[MediaResolution]
- """Optional. If specified, the media resolution specified will be used."""
-
- presence_penalty: Optional[float]
- """Optional. Positive penalties."""
-
- response_logprobs: Optional[bool]
- """Optional. If true, export the logprobs results in response."""
-
- response_mime_type: Optional[str]
- """Optional. Output response mimetype of the generated candidate text. Supported mimetype: - `text/plain`: (default) Text output. - `application/json`: JSON response in the candidates. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature."""
-
- response_modalities: Optional[list[Modality]]
- """Optional. The modalities of the response."""
-
- response_schema: Optional[SchemaDict]
- """Optional. The `Schema` object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema). If set, a compatible response_mime_type must also be set. Compatible mimetypes: `application/json`: Schema for JSON response."""
-
- routing_config: Optional[GenerationConfigRoutingConfigDict]
- """Optional. Routing configuration. This field is not supported in Gemini API."""
-
- seed: Optional[int]
- """Optional. Seed."""
-
- speech_config: Optional[SpeechConfigDict]
- """Optional. The speech generation config."""
-
- stop_sequences: Optional[list[str]]
- """Optional. Stop sequences."""
-
- temperature: Optional[float]
- """Optional. Controls the randomness of predictions."""
-
- thinking_config: Optional[ThinkingConfigDict]
- """Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking."""
-
- top_k: Optional[float]
- """Optional. If specified, top-k sampling will be used."""
-
- top_p: Optional[float]
- """Optional. If specified, nucleus sampling will be used."""
-
- enable_enhanced_civic_answers: Optional[bool]
- """Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI."""
-
-
-GenerationConfigOrDict = Union[GenerationConfig, GenerationConfigDict]
-
-
class CountTokensConfig(_common.BaseModel):
"""Config for the count_tokens method."""