Note

The code examples in this section use the Cohere v1 API. The v2 API is not yet supported for cloud deployments and will be coming soon.

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:

PYTHON
1import cohere
2
3co = cohere.BedrockClient(
4 aws_region="us-east-1",
5 aws_access_key="...",
6 aws_secret_key="...",
7 aws_session_token="...",
8)
9
10# Input parameters for embed. In this example we are embedding hacker news post titles.
11texts = ["Interesting (Non software) books?",
12 "Non-tech books that have helped you grow professionally?",
13 "I sold my company last month for $5m. What do I do with the money?",
14 "How are you getting through (and back from) burning out?",
15 "I made $24k over the last month. Now what?",
16 "What kind of personal financial investment do you do?",
17 "Should I quit the field of software development?"]
18input_type = "clustering"
19truncate = "NONE" # optional
20model_id = "cohere.embed-english-v3" # or "cohere.embed-multilingual-v3"
21
22
23# Invoke the model and print the response
24result = co.embed(
25 model=model_id,
26 input_type=input_type,
27 texts=texts,
28 truncate=truncate) # aws_client.invoke_model(**params)
29
30print(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:

PYTHON
1import cohere
2
3co = cohere.BedrockClient(
4 aws_region="us-east-1",
5 aws_access_key="...",
6 aws_secret_key="...",
7 aws_session_token="...",
8)
9
10result = co.chat(message="Write a LinkedIn post about starting a career in tech:",
11 model='cohere.command-r-plus-v1:0' # or 'cohere.command-r-v1:0'
12 )
13
14print(result)