|
69 | 69 | _GENERATION_CONFIG_SCHEMA_PARAMS = {"response_schema", "response_mime_type"} |
70 | 70 |
|
71 | 71 |
|
72 | | -def _strip_unsupported_schema_fields(schema: dict[str, Any]) -> dict[str, Any]: |
73 | | - """Recursively remove JSON Schema fields not supported by VertexAI's Schema proto. |
74 | | -
|
75 | | - For example, Pydantic adds ``additionalProperties: false`` when a model uses |
76 | | - ``extra="forbid"``, but the VertexAI protobuf Schema type does not have that |
77 | | - field and raises a ``ParseError`` when it encounters it. |
78 | | - """ |
79 | | - _UNSUPPORTED = {"additionalProperties", "$defs", "$schema"} |
80 | | - result = {k: v for k, v in schema.items() if k not in _UNSUPPORTED} |
81 | | - if "properties" in result and isinstance(result["properties"], dict): |
82 | | - result["properties"] = { |
83 | | - k: _strip_unsupported_schema_fields(v) |
84 | | - for k, v in result["properties"].items() |
85 | | - } |
86 | | - if "items" in result and isinstance(result["items"], dict): |
87 | | - result["items"] = _strip_unsupported_schema_fields(result["items"]) |
88 | | - if "anyOf" in result and isinstance(result["anyOf"], list): |
89 | | - result["anyOf"] = [ |
90 | | - _strip_unsupported_schema_fields(s) if isinstance(s, dict) else s |
91 | | - for s in result["anyOf"] |
92 | | - ] |
93 | | - return result |
94 | | - |
95 | | - |
96 | 72 | def _extract_generation_config_params( |
97 | 73 | config: Any, exclude_schema: bool = True |
98 | 74 | ) -> dict[str, Any]: |
@@ -598,9 +574,7 @@ def _get_call_params_v2( |
598 | 574 | response_format, BaseModel |
599 | 575 | ): |
600 | 576 | # if we migrate to new google-genai-sdk, Pydantic models can be passed directly |
601 | | - schema = _strip_unsupported_schema_fields( |
602 | | - response_format.model_json_schema() |
603 | | - ) |
| 577 | + schema = response_format.model_json_schema() |
604 | 578 | else: |
605 | 579 | schema = response_format |
606 | 580 | params["response_mime_type"] = "application/json" |
|
0 commit comments