Skip to content

Commit

Permalink
Sagemaker endpoint capability to inject boto3 client for cross accoun…
Browse files Browse the repository at this point in the history
…t scenarios (#10728)

- **Description: Allow to inject boto3 client for Cross account access
type of scenarios in using Sagemaker Endpoint **
  - **Issue:#10634 #10184** 
  - **Dependencies: None** 
  - **Tag maintainer:** 
  - **Twitter handle:lethargicoder**

Co-authored-by: Vikram(VS) <[email protected]>
  • Loading branch information
vikramshitole and Vikram(VS) authored Sep 19, 2023
1 parent c8f386d commit a4e858b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion libs/langchain/langchain/llms/sagemaker_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ class SagemakerEndpoint(LLM):
"""

"""
Args:
region_name: The aws region e.g., `us-west-2`.
Fallsback to AWS_DEFAULT_REGION env variable
or region specified in ~/.aws/config.
credentials_profile_name: The name of the profile in the ~/.aws/credentials
or ~/.aws/config files, which has either access keys or role information
specified. If not specified, the default credential profile or, if on an
EC2 instance, credentials from IMDS will be used.
client: boto3 client for Sagemaker Endpoint
content_handler: Implementation for model specific LLMContentHandler
Example:
.. code-block:: python
Expand All @@ -98,8 +114,21 @@ class SagemakerEndpoint(LLM):
region_name=region_name,
credentials_profile_name=credentials_profile_name
)
#Use with boto3 client
client = boto3.client(
"sagemaker-runtime",
region_name=region_name
)
se = SagemakerEndpoint(
endpoint_name=endpoint_name,
client=client
)
"""
client: Any #: :meta private:
client: Any = None
"""Boto3 client for sagemaker runtime"""

endpoint_name: str = ""
"""The name of the endpoint from the deployed Sagemaker model.
Expand Down Expand Up @@ -157,6 +186,10 @@ class Config:

@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Dont do anything if client provided externally"""
if values.get("client") is not None:
return values

"""Validate that AWS credentials to and python package exists in environment."""
try:
import boto3
Expand Down

0 comments on commit a4e858b

Please sign in to comment.