Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 final #151

Merged
merged 18 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fern/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ versions:
- display-name: v1
path: v1.yml
slug: v1
- display-name: v2
path: v2.yml
slug: v2

logo:
light: assets/logo.svg
Expand Down
35 changes: 35 additions & 0 deletions fern/pages/changelog/2024-09-18-api-v2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "New Embed, Rerank, Chat, and Classify APIs"
slug: "changelog/v2-api-release"
createdAt: "Thurs Sept 19 2024 09:30:00 (EST)"
hidden: false
description: >-
Introducing improvements to our Chat, Classify, Embed, and Rerank APIs in a major version upgrade, making it easier and faster to build with Cohere.
---
We're excited to introduce improvements to our Chat, Classify, Embed, and Rerank APIs in a major version upgrade, making it easier and faster to build with Cohere. We are also releasing a new SDK, `cohere.ClientV2`.

## New at a glance
* V2 Chat, Classify, Embed, and Rerank: `model` is a required parameter
* V2 Embed: `embedding_types` is a required parameter
* V2 Chat: Message and chat history are combined in a single `messages` array
* V2 Chat: Tools are defined in JSON schema
* V2 Chat: Introduces `tool_call_ids` to match tool calls with tool results
* V2 Chat: `documents` [supports a list of strings or a list of objects](/v2/docs/migrating-v1-to-v2#documents) with document metadata
* V2 Chat streaming: Uses [server-sent events](/v2/docs/migrating-v1-to-v2#streaming)

## Other updates
We are simplifying the Chat API by removing support for the following parameters available in V1:
* `search_queries_only`, which generates only a search query given a user’s message input. `search_queries_only` is not supported in the V2 Chat API today, but will be supported at a later date.
* `connectors`, which enables users to register a data source with Cohere for RAG queries. To use the Chat V2 API with web search, see our [migration guide](/v2/docs/migrating-v1-to-v2#) for instructios to implement a web search tool.
* `conversation_id`, used to manage chat history on behalf of the developer. This will not be supported in the V2 Chat API.
* `prompt_truncation`, used to automatically rerank and remove documents if the query did not fit in the model’s context limit. This will not be supported in the V2 Chat API.
* `force_single_step`, which forced the model to finish tool calling in one set of turns. This will not be supported in the V2 Chat API.
* `preamble`, used for giving the model task, context, and style instructions. Use a system turn at the beginning of your `messages` array in V2.
* `citation_quality`, for users to select between `fast` citations, `accurate` citations (slightly higher latency than fast), or citations `off`. In V2 Chat, we are introducing a top level `citation_options` parameter for all citation settings. `citation_quality` will be replaced by a `mode` parameter within `citation_options`.


See our Chat API [migration guide](/v2/docs/migrating-v1-to-v2) for detailed instructions to update your implementation.


These APIs are in Beta and are subject to updates. We welcome feedback in our [Discord](https://discord.com/invite/co-mmunity) channel.

58 changes: 39 additions & 19 deletions fern/pages/cohere-api/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ python -m pip install cohere --upgrade
```python
import cohere

co = cohere.Client("Your API key")
co = cohere.ClientV2("<<apiKey>>")

response = co.chat(
message="hello world!"
model="command-r-plus",
messages=[
{
"role": "user",
"content": "hello world!"
}
]
)

print(response)
Expand All @@ -49,15 +55,21 @@ npm i -s cohere-ai
```

```typescript
const { CohereClient } = require("cohere-ai");
const { CohereClientV2 } = require('cohere-ai');

const cohere = new CohereClient({
token: "Your API key",
const cohere = new CohereClientV2({
token: '<<apiKey>>',
});

(async () => {
const response = await cohere.chat({
message: "hello world!",
model: 'command-r-plus',
messages: [
{
role: 'user',
content: 'hello world!',
},
],
});

console.log(response);
Expand All @@ -73,27 +85,35 @@ implementation 'com.cohere:cohere-java:1.x.x'
```

```java
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.ChatMessageRole;
import com.cohere.api.types.NonStreamedChatResponse;
package chatv2post;

import com.cohere.api.Cohere;
import com.cohere.api.resources.v2.requests.V2ChatRequest;
import com.cohere.api.types.*;
import java.util.List;


public class ChatPost {
public class Default {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("Your API key").build();

NonStreamedChatResponse response = cohere.chat(
ChatRequest.builder()
.message("What year was he born?").build());
Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();

ChatResponse response =
cohere.v2()
.chat(
V2ChatRequest.builder()
.model("command-r-plus")
.messages(
List.of(
ChatMessageV2.user(
UserMessage.builder()
.content(
UserMessageContent
.of("Hello world!"))
.build())))
.build());

System.out.println(response);
}
}

```

### Go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ create_response = co.finetuning.create_finetuned_model(
)
```

## Calling your Chat Model with co.chat()
## Calling your Chat Model with the Chat API

Once your model completes training, you can call it via [co.chat()](/docs/chat-api) and pass your custom model's `model_id`.
Once your model completes training, you can call it via the [Chat API](/docs/chat-api) and pass your custom model's ID via the `model` parameter.

Please note, the `model_id` is the `id` returned by the fine-tuned model object with the `"-ft"` suffix.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Amazon Bedrock
slug: v2/docs/amazon-bedrock
hidden: false
description: >-
This document provides a guide for using Cohere's models on Amazon Bedrock.
image: ../../../../assets/images/8dbcb80-cohere_meta_image.jpg
keywords: 'Cohere on AWS, language models on AWS, Amazon Bedrock, Amazon SageMaker'
createdAt: 'Thu Feb 01 2024 18:08:37 GMT+0000 (Coordinated Universal Time)'
updatedAt: 'Thu May 30 2024 16:00:53 GMT+0000 (Coordinated Universal Time)'
---
<Info title="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.
</Info>
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](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html).
- 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](https://github.com/cohere-ai/cohere-aws/) and [related notebooks](https://github.com/cohere-ai/cohere-aws/tree/main/notebooks/bedrock).
- Finally, you'll have to configure your authentication credentials for AWS. This [document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) 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 PYTHON
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:

```python PYTHON
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)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: "Amazon SageMaker"
slug: "v2/docs/amazon-sagemaker-setup-guide"

hidden: false
description: "This document will guide you through enabling development teams to access Cohere’s offerings on Amazon SageMaker."
image: "../../../../assets/images/6330341-cohere_meta_image.jpg"
keywords: "Amazon SageMaker, Generative AI on AWS"

createdAt: "Wed Jun 28 2023 14:29:11 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Thu May 30 2024 16:01:40 GMT+0000 (Coordinated Universal Time)"
---
<Info title="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.
</Info>
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.

This document will guide you through enabling development teams to access [Cohere’s offerings on Amazon SageMaker](https://aws.amazon.com/marketplace/seller-profile?id=87af0c85-6cf9-4ed8-bee0-b40ce65167e0).

## Prerequisites

In order to successfully subscribe to Cohere’s offerings on Amazon SageMaker, the user will need the following **Identity and Access Management (IAM)** permissions:

- **AmazonSageMakerFullAccess**
- **aws-marketplace:ViewSubscriptions**
- **aws-marketplace:Subscribe**
- **aws-marketplace:Unsubscribe**

These permissions allow a user to manage your organization’s Amazon SageMaker subscriptions. Learn more about [managing Amazon’s IAM Permissions here](https://aws.amazon.com/iam/?trk=cf28fddb-12ed-4ffd-981b-b89c14793bf1&sc_channel=ps&ef_id=CjwKCAjwsvujBhAXEiwA_UXnAJ4JEQ3KgW0eFBzr5nuwt9L5S7w3A0f3wqensQJgUQ7Mf_ZEdArZRxoCjKQQAvD_BwE:G:s&s_kwcid=AL!4422!3!652240143562!e!!g!!amazon%20iam!19878797467!148973348604). Contact your AWS administrator if you have questions about account permissions.

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 want to upgrade to the most recent version of the SDK).

## Cohere with Amazon SageMaker Setup

First, navigate to [Cohere’s SageMaker Marketplace](https://aws.amazon.com/marketplace/seller-profile?id=87af0c85-6cf9-4ed8-bee0-b40ce65167e0) to view the available product offerings. Select the product offering to which you are interested in subscribing.

Next, explore the tools on the **Product Detail** page to evaluate how you want to configure your subscription. It contains information related to:

- Pricing: This section allows you to estimate the cost of running inference on different types of instances.
- Usage: This section contains the technical details around supported data formats for each model, and offers links to documentation and notebooks that will help developers scope out the effort required to integrate with Cohere’s models.
- Subscribing: This section will once again present you with both the pricing details and the EULA for final review before you accept the offer. This information is identical to the information on Product Detail page.
- Configuration: The primary goal of this section is to retrieve the [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html) for the product you have subscribed to.

## Embeddings

You can use this code to invoke Cohere's embed model on Amazon SageMaker:

```python PYTHON
import cohere

co = cohere.SageMakerClient(
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 = "<YOUR ENDPOINT NAME>" # On SageMaker, you create a model name that you'll pass here.


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

print(result)
```

## Text Generation

You can use this code to invoke Cohere's Command models on Amazon SageMaker:

```python PYTHON
import cohere

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

# Invoke the model and print the response
result = co.chat(message="Write a LinkedIn post about starting a career in tech:",
model="<YOUR ENDPOINT NAME>") # On SageMaker, you create a model name that you'll pass here.

print(result)
```

## Next Steps

With your selected configuration and Product ARN available, you now have everything you need to integrate with Cohere’s model offerings on SageMaker.

Cohere recommends your next step be to find the appropriate notebook in [Cohere's list of Amazon SageMaker notebooks](https://github.com/cohere-ai/cohere-aws/tree/main/notebooks/sagemaker), and follow the instructions there, or provide the link to Cohere’s SageMaker notebooks to your development team to implement. The notebooks are thorough, developer-centric guides that will enable your team to begin leveraging Cohere’s endpoints in production for live inference.

If you have further questions about subscribing or configuring Cohere’s product offerings on Amazon SageMaker, please contact our team at [[email protected]](mailto:[email protected]).
Loading
Loading