From fffbc810e465ce59633242b65c5de8ba40cb328f Mon Sep 17 00:00:00 2001 From: jorisvanraaij Date: Thu, 25 Jul 2024 12:33:34 +0200 Subject: [PATCH 1/5] Added _configure_openai_config_for_bedrock to include aws variables in openai_config, necessary for setting AnthropicBedrock as client. --- autogen/oai/client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/autogen/oai/client.py b/autogen/oai/client.py index 4e9d794a1f75..5fbe1210cc3b 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -454,12 +454,20 @@ def _configure_azure_openai(self, config: Dict[str, Any], openai_config: Dict[st azure.identity.DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default" ) + def _configure_openai_config_for_bedrock(self, config: Dict[str, Any], openai_config: Dict[str, Any]) -> None: + """Update openai_config with AWS credentials from config.""" + required_keys = ["aws_access_key", "aws_secret_key", "aws_session_token", "aws_region"] + + for key in required_keys: + if key in config: + openai_config[key] = config[key] + def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[str, Any]) -> None: """Create a client with the given config to override openai_config, after removing extra kwargs. For Azure models/deployment names there's a convenience modification of model removing dots in - the it's value (Azure deploment names can't have dots). I.e. if you have Azure deployment name + the it's value (Azure deployment names can't have dots). I.e. if you have Azure deployment name "gpt-35-turbo" and define model "gpt-3.5-turbo" in the config the function will remove the dot from the name and create a client that connects to "gpt-35-turbo" Azure deployment. """ @@ -485,6 +493,8 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s client = GeminiClient(**openai_config) self._clients.append(client) elif api_type is not None and api_type.startswith("anthropic"): + if "api_key" not in config: + self._configure_openai_config_for_bedrock(config, openai_config) if anthropic_import_exception: raise ImportError("Please install `anthropic` to use Anthropic API.") client = AnthropicClient(**openai_config) From f0548409eb7d55c762369df0e308289d8a68fe1a Mon Sep 17 00:00:00 2001 From: jorisvanraaij Date: Thu, 25 Jul 2024 15:29:21 +0200 Subject: [PATCH 2/5] Removed aws_session_token from required_keys --- autogen/oai/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/oai/client.py b/autogen/oai/client.py index 5fbe1210cc3b..4cc7c697f738 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -456,7 +456,7 @@ def _configure_azure_openai(self, config: Dict[str, Any], openai_config: Dict[st def _configure_openai_config_for_bedrock(self, config: Dict[str, Any], openai_config: Dict[str, Any]) -> None: """Update openai_config with AWS credentials from config.""" - required_keys = ["aws_access_key", "aws_secret_key", "aws_session_token", "aws_region"] + required_keys = ["aws_access_key", "aws_secret_key", "aws_region"] for key in required_keys: if key in config: From d5d1e48e64193b67dc3681d7ff6b1f125a0b4a54 Mon Sep 17 00:00:00 2001 From: jorisvanraaij Date: Thu, 25 Jul 2024 15:38:38 +0200 Subject: [PATCH 3/5] Removed check for aws_session_token --- autogen/oai/anthropic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/autogen/oai/anthropic.py b/autogen/oai/anthropic.py index 62078d42631d..cd505f3b056a 100644 --- a/autogen/oai/anthropic.py +++ b/autogen/oai/anthropic.py @@ -108,7 +108,6 @@ def __init__(self, **kwargs: Any): if self._api_key is None and ( self._aws_access_key is None or self._aws_secret_key is None - or self._aws_session_token is None or self._aws_region is None ): raise ValueError("API key or AWS credentials are required to use the Anthropic API.") From d39e912730f32d6eda34009e4a80871e524f8087 Mon Sep 17 00:00:00 2001 From: jorisvanraaij Date: Thu, 25 Jul 2024 15:45:56 +0200 Subject: [PATCH 4/5] Removed all checks for aws_session_token --- autogen/oai/anthropic.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/autogen/oai/anthropic.py b/autogen/oai/anthropic.py index cd505f3b056a..f84593bf64dd 100644 --- a/autogen/oai/anthropic.py +++ b/autogen/oai/anthropic.py @@ -99,9 +99,6 @@ def __init__(self, **kwargs: Any): if not self._aws_secret_key: self._aws_secret_key = os.getenv("AWS_SECRET_KEY") - if not self._aws_session_token: - self._aws_session_token = os.getenv("AWS_SESSION_TOKEN") - if not self._aws_region: self._aws_region = os.getenv("AWS_REGION") From 9f60a7fb05bf52928b98c7ed4c016e5344fdff47 Mon Sep 17 00:00:00 2001 From: jorisvanraaij Date: Thu, 25 Jul 2024 16:00:04 +0200 Subject: [PATCH 5/5] Ran pre-commit --- autogen/oai/anthropic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autogen/oai/anthropic.py b/autogen/oai/anthropic.py index f84593bf64dd..8ed6f909e6bc 100644 --- a/autogen/oai/anthropic.py +++ b/autogen/oai/anthropic.py @@ -103,9 +103,7 @@ def __init__(self, **kwargs: Any): self._aws_region = os.getenv("AWS_REGION") if self._api_key is None and ( - self._aws_access_key is None - or self._aws_secret_key is None - or self._aws_region is None + self._aws_access_key is None or self._aws_secret_key is None or self._aws_region is None ): raise ValueError("API key or AWS credentials are required to use the Anthropic API.")