|
4 | 4 | from . import ModelProfile |
5 | 5 |
|
6 | 6 |
|
7 | | -def google_model_profile(model_name: str) -> ModelProfile | None: |
8 | | - """Get the model profile for a Google model.""" |
| 7 | +def google_model_profile(model_name: str, *, is_vertexai: bool = False) -> ModelProfile | None: |
| 8 | + """Get the model profile for a Google model. |
| 9 | +
|
| 10 | + Args: |
| 11 | + model_name: The name of the model. |
| 12 | + is_vertexai: Whether this is a Vertex AI model (as opposed to GLA). |
| 13 | + """ |
9 | 14 | is_image_model = 'image' in model_name |
| 15 | + # For GLA, use the transformer that inlines defs (defensive approach for recursive schemas) |
| 16 | + # For Vertex AI, use the regular transformer with enhanced JSON Schema support |
| 17 | + transformer_class = GoogleJsonSchemaTransformer if is_vertexai else GoogleGLAJsonSchemaTransformer |
10 | 18 | return ModelProfile( |
11 | | - json_schema_transformer=GoogleJsonSchemaTransformer, |
| 19 | + json_schema_transformer=transformer_class, |
12 | 20 | supports_image_output=is_image_model, |
13 | 21 | supports_json_schema_output=not is_image_model, |
14 | 22 | supports_json_object_output=not is_image_model, |
@@ -44,3 +52,15 @@ def transform(self, schema: JsonSchema) -> JsonSchema: |
44 | 52 | schema.pop('exclusiveMaximum', None) |
45 | 53 |
|
46 | 54 | return schema |
| 55 | + |
| 56 | + |
| 57 | +class GoogleGLAJsonSchemaTransformer(GoogleJsonSchemaTransformer): |
| 58 | + """Transforms the JSON Schema for Google's Generative Language API (GLA). |
| 59 | +
|
| 60 | + This transformer inlines $defs as a defensive measure for recursive schemas, |
| 61 | + which have historically had reliability issues on GLA. |
| 62 | + """ |
| 63 | + |
| 64 | + def __init__(self, schema: JsonSchema, *, strict: bool | None = None): |
| 65 | + # Initialize with prefer_inlined_defs=True to inline definitions |
| 66 | + super().__init__(schema, strict=strict, prefer_inlined_defs=True) |
0 commit comments