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:

  1. Create an Amazon SageMaker instance and configure it for AI21 models.
  2. Install or update the AI21 Studio Python SDK with the latest AWS integration:
    pip install -U "ai21[AWS] >= 2.1.1"
  3. 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.
  4. 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)

πŸ“˜

See more examples


Additional resources