Skip to content

Commit 113aca0

Browse files
Allow implicit aws credential setting for AnthropicBedrockChatCompletionClient (#6561)
<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Allows implicit AWS credential setting when using AnthropicBedrockChatCompletionClient in an instance where you have already logged into AWS with SSO and credentials are set as environment variables. ## Related issue number Closes #6560 ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed. Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
1 parent bd3b97a commit 113aca0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,15 @@ def __init__(self, **kwargs: Unpack[AnthropicBedrockClientConfiguration]):
11931193
if bedrock_info is None:
11941194
raise ValueError("bedrock_info is required for AnthropicBedrockChatCompletionClient")
11951195

1196-
# Handle bedrock_info as secretestr
1196+
# Handle bedrock_info
11971197
aws_region = bedrock_info["aws_region"]
1198-
aws_access_key = bedrock_info["aws_access_key"]
1199-
aws_secret_key = bedrock_info["aws_secret_key"]
1200-
aws_session_token = bedrock_info["aws_session_token"]
1198+
aws_access_key: Optional[str] = None
1199+
aws_secret_key: Optional[str] = None
1200+
aws_session_token: Optional[str] = None
1201+
if all(key in bedrock_info for key in ("aws_access_key", "aws_secret_key", "aws_session_token")):
1202+
aws_access_key = bedrock_info["aws_access_key"]
1203+
aws_secret_key = bedrock_info["aws_secret_key"]
1204+
aws_session_token = bedrock_info["aws_session_token"]
12011205

12021206
client = AsyncAnthropicBedrock(
12031207
aws_access_key=aws_access_key,

0 commit comments

Comments
 (0)