-
Notifications
You must be signed in to change notification settings - Fork 415
Add support for AWS Bedrock LLM Provider #238
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
Merged
Merged
Changes from 62 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
f39c450
Fix broken links in examples documentation (#177)
dagardner-nv 3b3f59b
Remove support for Python `3.13` (#178)
yczhang-nv b3ccd3f
Add transitional packages (#181)
dagardner-nv ca5ac3a
Add a tunable RAG evaluator (#110)
liamy-nv f2fc50b
CLI Documentation fixes in remote registry configuration section (#184)
mpenn 8bcaada
Fix uploading of transitional packages (#187)
dagardner-nv c1561f6
Update `AIQChatRequest` to support image and audio input (#182)
yczhang-nv 0202e10
Fix hyperlink ins the simple_calculator README (#188)
AnuradhaKaruppiah 91eb97c
Add support for fine-grained tracing using W&B Weave (#170)
ayulockin cda127c
Fix typo in CPR detected by co-pilot (#190)
AnuradhaKaruppiah b47651e
Note the name change in the top-level documentation and README.md (#163)
dagardner-nv bf04088
fix typo in evaluate documentation for max_concurrency (#191)
soumilinandi 650d43a
Fix a typo in the weave README (#195)
AnuradhaKaruppiah 8cc8481
Update simple example `eval` dataset (#200)
yczhang-nv 99c034d
Config option to specify the intermediate step types in workflow_outp…
AnuradhaKaruppiah d35a94b
Update the Judge LLM settings in the examples to avoid retries (#204)
AnuradhaKaruppiah 813ffca
Make `opentelemetry` and `phoenix` as optional dependencies (#167)
yczhang-nv bada671
Support user-defined HTTP request metadata in workflow tools. (#130)
ericevans-nv 840fa9c
Check if request is present before setting attributes (#209)
AnuradhaKaruppiah 6e3eb77
Add the alert triage agent example (#193)
hsin-c 2e442e0
Updating ui submodule (#211)
ericevans-nv 52e30c0
Fix plugin dependencies (#208)
dagardner-nv b8a7e2d
[FEA]add profiler agent to the examples folder (#120)
zac-wang-nv f5ac178
Regenerate `uv.lock`, cleaned up `pyproject.toml` for profiler agent …
yczhang-nv 251ae1d
Removed `disable=unused-argument` from pylint checks (#186)
Hritik003 edf21ae
Exception handling for discovery_metadata.py (#215)
VictorYudin dccaa17
Fix incorrect eval output config access (#219)
AnuradhaKaruppiah 3e23ab6
Treat a tagged commit the same as a nightly build (#217)
dagardner-nv 3fb2d4c
Feature/add aiqtoolkit UI submodule (#214)
ericevans-nv bf5a587
Add a CLI command to list all tools available via the MCP server (#221)
AnuradhaKaruppiah ef4d503
For remote evaluation, workflow config is not needed (#225)
AnuradhaKaruppiah 46db735
Move configurable parameters from env vars to config file (#222)
hsin-c 1e98a4c
Fix vulnerabilities in the alert triage agent example (#227)
hsin-c 63e705b
Add e2e test for the alert triage agent (#226)
hsin-c f047bee
Fix remaining nSpect vulnerabilities for `1.1.0` (#229)
yczhang-nv 58f16f0
Remove redundant span stack handling and error logging (#231)
dnandakumar-nv 01b7cd2
Feature/add aiqtoolkit UI submodule (#234)
ericevans-nv 7cace86
Move configurable parameters from env vars to config file (#222)
hsin-c baacee8
Fix vulnerabilities in the alert triage agent example (#227)
hsin-c c790a6c
Fix remaining nSpect vulnerabilities for `1.1.0` (#229)
yczhang-nv 5144dca
update uv.lock
yczhang-nv 9be5767
fix comments
yczhang-nv a3d05eb
update uv.lock
yczhang-nv 2f66d0f
Initial commit for AWSBedrock LLM provider
yczhang-nv d57b8c9
add aws bedrock llm client for llama-index
yczhang-nv 8c1b336
added unit tests for llm provider and llm framework combinations
yczhang-nv c842424
add headers
yczhang-nv d652426
roll back
yczhang-nv 84938d2
re-generate uv.lock
yczhang-nv 4ab57f5
merge upstream
yczhang-nv 70f9c22
update uv.lock and pyproject.toml
yczhang-nv 587113a
fix CI
yczhang-nv 356ee0f
fix CI
yczhang-nv b0fc780
Merge remote-tracking branch 'upstream/develop' into yuchen-fix-aiq-1213
yczhang-nv 8113a7b
Merge branch 'NVIDIA:develop' into yuchen-fix-aiq-1213
yczhang-nv d49db6c
remove comments
yczhang-nv 984d7a1
update uv.lock
yczhang-nv 52dd239
Merge remote-tracking branch 'upstream/develop' into yuchen-fix-aiq-1213
yczhang-nv 4110244
add documentation of AWS account set up
yczhang-nv f0cec8b
Merge branch 'develop' into yuchen-fix-aiq-1213
mdemoret-nv 7cae437
Merge remote-tracking branch 'upstream/develop' into yuchen-fix-aiq-1213
yczhang-nv 8f06f54
Merge branch 'yuchen-fix-aiq-1213' of https://github.com/yczhang-nv/A…
yczhang-nv aec994e
fix comments
yczhang-nv c5b1f86
update doc
yczhang-nv f81f5c1
update doc
yczhang-nv 69a67a7
update docs
yczhang-nv 93ac48f
add doc into toctree
yczhang-nv 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
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,49 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| # Integrating AWS Bedrock Models to AIQ Toolkit Workflow | ||
|
|
||
| To integrate AWS Bedrock models into your AIQ Toolkit workflow, follow these steps: | ||
|
|
||
| 1. **Prerequisites**: | ||
| - Set up AWS credentials by configuring `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. For detailed setup instructions, refer to the [AWS Bedrock setup guide](https://docs.aws.amazon.com/bedrock/latest/userguide/setting-up.html) | ||
|
|
||
| 1. **Configuration**: | ||
| Add the AWS Bedrock LLM configuration to your workflow config file. Make sure the `region_name` matches the region of your `AWS` account, and the `credentials_profile_name` matches the field in your credential file. Here's an example: | ||
|
|
||
| ```yaml | ||
| llms: | ||
| aws_bedrock_llm: | ||
| _type: aws_bedrock | ||
| model_name: meta.llama3-3-70b-instruct-v1:0 | ||
| temperature: 0.0 | ||
| max_tokens: 1024 | ||
| region_name: us-east-2 | ||
| credentials_profile_name: default | ||
| ``` | ||
| 3. **Usage in Workflow**: | ||
| Reference the AWS Bedrock LLM in your workflow configuration: | ||
| ```yaml | ||
| workflow: | ||
| _type: react_agent | ||
| llm_name: aws_bedrock_llm | ||
| # ... other workflow configurations | ||
| ``` | ||
|
|
||
| The AWS Bedrock integration supports various models and configurations, allowing you to leverage AWS's managed LLM services within your AIQ Toolkit workflows. | ||
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
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,54 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pydantic import AliasChoices | ||
| from pydantic import ConfigDict | ||
| from pydantic import Field | ||
|
|
||
| from aiq.builder.builder import Builder | ||
| from aiq.builder.llm import LLMProviderInfo | ||
| from aiq.cli.register_workflow import register_llm_provider | ||
| from aiq.data_models.llm import LLMBaseConfig | ||
|
|
||
|
|
||
| class AWSBedrockModelConfig(LLMBaseConfig, name="aws_bedrock"): | ||
| """An AWS Bedrock llm provider to be used with an LLM client.""" | ||
|
|
||
| model_config = ConfigDict(protected_namespaces=()) | ||
|
|
||
| # Completion parameters | ||
| model_name: str = Field(validation_alias=AliasChoices("model_name", "model"), | ||
| serialization_alias="model", | ||
| description="The model name for the hosted AWS Bedrock.") | ||
| temperature: float = Field(default=0.0, description="Sampling temperature in [0, 1].") | ||
| max_tokens: int | None = Field(default=1024, | ||
| description="Maximum number of tokens to generate." | ||
| "This field is ONLY required when using AWS Bedrock with Langchain.") | ||
| context_size: int | None = Field(default=1024, | ||
| description="Maximum number of tokens to generate." | ||
| "This field is ONLY required when using AWS Bedrock with LlamaIndex.") | ||
yczhang-nv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Client parameters | ||
| region_name: str | None = Field(default="None", description="AWS region to use.") | ||
| base_url: str | None = Field( | ||
| default=None, description="Bedrock endpoint to use. Needed if you don't want to default to us-east-1 endpoint.") | ||
| credentials_profile_name: str | None = Field( | ||
| default=None, description="The name of the profile in the ~/.aws/credentials or ~/.aws/config files.") | ||
|
|
||
|
|
||
| @register_llm_provider(config_type=AWSBedrockModelConfig) | ||
| async def aws_bedrock_model(llm_config: AWSBedrockModelConfig, builder: Builder): | ||
|
|
||
| yield LLMProviderInfo(config=llm_config, description="A AWS Bedrock model for use with an LLM client.") | ||
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,98 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import pytest | ||
| from langchain_core.messages import AIMessage | ||
| from langchain_core.prompts import ChatPromptTemplate | ||
|
|
||
| from aiq.builder.framework_enum import LLMFrameworkEnum | ||
| from aiq.builder.workflow_builder import WorkflowBuilder | ||
| from aiq.llm.aws_bedrock_llm import AWSBedrockModelConfig | ||
| from aiq.llm.nim_llm import NIMModelConfig | ||
| from aiq.llm.openai_llm import OpenAIModelConfig | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| @pytest.mark.asyncio | ||
yczhang-nv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| async def test_nim_langchain_agent(): | ||
| """ | ||
| Test NIM LLM with LangChain agent. Requires NVIDIA_API_KEY to be set. | ||
| """ | ||
|
|
||
| prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful AI assistant."), ("human", "{input}")]) | ||
|
|
||
| llm_config = NIMModelConfig(model_name="meta/llama-3.1-70b-instruct", temperature=0.0) | ||
|
|
||
| async with WorkflowBuilder() as builder: | ||
| await builder.add_llm("nim_llm", llm_config) | ||
| llm = await builder.get_llm("nim_llm", wrapper_type=LLMFrameworkEnum.LANGCHAIN) | ||
|
|
||
| agent = prompt | llm | ||
|
|
||
| response = await agent.ainvoke({"input": "What is 1+2?"}) | ||
| assert isinstance(response, AIMessage) | ||
| assert response.content is not None | ||
| assert isinstance(response.content, str) | ||
| assert "3" in response.content.lower() | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| @pytest.mark.asyncio | ||
| async def test_openai_langchain_agent(): | ||
| """ | ||
| Test OpenAI LLM with LangChain agent. Requires OPENAI_API_KEY to be set. | ||
| """ | ||
| prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful AI assistant."), ("human", "{input}")]) | ||
|
|
||
| llm_config = OpenAIModelConfig(model_name="gpt-3.5-turbo", temperature=0.0) | ||
|
|
||
| async with WorkflowBuilder() as builder: | ||
| await builder.add_llm("openai_llm", llm_config) | ||
| llm = await builder.get_llm("openai_llm", wrapper_type=LLMFrameworkEnum.LANGCHAIN) | ||
|
|
||
| agent = prompt | llm | ||
|
|
||
| response = await agent.ainvoke({"input": "What is 1+2?"}) | ||
| assert isinstance(response, AIMessage) | ||
| assert response.content is not None | ||
| assert isinstance(response.content, str) | ||
| assert "3" in response.content.lower() | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| @pytest.mark.asyncio | ||
| async def test_aws_bedrock_langchain_agent(): | ||
| """ | ||
| Test AWS Bedrock LLM with LangChain agent. | ||
| Requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be set. | ||
| See https://docs.aws.amazon.com/bedrock/latest/userguide/setting-up.html for more information. | ||
| """ | ||
| prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful AI assistant."), ("human", "{input}")]) | ||
|
|
||
| llm_config = AWSBedrockModelConfig(model_name="meta.llama3-3-70b-instruct-v1:0", | ||
| temperature=0.0, | ||
| region_name="us-east-2", | ||
| max_tokens=1024) | ||
|
|
||
| async with WorkflowBuilder() as builder: | ||
| await builder.add_llm("aws_bedrock_llm", llm_config) | ||
| llm = await builder.get_llm("aws_bedrock_llm", wrapper_type=LLMFrameworkEnum.LANGCHAIN) | ||
|
|
||
| agent = prompt | llm | ||
|
|
||
| response = await agent.ainvoke({"input": "What is 1+2?"}) | ||
| assert isinstance(response, AIMessage) | ||
| assert response.content is not None | ||
| assert isinstance(response.content, str) | ||
| assert "3" in response.content.lower() | ||
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.