diff --git a/metagpt/configs/llm_config.py b/metagpt/configs/llm_config.py index e7c280ee3..48b66640f 100644 --- a/metagpt/configs/llm_config.py +++ b/metagpt/configs/llm_config.py @@ -57,6 +57,7 @@ class LLMConfig(YamlModel): # For Cloud Service Provider like Baidu/ Alibaba access_key: Optional[str] = None secret_key: Optional[str] = None + session_token: Optional[str] = None endpoint: Optional[str] = None # for self-deployed model on the cloud # For Spark(Xunfei), maybe remove later diff --git a/metagpt/provider/bedrock_api.py b/metagpt/provider/bedrock_api.py index 03954e5c2..e336297b6 100644 --- a/metagpt/provider/bedrock_api.py +++ b/metagpt/provider/bedrock_api.py @@ -1,3 +1,4 @@ +import os import asyncio import json from functools import partial @@ -30,12 +31,13 @@ class BedrockLLM(BaseLLM): def __init_client(self, service_name: Literal["bedrock-runtime", "bedrock"]): """initialize boto3 client""" # access key and secret key from https://us-east-1.console.aws.amazon.com/iam - self.__credentital_kwargs = { - "aws_secret_access_key": self.config.secret_key, - "aws_access_key_id": self.config.access_key, - "region_name": self.config.region_name, + self.__credential_kwargs = { + "aws_secret_access_key": os.environ.get("AWS_SECRET_ACCESS_KEY", self.config.secret_key), + "aws_access_key_id": os.environ.get("AWS_ACCESS_KEY_ID", self.config.access_key), + "aws_session_token": os.environ.get("AWS_SESSION_TOKEN", self.config.session_token), + "region_name": os.environ.get("AWS_DEFAULT_REGION", self.config.region_name), } - session = boto3.Session(**self.__credentital_kwargs) + session = boto3.Session(**self.__credential_kwargs) client = session.client(service_name) return client