Amazon Bedrock

In an effort to make our language-model capabilities more widely available, we've partnered with a few major platforms to create hosted versions of our offerings.

Here, you'll learn how to use Amazon Bedrock to deploy both the Cohere Command and the Cohere Embed models on the AWS cloud computing platform. The following models are available on Bedrock:

  • Command R
  • Command R+
  • Command Light
  • Command
  • Embed - English
  • Embed - Multilingual

Prerequisites

Here are the steps you'll need to get set up in advance of running Cohere models on Amazon Bedrock.

  • Subscribe to Cohere's models on Amazon Bedrock. For more details, see here.
  • You'll also need to install the AWS Python SDK and some related tooling. Run:
    • pip install cohere-aws (or pip install --upgrade cohere-aws if you need to upgrade). You can also install from source with python setup.py install.
    • For more details, see this GitHub repo and related notebooks.
  • Finally, you'll have to configure your authentication credentials for AWS. This document has more information.

Embeddings

You can use this code to invoke Cohere's Embed English v3 model (cohere.embed-english-v3) or Embed Multilingual v3 model (cohere.embed-multilingual-v3) on Amazon Bedrock:

import cohere

co = cohere.BedrockClient(
    aws_region="us-east-1",
    aws_access_key="...",
    aws_secret_key="...",
    aws_session_token="...",
)

# Input parameters for embed. In this example we are embedding hacker news post titles.
texts = ["Interesting (Non software) books?",
         "Non-tech books that have helped you grow professionally?",
         "I sold my company last month for $5m. What do I do with the money?",
         "How are you getting through (and back from) burning out?",
         "I made $24k over the last month. Now what?",
         "What kind of personal financial investment do you do?",
         "Should I quit the field of software development?"]
input_type = "clustering"
truncate = "NONE" # optional
model_id = "cohere.embed-english-v3" # or "cohere.embed-multilingual-v3"


# Invoke the model and print the response
result = co.embed(
						model=model_id,
  					input_type=input_type,
  				  texts=texts,
  					truncate=truncate) # aws_client.invoke_model(**params)

print(result)

Text Generation

You can use this code to invoke either Command R (cohere.command-r-v1:0), Command R+ (cohere.command-r-plus-v1:0), Command (cohere.command-text-v14), or Command light (cohere.command-light-text-v14) on Amazon Bedrock:

import cohere

co = cohere.BedrockClient(
    aws_region="us-east-1",
    aws_access_key="...",
    aws_secret_key="...",
    aws_session_token="...",
)

result = co.chat(message="Write a LinkedIn post about starting a career in tech:",
                 model='cohere.command-r-plus-v1:0' # or 'cohere.command-r-v1:0'
                 )

print(result)