浏览代码

[Bug Fix] Add support for `AWS_REGION` override (#1237)

Thomas T 1 年之前
父节点
当前提交
8fe2c3effc
共有 2 个文件被更改,包括 5 次插入2 次删除
  1. 3 1
      docs/components/llms.mdx
  2. 2 1
      embedchain/llm/aws_bedrock.py

+ 3 - 1
docs/components/llms.mdx

@@ -666,7 +666,8 @@ embedder:
 
 ### Setup
 - Before using the AWS Bedrock LLM, make sure you have the appropriate model access from [Bedrock Console](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess).
-- You will also need `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` to authenticate the API with AWS. You can find these in your [AWS Console](https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-1#/users).
+- You will also need to authenticate the `boto3` client by using a method in the [AWS documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials)
+- You can optionally export an `AWS_REGION`
 
 
 ### Usage
@@ -679,6 +680,7 @@ from embedchain import App
 
 os.environ["AWS_ACCESS_KEY_ID"] = "xxx"
 os.environ["AWS_SECRET_ACCESS_KEY"] = "xxx"
+os.environ["AWS_REGION"] = "us-west-2"
 
 app = App.from_config(config_path="config.yaml")
 ```

+ 2 - 1
embedchain/llm/aws_bedrock.py

@@ -1,3 +1,4 @@
+import os
 from typing import Optional
 
 from langchain.llms import Bedrock
@@ -25,7 +26,7 @@ class AWSBedrockLlm(BaseLlm):
                 'Please install with `pip install --upgrade "embedchain[aws-bedrock]"`'
             ) from None
 
-        self.boto_client = boto3.client("bedrock-runtime", "us-west-2")
+        self.boto_client = boto3.client("bedrock-runtime", "us-west-2" or os.environ.get("AWS_REGION"))
 
         kwargs = {
             "model_id": config.model or "amazon.titan-text-express-v1",