Using the Python SDK on AWS SageMaker
This guide covers how to use the AI21 Studio Python SDK on AWS SageMaker.
Using AI21 Studio Python SDK with SageMaker
To use the AI21 Studio Python SDK with SageMaker:
- Create an Amazon SageMaker instance and configure it for AI21 models.
- Install or update the AI21 Studio Python SDK with the latest AWS integration:
pip install -U "ai21[AWS] >= 2.1.1"
- Create your
AI21SageMakerClient
client , passing in your endpoint. See the list of models supported for SageMaker.- You can either use your current environment's AWS session keys, or else create and pass in a
boto3
session explicitly, if you want to manage your keys explicitly. You do not need to use AI21 client keys, only AWS keys, because AWS handles your AI21 authorization for you. - The only region currently supported is
us-east-1
.
- You can either use your current environment's AWS session keys, or else create and pass in a
- Call the
create
method of the proper model name, passing in the appropriate parameters. See which models are available on SageMaker. General usage is described in the AI21 Studio Python SDK Guide, but be
Examples
from ai21 import AI21SageMakerClient
client = AI21SageMakerClient(endpoint_name="sm_endpoint_name")
response = client.completion.create(prompt="What is the meaning of life?")
print(response)
Additional resources
- You can find SageMaker examples in our GitHub repository.
- You can try out AI21 SageMaker examples in your browser in our Jupyter notebooks.
- Learn how to use the Python SDK
Updated 4 months ago