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 Jul 30, 2024
1 parent 7e1d1f7 commit fa70d55
Show file tree
Hide file tree
Showing 206 changed files with 17,391 additions and 0 deletions.
13,580 changes: 13,580 additions & 0 deletions cohere-openapi.yaml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions snippets/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions snippets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
13 changes: 13 additions & 0 deletions snippets/curl/chat-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
curl --request POST \
--url https://api.cohere.com/v1/chat \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"chat_history": [
{"role": "USER", "message": "Who discovered gravity?"},
{"role": "CHATBOT", "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton"}
],
"message": "What year was he born?",
"connectors": [{"id": "web-search"}]
}'
20 changes: 20 additions & 0 deletions snippets/curl/classify-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
curl --request POST \
--url https://api.cohere.com/v1/classify \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"inputs": ["Confirm your email address", "hey i need u to send some $"],
"examples": [
{"text": "Dermatologists don'\''t like her!","label": "Spam"},
{"text": "'\''Hello, open to this?'\''","label": "Spam"},
{"text": "I need help please wire me $1000 right now","label": "Spam"},
{"text": "Nice to know you ;)","label": "Spam"},
{"text": "Please help me?","label": "Spam"},
{"text": "Your parcel will be delivered today","label": "Not spam"},
{"text": "Review changes to our Terms and Conditions","label": "Not spam"},
{"text": "Weekly sync notes","label": "Not spam"},
{"text": "'\''Re: Follow up from today'\''s meeting'\''","label": "Not spam"},
{"text": "Pre-read for tomorrow","label": "Not spam"}
]
}'
9 changes: 9 additions & 0 deletions snippets/curl/connector-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl --request POST \
--url https://api.cohere.com/v1/connectors \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"name": "Example connector",
"url": "https://connector-example.com/search"
}'
4 changes: 4 additions & 0 deletions snippets/curl/connector-delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request DELETE \
--url https://api.cohere.com/v1/connectors/id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/connector-get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/connectors/id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
9 changes: 9 additions & 0 deletions snippets/curl/connector-patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl --request PATCH \
--url https://api.cohere.com/v1/connectors/id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"name": "new name",
"url": "https://example.com/search"
}'
4 changes: 4 additions & 0 deletions snippets/curl/connectors-id-oauth-authorize-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request POST \
--url https://api.cohere.com/v1/connectors/id/oauth/authorize \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/connectors-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/connectors \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
5 changes: 5 additions & 0 deletions snippets/curl/dataset-delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl --request DELETE \
--url https://api.cohere.com/v1/datasets/id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/dataset-get.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"
5 changes: 5 additions & 0 deletions snippets/curl/dataset-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl --request POST \
--url "https://api.cohere.com/v1/datasets?name=my-dataset&type=generative-finetune-input" \
--header 'Content-Type: multipart/form-data' \
--header "Authorization: Bearer $CO_API_KEY" \
--form file=@./path/to/file.jsonl
4 changes: 4 additions & 0 deletions snippets/curl/dataset-usage-get.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/usage \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
9 changes: 9 additions & 0 deletions snippets/curl/detokenize-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl --request POST \
--url https://api.cohere.com/v1/detokenize \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"model": "command",
"tokens": [8466, 5169, 2594, 8, 2792, 43]
}'
5 changes: 5 additions & 0 deletions snippets/curl/embed-jobs-cancel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl --request POST \
--url https://api.cohere.com/v1/embed-jobs/id/cancel \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/embed-jobs-get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/embed-jobs \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
9 changes: 9 additions & 0 deletions snippets/curl/embed-jobs-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl --request POST \
--url https://api.cohere.com/v1/embed-jobs \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"model": "embed-english-v3.0",
"dataset_id": "my-dataset"
}'
10 changes: 10 additions & 0 deletions snippets/curl/embed-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
curl --request POST \
--url https://api.cohere.com/v1/embed \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"model": "embed-english-v3.0",
"texts": ["hello", "goodbye"],
"input_type": "classification"
}'
4 changes: 4 additions & 0 deletions snippets/curl/emebed-jobs-get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/embed-jobs/id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
14 changes: 14 additions & 0 deletions snippets/curl/finetuning/create-finetuned-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
curl --request POST \
--url https://api.cohere.com/v1/finetuning/finetuned-models \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"name": "test-finetuned-model",
"settings": {
"base_model": {
"base_type": "BASE_TYPE_GENERATIVE",
},
"dataset_id": "test-dataset-id"
}
}'
4 changes: 4 additions & 0 deletions snippets/curl/finetuning/delete-finetuned-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request DELETE \
--url https://api.cohere.com/v1/finetuning/finetuned-models/test-id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/finetuning/get-finetuned-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/finetuning/finetuned-models/test-id \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/finetuning/list-events.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/finetuning/finetuned-models/test-id/events \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/finetuning/list-finetuned-models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/finetuning/finetuned-models \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
4 changes: 4 additions & 0 deletions snippets/curl/finetuning/list-training-step-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/finetuning/finetuned-models/test-id/training-step-metrics \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
6 changes: 6 additions & 0 deletions snippets/curl/finetuning/update-finetuned-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
curl --request PATCH \
--url https://api.cohere.com/v1/finetuning/finetuned-models/test-id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{ "name": "new name" }'
8 changes: 8 additions & 0 deletions snippets/curl/generate-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
curl --request POST \
--url https://api.cohere.com/v1/generate \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"prompt": "Please explain to me how LLMs work"
}'
4 changes: 4 additions & 0 deletions snippets/curl/models-list-get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --request GET \
--url https://api.cohere.com/v1/models \
--header 'accept: application/json' \
--header "Authorization: bearer $CO_API_KEY"
15 changes: 15 additions & 0 deletions snippets/curl/rerank-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
curl --request POST \
--url https://api.cohere.com/v1/rerank \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"model": "rerank-english-v3.0",
"query": "What is the capital of the United States?",
"top_n": 3,
"documents": ["Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
"Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."]
}'
8 changes: 8 additions & 0 deletions snippets/curl/summarize-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
curl --request POST \
--url https://api.cohere.com/v1/summarize \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"text": "Ice cream is a sweetened frozen food typically eaten as a snack or dessert. It may be made from milk or cream and is flavoured with a sweetener, either sugar or an alternative, and a spice, such as cocoa or vanilla, or with fruit such as strawberries or peaches. It can also be made by whisking a flavored cream base and liquid nitrogen together. Food coloring is sometimes added, in addition to stabilizers. The mixture is cooled below the freezing point of water and stirred to incorporate air spaces and to prevent detectable ice crystals from forming. The result is a smooth, semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F). It becomes more malleable as its temperature increases.\n\nThe meaning of the name \"ice cream\" varies from one country to another. In some countries, such as the United States, \"ice cream\" applies only to a specific variety, and most governments regulate the commercial use of the various terms according to the relative quantities of the main ingredients, notably the amount of cream. Products that do not meet the criteria to be called ice cream are sometimes labelled \"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, one word is used for all variants. Analogues made from dairy alternatives, such as goat'\''s or sheep'\''s milk, or milk substitutes (e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are lactose intolerant, allergic to dairy protein or vegan."
}'
9 changes: 9 additions & 0 deletions snippets/curl/tokenize-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl --request POST \
--url https://api.cohere.com/v1/tokenize \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: bearer $CO_API_KEY" \
--data '{
"model": "command",
"text": "tokenize me! :D"
}'
42 changes: 42 additions & 0 deletions snippets/go/chat-post/default/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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(client.WithToken("<<apiKey>>"))

resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
ChatHistory: []*cohere.Message{
{
Role: "USER",
User: &cohere.ChatMessage{
Message: "Who discovered gravity?",
},
},
{
Role: "CHATBOT",
Chatbot: &cohere.ChatMessage{
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
}},
Message: "What year was he born?",
Connectors: []*cohere.ChatConnector{
{Id: "web-search"},
},
},
)

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

log.Printf("%+v", resp)
}
61 changes: 61 additions & 0 deletions snippets/go/chat-post/documents/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"errors"
"io"
"log"

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

func main() {
co := client.NewClient(client.WithToken("<<apiKey>>"))

resp, err := co.ChatStream(
context.TODO(),
&cohere.ChatStreamRequest{
ChatHistory: []*cohere.Message{
{
Role: "USER",
User: &cohere.ChatMessage{
Message: "Who discovered gravity?",
},
},
{
Role: "CHATBOT",
Chatbot: &cohere.ChatMessage{
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
}},
Message: "What year was he born?",
Connectors: []*cohere.ChatConnector{
{Id: "web-search"},
},
},
)

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

// Make sure to close the stream when you're done reading.
// This is easily handled with defer.
defer resp.Close()

for {
message, err := resp.Recv()

if errors.Is(err, io.EOF) {
// An io.EOF error means the server is done sending messages
// and should be treated as a success.
break
}

if message.TextGeneration != nil {
log.Printf("%+v", resp)
}
}

}
Loading

0 comments on commit fa70d55

Please sign in to comment.