Skip to content

Commit

Permalink
Add spec changes
Browse files Browse the repository at this point in the history
Co-authored-by: billytrend-cohere <[email protected]>
  • Loading branch information
platform-endpoints and billytrend-cohere committed Aug 15, 2024
1 parent 8526713 commit 01a2aa8
Show file tree
Hide file tree
Showing 16 changed files with 735 additions and 17 deletions.
503 changes: 493 additions & 10 deletions cohere-openapi.yaml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions snippets/snippets/node/chat-v2-post/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { CohereClientV2 } = require('cohere-ai');

const cohere = new CohereClientV2({
token: '<<apiKey>>',
});

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

console.log(response);
})();
22 changes: 22 additions & 0 deletions snippets/snippets/node/chat-v2-post/documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { CohereClientV2 } = require('cohere-ai');

const cohere = new CohereClientV2({
token: '<<apiKey>>',
});

(async () => {
const response = await cohere.chat({
model: 'command-r-plus',
messages: [
{
role: 'user',
content: [
{ type: 'document', id: '1', document: { text: 'Cohere is the best!' } },
{ type: 'text', text: "Who's the best?" },
],
},
],
});

console.log(response);
})();
23 changes: 23 additions & 0 deletions snippets/snippets/node/chat-v2-post/stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { CohereClientV2 } = require('cohere-ai');

const cohere = new CohereClientV2({
token: '<<apiKey>>',
});

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

for await (const chatEvent of stream) {
if (chatEvent.type === 'content-delta') {
console.log(chatEvent.delta?.message);
}
}
})();
52 changes: 52 additions & 0 deletions snippets/snippets/node/chat-v2-post/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { CohereClientV2 } = require('cohere-ai');

const cohere = new CohereClientV2({
token: '<<apiKey>>',
});

(async () => {
const response = await cohere.chat({
model: 'command-r-plus',
tools: [
{
type: 'function',
function: {
name: 'query_daily_sales_report',
description:
'Connects to a database to retrieve overall sales volumes and sales information for a given day.',
parameters: {
day: {
description: 'Retrieves sales data for this day, formatted as YYYY-MM-DD.',
type: 'str',
required: true,
},
},
},
},
{
type: 'function',
function: {
name: 'query_product_catalog',
description:
'Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.',
parameters: {
category: {
description: 'Retrieves product information data for all products in this category.',
type: 'str',
required: true,
},
},
},
},
],
messages: [
{
role: 'user',
content:
"Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?",
},
],
});

console.log(response);
})();
19 changes: 19 additions & 0 deletions snippets/snippets/python-async/chat-v2-post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cohere
import asyncio

co = cohere.AsyncClientV2("<<apiKey>>")


async def main():
response = await co.chat(
model="command-r-plus",
messages=[
cohere.v2.ChatMessage2_User(
content="hello world!"
)
]
)

print(response)

asyncio.run(main())
4 changes: 2 additions & 2 deletions snippets/snippets/python-async/embed-jobs-post.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

async def main():
# start an embed job
response = await co.embed_jobs.create(
dataset_id=ds.id, input_type="search_document", model="embed-english-v3.0"
job = await co.embed_jobs.create(
dataset_id="my-dataset-id", input_type="search_document", model="embed-english-v3.0"
)

# poll the server until the job is complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def main():
name="test-finetuned-model",
settings=Settings(
base_model=BaseModel(
base_type=BaseType.BASE_TYPE_GENERATIVE,
base_type=BaseType.BASE_TYPE_CHAT,
),
dataset_id="my-dataset-id",
),
Expand Down
14 changes: 14 additions & 0 deletions snippets/snippets/python/chat-v2-post/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cohere

co = cohere.ClientV2("<<apiKey>>")

response = co.chat(
model="command-r-plus",
messages=[
cohere.v2.ChatMessage2_User(
content="hello world!"
)
]
)

print(response)
21 changes: 21 additions & 0 deletions snippets/snippets/python/chat-v2-post/documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import cohere

co = cohere.ClientV2("<<apiKey>>")

response = co.chat(
model="command-r-plus",
messages=[
cohere.v2.ChatMessage2_User(
content=[
cohere.v2.DocumentContent(
id=1,
document={'title': 'The best',
'text': 'Cohere is the best!'}
),
cohere.v2.TextContent(text="Who's the best?"),
]
)
]
)

print(response)
16 changes: 16 additions & 0 deletions snippets/snippets/python/chat-v2-post/stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cohere

co = cohere.ClientV2("<<apiKey>>")

response = co.chat_stream(
model="command-r-plus",
messages=[
cohere.v2.ChatMessage2_User(
content="hello world!"
)
]
)

for event in response:
if event.event_type == "text-generation":
print(event.text, end='')
38 changes: 38 additions & 0 deletions snippets/snippets/python/chat-v2-post/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import cohere

co = cohere.Client("<<apiKey>>")

response = co.chat(
model="command-r-plus",
tools=[
cohere.v2.Tool2(type='function', function={
"name": 'query_daily_sales_report',
"description": 'Connects to a database to retrieve overall sales volumes and sales information for a given day.',
"parameters": {
"day": {
"description": 'Retrieves sales data for this day, formatted as YYYY-MM-DD.',
"type": 'str',
"required": True,
},
}
}),
cohere.v2.Tool2(type='function', function={
"name": 'query_product_catalog',
"description": 'Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.',
"parameters": {
"category": {
"description": 'Retrieves product information data for all products in this category.',
"type": 'str',
"required": True,
},
}
})
],
messages=[
cohere.v2.ChatMessage2_User(
content="Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?"
)
]
)

print(response)
2 changes: 1 addition & 1 deletion snippets/snippets/python/dataset-post.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
co = cohere.Client("<<apiKey>>")

# upload a dataset
response = co.datasets.create(
my_dataset = co.datasets.create(
name="prompt-completion-dataset",
data=open("./prompt-completion.jsonl", "rb"),
type="prompt-completion-finetune-input",
Expand Down
4 changes: 2 additions & 2 deletions snippets/snippets/python/embed-jobs-post.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
co = cohere.Client("<<apiKey>>")

# start an embed job
response = co.embed_jobs.create(
dataset_id=ds.id, input_type="search_document", model="embed-english-v3.0"
job = co.embed_jobs.create(
dataset_id="my-dataset-id", input_type="search_document", model="embed-english-v3.0"
)

# poll the server until the job is complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FinetunedModel,
Hyperparameters,
Settings,
WandbConfig
)
import cohere

Expand All @@ -14,6 +15,11 @@
train_epoch=1,
learning_rate=0.01,
)
wnb_config = WandbConfig(
project="test-project",
api_key="<<wandbApiKey>>",
entity="test-entity",
)
finetuned_model = co.finetuning.create_finetuned_model(
request=FinetunedModel(
name="test-finetuned-model",
Expand All @@ -23,7 +29,8 @@
),
dataset_id="my-dataset-id",
hyperparameters=hp,
wandb=wnb_config,
),
)
)
print(response)
print(finetuned_model)
4 changes: 4 additions & 0 deletions snippets/snippets/python/finetuning/update-finetuned-model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from cohere.finetuning import (
BaseModel,
Settings,
)
import cohere

co = cohere.Client("<<apiKey>>")
Expand Down

0 comments on commit 01a2aa8

Please sign in to comment.