Skip to content

Commit

Permalink
Merge branch 'main' into get-started
Browse files Browse the repository at this point in the history
  • Loading branch information
billytrend-cohere authored Jan 8, 2025
2 parents 8c728c5 + 079c369 commit 8577933
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 63 deletions.
56 changes: 27 additions & 29 deletions cohere-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17521,13 +17521,16 @@ paths:
"context"
"log"

cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
)

func main() {
co := client.NewClient()

resp, err := co.Datasets.Get(context.TODO(), "dataset_id")
resp, err := co.Datasets.List(
context.TODO(),
&cohere.DatasetsListRequest{})

if err != nil {
log.Fatal(err)
Expand All @@ -17542,8 +17545,8 @@ paths:

co = cohere.Client()

# get dataset
response = co.datasets.get(id="<<datasetId>>")
# get list of datasets
response = co.datasets.list()

print(response)
- sdk: python
Expand All @@ -17556,7 +17559,7 @@ paths:


async def main():
response = await co.datasets.get(id="<<datasetId>>")
response = await co.datasets.list()

print(response)

Expand All @@ -17577,7 +17580,7 @@ paths:
public static void main(String[] args) {
Cohere cohere = Cohere.builder().clientName("snippet").build();

DatasetsGetResponse response = cohere.datasets().get("dataset_id");
DatasetsGetResponse response = cohere.datasets().list();

System.out.println(response);
}
Expand All @@ -17590,13 +17593,13 @@ paths:
const cohere = new CohereClient({});

(async () => {
const datasets = await cohere.datasets.get('<<datasetId>>');
const datasets = await cohere.datasets.list();

console.log(datasets);
})();
- sdk: curl
name: cURL
code: |-
code: |
curl --request GET \
--url https://api.cohere.com/v1/datasets \
--header 'accept: application/json' \
Expand Down Expand Up @@ -17891,9 +17894,9 @@ paths:
})();
- sdk: curl
name: cURL
code: |-
code: |
curl --request GET \
--url https://api.cohere.com/v1/datasets \
--url https://api.cohere.com/v1/datasets/id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
responses:
Expand Down Expand Up @@ -22948,8 +22951,11 @@ components:
delta:
type: object
properties:
tool_plan:
type: string
message:
type: object
properties:
tool_plan:
type: string
ChatToolCallStartEvent:
description: A streamed event delta which signifies a tool call has started streaming.
allOf:
Expand All @@ -22961,22 +22967,11 @@ components:
delta:
type: object
properties:
tool_call:
message:
type: object
properties:
id:
type: string
type:
type: string
enum:
- function
function:
type: object
properties:
name:
type: string
arguments:
type: string
tool_calls:
$ref: "#/components/schemas/ToolCallV2"
ChatToolCallDeltaEvent:
description: A streamed event delta which signifies a delta in tool call arguments.
allOf:
Expand All @@ -22988,14 +22983,17 @@ components:
delta:
type: object
properties:
tool_call:
message:
type: object
properties:
function:
tool_calls:
type: object
properties:
arguments:
type: string
function:
type: object
properties:
arguments:
type: string
ChatToolCallEndEvent:
description: A streamed event delta which signifies a tool call has finished
streaming.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,24 @@ Using `co.finetuning.create_finetuned_model()`, you can create a fine-tuned mode

Here are some example code snippets for you to use.

### Starting a Single-label Fine-tune
### Starting a single-label fine-tuning job

```python PYTHON
# create dataset
single_label_dataset = co.datasets.create(name="single-label-dataset",
data=open("path/to/train.csv, "rb"),
type="single-label-finetune-input",
parse_info=ParseInfo(delimiter=",")) # parse_info is optional
print(single_label_dataset.await_validation())
single_label_dataset = co.datasets.create(
name="single-label-dataset",
data=open("single_label_dataset.jsonl", "rb"),
type="single-label-classification-finetune-input",
)

print(co.wait(single_label_dataset).dataset.validation_status)

# start the fine-tune job using this dataset
finetune = co.finetuning.create_finetuned_model(
from cohere.finetuning.finetuning import BaseModel, FinetunedModel, Settings

single_label_finetune = co.finetuning.create_finetuned_model(
request=FinetunedModel(
name="single-label-ft",
name="single-label-finetune",
settings=Settings(
base_model=BaseModel(
base_type="BASE_TYPE_CLASSIFICATION",
Expand All @@ -117,50 +121,54 @@ finetune = co.finetuning.create_finetuned_model(
),
)

print(f"fine-tune ID: {finetune.id}, fine-tune status: {finetune.status}")
print(f"fine-tune ID: {single_label_finetune.finetuned_model.id}, fine-tune status: {single_label_finetune.finetuned_model.status}")
```

### Starting a Multi-label Fine-tune
### Starting a multi-label fine-tuning job

```python PYTHON
# create dataset
multi_label_dataset = co.create_dataset(name="multi-label-dataset",
data=open("path/to/train.jsonl", "rb"),
dataset_type="multi-label-finetune-input")

print(multi_label_dataset.await_validation())
multi_label_dataset = co.datasets.create(
name="multi-label-dataset",
data=open("multi_label_dataset.jsonl", "rb"),
type="multi-label-classification-finetune-input",
)

print(co.wait(multi_label_dataset).dataset.validation_status)

# start the fine-tune job using this dataset
finetune = co.finetuning.create_finetuned_model(
from cohere.finetuning.finetuning import BaseModel, FinetunedModel, Settings

multi_label_finetune = co.finetuning.create_finetuned_model(
request=FinetunedModel(
name="single-label-ft",
name="multi-label-finetune",
settings=Settings(
base_model=BaseModel(
base_type="BASE_TYPE_CLASSIFICATION",
),
dataset_id=single_label_dataset.id,
dataset_id=multi_label_dataset.id,
),
),
)

print(f"fine-tune ID: {finetune.id}, fine-tune status: {finetune.status}")
print(f"fine-tune ID: {multi_label_finetune.finetuned_model.id}, fine-tune status: {multi_label_finetune.finetuned_model.status}")
```

### Calling a fine-tune
### Calling a fine-tuned model

```python PYTHON
import cohere

co = cohere.ClientV2('Your API key')
# get the custom model object
ft = co.finetuning.get_finetuned_model(finetune.finetuned_model.id)
# get the custom model object (replace with your finetune name e.g. multi_label_finetune)
model_id = single_label_finetune.finetuned_model.id


response = co.classify(
inputs=["classify this!"],
model=ft.id+"-ft",
model=model_id+"-ft"
)

# Printing the model's response.
print(response)
```

Expand Down
2 changes: 1 addition & 1 deletion fern/pages/v2/text-generation/structured-outputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: "v2/docs/structured-outputs"

hidden: false

description: "This page describes how to get Cohere models to create outputs in a certain format, such as JSON."
description: "This page describes how to get Cohere models to create outputs in a certain format, such as JSON, TOOLS."
image: "../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, language models, structured outputs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, chatbot"
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt3.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt3_v2.ipynb">Open in Colab</a>

As its name implies, the Chat endpoint enables developers to build chatbots that can handle conversations. At the core of a conversation is a multi-turn dialog between the user and the chatbot. This requires the chatbot to have the state (or “memory”) of all the previous turns to maintain the state of the conversation.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, agents"
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt7.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb">Open in Colab</a>

Tool use extends the ideas from [RAG](/v2/docs/rag-with-cohere), where external systems are used to guide the response of an LLM, but by leveraging a much bigger set of tools than what’s possible with RAG. The concept of tool use leverages LLMs' useful feature of being able to act as a reasoning and decision-making engine.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, retrieval-augmented generation, RAG"
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt6.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt6_v2.ipynb">Open in Colab</a>

The Chat endpoint provides comprehensive support for various text generation use cases, including retrieval-augmented generation (RAG).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, language models, ReRank models"
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt5.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt5_v2.ipynb">Open in Colab</a>

Reranking is a technique that leverages [embeddings](/v2/docs/embeddings) as the last stage of a retrieval process, and is especially useful in [RAG systems](/v2/docs/retrieval-augmented-generation-rag).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, language models, "
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt4.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt4_v2.ipynb">Open in Colab</a>

[Text embeddings](/v2/docs/embeddings) are lists of numbers that represent the context or meaning inside a piece of text. This is particularly useful in search or information retrieval applications. With text embeddings, this is called semantic search.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
keywords: "Cohere, how do LLMs generate text"
---

<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt2.ipynb">Open in Colab</a>
<a target="_blank" href="https://colab.research.google.com/github/cohere-ai/cohere-developer-experience/blob/main/notebooks/guides/getting-started/v2/tutorial_pt2_v2.ipynb">Open in Colab</a>

Command is Cohere’s flagship LLM. It generates a response based on a user message or prompt. It is trained to follow user commands and to be instantly useful in practical business applications, like summarization, copywriting, extraction, and question-answering.

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[project]
name = "cohere-developer-experience"

[tool.poetry]
name = "py-snips"
name = "cohere-developer-experience"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.11"
Expand Down
4 changes: 2 additions & 2 deletions snippets/snippets/curl/dataset-get.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/datasets \
--url https://api.cohere.com/v1/datasets/id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/snippets/curl/dataset-list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/datasets \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
23 changes: 23 additions & 0 deletions snippets/snippets/go/dataset-list/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"context"
"log"

cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
)

func main() {
co := client.NewClient()

resp, err := co.Datasets.List(
context.TODO(),
&cohere.DatasetsListRequest{})

if err != nil {
log.Fatal(err)
}

log.Printf("%+v", resp)
}
13 changes: 13 additions & 0 deletions snippets/snippets/java/app/src/main/java/DatasetList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* (C)2024 */
import com.cohere.api.Cohere;
import com.cohere.api.resources.datasets.types.DatasetsGetResponse;

public class DatasetGet {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().clientName("snippet").build();

DatasetsGetResponse response = cohere.datasets().list();

System.out.println(response);
}
}
9 changes: 9 additions & 0 deletions snippets/snippets/node/dataset-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { CohereClient } = require('cohere-ai');

const cohere = new CohereClient({});

(async () => {
const datasets = await cohere.datasets.list();

console.log(datasets);
})();
13 changes: 13 additions & 0 deletions snippets/snippets/python-async/dataset-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import cohere
import asyncio

co = cohere.AsyncClient()


async def main():
response = await co.datasets.list()

print(response)


asyncio.run(main())
Loading

0 comments on commit 8577933

Please sign in to comment.