Skip to content
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

Fix ChatBedrock integration with Amazon Bedrock model #339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/aws/langchain_aws/chat_models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ def _as_converse(self) -> ChatBedrockConverse:
kwargs["temperature"] = self.temperature
return ChatBedrockConverse(
model=self.model_id,
region_name=self.region_name,
region_name=self.region_name or os.getenv("AWS_REGION"),
credentials_profile_name=self.credentials_profile_name,
aws_access_key_id=self.aws_access_key_id,
aws_secret_access_key=self.aws_secret_access_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def chat_model_class(self) -> Type[BaseChatModel]:

@property
def chat_model_params(self) -> dict:
return {"model": "us.amazon.nova-pro-v1:0"}
return {"model": "us.amazon.nova-pro-v1:0", "region_name": "us-east-1"}

@property
def standard_chat_model_params(self) -> dict:
Expand Down Expand Up @@ -242,3 +242,22 @@ def test_guardrails() -> None:
)
assert response.response_metadata["stopReason"] == "guardrail_intervened"
assert response.response_metadata["trace"] is not None


def test_chat_bedrock_converse_with_region_name() -> None:
model = ChatBedrockConverse(
model="us.amazon.nova-pro-v1:0", region_name="us-east-1", temperature=0
)
response = model.invoke("Create a list of 3 pop songs")
assert isinstance(response, BaseModel)
assert response.content is not None


def test_chat_bedrock_converse_with_aws_region_env() -> None:
import os

os.environ["AWS_REGION"] = "us-east-1"
model = ChatBedrockConverse(model="us.amazon.nova-pro-v1:0", temperature=0)
response = model.invoke("Create a list of 3 pop songs")
assert isinstance(response, BaseModel)
assert response.content is not None