-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (provider/vertex): add schema support (#3147)
- Loading branch information
Showing
6 changed files
with
193 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/google-vertex': patch | ||
--- | ||
|
||
feat (provider/vertex): add schema support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
examples/ai-core/src/generate-object/google-vertex-tool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters