diff --git a/examples/ai-core/src/generate-object/google-vertex-tool.ts b/examples/ai-core/src/generate-object/google-vertex-tool.ts new file mode 100644 index 000000000000..f3676a99dc65 --- /dev/null +++ b/examples/ai-core/src/generate-object/google-vertex-tool.ts @@ -0,0 +1,31 @@ +import { vertex } from '@ai-sdk/google-vertex'; +import { generateObject } from 'ai'; +import 'dotenv/config'; +import { z } from 'zod'; + +async function main() { + const result = await generateObject({ + model: vertex('gemini-1.5-pro'), + mode: 'tool', + schema: z.object({ + recipe: z.object({ + name: z.string(), + ingredients: z.array( + z.object({ + name: z.string(), + amount: z.string(), + }), + ), + steps: z.array(z.string()), + }), + }), + prompt: 'Generate a lasagna recipe.', + }); + + console.log(JSON.stringify(result.object.recipe, null, 2)); + console.log(); + console.log('Token usage:', result.usage); + console.log('Finish reason:', result.finishReason); +} + +main().catch(console.error);