@@ -236,6 +236,42 @@ def transform_schema_node(node: Any) -> Any:
236236 return FunctionSchema (** schema ).model_dump (exclude_none = True , exclude_unset = True )
237237
238238
239+ if TYPE_CHECKING :
240+ from google .genai import types as genai_types
241+
242+
243+ def map_to_genai_schema (obj : dict [str , Any ]) -> genai_types .Schema :
244+ from google .genai import types
245+
246+ schema = map_to_gemini_function_schema (obj )
247+
248+ def normalize (node : Any ) -> Any :
249+ if isinstance (node , list ):
250+ return [normalize (item ) for item in node ]
251+
252+ if not isinstance (node , dict ):
253+ return node
254+
255+ key_map = {
256+ "anyOf" : "any_of" ,
257+ "$ref" : "ref" ,
258+ "$defs" : "defs" ,
259+ "maxItems" : "max_items" ,
260+ "minItems" : "min_items" ,
261+ "maxLength" : "max_length" ,
262+ "minLength" : "min_length" ,
263+ "maxProperties" : "max_properties" ,
264+ "minProperties" : "min_properties" ,
265+ }
266+
267+ normalized : dict [str , Any ] = {}
268+ for key , value in node .items ():
269+ normalized [key_map .get (key , key )] = normalize (value )
270+ return normalized
271+
272+ return types .Schema .model_validate (normalize (schema ))
273+
274+
239275def update_genai_kwargs (
240276 kwargs : dict [str , Any ], base_config : dict [str , Any ]
241277) -> dict [str , Any ]:
@@ -583,7 +619,7 @@ def reask_vertexai_tools(
583619 Kwargs modifications:
584620 - Adds: "contents" (tool response messages indicating validation errors)
585621 """
586- from instructor . client_vertexai import vertexai_function_response_parser
622+ from .. vertexai . client import vertexai_function_response_parser
587623
588624 kwargs = kwargs .copy ()
589625 reask_msgs = [
@@ -605,7 +641,7 @@ def reask_vertexai_json(
605641 Kwargs modifications:
606642 - Adds: "contents" (user message requesting JSON correction)
607643 """
608- from instructor . client_vertexai import vertexai_message_parser
644+ from .. vertexai . client import vertexai_message_parser
609645
610646 kwargs = kwargs .copy ()
611647
@@ -931,7 +967,7 @@ def handle_genai_tools(
931967 if "thinking_config" not in new_kwargs and user_thinking_config is not None :
932968 new_kwargs ["thinking_config" ] = user_thinking_config
933969
934- schema = map_to_gemini_function_schema (_get_model_schema (response_model ))
970+ schema = map_to_genai_schema (_get_model_schema (response_model ))
935971 function_definition = types .FunctionDeclaration (
936972 name = _get_model_name (response_model ),
937973 description = getattr (response_model , "__doc__" , None ),
@@ -951,7 +987,8 @@ def handle_genai_tools(
951987 "tools" : [types .Tool (function_declarations = [function_definition ])],
952988 "tool_config" : types .ToolConfig (
953989 function_calling_config = types .FunctionCallingConfig (
954- mode = "ANY" , allowed_function_names = [_get_model_name (response_model )]
990+ mode = types .FunctionCallingConfigMode .ANY ,
991+ allowed_function_names = [_get_model_name (response_model )],
955992 ),
956993 ),
957994 }
@@ -989,7 +1026,7 @@ def handle_vertexai_parallel_tools(
9891026 """
9901027 from typing import get_args
9911028
992- from instructor . client_vertexai import vertexai_process_response
1029+ from .. vertexai . client import vertexai_process_response
9931030 from instructor .dsl .parallel import VertexAIParallelModel
9941031
9951032 if new_kwargs .get ("stream" , False ):
@@ -1010,7 +1047,7 @@ def handle_vertexai_parallel_tools(
10101047def handle_vertexai_tools (
10111048 response_model : type [Any ] | None , new_kwargs : dict [str , Any ]
10121049) -> tuple [type [Any ] | None , dict [str , Any ]]:
1013- from instructor . client_vertexai import vertexai_process_response
1050+ from .. vertexai . client import vertexai_process_response
10141051
10151052 """
10161053 Handle Vertex AI tools mode.
0 commit comments