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> cancel(String id) { * Cancels an in-progress batch */ public CohereHttpResponse> 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/connectors/AsyncConnectorsClient.java b/src/main/java/com/cohere/api/resources/connectors/AsyncConnectorsClient.java index 320f3f5..42980e1 100644 --- a/src/main/java/com/cohere/api/resources/connectors/AsyncConnectorsClient.java +++ b/src/main/java/com/cohere/api/resources/connectors/AsyncConnectorsClient.java @@ -41,6 +41,13 @@ public CompletableFuture list() { return this.rawClient.list().thenApply(response -> response.body()); } + /** + * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. + */ + public CompletableFuture list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).thenApply(response -> response.body()); + } + /** * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. */ @@ -106,6 +113,13 @@ public CompletableFuture update(String id) { return this.rawClient.update(id).thenApply(response -> response.body()); } + /** + * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. + */ + public CompletableFuture update(String id, RequestOptions requestOptions) { + return this.rawClient.update(id, requestOptions).thenApply(response -> response.body()); + } + /** * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. */ @@ -128,6 +142,13 @@ public CompletableFuture oAuthAuthorize(String id) { return this.rawClient.oAuthAuthorize(id).thenApply(response -> response.body()); } + /** + * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. + */ + public CompletableFuture oAuthAuthorize(String id, RequestOptions requestOptions) { + return this.rawClient.oAuthAuthorize(id, requestOptions).thenApply(response -> response.body()); + } + /** * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. */ diff --git a/src/main/java/com/cohere/api/resources/connectors/AsyncRawConnectorsClient.java b/src/main/java/com/cohere/api/resources/connectors/AsyncRawConnectorsClient.java index 6476616..d4aa778 100644 --- a/src/main/java/com/cohere/api/resources/connectors/AsyncRawConnectorsClient.java +++ b/src/main/java/com/cohere/api/resources/connectors/AsyncRawConnectorsClient.java @@ -62,6 +62,13 @@ public CompletableFuture> list() { return list(ConnectorsListRequest.builder().build()); } + /** + * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. + */ + public CompletableFuture> list(RequestOptions requestOptions) { + return list(ConnectorsListRequest.builder().build(), requestOptions); + } + /** * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. */ @@ -85,6 +92,11 @@ public CompletableFuture> list( QueryStringMapper.addQueryParameter( httpUrl, "offset", request.getOffset().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) @@ -202,10 +214,14 @@ public CompletableFuture> create(Cre */ public CompletableFuture> create( CreateConnectorRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/connectors") - .build(); + .addPathSegments("v1/connectors"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -214,7 +230,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") @@ -330,13 +346,17 @@ public CompletableFuture> get(String id * Retrieve a connector by ID. See 'Connectors' for more information. */ public CompletableFuture> get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .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") @@ -451,13 +471,17 @@ public CompletableFuture>> delete(String * Delete a connector by ID. See 'Connectors' for more information. */ public CompletableFuture>> delete(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") @@ -569,6 +593,14 @@ public CompletableFuture> update(Str return update(id, UpdateConnectorRequest.builder().build()); } + /** + * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. + */ + public CompletableFuture> update( + String id, RequestOptions requestOptions) { + return update(id, UpdateConnectorRequest.builder().build(), requestOptions); + } + /** * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. */ @@ -582,11 +614,15 @@ public CompletableFuture> update( */ public CompletableFuture> update( String id, UpdateConnectorRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .addPathSegment(id) - .build(); + .addPathSegment(id); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -595,7 +631,7 @@ public CompletableFuture> update( throw new CohereException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PATCH", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -707,6 +743,14 @@ public CompletableFuture> oAuthAuthor return oAuthAuthorize(id, ConnectorsOAuthAuthorizeRequest.builder().build()); } + /** + * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. + */ + public CompletableFuture> oAuthAuthorize( + String id, RequestOptions requestOptions) { + return oAuthAuthorize(id, ConnectorsOAuthAuthorizeRequest.builder().build(), requestOptions); + } + /** * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. */ @@ -733,6 +777,11 @@ public CompletableFuture> oAuthAuthor request.getAfterTokenRedirect().get(), false); } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) .method("POST", RequestBody.create("", null)) diff --git a/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java b/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java index e79ebca..4128563 100644 --- a/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java +++ b/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java @@ -40,6 +40,13 @@ public ListConnectorsResponse list() { return this.rawClient.list().body(); } + /** + * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. + */ + public ListConnectorsResponse list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).body(); + } + /** * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. */ @@ -103,6 +110,13 @@ public UpdateConnectorResponse update(String id) { return this.rawClient.update(id).body(); } + /** + * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. + */ + public UpdateConnectorResponse update(String id, RequestOptions requestOptions) { + return this.rawClient.update(id, requestOptions).body(); + } + /** * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. */ @@ -124,6 +138,13 @@ public OAuthAuthorizeResponse oAuthAuthorize(String id) { return this.rawClient.oAuthAuthorize(id).body(); } + /** + * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. + */ + public OAuthAuthorizeResponse oAuthAuthorize(String id, RequestOptions requestOptions) { + return this.rawClient.oAuthAuthorize(id, requestOptions).body(); + } + /** * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. */ diff --git a/src/main/java/com/cohere/api/resources/connectors/RawConnectorsClient.java b/src/main/java/com/cohere/api/resources/connectors/RawConnectorsClient.java index 1f4c18e..c7295fd 100644 --- a/src/main/java/com/cohere/api/resources/connectors/RawConnectorsClient.java +++ b/src/main/java/com/cohere/api/resources/connectors/RawConnectorsClient.java @@ -58,6 +58,13 @@ public CohereHttpResponse list() { return list(ConnectorsListRequest.builder().build()); } + /** + * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. + */ + public CohereHttpResponse list(RequestOptions requestOptions) { + return list(ConnectorsListRequest.builder().build(), requestOptions); + } + /** * Returns a list of connectors ordered by descending creation date (newer first). See 'Managing your Connector' for more information. */ @@ -81,6 +88,11 @@ public CohereHttpResponse list( QueryStringMapper.addQueryParameter( httpUrl, "offset", request.getOffset().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) @@ -161,10 +173,14 @@ public CohereHttpResponse create(CreateConnectorRequest */ public CohereHttpResponse create( CreateConnectorRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/connectors") - .build(); + .addPathSegments("v1/connectors"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -173,7 +189,7 @@ public CohereHttpResponse 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") @@ -252,13 +268,17 @@ public CohereHttpResponse get(String id) { * Retrieve a connector by ID. See 'Connectors' for more information. */ public CohereHttpResponse get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .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") @@ -335,13 +355,17 @@ public CohereHttpResponse> delete(String id) { * Delete a connector by ID. See 'Connectors' for more information. */ public CohereHttpResponse> delete(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") @@ -416,6 +440,13 @@ public CohereHttpResponse update(String id) { return update(id, UpdateConnectorRequest.builder().build()); } + /** + * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. + */ + public CohereHttpResponse update(String id, RequestOptions requestOptions) { + return update(id, UpdateConnectorRequest.builder().build(), requestOptions); + } + /** * Update a connector by ID. Omitted fields will not be updated. See 'Managing your Connector' for more information. */ @@ -428,11 +459,15 @@ public CohereHttpResponse update(String id, UpdateConne */ public CohereHttpResponse update( String id, UpdateConnectorRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors") - .addPathSegment(id) - .build(); + .addPathSegment(id); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -441,7 +476,7 @@ public CohereHttpResponse update( throw new CohereException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PATCH", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -516,6 +551,13 @@ public CohereHttpResponse oAuthAuthorize(String id) { return oAuthAuthorize(id, ConnectorsOAuthAuthorizeRequest.builder().build()); } + /** + * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. + */ + public CohereHttpResponse oAuthAuthorize(String id, RequestOptions requestOptions) { + return oAuthAuthorize(id, ConnectorsOAuthAuthorizeRequest.builder().build(), requestOptions); + } + /** * Authorize the connector with the given ID for the connector oauth app. See 'Connector Authentication' for more information. */ @@ -542,6 +584,11 @@ public CohereHttpResponse oAuthAuthorize( request.getAfterTokenRedirect().get(), false); } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) .method("POST", RequestBody.create("", null)) diff --git a/src/main/java/com/cohere/api/resources/datasets/AsyncDatasetsClient.java b/src/main/java/com/cohere/api/resources/datasets/AsyncDatasetsClient.java index 3f99786..ee6ca2b 100644 --- a/src/main/java/com/cohere/api/resources/datasets/AsyncDatasetsClient.java +++ b/src/main/java/com/cohere/api/resources/datasets/AsyncDatasetsClient.java @@ -40,6 +40,13 @@ public CompletableFuture list() { return this.rawClient.list().thenApply(response -> response.body()); } + /** + * List datasets that have been created. + */ + public CompletableFuture list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).thenApply(response -> response.body()); + } + /** * List datasets that have been created. */ diff --git a/src/main/java/com/cohere/api/resources/datasets/AsyncRawDatasetsClient.java b/src/main/java/com/cohere/api/resources/datasets/AsyncRawDatasetsClient.java index 71ea815..dbe1f86 100644 --- a/src/main/java/com/cohere/api/resources/datasets/AsyncRawDatasetsClient.java +++ b/src/main/java/com/cohere/api/resources/datasets/AsyncRawDatasetsClient.java @@ -63,6 +63,13 @@ public CompletableFuture> list() { return list(DatasetsListRequest.builder().build()); } + /** + * List datasets that have been created. + */ + public CompletableFuture> list(RequestOptions requestOptions) { + return list(DatasetsListRequest.builder().build(), requestOptions); + } + /** * List datasets that have been created. */ @@ -102,6 +109,11 @@ public CompletableFuture> list( QueryStringMapper.addQueryParameter( httpUrl, "validationStatus", request.getValidationStatus().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) @@ -252,16 +264,22 @@ public CompletableFuture> create( QueryStringMapper.addQueryParameter( httpUrl, "optional_fields", request.getOptionalFields().get(), true); } - MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); try { String dataMimeType = Files.probeContentType(data.toPath()); MediaType dataMimeTypeMediaType = dataMimeType != null ? MediaType.parse(dataMimeType) : null; - body.addFormDataPart("data", data.getName(), RequestBody.create(data, dataMimeTypeMediaType)); + multipartBodyBuilder.addFormDataPart( + "data", data.getName(), RequestBody.create(data, dataMimeTypeMediaType)); if (evalData.isPresent()) { String evalDataMimeType = Files.probeContentType(evalData.get().toPath()); MediaType evalDataMimeTypeMediaType = evalDataMimeType != null ? MediaType.parse(evalDataMimeType) : null; - body.addFormDataPart( + multipartBodyBuilder.addFormDataPart( "eval_data", evalData.get().getName(), RequestBody.create(evalData.get(), evalDataMimeTypeMediaType)); @@ -271,7 +289,7 @@ public CompletableFuture> create( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", body.build()) + .method("POST", multipartBodyBuilder.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -385,12 +403,16 @@ public CompletableFuture> getUsage( * View the dataset storage usage for your Organization. Each Organization can have up to 10GB of storage across all their users. */ public CompletableFuture> getUsage(RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/datasets/usage") - .build(); + .addPathSegments("v1/datasets/usage"); + 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") @@ -505,13 +527,17 @@ public CompletableFuture> get(String id) * Retrieve a dataset by ID. See 'Datasets' for more information. */ public CompletableFuture> get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/datasets") - .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") @@ -626,13 +652,17 @@ public CompletableFuture>> delete(String * Delete a dataset by ID. Datasets are automatically deleted after 30 days, but they can also be deleted manually. */ public CompletableFuture>> delete(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/datasets") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") diff --git a/src/main/java/com/cohere/api/resources/datasets/DatasetsClient.java b/src/main/java/com/cohere/api/resources/datasets/DatasetsClient.java index 58a5141..e48a5b1 100644 --- a/src/main/java/com/cohere/api/resources/datasets/DatasetsClient.java +++ b/src/main/java/com/cohere/api/resources/datasets/DatasetsClient.java @@ -39,6 +39,13 @@ public DatasetsListResponse list() { return this.rawClient.list().body(); } + /** + * List datasets that have been created. + */ + public DatasetsListResponse list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).body(); + } + /** * List datasets that have been created. */ diff --git a/src/main/java/com/cohere/api/resources/datasets/RawDatasetsClient.java b/src/main/java/com/cohere/api/resources/datasets/RawDatasetsClient.java index 7fe0b85..984dd2e 100644 --- a/src/main/java/com/cohere/api/resources/datasets/RawDatasetsClient.java +++ b/src/main/java/com/cohere/api/resources/datasets/RawDatasetsClient.java @@ -59,6 +59,13 @@ public CohereHttpResponse list() { return list(DatasetsListRequest.builder().build()); } + /** + * List datasets that have been created. + */ + public CohereHttpResponse list(RequestOptions requestOptions) { + return list(DatasetsListRequest.builder().build(), requestOptions); + } + /** * List datasets that have been created. */ @@ -97,6 +104,11 @@ public CohereHttpResponse list(DatasetsListRequest request QueryStringMapper.addQueryParameter( httpUrl, "validationStatus", request.getValidationStatus().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) @@ -209,16 +221,22 @@ public CohereHttpResponse create( QueryStringMapper.addQueryParameter( httpUrl, "optional_fields", request.getOptionalFields().get(), true); } - MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } + MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); try { String dataMimeType = Files.probeContentType(data.toPath()); MediaType dataMimeTypeMediaType = dataMimeType != null ? MediaType.parse(dataMimeType) : null; - body.addFormDataPart("data", data.getName(), RequestBody.create(data, dataMimeTypeMediaType)); + multipartBodyBuilder.addFormDataPart( + "data", data.getName(), RequestBody.create(data, dataMimeTypeMediaType)); if (evalData.isPresent()) { String evalDataMimeType = Files.probeContentType(evalData.get().toPath()); MediaType evalDataMimeTypeMediaType = evalDataMimeType != null ? MediaType.parse(evalDataMimeType) : null; - body.addFormDataPart( + multipartBodyBuilder.addFormDataPart( "eval_data", evalData.get().getName(), RequestBody.create(evalData.get(), evalDataMimeTypeMediaType)); @@ -228,7 +246,7 @@ public CohereHttpResponse create( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", body.build()) + .method("POST", multipartBodyBuilder.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -305,12 +323,16 @@ public CohereHttpResponse getUsage() { * View the dataset storage usage for your Organization. Each Organization can have up to 10GB of storage across all their users. */ public CohereHttpResponse getUsage(RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/datasets/usage") - .build(); + .addPathSegments("v1/datasets/usage"); + 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") @@ -388,13 +410,17 @@ public CohereHttpResponse get(String id) { * Retrieve a dataset by ID. See 'Datasets' for more information. */ public CohereHttpResponse get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/datasets") - .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") @@ -471,13 +497,17 @@ public CohereHttpResponse> delete(String id) { * Delete a dataset by ID. Datasets are automatically deleted after 30 days, but they can also be deleted manually. */ public CohereHttpResponse> delete(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/datasets") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") diff --git a/src/main/java/com/cohere/api/resources/embedjobs/AsyncRawEmbedJobsClient.java b/src/main/java/com/cohere/api/resources/embedjobs/AsyncRawEmbedJobsClient.java index 0587ef9..b5c0c1c 100644 --- a/src/main/java/com/cohere/api/resources/embedjobs/AsyncRawEmbedJobsClient.java +++ b/src/main/java/com/cohere/api/resources/embedjobs/AsyncRawEmbedJobsClient.java @@ -58,12 +58,16 @@ public CompletableFuture> list() { * The list embed job endpoint allows users to view all embed jobs history for that specific user. */ public CompletableFuture> list(RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/embed-jobs") - .build(); + .addPathSegments("v1/embed-jobs"); + 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") @@ -179,10 +183,14 @@ public CompletableFuture> create(Crea */ public CompletableFuture> create( CreateEmbedJobRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/embed-jobs") - .build(); + .addPathSegments("v1/embed-jobs"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -191,7 +199,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") @@ -307,13 +315,17 @@ public CompletableFuture> get(String id) { * This API retrieves the details about an embed job started by the same user. */ public CompletableFuture> get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/embed-jobs") - .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") @@ -427,14 +439,18 @@ public CompletableFuture> cancel(String id) { * This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation. */ 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("v1/embed-jobs") .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/embedjobs/RawEmbedJobsClient.java b/src/main/java/com/cohere/api/resources/embedjobs/RawEmbedJobsClient.java index 11de558..4acd6da 100644 --- a/src/main/java/com/cohere/api/resources/embedjobs/RawEmbedJobsClient.java +++ b/src/main/java/com/cohere/api/resources/embedjobs/RawEmbedJobsClient.java @@ -54,12 +54,16 @@ public CohereHttpResponse list() { * The list embed job endpoint allows users to view all embed jobs history for that specific user. */ public CohereHttpResponse list(RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/embed-jobs") - .build(); + .addPathSegments("v1/embed-jobs"); + 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") @@ -137,10 +141,14 @@ public CohereHttpResponse create(CreateEmbedJobRequest r */ public CohereHttpResponse create( CreateEmbedJobRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/embed-jobs") - .build(); + .addPathSegments("v1/embed-jobs"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -149,7 +157,7 @@ public CohereHttpResponse 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") @@ -228,13 +236,17 @@ public CohereHttpResponse get(String id) { * This API retrieves the details about an embed job started by the same user. */ public CohereHttpResponse get(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/embed-jobs") - .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") @@ -311,14 +323,18 @@ public CohereHttpResponse cancel(String id) { * This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation. */ public CohereHttpResponse cancel(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/embed-jobs") .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/finetuning/AsyncFinetuningClient.java b/src/main/java/com/cohere/api/resources/finetuning/AsyncFinetuningClient.java index a237b35..d013fd6 100644 --- a/src/main/java/com/cohere/api/resources/finetuning/AsyncFinetuningClient.java +++ b/src/main/java/com/cohere/api/resources/finetuning/AsyncFinetuningClient.java @@ -43,6 +43,13 @@ public CompletableFuture listFinetunedModels() { return this.rawClient.listFinetunedModels().thenApply(response -> response.body()); } + /** + * Returns a list of fine-tuned models that the user has access to. + */ + public CompletableFuture listFinetunedModels(RequestOptions requestOptions) { + return this.rawClient.listFinetunedModels(requestOptions).thenApply(response -> response.body()); + } + /** * Returns a list of fine-tuned models that the user has access to. */ @@ -129,6 +136,15 @@ public CompletableFuture listEvents(String finetunedModelId) return this.rawClient.listEvents(finetunedModelId).thenApply(response -> response.body()); } + /** + * Returns a list of events that occurred during the life-cycle of the fine-tuned model. + * The events are ordered by creation time, with the most recent event first. + * The list can be paginated using page_size and page_token parameters. + */ + public CompletableFuture listEvents(String finetunedModelId, RequestOptions requestOptions) { + return this.rawClient.listEvents(finetunedModelId, requestOptions).thenApply(response -> response.body()); + } + /** * Returns a list of events that occurred during the life-cycle of the fine-tuned model. * The events are ordered by creation time, with the most recent event first. @@ -160,6 +176,18 @@ public CompletableFuture listTrainingStepMetric return this.rawClient.listTrainingStepMetrics(finetunedModelId).thenApply(response -> response.body()); } + /** + * Returns a list of metrics measured during the training of a fine-tuned model. + * The metrics are ordered by step number, with the most recent step first. + * The list can be paginated using page_size and page_token parameters. + */ + public CompletableFuture listTrainingStepMetrics( + String finetunedModelId, RequestOptions requestOptions) { + return this.rawClient + .listTrainingStepMetrics(finetunedModelId, requestOptions) + .thenApply(response -> response.body()); + } + /** * Returns a list of metrics measured during the training of a fine-tuned model. * The metrics are ordered by step number, with the most recent step first. diff --git a/src/main/java/com/cohere/api/resources/finetuning/AsyncRawFinetuningClient.java b/src/main/java/com/cohere/api/resources/finetuning/AsyncRawFinetuningClient.java index f8531b6..36560f6 100644 --- a/src/main/java/com/cohere/api/resources/finetuning/AsyncRawFinetuningClient.java +++ b/src/main/java/com/cohere/api/resources/finetuning/AsyncRawFinetuningClient.java @@ -59,6 +59,15 @@ public CompletableFuture> listFi FinetuningListFinetunedModelsRequest.builder().build()); } + /** + * Returns a list of fine-tuned models that the user has access to. + */ + public CompletableFuture> listFinetunedModels( + RequestOptions requestOptions) { + return listFinetunedModels( + FinetuningListFinetunedModelsRequest.builder().build(), requestOptions); + } + /** * Returns a list of fine-tuned models that the user has access to. */ @@ -87,6 +96,11 @@ public CompletableFuture> listFi 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) @@ -176,10 +190,14 @@ public CompletableFuture> creat */ public CompletableFuture> createFinetunedModel( FinetunedModel request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/finetuning/finetuned-models") - .build(); + .addPathSegments("v1/finetuning/finetuned-models"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -188,7 +206,7 @@ public CompletableFuture> creat 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") @@ -276,13 +294,17 @@ public CompletableFuture> getFinet */ public CompletableFuture> getFinetunedModel( String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .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") @@ -371,13 +393,17 @@ public CompletableFuture>> deleteFinetune */ public CompletableFuture>> deleteFinetunedModel( String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") @@ -465,11 +491,15 @@ public CompletableFuture> updat */ public CompletableFuture> updateFinetunedModel( String id, FinetuningUpdateFinetunedModelRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .addPathSegment(id) - .build(); + .addPathSegment(id); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -478,7 +508,7 @@ public CompletableFuture> updat throw new CohereException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PATCH", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -564,6 +594,17 @@ public CompletableFuture> listEvents(Stri finetunedModelId, FinetuningListEventsRequest.builder().build()); } + /** + * Returns a list of events that occurred during the life-cycle of the fine-tuned model. + * The events are ordered by creation time, with the most recent event first. + * The list can be paginated using page_size and page_token parameters. + */ + public CompletableFuture> listEvents( + String finetunedModelId, RequestOptions requestOptions) { + return listEvents( + finetunedModelId, FinetuningListEventsRequest.builder().build(), requestOptions); + } + /** * Returns a list of events that occurred during the life-cycle of the fine-tuned model. * The events are ordered by creation time, with the most recent event first. @@ -598,6 +639,11 @@ public CompletableFuture> listEvents( 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) @@ -685,6 +731,19 @@ public CompletableFuture> li FinetuningListTrainingStepMetricsRequest.builder().build()); } + /** + * Returns a list of metrics measured during the training of a fine-tuned model. + * The metrics are ordered by step number, with the most recent step first. + * The list can be paginated using page_size and page_token parameters. + */ + public CompletableFuture> listTrainingStepMetrics( + String finetunedModelId, RequestOptions requestOptions) { + return listTrainingStepMetrics( + finetunedModelId, + FinetuningListTrainingStepMetricsRequest.builder().build(), + requestOptions); + } + /** * Returns a list of metrics measured during the training of a fine-tuned model. * The metrics are ordered by step number, with the most recent step first. @@ -715,6 +774,11 @@ public CompletableFuture> li QueryStringMapper.addQueryParameter( httpUrl, "page_token", request.getPageToken().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) diff --git a/src/main/java/com/cohere/api/resources/finetuning/FinetuningClient.java b/src/main/java/com/cohere/api/resources/finetuning/FinetuningClient.java index b26fd12..b9703a4 100644 --- a/src/main/java/com/cohere/api/resources/finetuning/FinetuningClient.java +++ b/src/main/java/com/cohere/api/resources/finetuning/FinetuningClient.java @@ -42,6 +42,13 @@ public ListFinetunedModelsResponse listFinetunedModels() { return this.rawClient.listFinetunedModels().body(); } + /** + * Returns a list of fine-tuned models that the user has access to. + */ + public ListFinetunedModelsResponse listFinetunedModels(RequestOptions requestOptions) { + return this.rawClient.listFinetunedModels(requestOptions).body(); + } + /** * Returns a list of fine-tuned models that the user has access to. */ @@ -125,6 +132,15 @@ public ListEventsResponse listEvents(String finetunedModelId) { return this.rawClient.listEvents(finetunedModelId).body(); } + /** + * Returns a list of events that occurred during the life-cycle of the fine-tuned model. + * The events are ordered by creation time, with the most recent event first. + * The list can be paginated using page_size and page_token parameters. + */ + public ListEventsResponse listEvents(String finetunedModelId, RequestOptions requestOptions) { + return this.rawClient.listEvents(finetunedModelId, requestOptions).body(); + } + /** * Returns a list of events that occurred during the life-cycle of the fine-tuned model. * The events are ordered by creation time, with the most recent event first. @@ -155,6 +171,18 @@ public ListTrainingStepMetricsResponse listTrainingStepMetrics(String finetunedM return this.rawClient.listTrainingStepMetrics(finetunedModelId).body(); } + /** + * Returns a list of metrics measured during the training of a fine-tuned model. + * The metrics are ordered by step number, with the most recent step first. + * The list can be paginated using page_size and page_token parameters. + */ + public ListTrainingStepMetricsResponse listTrainingStepMetrics( + String finetunedModelId, RequestOptions requestOptions) { + return this.rawClient + .listTrainingStepMetrics(finetunedModelId, requestOptions) + .body(); + } + /** * Returns a list of metrics measured during the training of a fine-tuned model. * The metrics are ordered by step number, with the most recent step first. diff --git a/src/main/java/com/cohere/api/resources/finetuning/RawFinetuningClient.java b/src/main/java/com/cohere/api/resources/finetuning/RawFinetuningClient.java index 02f48c4..d68c071 100644 --- a/src/main/java/com/cohere/api/resources/finetuning/RawFinetuningClient.java +++ b/src/main/java/com/cohere/api/resources/finetuning/RawFinetuningClient.java @@ -55,6 +55,14 @@ public CohereHttpResponse listFinetunedModels() { FinetuningListFinetunedModelsRequest.builder().build()); } + /** + * Returns a list of fine-tuned models that the user has access to. + */ + public CohereHttpResponse listFinetunedModels(RequestOptions requestOptions) { + return listFinetunedModels( + FinetuningListFinetunedModelsRequest.builder().build(), requestOptions); + } + /** * Returns a list of fine-tuned models that the user has access to. */ @@ -83,6 +91,11 @@ public CohereHttpResponse listFinetunedModels( 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) @@ -145,10 +158,14 @@ public CohereHttpResponse createFinetunedModel(Fin */ public CohereHttpResponse createFinetunedModel( FinetunedModel request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v1/finetuning/finetuned-models") - .build(); + .addPathSegments("v1/finetuning/finetuned-models"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -157,7 +174,7 @@ public CohereHttpResponse createFinetunedModel( 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") @@ -218,13 +235,17 @@ public CohereHttpResponse getFinetunedModel(String id * Retrieve a fine-tuned model by its ID. */ public CohereHttpResponse getFinetunedModel(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .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") @@ -286,13 +307,17 @@ public CohereHttpResponse> deleteFinetunedModel(String id) { * This operation is irreversible. */ public CohereHttpResponse> deleteFinetunedModel(String id, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .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("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") @@ -355,11 +380,15 @@ public CohereHttpResponse updateFinetunedModel( */ public CohereHttpResponse updateFinetunedModel( String id, FinetuningUpdateFinetunedModelRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/finetuning/finetuned-models") - .addPathSegment(id) - .build(); + .addPathSegment(id); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -368,7 +397,7 @@ public CohereHttpResponse updateFinetunedModel( throw new CohereException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PATCH", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -428,6 +457,16 @@ public CohereHttpResponse listEvents(String finetunedModelId finetunedModelId, FinetuningListEventsRequest.builder().build()); } + /** + * Returns a list of events that occurred during the life-cycle of the fine-tuned model. + * The events are ordered by creation time, with the most recent event first. + * The list can be paginated using page_size and page_token parameters. + */ + public CohereHttpResponse listEvents(String finetunedModelId, RequestOptions requestOptions) { + return listEvents( + finetunedModelId, FinetuningListEventsRequest.builder().build(), requestOptions); + } + /** * Returns a list of events that occurred during the life-cycle of the fine-tuned model. * The events are ordered by creation time, with the most recent event first. @@ -462,6 +501,11 @@ public CohereHttpResponse listEvents( 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) @@ -522,6 +566,19 @@ public CohereHttpResponse listTrainingStepMetri FinetuningListTrainingStepMetricsRequest.builder().build()); } + /** + * Returns a list of metrics measured during the training of a fine-tuned model. + * The metrics are ordered by step number, with the most recent step first. + * The list can be paginated using page_size and page_token parameters. + */ + public CohereHttpResponse listTrainingStepMetrics( + String finetunedModelId, RequestOptions requestOptions) { + return listTrainingStepMetrics( + finetunedModelId, + FinetuningListTrainingStepMetricsRequest.builder().build(), + requestOptions); + } + /** * Returns a list of metrics measured during the training of a fine-tuned model. * The metrics are ordered by step number, with the most recent step first. @@ -552,6 +609,11 @@ public CohereHttpResponse listTrainingStepMetri QueryStringMapper.addQueryParameter( httpUrl, "page_token", request.getPageToken().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) diff --git a/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java b/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java index 135c199..9e6e320 100644 --- a/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java @@ -48,6 +48,13 @@ public CompletableFuture list() { return this.rawClient.list().thenApply(response -> response.body()); } + /** + * Returns a list of models available for use. + */ + public CompletableFuture list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).thenApply(response -> response.body()); + } + /** * Returns a list of models available for use. */ diff --git a/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java b/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java index 016b831..cd9ea06 100644 --- a/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java @@ -56,13 +56,17 @@ public CompletableFuture> get(String model) * Returns the details of a model, provided its name. */ public CompletableFuture> get(String model, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/models") - .addPathSegment(model) - .build(); + .addPathSegment(model); + 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") @@ -173,6 +177,13 @@ public CompletableFuture> list() { return list(ModelsListRequest.builder().build()); } + /** + * Returns a list of models available for use. + */ + public CompletableFuture> list(RequestOptions requestOptions) { + return list(ModelsListRequest.builder().build(), requestOptions); + } + /** * Returns a list of models available for use. */ @@ -204,6 +215,11 @@ public CompletableFuture> list( QueryStringMapper.addQueryParameter( httpUrl, "default_only", request.getDefaultOnly().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) diff --git a/src/main/java/com/cohere/api/resources/models/ModelsClient.java b/src/main/java/com/cohere/api/resources/models/ModelsClient.java index 237e9ff..d464e7e 100644 --- a/src/main/java/com/cohere/api/resources/models/ModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/ModelsClient.java @@ -47,6 +47,13 @@ public ListModelsResponse list() { return this.rawClient.list().body(); } + /** + * Returns a list of models available for use. + */ + public ListModelsResponse list(RequestOptions requestOptions) { + return this.rawClient.list(requestOptions).body(); + } + /** * Returns a list of models available for use. */ diff --git a/src/main/java/com/cohere/api/resources/models/RawModelsClient.java b/src/main/java/com/cohere/api/resources/models/RawModelsClient.java index 3fbcbfa..510855f 100644 --- a/src/main/java/com/cohere/api/resources/models/RawModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/RawModelsClient.java @@ -52,13 +52,17 @@ public CohereHttpResponse get(String model) { * Returns the details of a model, provided its name. */ public CohereHttpResponse get(String model, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/models") - .addPathSegment(model) - .build(); + .addPathSegment(model); + 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") @@ -131,6 +135,13 @@ public CohereHttpResponse list() { return list(ModelsListRequest.builder().build()); } + /** + * Returns a list of models available for use. + */ + public CohereHttpResponse list(RequestOptions requestOptions) { + return list(ModelsListRequest.builder().build(), requestOptions); + } + /** * Returns a list of models available for use. */ @@ -161,6 +172,11 @@ public CohereHttpResponse list(ModelsListRequest request, Re QueryStringMapper.addQueryParameter( httpUrl, "default_only", request.getDefaultOnly().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) diff --git a/src/main/java/com/cohere/api/resources/v2/AsyncRawV2Client.java b/src/main/java/com/cohere/api/resources/v2/AsyncRawV2Client.java index 0addea0..9eef727 100644 --- a/src/main/java/com/cohere/api/resources/v2/AsyncRawV2Client.java +++ b/src/main/java/com/cohere/api/resources/v2/AsyncRawV2Client.java @@ -68,10 +68,14 @@ public CompletableFuture>> cha */ public CompletableFuture>> chatStream( V2ChatStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/chat") - .build(); + .addPathSegments("v2/chat"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -80,11 +84,10 @@ public CompletableFuture>> cha 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()) { @@ -200,10 +203,14 @@ public CompletableFuture> chat(V2ChatRequest */ public CompletableFuture> chat( V2ChatRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/chat") - .build(); + .addPathSegments("v2/chat"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -212,7 +219,7 @@ public CompletableFuture> chat( 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") @@ -333,10 +340,14 @@ public CompletableFuture> embed(V2EmbedR */ public CompletableFuture> embed( V2EmbedRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/embed") - .build(); + .addPathSegments("v2/embed"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -345,7 +356,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") @@ -462,10 +473,14 @@ public CompletableFuture> rerank(V2RerankRe */ public CompletableFuture> rerank( V2RerankRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/rerank") - .build(); + .addPathSegments("v2/rerank"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -474,7 +489,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") diff --git a/src/main/java/com/cohere/api/resources/v2/RawV2Client.java b/src/main/java/com/cohere/api/resources/v2/RawV2Client.java index ab9d1a1..da70ced 100644 --- a/src/main/java/com/cohere/api/resources/v2/RawV2Client.java +++ b/src/main/java/com/cohere/api/resources/v2/RawV2Client.java @@ -63,10 +63,14 @@ public CohereHttpResponse> chatStream(V2ChatStrea */ public CohereHttpResponse> chatStream( V2ChatStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/chat") - .build(); + .addPathSegments("v2/chat"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -75,11 +79,10 @@ public CohereHttpResponse> chatStream( 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()) { @@ -156,10 +159,14 @@ public CohereHttpResponse chat(V2ChatRequest request) { *

Follow the Migration Guide for instructions on moving from API v1 to API v2.

*/ public CohereHttpResponse chat(V2ChatRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/chat") - .build(); + .addPathSegments("v2/chat"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -168,7 +175,7 @@ public CohereHttpResponse chat(V2ChatRequest request, RequestOpt 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") @@ -250,10 +257,14 @@ public CohereHttpResponse embed(V2EmbedRequest request) { *

If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.

*/ public CohereHttpResponse embed(V2EmbedRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/embed") - .build(); + .addPathSegments("v2/embed"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -262,7 +273,7 @@ public CohereHttpResponse embed(V2EmbedRequest request, Req 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") @@ -340,10 +351,14 @@ public CohereHttpResponse rerank(V2RerankRequest 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(V2RerankRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("v2/rerank") - .build(); + .addPathSegments("v2/rerank"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -352,7 +367,7 @@ public CohereHttpResponse rerank(V2RerankRequest request, Requ 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") diff --git a/src/main/java/com/cohere/api/types/AssistantMessageV2Content.java b/src/main/java/com/cohere/api/types/AssistantMessageV2Content.java index 8641074..be2a218 100644 --- a/src/main/java/com/cohere/api/types/AssistantMessageV2Content.java +++ b/src/main/java/com/cohere/api/types/AssistantMessageV2Content.java @@ -36,7 +36,7 @@ public T visit(Visitor visitor) { if (this.type == 0) { return visitor.visit((String) this.value); } else if (this.type == 1) { - return visitor.visit((List) this.value); + return visitor.visit((List) this.value); } throw new IllegalStateException("Failed to visit value. This should never happen."); } @@ -65,14 +65,14 @@ public static AssistantMessageV2Content of(String value) { return new AssistantMessageV2Content(value, 0); } - public static AssistantMessageV2Content of(List value) { + public static AssistantMessageV2Content of(List value) { return new AssistantMessageV2Content(value, 1); } public interface Visitor { T visit(String value); - T visit(List value); + T visit(List value); } static final class Deserializer extends StdDeserializer { @@ -89,7 +89,7 @@ public AssistantMessageV2Content deserialize(JsonParser p, DeserializationContex } try { return of(ObjectMappers.JSON_MAPPER.convertValue( - value, new TypeReference>() {})); + value, new TypeReference>() {})); } catch (RuntimeException e) { } throw new JsonParseException(p, "Failed to deserialize"); diff --git a/src/main/java/com/cohere/api/types/AssistantMessageV2ContentItem.java b/src/main/java/com/cohere/api/types/AssistantMessageV2ContentOneItem.java similarity index 88% rename from src/main/java/com/cohere/api/types/AssistantMessageV2ContentItem.java rename to src/main/java/com/cohere/api/types/AssistantMessageV2ContentOneItem.java index 2636dda..b910d0b 100644 --- a/src/main/java/com/cohere/api/types/AssistantMessageV2ContentItem.java +++ b/src/main/java/com/cohere/api/types/AssistantMessageV2ContentOneItem.java @@ -14,11 +14,11 @@ import java.util.Objects; import java.util.Optional; -public final class AssistantMessageV2ContentItem { +public final class AssistantMessageV2ContentOneItem { private final Value value; @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - private AssistantMessageV2ContentItem(Value value) { + private AssistantMessageV2ContentOneItem(Value value) { this.value = value; } @@ -26,12 +26,12 @@ public T visit(Visitor visitor) { return value.visit(visitor); } - public static AssistantMessageV2ContentItem text(ChatTextContent value) { - return new AssistantMessageV2ContentItem(new TextValue(value)); + public static AssistantMessageV2ContentOneItem text(ChatTextContent value) { + return new AssistantMessageV2ContentOneItem(new TextValue(value)); } - public static AssistantMessageV2ContentItem thinking(ChatThinkingContent value) { - return new AssistantMessageV2ContentItem(new ThinkingValue(value)); + public static AssistantMessageV2ContentOneItem thinking(ChatThinkingContent value) { + return new AssistantMessageV2ContentOneItem(new ThinkingValue(value)); } public boolean isText() { @@ -122,7 +122,7 @@ public int hashCode() { @java.lang.Override public String toString() { - return "AssistantMessageV2ContentItem{" + "value: " + value + "}"; + return "AssistantMessageV2ContentOneItem{" + "value: " + value + "}"; } } @@ -161,7 +161,7 @@ public int hashCode() { @java.lang.Override public String toString() { - return "AssistantMessageV2ContentItem{" + "value: " + value + "}"; + return "AssistantMessageV2ContentOneItem{" + "value: " + value + "}"; } } @@ -197,7 +197,7 @@ public int hashCode() { @java.lang.Override public String toString() { - return "AssistantMessageV2ContentItem{" + "type: " + type + ", value: " + value + "}"; + return "AssistantMessageV2ContentOneItem{" + "type: " + type + ", value: " + value + "}"; } } } diff --git a/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java b/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java index 55f2169..9103d2b 100644 --- a/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java +++ b/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java @@ -22,6 +22,8 @@ @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = EmbedByTypeResponse.Builder.class) public final class EmbedByTypeResponse { + private final Optional responseType; + private final String id; private final EmbedByTypeResponseEmbeddings embeddings; @@ -35,12 +37,14 @@ public final class EmbedByTypeResponse { private final Map additionalProperties; private EmbedByTypeResponse( + Optional responseType, String id, EmbedByTypeResponseEmbeddings embeddings, Optional> texts, Optional> images, Optional meta, Map additionalProperties) { + this.responseType = responseType; this.id = id; this.embeddings = embeddings; this.texts = texts; @@ -49,6 +53,11 @@ private EmbedByTypeResponse( this.additionalProperties = additionalProperties; } + @JsonProperty("response_type") + public Optional getResponseType() { + return responseType; + } + @JsonProperty("id") public String getId() { return id; @@ -95,7 +104,8 @@ public Map getAdditionalProperties() { } private boolean equalTo(EmbedByTypeResponse other) { - return id.equals(other.id) + return responseType.equals(other.responseType) + && id.equals(other.id) && embeddings.equals(other.embeddings) && texts.equals(other.texts) && images.equals(other.images) @@ -104,7 +114,7 @@ private boolean equalTo(EmbedByTypeResponse other) { @java.lang.Override public int hashCode() { - return Objects.hash(this.id, this.embeddings, this.texts, this.images, this.meta); + return Objects.hash(this.responseType, this.id, this.embeddings, this.texts, this.images, this.meta); } @java.lang.Override @@ -132,6 +142,10 @@ public interface EmbeddingsStage { public interface _FinalStage { EmbedByTypeResponse build(); + _FinalStage responseType(Optional responseType); + + _FinalStage responseType(EmbedByTypeResponseResponseType responseType); + /** *

The text entries for which embeddings were returned.

*/ @@ -163,6 +177,8 @@ public static final class Builder implements IdStage, EmbeddingsStage, _FinalSta private Optional> texts = Optional.empty(); + private Optional responseType = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -170,6 +186,7 @@ private Builder() {} @java.lang.Override public Builder from(EmbedByTypeResponse other) { + responseType(other.getResponseType()); id(other.getId()); embeddings(other.getEmbeddings()); texts(other.getTexts()); @@ -250,9 +267,22 @@ public _FinalStage texts(Optional> texts) { return this; } + @java.lang.Override + public _FinalStage responseType(EmbedByTypeResponseResponseType responseType) { + this.responseType = Optional.ofNullable(responseType); + return this; + } + + @java.lang.Override + @JsonSetter(value = "response_type", nulls = Nulls.SKIP) + public _FinalStage responseType(Optional responseType) { + this.responseType = responseType; + return this; + } + @java.lang.Override public EmbedByTypeResponse build() { - return new EmbedByTypeResponse(id, embeddings, texts, images, meta, additionalProperties); + return new EmbedByTypeResponse(responseType, id, embeddings, texts, images, meta, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/types/EmbedByTypeResponseResponseType.java b/src/main/java/com/cohere/api/types/EmbedByTypeResponseResponseType.java new file mode 100644 index 0000000..9c1f8eb --- /dev/null +++ b/src/main/java/com/cohere/api/types/EmbedByTypeResponseResponseType.java @@ -0,0 +1,86 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public final class EmbedByTypeResponseResponseType { + public static final EmbedByTypeResponseResponseType EMBEDDINGS_FLOATS = + new EmbedByTypeResponseResponseType(Value.EMBEDDINGS_FLOATS, "embeddings_floats"); + + public static final EmbedByTypeResponseResponseType EMBEDDINGS_BY_TYPE = + new EmbedByTypeResponseResponseType(Value.EMBEDDINGS_BY_TYPE, "embeddings_by_type"); + + private final Value value; + + private final String string; + + EmbedByTypeResponseResponseType(Value value, String string) { + this.value = value; + this.string = string; + } + + public Value getEnumValue() { + return value; + } + + @java.lang.Override + @JsonValue + public String toString() { + return this.string; + } + + @java.lang.Override + public boolean equals(Object other) { + return (this == other) + || (other instanceof EmbedByTypeResponseResponseType + && this.string.equals(((EmbedByTypeResponseResponseType) other).string)); + } + + @java.lang.Override + public int hashCode() { + return this.string.hashCode(); + } + + public T visit(Visitor visitor) { + switch (value) { + case EMBEDDINGS_FLOATS: + return visitor.visitEmbeddingsFloats(); + case EMBEDDINGS_BY_TYPE: + return visitor.visitEmbeddingsByType(); + case UNKNOWN: + default: + return visitor.visitUnknown(string); + } + } + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + public static EmbedByTypeResponseResponseType valueOf(String value) { + switch (value) { + case "embeddings_floats": + return EMBEDDINGS_FLOATS; + case "embeddings_by_type": + return EMBEDDINGS_BY_TYPE; + default: + return new EmbedByTypeResponseResponseType(Value.UNKNOWN, value); + } + } + + public enum Value { + EMBEDDINGS_FLOATS, + + EMBEDDINGS_BY_TYPE, + + UNKNOWN + } + + public interface Visitor { + T visitEmbeddingsFloats(); + + T visitEmbeddingsByType(); + + T visitUnknown(String unknownType); + } +} diff --git a/src/main/java/com/cohere/api/types/SystemMessageV2Content.java b/src/main/java/com/cohere/api/types/SystemMessageV2Content.java index 2803cbd..dbdb9a6 100644 --- a/src/main/java/com/cohere/api/types/SystemMessageV2Content.java +++ b/src/main/java/com/cohere/api/types/SystemMessageV2Content.java @@ -36,7 +36,7 @@ public T visit(Visitor visitor) { if (this.type == 0) { return visitor.visit((String) this.value); } else if (this.type == 1) { - return visitor.visit((List) this.value); + return visitor.visit((List) this.value); } throw new IllegalStateException("Failed to visit value. This should never happen."); } @@ -65,14 +65,14 @@ public static SystemMessageV2Content of(String value) { return new SystemMessageV2Content(value, 0); } - public static SystemMessageV2Content of(List value) { + public static SystemMessageV2Content of(List value) { return new SystemMessageV2Content(value, 1); } public interface Visitor { T visit(String value); - T visit(List value); + T visit(List value); } static final class Deserializer extends StdDeserializer { @@ -89,7 +89,7 @@ public SystemMessageV2Content deserialize(JsonParser p, DeserializationContext c } try { return of(ObjectMappers.JSON_MAPPER.convertValue( - value, new TypeReference>() {})); + value, new TypeReference>() {})); } catch (RuntimeException e) { } throw new JsonParseException(p, "Failed to deserialize"); diff --git a/src/main/java/com/cohere/api/types/SystemMessageV2ContentItem.java b/src/main/java/com/cohere/api/types/SystemMessageV2ContentOneItem.java similarity index 89% rename from src/main/java/com/cohere/api/types/SystemMessageV2ContentItem.java rename to src/main/java/com/cohere/api/types/SystemMessageV2ContentOneItem.java index 6fcc422..1938dad 100644 --- a/src/main/java/com/cohere/api/types/SystemMessageV2ContentItem.java +++ b/src/main/java/com/cohere/api/types/SystemMessageV2ContentOneItem.java @@ -14,11 +14,11 @@ import java.util.Objects; import java.util.Optional; -public final class SystemMessageV2ContentItem { +public final class SystemMessageV2ContentOneItem { private final Value value; @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - private SystemMessageV2ContentItem(Value value) { + private SystemMessageV2ContentOneItem(Value value) { this.value = value; } @@ -26,8 +26,8 @@ public T visit(Visitor visitor) { return value.visit(visitor); } - public static SystemMessageV2ContentItem text(ChatTextContent value) { - return new SystemMessageV2ContentItem(new TextValue(value)); + public static SystemMessageV2ContentOneItem text(ChatTextContent value) { + return new SystemMessageV2ContentOneItem(new TextValue(value)); } public boolean isText() { @@ -105,7 +105,7 @@ public int hashCode() { @java.lang.Override public String toString() { - return "SystemMessageV2ContentItem{" + "value: " + value + "}"; + return "SystemMessageV2ContentOneItem{" + "value: " + value + "}"; } } @@ -141,7 +141,7 @@ public int hashCode() { @java.lang.Override public String toString() { - return "SystemMessageV2ContentItem{" + "type: " + type + ", value: " + value + "}"; + return "SystemMessageV2ContentOneItem{" + "type: " + type + ", value: " + value + "}"; } } } diff --git a/src/test/java/com/cohere/api/StreamTest.java b/src/test/java/com/cohere/api/StreamTest.java index 4de3538..1cfe1c8 100644 --- a/src/test/java/com/cohere/api/StreamTest.java +++ b/src/test/java/com/cohere/api/StreamTest.java @@ -9,6 +9,9 @@ import com.cohere.api.core.Stream; import java.io.IOException; import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -17,8 +20,9 @@ public final class StreamTest { @Test public void testJsonStream() { - List messages = List.of(Map.of("message", "hello"), Map.of("message", "world")); - List jsonStrings = messages.stream().map(StreamTest::mapToJson).collect(Collectors.toList()); + List> messages = + Arrays.asList(createMap("message", "hello"), createMap("message", "world")); + List jsonStrings = messages.stream().map(StreamTest::mapToJson).collect(Collectors.toList()); String input = String.join("\n", jsonStrings); StringReader jsonInput = new StringReader(input); Stream jsonStream = Stream.fromJson(Map.class, jsonInput); @@ -33,8 +37,8 @@ public void testJsonStream() { @Test public void testSseStream() { - List events = List.of(Map.of("event", "start"), Map.of("event", "end")); - List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); + List> events = Arrays.asList(createMap("event", "start"), createMap("event", "end")); + List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); String input = String.join("\n" + "\n", sseStrings); StringReader sseInput = new StringReader(input); Stream sseStream = Stream.fromSse(Map.class, sseInput); @@ -49,8 +53,9 @@ public void testSseStream() { @Test public void testSseStreamWithTerminator() { - List events = List.of(Map.of("message", "first"), Map.of("message", "second")); - List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); + List> events = Arrays.asList(createMap("message", "first"), createMap("message", "second")); + List sseStrings = + new ArrayList<>(events.stream().map(StreamTest::mapToSse).collect(Collectors.toList())); sseStrings.add("data: [DONE]"); String input = String.join("\n" + "\n", sseStrings); StringReader sseInput = new StringReader(input); @@ -83,4 +88,10 @@ private static String mapToJson(Map map) { private static String mapToSse(Map map) { return "data: " + mapToJson(map); } + + private static Map createMap(String key, String value) { + Map map = new HashMap<>(); + map.put(key, value); + return map; + } }