-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: billytrend-cohere <[email protected]>
- Loading branch information
1 parent
a017651
commit 2da76e7
Showing
15 changed files
with
3,127 additions
and
282 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."] | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
snippets/snippets/java/app/src/main/java/RerankV2Post.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
snippets/snippets/java/app/src/main/java/chatv2post/Default.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.