-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(amazon-bedrock): add Nova Web Grounding support #9885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huanshenyi
wants to merge
5
commits into
vercel:main
Choose a base branch
from
huanshenyi:feat/bedrock-nova-grounding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
111b2ec
feat(amazon-bedrock): add Nova Web Grounding support
huanshenyi fc26d96
fix(amazon-bedrock): update provider test for nova tools integration
huanshenyi 02f167b
fix(amazon-bedrock): exclude function tools when using provider-defin…
huanshenyi decb87e
fix(amazon-bedrock): remove novaTools export to fix load time
huanshenyi a015dcd
Merge branch 'main' into feat/bedrock-nova-grounding
huanshenyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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/amazon-bedrock': patch | ||
| --- | ||
|
|
||
| Add Nova Web Grounding support for Amazon Bedrock |
This file contains hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| import { LanguageModelV3ProviderDefinedTool } from '@ai-sdk/provider'; | ||
|
|
||
| /** | ||
| * Nova-specific tools that can be used with Nova models on Amazon Bedrock. | ||
| * These are system tools that are executed by the Bedrock service. | ||
| */ | ||
| export const novaTools = { | ||
| /** | ||
| * Nova Web Grounding tool for real-time web search and information retrieval. | ||
| * This is a system tool that is executed by the Bedrock service. | ||
| * | ||
| * Web Grounding provides a turnkey RAG option that allows Nova models to | ||
| * intelligently decide when to retrieve and incorporate relevant up-to-date | ||
| * information based on the context of the prompt. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { bedrock } from '@ai-sdk/amazon-bedrock'; | ||
| * import { generateText } from 'ai'; | ||
| * | ||
| * const result = await generateText({ | ||
| * model: bedrock('us.amazon.nova-premier-v1:0'), | ||
| * prompt: 'What are the current AWS Regions and their locations?', | ||
| * tools: { | ||
| * nova_grounding: bedrock.tools.nova_grounding(), | ||
| * }, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| nova_grounding: ( | ||
| args: Record<string, unknown> = {}, | ||
| ): LanguageModelV3ProviderDefinedTool => ({ | ||
| type: 'provider-defined' as const, | ||
| id: 'nova.nova_grounding', | ||
| name: 'nova_grounding', | ||
| args, | ||
| }), | ||
| }; |
163 changes: 163 additions & 0 deletions
163
packages/amazon-bedrock/src/bedrock-prepare-tools.test.ts
This file contains hidden or 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,163 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { prepareTools } from './bedrock-prepare-tools'; | ||
|
|
||
| describe('prepareTools', () => { | ||
| it('should return empty toolConfig when tools are null', async () => { | ||
| const result = await prepareTools({ | ||
| tools: undefined, | ||
| modelId: 'us.amazon.nova-premier-v1:0', | ||
| }); | ||
| expect(result).toEqual({ | ||
| toolConfig: {}, | ||
| additionalTools: undefined, | ||
| toolWarnings: [], | ||
| betas: new Set(), | ||
| }); | ||
| }); | ||
|
|
||
| it('should return empty toolConfig when tools are empty', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [], | ||
| modelId: 'us.amazon.nova-premier-v1:0', | ||
| }); | ||
| expect(result).toEqual({ | ||
| toolConfig: {}, | ||
| additionalTools: undefined, | ||
| toolWarnings: [], | ||
| betas: new Set(), | ||
| }); | ||
| }); | ||
|
|
||
| it('should correctly prepare function tools', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [ | ||
| { | ||
| type: 'function', | ||
| name: 'testFunction', | ||
| description: 'A test function', | ||
| inputSchema: { type: 'object', properties: {} }, | ||
| }, | ||
| ], | ||
| modelId: 'us.amazon.nova-premier-v1:0', | ||
| }); | ||
|
|
||
| expect(result.toolConfig.tools).toEqual([ | ||
| { | ||
| toolSpec: { | ||
| name: 'testFunction', | ||
| description: 'A test function', | ||
| inputSchema: { | ||
| json: { type: 'object', properties: {} }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(result.toolWarnings).toEqual([]); | ||
| }); | ||
|
|
||
| describe('Nova provider-defined tools', () => { | ||
| it('should correctly prepare nova_grounding tool', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [ | ||
| { | ||
| type: 'provider-defined', | ||
| id: 'nova.nova_grounding', | ||
| name: 'nova_grounding', | ||
| args: {}, | ||
| }, | ||
| ], | ||
| modelId: 'us.amazon.nova-premier-v1:0', | ||
| }); | ||
|
|
||
| expect(result.toolConfig.tools).toEqual([ | ||
| { | ||
| systemTool: { | ||
| name: 'nova_grounding', | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(result.toolWarnings).toEqual([]); | ||
| expect(result.betas.size).toBe(0); | ||
| }); | ||
|
|
||
| it('should warn when mixing Nova tools with function tools', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [ | ||
| { | ||
| type: 'provider-defined', | ||
| id: 'nova.nova_grounding', | ||
| name: 'nova_grounding', | ||
| args: {}, | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'testFunction', | ||
| inputSchema: { type: 'object', properties: {} }, | ||
| }, | ||
| ], | ||
| modelId: 'us.amazon.nova-premier-v1:0', | ||
| }); | ||
|
|
||
| expect(result.toolWarnings).toContainEqual({ | ||
| type: 'unsupported-setting', | ||
| setting: 'tools', | ||
| details: | ||
| 'Mixed Nova provider-defined tools and standard function tools are not supported in a single call to Bedrock. Only Nova tools will be used.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should not use Nova tools with non-Nova models', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [ | ||
| { | ||
| type: 'provider-defined', | ||
| id: 'nova.nova_grounding', | ||
| name: 'nova_grounding', | ||
| args: {}, | ||
| }, | ||
| ], | ||
| modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0', | ||
| }); | ||
|
|
||
| expect(result.toolConfig.tools).toBeUndefined(); | ||
| expect(result.toolWarnings).toContainEqual({ | ||
| type: 'unsupported-tool', | ||
| tool: { | ||
| type: 'provider-defined', | ||
| id: 'nova.nova_grounding', | ||
| name: 'nova_grounding', | ||
| args: {}, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Anthropic web_search tool filtering', () => { | ||
| it('should filter out web_search_20250305 and add warning', async () => { | ||
| const result = await prepareTools({ | ||
| tools: [ | ||
| { | ||
| type: 'provider-defined', | ||
| id: 'anthropic.web_search_20250305', | ||
| name: 'web_search', | ||
| args: {}, | ||
| }, | ||
| ], | ||
| modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0', | ||
| }); | ||
|
|
||
| expect(result.toolConfig.tools).toBeUndefined(); | ||
| expect(result.toolWarnings).toContainEqual({ | ||
| type: 'unsupported-tool', | ||
| tool: { | ||
| type: 'provider-defined', | ||
| id: 'anthropic.web_search_20250305', | ||
| name: 'web_search', | ||
| args: {}, | ||
| }, | ||
| details: | ||
| 'The web_search_20250305 tool is not supported on Amazon Bedrock.', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.