Skip to content

Commit

Permalink
add tool example
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Sep 27, 2024
1 parent b8b93ff commit 7076218
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/ai-core/src/generate-object/google-vertex-tool.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 7076218

Please sign in to comment.