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 Sep 24, 2024
1 parent a017651 commit 2da76e7
Show file tree
Hide file tree
Showing 15 changed files with 3,127 additions and 282 deletions.
2,826 changes: 2,571 additions & 255 deletions cohere-openapi.yaml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions snippets/snippets/curl/rerank-v2-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."]
}'
22 changes: 22 additions & 0 deletions snippets/snippets/java/app/src/main/java/EmbedV2Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* (C)2024 */
import com.cohere.api.Cohere;
import com.cohere.api.resources.v2.requests.V2EmbedRequest;
import com.cohere.api.types.EmbedByTypeResponse;
import com.cohere.api.types.EmbedInputType;
import java.util.List;

public class EmbedV2Post {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();

EmbedByTypeResponse response =
cohere.v2().embed(
V2EmbedRequest.builder()
.model("embed-english-v3.0")
.texts(List.of("hello", "goodbye"))
.inputType(EmbedInputType.CLASSIFICATION)
.build());

System.out.println(response);
}
}
52 changes: 52 additions & 0 deletions snippets/snippets/java/app/src/main/java/RerankV2Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* (C)2024 */
import com.cohere.api.Cohere;
import com.cohere.api.resources.v2.requests.V2RerankRequest;
import com.cohere.api.resources.v2.types.V2RerankRequestDocumentsItem;
import com.cohere.api.resources.v2.types.V2RerankResponse;
import java.util.List;

public class RerankV2Post {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();

V2RerankResponse response =
cohere.v2().rerank(
V2RerankRequest.builder()
.model("rerank-english-v3.0")
.query("What is the capital of the United States?")
.documents(
List.of(
V2RerankRequestDocumentsItem.of(
"Carson City is the capital city of the"
+ " American state of Nevada."),
V2RerankRequestDocumentsItem.of(
"The Commonwealth of the Northern Mariana"
+ " Islands is a group of islands in"
+ " the Pacific Ocean. Its capital is"
+ " Saipan."),
V2RerankRequestDocumentsItem.of(
"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."),
V2RerankRequestDocumentsItem.of(
"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."),
V2RerankRequestDocumentsItem.of(
"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.")))
.topN(3)
.build());

System.out.println(response);
}
}
26 changes: 14 additions & 12 deletions snippets/snippets/java/app/src/main/java/chatpost/Default.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.Message;
import com.cohere.api.types.NonStreamedChatResponse;
import java.util.List;

Expand All @@ -18,17 +18,19 @@ public static void main(String[] args) {
.message("What year was he born?")
.chatHistory(
List.of(
ChatMessage.builder()
.role(ChatMessageRole.USER)
.message("Who discovered gravity?")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.CHATBOT)
.message(
"The man who is widely credited"
+ " with discovering gravity is"
+ " Sir Isaac Newton")
.build()))
Message.user(
ChatMessage.builder()
.message("Who discovered gravity?")
.build()),
Message.chatbot(
ChatMessage.builder()
.message(
"The man who is widely"
+ " credited with"
+ " discovering gravity"
+ " is Sir Isaac"
+ " Newton")
.build())))
.build());

System.out.println(response);
Expand Down
26 changes: 14 additions & 12 deletions snippets/snippets/java/app/src/main/java/chatpost/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatStreamRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.ChatMessageRole;
import com.cohere.api.types.ChatTextGenerationEvent;
import com.cohere.api.types.Message;
import com.cohere.api.types.StreamedChatResponse;
import java.util.List;

Expand All @@ -19,17 +19,19 @@ public static void main(String[] args) {
.message("What year was he born?")
.chatHistory(
List.of(
ChatMessage.builder()
.role(ChatMessageRole.USER)
.message("Who discovered gravity?")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.CHATBOT)
.message(
"The man who is widely credited"
+ " with discovering gravity is"
+ " Sir Isaac Newton")
.build()))
Message.user(
ChatMessage.builder()
.message("Who discovered gravity?")
.build()),
Message.chatbot(
ChatMessage.builder()
.message(
"The man who is widely"
+ " credited with"
+ " discovering gravity"
+ " is Sir Isaac"
+ " Newton")
.build())))
.build());

for (StreamedChatResponse chatResponse : response) {
Expand Down
48 changes: 48 additions & 0 deletions snippets/snippets/java/app/src/main/java/chatv2post/Default.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* (C)2024 */
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 Default {
public static void main(String[] args) {
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(
"Who discovered"
+ " gravity?"))
.build()),
ChatMessageV2.assistant(
AssistantMessage.builder()
.content(
AssistantMessageContent
.of(
"The man"
+ " who is"
+ " widely"
+ " credited"
+ " with"
+ " discovering"
+ " gravity"
+ " is Sir"
+ " Isaac"
+ " Newton"))
.build())))
.build());

System.out.println(response);
}
}
Loading

0 comments on commit 2da76e7

Please sign in to comment.