diff --git a/.fern/metadata.json b/.fern/metadata.json
index 71d1ec6..1389994 100644
--- a/.fern/metadata.json
+++ b/.fern/metadata.json
@@ -1,8 +1,9 @@
{
- "cliVersion": "0.112.1",
+ "cliVersion": "3.50.1",
"generatorName": "fernapi/fern-java-sdk",
- "generatorVersion": "3.14.2",
+ "generatorVersion": "3.34.5",
"generatorConfig": {
"client-class-name": "Cohere"
- }
+ },
+ "sdkVersion": "1.9.5"
}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index a5930be..a9328cd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,10 +14,10 @@ repositories {
}
dependencies {
- api 'com.squareup.okhttp3:okhttp:4.12.0'
- api 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
- api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.2'
- api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2'
+ api 'com.squareup.okhttp3:okhttp:5.2.1'
+ api 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
+ api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2'
+ api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
@@ -47,7 +47,7 @@ java {
group = 'com.cohere'
-version = '1.9.4'
+version = '1.9.5'
jar {
dependsOn(":generatePomFileForMavenPublication")
@@ -78,7 +78,7 @@ publishing {
maven(MavenPublication) {
groupId = 'com.cohere'
artifactId = 'cohere-java'
- version = '1.9.4'
+ version = '1.9.5'
from components.java
pom {
name = 'cohere'
diff --git a/reference.md b/reference.md
index 0d8333a..d2bbdee 100644
--- a/reference.md
+++ b/reference.md
@@ -1,5 +1,5 @@
# Reference
-client.chatStream(request) -> Optional<StreamedChatResponse>
+client.chatStream(request) -> Iterable<StreamedChatResponse>
-
@@ -32,7 +32,6 @@ client.chatStream(
ChatStreamRequest
.builder()
.message("hello!")
- .stream(true)
.model("command-a-03-2025")
.build()
);
@@ -488,7 +487,6 @@ client.chatStream(
ChatStreamRequest
.builder()
.message("Tell me about LLMs")
- .stream(false)
.model("command-a-03-2025")
.build()
);
@@ -912,7 +910,7 @@ Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private D
-client.generateStream(request) -> Optional<GenerateStreamedResponse>
+client.generateStream(request) -> Iterable<GenerateStreamedResponse>
-
@@ -946,7 +944,6 @@ client.generateStream(
GenerateStreamRequest
.builder()
.prompt("Please explain to me how LLMs work")
- .stream(true)
.build()
);
```
@@ -1197,7 +1194,6 @@ client.generateStream(
GenerateStreamRequest
.builder()
.prompt("Please explain to me how LLMs work")
- .stream(false)
.build()
);
```
@@ -1573,6 +1569,7 @@ This endpoint takes in a query and a list of texts and produces an ordered array
client.rerank(
RerankRequest
.builder()
+ .query("What is the capital of the United States?")
.documents(
Arrays.asList(
RerankRequestDocumentsItem.of(),
@@ -1582,9 +1579,8 @@ client.rerank(
RerankRequestDocumentsItem.of()
)
)
- .query("What is the capital of the United States?")
- .topN(3)
.model("rerank-v4.0-pro")
+ .topN(3)
.build()
);
```
@@ -2043,10 +2039,10 @@ This endpoint takes tokens using byte-pair encoding and returns their text repre
client.detokenize(
DetokenizeRequest
.builder()
+ .model("command")
.tokens(
Arrays.asList(10002, 2261, 2012, 8, 2792, 43)
)
- .model("command")
.build()
);
```
@@ -2123,7 +2119,7 @@ client.checkApiKey();
## V2
-client.v2.chatStream(request) -> Optional<V2ChatStreamResponse>
+client.v2.chatStream(request) -> Iterable<V2ChatStreamResponse>
-
@@ -2168,7 +2164,6 @@ client.v2().chatStream(
)
)
)
- .stream(true)
.build()
);
```
@@ -2460,7 +2455,6 @@ client.v2().chatStream(
)
)
)
- .stream(false)
.build()
);
```
@@ -2907,11 +2901,11 @@ This endpoint takes in a query and a list of texts and produces an ordered array
client.v2().rerank(
V2RerankRequest
.builder()
+ .model("rerank-v4.0-pro")
+ .query("What is the capital of the United States?")
.documents(
Arrays.asList("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.", "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.", "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.", "Capital punishment 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.")
)
- .query("What is the capital of the United States?")
- .model("rerank-v4.0-pro")
.topN(3)
.build()
);
diff --git a/src/main/java/com/cohere/api/AsyncCohere.java b/src/main/java/com/cohere/api/AsyncCohere.java
index ff19ca9..ca894ac 100644
--- a/src/main/java/com/cohere/api/AsyncCohere.java
+++ b/src/main/java/com/cohere/api/AsyncCohere.java
@@ -158,6 +158,15 @@ public CompletableFuture embed() {
return this.rawClient.embed().thenApply(response -> response.body());
}
+ /**
+ * This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
+ *
Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
+ * If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.
+ */
+ public CompletableFuture embed(RequestOptions requestOptions) {
+ return this.rawClient.embed(requestOptions).thenApply(response -> response.body());
+ }
+
/**
* This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
* Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
diff --git a/src/main/java/com/cohere/api/AsyncCohereBuilder.java b/src/main/java/com/cohere/api/AsyncCohereBuilder.java
index 0aa8d20..05d0c12 100644
--- a/src/main/java/com/cohere/api/AsyncCohereBuilder.java
+++ b/src/main/java/com/cohere/api/AsyncCohereBuilder.java
@@ -229,6 +229,9 @@ protected void setAdditional(ClientOptions.Builder builder) {}
protected void validateConfiguration() {}
public AsyncCohere build() {
+ if (token == null) {
+ throw new RuntimeException("Please provide token or set the CO_API_KEY environment variable.");
+ }
validateConfiguration();
return new AsyncCohere(buildClientOptions());
}
diff --git a/src/main/java/com/cohere/api/AsyncRawCohere.java b/src/main/java/com/cohere/api/AsyncRawCohere.java
index 4e4ac98..d332913 100644
--- a/src/main/java/com/cohere/api/AsyncRawCohere.java
+++ b/src/main/java/com/cohere/api/AsyncRawCohere.java
@@ -47,8 +47,6 @@
import com.cohere.api.types.TokenizeResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import java.util.concurrent.CompletableFuture;
import okhttp3.Call;
import okhttp3.Callback;
@@ -82,50 +80,26 @@ public CompletableFuture>> cha
*/
public CompletableFuture>> chatStream(
ChatStreamRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/chat")
- .build();
- Map properties = new HashMap<>();
- properties.put("message", request.getMessage());
- properties.put("model", request.getModel());
- properties.put("stream", request.getStream());
- properties.put("preamble", request.getPreamble());
- properties.put("chat_history", request.getChatHistory());
- properties.put("conversation_id", request.getConversationId());
- properties.put("prompt_truncation", request.getPromptTruncation());
- properties.put("connectors", request.getConnectors());
- properties.put("search_queries_only", request.getSearchQueriesOnly());
- properties.put("documents", request.getDocuments());
- properties.put("citation_quality", request.getCitationQuality());
- properties.put("temperature", request.getTemperature());
- properties.put("max_tokens", request.getMaxTokens());
- properties.put("max_input_tokens", request.getMaxInputTokens());
- properties.put("k", request.getK());
- properties.put("p", request.getP());
- properties.put("seed", request.getSeed());
- properties.put("stop_sequences", request.getStopSequences());
- properties.put("frequency_penalty", request.getFrequencyPenalty());
- properties.put("presence_penalty", request.getPresencePenalty());
- properties.put("raw_prompting", request.getRawPrompting());
- properties.put("tools", request.getTools());
- properties.put("tool_results", request.getToolResults());
- properties.put("force_single_step", request.getForceSingleStep());
- properties.put("response_format", request.getResponseFormat());
- properties.put("safety_mode", request.getSafetyMode());
+ .addPathSegments("v1/chat");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
- ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON);
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (Exception e) {
throw new RuntimeException(e);
}
Request.Builder _requestBuilder = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
- .addHeader("Content-Type", "application/json")
- .addHeader("Accept", "application/json");
+ .addHeader("Content-Type", "application/json");
if (request.getAccepts().isPresent()) {
_requestBuilder.addHeader("Accepts", request.getAccepts().get());
}
@@ -244,46 +218,23 @@ public CompletableFuture> chat(ChatR
*/
public CompletableFuture> chat(
ChatRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/chat")
- .build();
- Map properties = new HashMap<>();
- properties.put("message", request.getMessage());
- properties.put("model", request.getModel());
- properties.put("stream", request.getStream());
- properties.put("preamble", request.getPreamble());
- properties.put("chat_history", request.getChatHistory());
- properties.put("conversation_id", request.getConversationId());
- properties.put("prompt_truncation", request.getPromptTruncation());
- properties.put("connectors", request.getConnectors());
- properties.put("search_queries_only", request.getSearchQueriesOnly());
- properties.put("documents", request.getDocuments());
- properties.put("citation_quality", request.getCitationQuality());
- properties.put("temperature", request.getTemperature());
- properties.put("max_tokens", request.getMaxTokens());
- properties.put("max_input_tokens", request.getMaxInputTokens());
- properties.put("k", request.getK());
- properties.put("p", request.getP());
- properties.put("seed", request.getSeed());
- properties.put("stop_sequences", request.getStopSequences());
- properties.put("frequency_penalty", request.getFrequencyPenalty());
- properties.put("presence_penalty", request.getPresencePenalty());
- properties.put("raw_prompting", request.getRawPrompting());
- properties.put("tools", request.getTools());
- properties.put("tool_results", request.getToolResults());
- properties.put("force_single_step", request.getForceSingleStep());
- properties.put("response_format", request.getResponseFormat());
- properties.put("safety_mode", request.getSafetyMode());
+ .addPathSegments("v1/chat");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
- ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON);
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (Exception e) {
throw new RuntimeException(e);
}
Request.Builder _requestBuilder = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -410,10 +361,14 @@ public CompletableFuture>>
*/
public CompletableFuture>> generateStream(
GenerateStreamRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/generate")
- .build();
+ .addPathSegments("v1/generate");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -422,11 +377,10 @@ public CompletableFuture>>
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
- .addHeader("Accept", "application/json")
.build();
OkHttpClient client = clientOptions.httpClient();
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
@@ -547,10 +501,14 @@ public CompletableFuture> generate(GenerateReques
*/
public CompletableFuture> generate(
GenerateRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/generate")
- .build();
+ .addPathSegments("v1/generate");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -559,7 +517,7 @@ public CompletableFuture> generate(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -672,6 +630,15 @@ public CompletableFuture> embed() {
return embed(EmbedRequest.builder().build());
}
+ /**
+ * This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
+ * Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
+ * If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.
+ */
+ public CompletableFuture> embed(RequestOptions requestOptions) {
+ return embed(EmbedRequest.builder().build(), requestOptions);
+ }
+
/**
* This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
* Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
@@ -688,10 +655,14 @@ public CompletableFuture> embed(EmbedRequest r
*/
public CompletableFuture> embed(
EmbedRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/embed")
- .build();
+ .addPathSegments("v1/embed");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -700,7 +671,7 @@ public CompletableFuture> embed(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -817,10 +788,14 @@ public CompletableFuture> rerank(RerankReques
*/
public CompletableFuture> rerank(
RerankRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/rerank")
- .build();
+ .addPathSegments("v1/rerank");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -829,7 +804,7 @@ public CompletableFuture> rerank(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -948,10 +923,14 @@ public CompletableFuture> classify(Classify
*/
public CompletableFuture> classify(
ClassifyRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/classify")
- .build();
+ .addPathSegments("v1/classify");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -960,7 +939,7 @@ public CompletableFuture> classify(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -1083,10 +1062,14 @@ public CompletableFuture> summarize(Summar
*/
public CompletableFuture> summarize(
SummarizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/summarize")
- .build();
+ .addPathSegments("v1/summarize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -1095,7 +1078,7 @@ public CompletableFuture> summarize(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -1212,10 +1195,14 @@ public CompletableFuture> tokenize(Tokenize
*/
public CompletableFuture> tokenize(
TokenizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/tokenize")
- .build();
+ .addPathSegments("v1/tokenize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -1224,7 +1211,7 @@ public CompletableFuture> tokenize(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -1341,10 +1328,14 @@ public CompletableFuture> detokenize(Deto
*/
public CompletableFuture> detokenize(
DetokenizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/detokenize")
- .build();
+ .addPathSegments("v1/detokenize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -1353,7 +1344,7 @@ public CompletableFuture> detokenize(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -1469,12 +1460,16 @@ public CompletableFuture> checkApiKey()
* Checks that the api key in the Authorization header is valid and active
*/
public CompletableFuture> checkApiKey(RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/check-api-key")
- .build();
+ .addPathSegments("v1/check-api-key");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", RequestBody.create("", null))
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
diff --git a/src/main/java/com/cohere/api/Cohere.java b/src/main/java/com/cohere/api/Cohere.java
index ee56fd7..f591479 100644
--- a/src/main/java/com/cohere/api/Cohere.java
+++ b/src/main/java/com/cohere/api/Cohere.java
@@ -156,6 +156,15 @@ public EmbedResponse embed() {
return this.rawClient.embed().body();
}
+ /**
+ * This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
+ * Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
+ * If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.
+ */
+ public EmbedResponse embed(RequestOptions requestOptions) {
+ return this.rawClient.embed(requestOptions).body();
+ }
+
/**
* This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
* Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
diff --git a/src/main/java/com/cohere/api/CohereBuilder.java b/src/main/java/com/cohere/api/CohereBuilder.java
index b1bbff9..9fabaad 100644
--- a/src/main/java/com/cohere/api/CohereBuilder.java
+++ b/src/main/java/com/cohere/api/CohereBuilder.java
@@ -229,6 +229,9 @@ protected void setAdditional(ClientOptions.Builder builder) {}
protected void validateConfiguration() {}
public Cohere build() {
+ if (token == null) {
+ throw new RuntimeException("Please provide token or set the CO_API_KEY environment variable.");
+ }
validateConfiguration();
return new Cohere(buildClientOptions());
}
diff --git a/src/main/java/com/cohere/api/RawCohere.java b/src/main/java/com/cohere/api/RawCohere.java
index 7f36061..a035211 100644
--- a/src/main/java/com/cohere/api/RawCohere.java
+++ b/src/main/java/com/cohere/api/RawCohere.java
@@ -47,8 +47,6 @@
import com.cohere.api.types.TokenizeResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
@@ -78,50 +76,26 @@ public CohereHttpResponse> chatStream(ChatStreamR
*/
public CohereHttpResponse> chatStream(
ChatStreamRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/chat")
- .build();
- Map properties = new HashMap<>();
- properties.put("message", request.getMessage());
- properties.put("model", request.getModel());
- properties.put("stream", request.getStream());
- properties.put("preamble", request.getPreamble());
- properties.put("chat_history", request.getChatHistory());
- properties.put("conversation_id", request.getConversationId());
- properties.put("prompt_truncation", request.getPromptTruncation());
- properties.put("connectors", request.getConnectors());
- properties.put("search_queries_only", request.getSearchQueriesOnly());
- properties.put("documents", request.getDocuments());
- properties.put("citation_quality", request.getCitationQuality());
- properties.put("temperature", request.getTemperature());
- properties.put("max_tokens", request.getMaxTokens());
- properties.put("max_input_tokens", request.getMaxInputTokens());
- properties.put("k", request.getK());
- properties.put("p", request.getP());
- properties.put("seed", request.getSeed());
- properties.put("stop_sequences", request.getStopSequences());
- properties.put("frequency_penalty", request.getFrequencyPenalty());
- properties.put("presence_penalty", request.getPresencePenalty());
- properties.put("raw_prompting", request.getRawPrompting());
- properties.put("tools", request.getTools());
- properties.put("tool_results", request.getToolResults());
- properties.put("force_single_step", request.getForceSingleStep());
- properties.put("response_format", request.getResponseFormat());
- properties.put("safety_mode", request.getSafetyMode());
+ .addPathSegments("v1/chat");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
- ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON);
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (Exception e) {
throw new RuntimeException(e);
}
Request.Builder _requestBuilder = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
- .addHeader("Content-Type", "application/json")
- .addHeader("Accept", "application/json");
+ .addHeader("Content-Type", "application/json");
if (request.getAccepts().isPresent()) {
_requestBuilder.addHeader("Accepts", request.getAccepts().get());
}
@@ -201,46 +175,23 @@ public CohereHttpResponse chat(ChatRequest request) {
* To learn how to use the Chat API and RAG follow our Text Generation guides.
*/
public CohereHttpResponse chat(ChatRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/chat")
- .build();
- Map properties = new HashMap<>();
- properties.put("message", request.getMessage());
- properties.put("model", request.getModel());
- properties.put("stream", request.getStream());
- properties.put("preamble", request.getPreamble());
- properties.put("chat_history", request.getChatHistory());
- properties.put("conversation_id", request.getConversationId());
- properties.put("prompt_truncation", request.getPromptTruncation());
- properties.put("connectors", request.getConnectors());
- properties.put("search_queries_only", request.getSearchQueriesOnly());
- properties.put("documents", request.getDocuments());
- properties.put("citation_quality", request.getCitationQuality());
- properties.put("temperature", request.getTemperature());
- properties.put("max_tokens", request.getMaxTokens());
- properties.put("max_input_tokens", request.getMaxInputTokens());
- properties.put("k", request.getK());
- properties.put("p", request.getP());
- properties.put("seed", request.getSeed());
- properties.put("stop_sequences", request.getStopSequences());
- properties.put("frequency_penalty", request.getFrequencyPenalty());
- properties.put("presence_penalty", request.getPresencePenalty());
- properties.put("raw_prompting", request.getRawPrompting());
- properties.put("tools", request.getTools());
- properties.put("tool_results", request.getToolResults());
- properties.put("force_single_step", request.getForceSingleStep());
- properties.put("response_format", request.getResponseFormat());
- properties.put("safety_mode", request.getSafetyMode());
+ .addPathSegments("v1/chat");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
- ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON);
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (Exception e) {
throw new RuntimeException(e);
}
Request.Builder _requestBuilder = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -329,10 +280,14 @@ public CohereHttpResponse> generateStream(Gen
*/
public CohereHttpResponse> generateStream(
GenerateStreamRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/generate")
- .build();
+ .addPathSegments("v1/generate");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -341,11 +296,10 @@ public CohereHttpResponse> generateStream(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
- .addHeader("Accept", "application/json")
.build();
OkHttpClient client = clientOptions.httpClient();
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
@@ -427,10 +381,14 @@ public CohereHttpResponse generate(GenerateRequest request) {
* Generates realistic text conditioned on a given input.
*/
public CohereHttpResponse generate(GenerateRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/generate")
- .build();
+ .addPathSegments("v1/generate");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -439,7 +397,7 @@ public CohereHttpResponse generate(GenerateRequest request, RequestO
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -515,6 +473,15 @@ public CohereHttpResponse embed() {
return embed(EmbedRequest.builder().build());
}
+ /**
+ * This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
+ * Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
+ * If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.
+ */
+ public CohereHttpResponse embed(RequestOptions requestOptions) {
+ return embed(EmbedRequest.builder().build(), requestOptions);
+ }
+
/**
* This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
* Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
@@ -530,10 +497,14 @@ public CohereHttpResponse embed(EmbedRequest request) {
* If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.
*/
public CohereHttpResponse embed(EmbedRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/embed")
- .build();
+ .addPathSegments("v1/embed");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -542,7 +513,7 @@ public CohereHttpResponse embed(EmbedRequest request, RequestOpti
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -620,10 +591,14 @@ public CohereHttpResponse rerank(RerankRequest request) {
* This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.
*/
public CohereHttpResponse rerank(RerankRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/rerank")
- .build();
+ .addPathSegments("v1/rerank");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -632,7 +607,7 @@ public CohereHttpResponse rerank(RerankRequest request, RequestO
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -712,10 +687,14 @@ public CohereHttpResponse classify(ClassifyRequest request) {
* Note: Fine-tuned models trained on classification examples don't require the examples parameter to be passed in explicitly.
*/
public CohereHttpResponse classify(ClassifyRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/classify")
- .build();
+ .addPathSegments("v1/classify");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -724,7 +703,7 @@ public CohereHttpResponse classify(ClassifyRequest request, Re
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -808,10 +787,14 @@ public CohereHttpResponse summarize(SummarizeRequest request)
* Generates a summary in English for a given text.
*/
public CohereHttpResponse summarize(SummarizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/summarize")
- .build();
+ .addPathSegments("v1/summarize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -820,7 +803,7 @@ public CohereHttpResponse summarize(SummarizeRequest request,
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -898,10 +881,14 @@ public CohereHttpResponse tokenize(TokenizeRequest request) {
* This endpoint splits input text into smaller units called tokens using byte-pair encoding (BPE). To learn more about tokenization and byte pair encoding, see the tokens page.
*/
public CohereHttpResponse tokenize(TokenizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/tokenize")
- .build();
+ .addPathSegments("v1/tokenize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -910,7 +897,7 @@ public CohereHttpResponse tokenize(TokenizeRequest request, Re
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -988,10 +975,14 @@ public CohereHttpResponse detokenize(DetokenizeRequest reque
* This endpoint takes tokens using byte-pair encoding and returns their text representation. To learn more about tokenization and byte pair encoding, see the tokens page.
*/
public CohereHttpResponse detokenize(DetokenizeRequest request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/detokenize")
- .build();
+ .addPathSegments("v1/detokenize");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -1000,7 +991,7 @@ public CohereHttpResponse detokenize(DetokenizeRequest reque
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -1078,12 +1069,16 @@ public CohereHttpResponse checkApiKey() {
* Checks that the api key in the Authorization header is valid and active
*/
public CohereHttpResponse checkApiKey(RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v1/check-api-key")
- .build();
+ .addPathSegments("v1/check-api-key");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", RequestBody.create("", null))
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
diff --git a/src/main/java/com/cohere/api/core/ClientOptions.java b/src/main/java/com/cohere/api/core/ClientOptions.java
index 7dcfc7e..980a4e6 100644
--- a/src/main/java/com/cohere/api/core/ClientOptions.java
+++ b/src/main/java/com/cohere/api/core/ClientOptions.java
@@ -35,10 +35,10 @@ private ClientOptions(
this.headers.putAll(headers);
this.headers.putAll(new HashMap() {
{
- put("User-Agent", "com.cohere:cohere-java/1.7.1");
+ put("User-Agent", "com.cohere:cohere-java/1.9.5");
put("X-Fern-Language", "JAVA");
put("X-Fern-SDK-Name", "com.cohere.fern:api-sdk");
- put("X-Fern-SDK-Version", "1.7.1");
+ put("X-Fern-SDK-Version", "1.9.5");
}
});
this.headerSuppliers = headerSuppliers;
@@ -185,6 +185,9 @@ public static Builder from(ClientOptions clientOptions) {
builder.environment = clientOptions.environment();
builder.timeout = Optional.of(clientOptions.timeout(null));
builder.httpClient = clientOptions.httpClient();
+ builder.headers.putAll(clientOptions.headers);
+ builder.headerSuppliers.putAll(clientOptions.headerSuppliers);
+ builder.maxRetries = clientOptions.maxRetries();
return builder;
}
}
diff --git a/src/main/java/com/cohere/api/core/RequestOptions.java b/src/main/java/com/cohere/api/core/RequestOptions.java
index fa9e403..a675b75 100644
--- a/src/main/java/com/cohere/api/core/RequestOptions.java
+++ b/src/main/java/com/cohere/api/core/RequestOptions.java
@@ -22,19 +22,27 @@ public final class RequestOptions {
private final Map> headerSuppliers;
+ private final Map queryParameters;
+
+ private final Map> queryParameterSuppliers;
+
private RequestOptions(
String token,
String clientName,
Optional timeout,
TimeUnit timeoutTimeUnit,
Map headers,
- Map> headerSuppliers) {
+ Map> headerSuppliers,
+ Map queryParameters,
+ Map> queryParameterSuppliers) {
this.token = token;
this.clientName = clientName;
this.timeout = timeout;
this.timeoutTimeUnit = timeoutTimeUnit;
this.headers = headers;
this.headerSuppliers = headerSuppliers;
+ this.queryParameters = queryParameters;
+ this.queryParameterSuppliers = queryParameterSuppliers;
}
public Optional getTimeout() {
@@ -60,6 +68,14 @@ public Map getHeaders() {
return headers;
}
+ public Map getQueryParameters() {
+ Map queryParameters = new HashMap<>(this.queryParameters);
+ this.queryParameterSuppliers.forEach((key, supplier) -> {
+ queryParameters.put(key, supplier.get());
+ });
+ return queryParameters;
+ }
+
public static Builder builder() {
return new Builder();
}
@@ -77,6 +93,10 @@ public static class Builder {
private final Map> headerSuppliers = new HashMap<>();
+ private final Map queryParameters = new HashMap<>();
+
+ private final Map> queryParameterSuppliers = new HashMap<>();
+
public Builder token(String token) {
this.token = token;
return this;
@@ -108,8 +128,26 @@ public Builder addHeader(String key, Supplier value) {
return this;
}
+ public Builder addQueryParameter(String key, String value) {
+ this.queryParameters.put(key, value);
+ return this;
+ }
+
+ public Builder addQueryParameter(String key, Supplier value) {
+ this.queryParameterSuppliers.put(key, value);
+ return this;
+ }
+
public RequestOptions build() {
- return new RequestOptions(token, clientName, timeout, timeoutTimeUnit, headers, headerSuppliers);
+ return new RequestOptions(
+ token,
+ clientName,
+ timeout,
+ timeoutTimeUnit,
+ headers,
+ headerSuppliers,
+ queryParameters,
+ queryParameterSuppliers);
}
}
}
diff --git a/src/main/java/com/cohere/api/requests/ChatRequest.java b/src/main/java/com/cohere/api/requests/ChatRequest.java
index 0dcbc0d..005d1e3 100644
--- a/src/main/java/com/cohere/api/requests/ChatRequest.java
+++ b/src/main/java/com/cohere/api/requests/ChatRequest.java
@@ -14,6 +14,7 @@
import com.cohere.api.types.ToolResult;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -144,7 +145,7 @@ private ChatRequest(
/**
* @return Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.
*/
- @JsonProperty("Accepts")
+ @JsonIgnore
public Optional getAccepts() {
return accepts;
}
@@ -1543,7 +1544,6 @@ public _FinalStage accepts(String accepts) {
* Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.
*/
@java.lang.Override
- @JsonSetter(value = "Accepts", nulls = Nulls.SKIP)
public _FinalStage accepts(Optional accepts) {
this.accepts = accepts;
return this;
diff --git a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java
index 292e17a..f3f1f75 100644
--- a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java
+++ b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java
@@ -14,6 +14,7 @@
import com.cohere.api.types.ToolResult;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -144,7 +145,7 @@ private ChatStreamRequest(
/**
* @return Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.
*/
- @JsonProperty("Accepts")
+ @JsonIgnore
public Optional getAccepts() {
return accepts;
}
@@ -1543,7 +1544,6 @@ public _FinalStage accepts(String accepts) {
* Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.
*/
@java.lang.Override
- @JsonSetter(value = "Accepts", nulls = Nulls.SKIP)
public _FinalStage accepts(Optional accepts) {
this.accepts = accepts;
return this;
diff --git a/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java
index b425fec..263d2ca 100644
--- a/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java
+++ b/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java
@@ -37,6 +37,13 @@ public CompletableFuture list() {
return this.rawClient.list().thenApply(response -> response.body());
}
+ /**
+ * List the batches for the current user
+ */
+ public CompletableFuture list(RequestOptions requestOptions) {
+ return this.rawClient.list(requestOptions).thenApply(response -> response.body());
+ }
+
/**
* List the batches for the current user
*/
diff --git a/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java
index 7b1d79d..1ea82a6 100644
--- a/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java
+++ b/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java
@@ -52,6 +52,13 @@ public CompletableFuture> list() {
return list(BatchesListBatchesRequest.builder().build());
}
+ /**
+ * List the batches for the current user
+ */
+ public CompletableFuture> list(RequestOptions requestOptions) {
+ return list(BatchesListBatchesRequest.builder().build(), requestOptions);
+ }
+
/**
* List the batches for the current user
*/
@@ -79,6 +86,11 @@ public CompletableFuture> list(
QueryStringMapper.addQueryParameter(
httpUrl, "order_by", request.getOrderBy().get(), false);
}
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
@@ -166,10 +178,14 @@ public CompletableFuture> create(Batch r
*/
public CompletableFuture> create(
Batch request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v2/batches")
- .build();
+ .addPathSegments("v2/batches");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -178,7 +194,7 @@ public CompletableFuture> create(
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -264,13 +280,17 @@ public CompletableFuture> retrieve(String i
* Retrieves a batch
*/
public CompletableFuture> retrieve(String id, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/batches")
- .addPathSegment(id)
- .build();
+ .addPathSegment(id);
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
@@ -355,14 +375,18 @@ public CompletableFuture>> cancel(String
* Cancels an in-progress batch
*/
public CompletableFuture>> cancel(String id, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/batches")
.addPathSegment(id)
- .addPathSegments(":cancel")
- .build();
+ .addPathSegments(":cancel");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", RequestBody.create("", null))
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
diff --git a/src/main/java/com/cohere/api/resources/batches/BatchesClient.java b/src/main/java/com/cohere/api/resources/batches/BatchesClient.java
index 82f4fd0..d2c4b18 100644
--- a/src/main/java/com/cohere/api/resources/batches/BatchesClient.java
+++ b/src/main/java/com/cohere/api/resources/batches/BatchesClient.java
@@ -36,6 +36,13 @@ public ListBatchesResponse list() {
return this.rawClient.list().body();
}
+ /**
+ * List the batches for the current user
+ */
+ public ListBatchesResponse list(RequestOptions requestOptions) {
+ return this.rawClient.list(requestOptions).body();
+ }
+
/**
* List the batches for the current user
*/
diff --git a/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java
index 6dfed17..ae49915 100644
--- a/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java
+++ b/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java
@@ -48,6 +48,13 @@ public CohereHttpResponse list() {
return list(BatchesListBatchesRequest.builder().build());
}
+ /**
+ * List the batches for the current user
+ */
+ public CohereHttpResponse list(RequestOptions requestOptions) {
+ return list(BatchesListBatchesRequest.builder().build(), requestOptions);
+ }
+
/**
* List the batches for the current user
*/
@@ -75,6 +82,11 @@ public CohereHttpResponse list(
QueryStringMapper.addQueryParameter(
httpUrl, "order_by", request.getOrderBy().get(), false);
}
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
@@ -135,10 +147,14 @@ public CohereHttpResponse create(Batch request) {
* Creates and executes a batch from an uploaded dataset of requests
*/
public CohereHttpResponse create(Batch request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
- .addPathSegments("v2/batches")
- .build();
+ .addPathSegments("v2/batches");
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
RequestBody body;
try {
body = RequestBody.create(
@@ -147,7 +163,7 @@ public CohereHttpResponse create(Batch request, RequestOpti
throw new CohereException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("POST", body)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
@@ -207,13 +223,17 @@ public CohereHttpResponse retrieve(String id) {
* Retrieves a batch
*/
public CohereHttpResponse retrieve(String id, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/batches")
- .addPathSegment(id)
- .build();
+ .addPathSegment(id);
+ if (requestOptions != null) {
+ requestOptions.getQueryParameters().forEach((_key, _value) -> {
+ httpUrl.addQueryParameter(_key, _value);
+ });
+ }
Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
+ .url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
@@ -272,14 +292,18 @@ public CohereHttpResponse