From 7c48d90daef71166690267b59e91c3e37cffb78b Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Fri, 27 Sep 2024 17:27:47 +0200 Subject: [PATCH] docs --- .../01-ai-sdk-providers/11-google-vertex.mdx | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/content/providers/01-ai-sdk-providers/11-google-vertex.mdx b/content/providers/01-ai-sdk-providers/11-google-vertex.mdx index 8177b6fcfb8..5b83ce4a221 100644 --- a/content/providers/01-ai-sdk-providers/11-google-vertex.mdx +++ b/content/providers/01-ai-sdk-providers/11-google-vertex.mdx @@ -111,6 +111,17 @@ const model = vertex('gemini-1.5-pro', { The following optional settings are available for Google Vertex models: +- **structuredOutputs** _boolean_ + + Optional. Enable structured output. Default is true. + + This is useful when the JSON Schema contains elements that are + not supported by the OpenAPI schema version that + Google Vertex uses. You can use this to disable + structured outputs if you need to. + + See [Troubleshooting: Schema Limitations](#troubleshooting-schema-limitations) for more details. + - **safetySettings** _Array\<\{ category: string; threshold: string \}\>_ Optional. Safety settings for the model. @@ -207,14 +218,46 @@ const { text } = await generateText({ }); ``` +### Troubleshooting: Schema Limitations + +The Google Vertex API uses a subset of the OpenAPI 3.0 schema, +which does not support features such as unions. +The errors that you get in this case look like this: + +`GenerateContentRequest.generation_config.response_schema.properties[occupation].type: must be specified` + +By default, structured outputs are enabled (and for tool calling they are required). +You can disable structured outputs for object generation as a workaround: + +```ts highlight="3,8" +const result = await generateObject({ + model: vertex('gemini-1.5-pro', { + structuredOutputs: false, + }), + schema: z.object({ + name: z.string(), + age: z.number(), + contact: z.union([ + z.object({ + type: z.literal('email'), + value: z.string(), + }), + z.object({ + type: z.literal('phone'), + value: z.string(), + }), + ]), + }), + prompt: 'Generate an example person for testing.', +}); +``` + ### Model Capabilities -| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | -| ----------------------- | ------------------- | ------------------- | ------------------- | ------------------- | -| `gemini-1.5-flash` | | | | | -| `gemini-1.5-pro` | | | | | -| `gemini-1.0-pro-vision` | | | | | -| `gemini-1.0-pro` | | | | | +| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | +| ------------------ | ------------------- | ------------------- | ------------------- | ------------------- | +| `gemini-1.5-flash` | | | | | +| `gemini-1.5-pro` | | | | | The table above lists popular models. You can also pass any available provider