diff --git a/build.gradle b/build.gradle index 6da2fa7..102bc1e 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ java { group = 'com.cohere' -version = '1.8.2' +version = '1.8.0' jar { dependsOn(":generatePomFileForMavenPublication") @@ -77,7 +77,7 @@ publishing { maven(MavenPublication) { groupId = 'com.cohere' artifactId = 'cohere-java' - version = '1.8.2' + version = '1.8.0' from components.java pom { name = 'cohere' diff --git a/reference.md b/reference.md index 0a2e614..7a8a293 100644 --- a/reference.md +++ b/reference.md @@ -31,8 +31,9 @@ To learn how to use the Chat API and RAG follow our [Text Generation guides](htt client.chatStream( ChatStreamRequest .builder() - .message("hello world!") + .message("hello!") .stream(true) + .model("command-a-03-2025") .build() ); ``` @@ -223,9 +224,8 @@ Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private D **citationQuality:** `Optional` -Defaults to `"accurate"`. - -Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results, `"fast"` results or no results. +Defaults to `"enabled"`. +Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`. Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments @@ -487,36 +487,9 @@ To learn how to use the Chat API and RAG follow our [Text Generation guides](htt client.chatStream( ChatStreamRequest .builder() - .message("What year was he born?") + .message("Tell me about LLMs") .stream(false) - .chatHistory( - new ArrayList( - Arrays.asList( - Message.user( - ChatMessage - .builder() - .message("Who discovered gravity?") - .build() - ), - Message.chatbot( - ChatMessage - .builder() - .message("The man who is widely credited with discovering gravity is Sir Isaac Newton") - .build() - ) - ) - ) - ) - .connectors( - new ArrayList( - Arrays.asList( - ChatConnector - .builder() - .id("web-search") - .build() - ) - ) - ) + .model("command-a-03-2025") .build() ); ``` @@ -707,9 +680,8 @@ Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private D **citationQuality:** `Optional` -Defaults to `"accurate"`. - -Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results, `"fast"` results or no results. +Defaults to `"enabled"`. +Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`. Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments @@ -1511,7 +1483,7 @@ client.embed( An array of image data URIs for the model to embed. Maximum number of images per call is `1`. -The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. +The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg`, `image/png`, `image/webp`, or `image/gif` format and has a maximum size of 5MB. Images are only supported with Embed v3.0 and newer models. @@ -2189,7 +2161,7 @@ Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2) client.v2().chatStream( V2ChatStreamRequest .builder() - .model("command-r") + .model("command-a-03-2025") .messages( new ArrayList( Arrays.asList( @@ -2197,7 +2169,7 @@ client.v2().chatStream( UserMessageV2 .builder() .content( - UserMessageV2Content.of("Hello!") + UserMessageV2Content.of("Tell me about LLMs") ) .build() ) @@ -2235,7 +2207,7 @@ Streaming is beneficial for user interfaces that render the contents of the resp
-**model:** `String` — The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model. +**model:** `String` — The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models).
@@ -2433,6 +2405,17 @@ If tool_choice isn't specified, then the model is free to choose whether to use **thinking:** `Optional` + + + +
+
+ +**priority:** `Optional` + +The priority of the request (lower means earlier handling; default 0 highest priority). +Higher priority requests are handled first, and dropped last when the system is under load. +
@@ -2521,7 +2504,7 @@ Streaming is beneficial for user interfaces that render the contents of the resp
-**model:** `String` — The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model. +**model:** `String` — The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models).
@@ -2719,6 +2702,17 @@ If tool_choice isn't specified, then the model is free to choose whether to use **thinking:** `Optional` + + + +
+
+ +**priority:** `Optional` + +The priority of the request (lower means earlier handling; default 0 highest priority). +Higher priority requests are handled first, and dropped last when the system is under load. +
@@ -2803,7 +2797,7 @@ client.v2().embed( An array of image data URIs for the model to embed. Maximum number of images per call is `1`. -The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. +The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg`, `image/png`, `image/webp`, or `image/gif` format and has a maximum size of 5MB. Image embeddings are supported with Embed v3.0 and newer models. @@ -2881,6 +2875,17 @@ Passing `START` will discard the start of the input. `END` will discard the end If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. + + + +
+
+ +**priority:** `Optional` + +The priority of the request (lower means earlier handling; default 0 highest priority). +Higher priority requests are handled first, and dropped last when the system is under load. +
@@ -2986,6 +2991,272 @@ For optimal performance we recommend against sending more than 1,000 documents i **maxTokensPerDoc:** `Optional` — Defaults to `4096`. Long documents will be automatically truncated to the specified number of tokens. + + + +
+
+ +**priority:** `Optional` + +The priority of the request (lower means earlier handling; default 0 highest priority). +Higher priority requests are handled first, and dropped last when the system is under load. + +
+
+ + + + + + + + +## Batches +
client.batches.list() -> ListBatchesResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List the batches for the current user +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.batches().list( + BatchesListBatchesRequest + .builder() + .build() +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageSize:** `Optional` + +The maximum number of batches to return. The service may return fewer than +this value. +If unspecified, at most 50 batches will be returned. +The maximum value is 1000; values above 1000 will be coerced to 1000. + +
+
+ +
+
+ +**pageToken:** `Optional` + +A page token, received from a previous `ListBatches` call. +Provide this to retrieve the subsequent page. + +
+
+ +
+
+ +**orderBy:** `Optional` + +Batches can be ordered by creation time or last updated time. +Use `created_at` for creation time or `updated_at` for last updated time. + +
+
+
+
+ + +
+
+
+ +
client.batches.create(request) -> CreateBatchResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Creates and executes a batch from an uploaded dataset of requests +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.batches().create( + Batch + .builder() + .name("name") + .inputDatasetId("input_dataset_id") + .model("model") + .build() +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `Batch` + +
+
+
+
+ + +
+
+
+ +
client.batches.retrieve(id) -> GetBatchResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieves a batch +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.batches().retrieve("id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**id:** `String` — The batch ID. + +
+
+
+
+ + +
+
+
+ +
client.batches.cancel(id) -> Map<String, Object> +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Cancels an in-progress batch +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```java +client.batches().cancel("id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**id:** `String` — The batch ID. +
@@ -3421,7 +3692,7 @@ client.datasets().create(
-**type:** `DatasetType` — The dataset type, which is used to validate the data. Valid types are `embed-input`, `reranker-finetune-input`, `single-label-classification-finetune-input`, `chat-finetune-input`, and `multi-label-classification-finetune-input`. +**type:** `DatasetType` — The dataset type, which is used to validate the data. The only valid type is `embed-input` used in conjunction with the Embed Jobs API.
@@ -4168,7 +4439,7 @@ client.models().get("command-a-03-2025");
-Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. +Returns a list of models available for use.
diff --git a/src/main/java/com/cohere/api/AsyncCohere.java b/src/main/java/com/cohere/api/AsyncCohere.java index 5623a66..ff19ca9 100644 --- a/src/main/java/com/cohere/api/AsyncCohere.java +++ b/src/main/java/com/cohere/api/AsyncCohere.java @@ -16,6 +16,7 @@ import com.cohere.api.requests.RerankRequest; import com.cohere.api.requests.SummarizeRequest; import com.cohere.api.requests.TokenizeRequest; +import com.cohere.api.resources.batches.AsyncBatchesClient; import com.cohere.api.resources.connectors.AsyncConnectorsClient; import com.cohere.api.resources.datasets.AsyncDatasetsClient; import com.cohere.api.resources.embedjobs.AsyncEmbedJobsClient; @@ -43,6 +44,8 @@ public class AsyncCohere { protected final Supplier v2Client; + protected final Supplier batchesClient; + protected final Supplier embedJobsClient; protected final Supplier datasetsClient; @@ -57,6 +60,7 @@ public AsyncCohere(ClientOptions clientOptions) { this.clientOptions = clientOptions; this.rawClient = new AsyncRawCohere(clientOptions); this.v2Client = Suppliers.memoize(() -> new AsyncV2Client(clientOptions)); + this.batchesClient = Suppliers.memoize(() -> new AsyncBatchesClient(clientOptions)); this.embedJobsClient = Suppliers.memoize(() -> new AsyncEmbedJobsClient(clientOptions)); this.datasetsClient = Suppliers.memoize(() -> new AsyncDatasetsClient(clientOptions)); this.connectorsClient = Suppliers.memoize(() -> new AsyncConnectorsClient(clientOptions)); @@ -268,6 +272,10 @@ public AsyncV2Client v2() { return this.v2Client.get(); } + public AsyncBatchesClient batches() { + return this.batchesClient.get(); + } + public AsyncEmbedJobsClient embedJobs() { return this.embedJobsClient.get(); } diff --git a/src/main/java/com/cohere/api/AsyncCohereBuilder.java b/src/main/java/com/cohere/api/AsyncCohereBuilder.java index 8d89214..231aa21 100644 --- a/src/main/java/com/cohere/api/AsyncCohereBuilder.java +++ b/src/main/java/com/cohere/api/AsyncCohereBuilder.java @@ -209,9 +209,6 @@ 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/Cohere.java b/src/main/java/com/cohere/api/Cohere.java index aa2a15e..ee56fd7 100644 --- a/src/main/java/com/cohere/api/Cohere.java +++ b/src/main/java/com/cohere/api/Cohere.java @@ -16,6 +16,7 @@ import com.cohere.api.requests.RerankRequest; import com.cohere.api.requests.SummarizeRequest; import com.cohere.api.requests.TokenizeRequest; +import com.cohere.api.resources.batches.BatchesClient; import com.cohere.api.resources.connectors.ConnectorsClient; import com.cohere.api.resources.datasets.DatasetsClient; import com.cohere.api.resources.embedjobs.EmbedJobsClient; @@ -42,6 +43,8 @@ public class Cohere { protected final Supplier v2Client; + protected final Supplier batchesClient; + protected final Supplier embedJobsClient; protected final Supplier datasetsClient; @@ -56,6 +59,7 @@ public Cohere(ClientOptions clientOptions) { this.clientOptions = clientOptions; this.rawClient = new RawCohere(clientOptions); this.v2Client = Suppliers.memoize(() -> new V2Client(clientOptions)); + this.batchesClient = Suppliers.memoize(() -> new BatchesClient(clientOptions)); this.embedJobsClient = Suppliers.memoize(() -> new EmbedJobsClient(clientOptions)); this.datasetsClient = Suppliers.memoize(() -> new DatasetsClient(clientOptions)); this.connectorsClient = Suppliers.memoize(() -> new ConnectorsClient(clientOptions)); @@ -266,6 +270,10 @@ public V2Client v2() { return this.v2Client.get(); } + public BatchesClient batches() { + return this.batchesClient.get(); + } + public EmbedJobsClient embedJobs() { return this.embedJobsClient.get(); } diff --git a/src/main/java/com/cohere/api/CohereBuilder.java b/src/main/java/com/cohere/api/CohereBuilder.java index 2050387..041d384 100644 --- a/src/main/java/com/cohere/api/CohereBuilder.java +++ b/src/main/java/com/cohere/api/CohereBuilder.java @@ -209,9 +209,6 @@ 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/requests/ChatRequest.java b/src/main/java/com/cohere/api/requests/ChatRequest.java index 487f9c7..0dcbc0d 100644 --- a/src/main/java/com/cohere/api/requests/ChatRequest.java +++ b/src/main/java/com/cohere/api/requests/ChatRequest.java @@ -267,8 +267,8 @@ public Optional>> getDocuments() { } /** - * @return Defaults to "accurate". - *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ * @return Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled". *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ @JsonProperty("citation_quality") @@ -630,8 +630,8 @@ public interface _FinalStage { _FinalStage documents(List> documents); /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ _FinalStage citationQuality(Optional citationQuality); @@ -1280,8 +1280,8 @@ public _FinalStage temperature(Optional temperature) { } /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @@ -1292,8 +1292,8 @@ public _FinalStage citationQuality(ChatRequestCitationQuality citationQuality) { } /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ @java.lang.Override diff --git a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java index 299342b..292e17a 100644 --- a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java +++ b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java @@ -267,8 +267,8 @@ public Optional>> getDocuments() { } /** - * @return Defaults to "accurate". - *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ * @return Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled". *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ @JsonProperty("citation_quality") @@ -630,8 +630,8 @@ public interface _FinalStage { _FinalStage documents(List> documents); /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ _FinalStage citationQuality(Optional citationQuality); @@ -1280,8 +1280,8 @@ public _FinalStage temperature(Optional temperature) { } /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @@ -1292,8 +1292,8 @@ public _FinalStage citationQuality(ChatStreamRequestCitationQuality citationQual } /** - *

Defaults to "accurate".

- *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

*/ @java.lang.Override diff --git a/src/main/java/com/cohere/api/requests/EmbedRequest.java b/src/main/java/com/cohere/api/requests/EmbedRequest.java index 25329ed..e8af641 100644 --- a/src/main/java/com/cohere/api/requests/EmbedRequest.java +++ b/src/main/java/com/cohere/api/requests/EmbedRequest.java @@ -65,7 +65,7 @@ public Optional> getTexts() { /** * @return An array of image data URIs for the model to embed. Maximum number of images per call is 1. - *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Images are only supported with Embed v3.0 and newer models.

*/ @JsonProperty("images") @@ -190,7 +190,7 @@ public Builder texts(List texts) { /** *

An array of image data URIs for the model to embed. Maximum number of images per call is 1.

- *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Images are only supported with Embed v3.0 and newer models.

*/ @JsonSetter(value = "images", nulls = Nulls.SKIP) diff --git a/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java new file mode 100644 index 0000000..b425fec --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/AsyncBatchesClient.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches; + +import com.cohere.api.core.ClientOptions; +import com.cohere.api.core.RequestOptions; +import com.cohere.api.resources.batches.requests.BatchesListBatchesRequest; +import com.cohere.api.resources.batches.types.Batch; +import com.cohere.api.resources.batches.types.CreateBatchResponse; +import com.cohere.api.resources.batches.types.GetBatchResponse; +import com.cohere.api.resources.batches.types.ListBatchesResponse; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class AsyncBatchesClient { + protected final ClientOptions clientOptions; + + private final AsyncRawBatchesClient rawClient; + + public AsyncBatchesClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + this.rawClient = new AsyncRawBatchesClient(clientOptions); + } + + /** + * Get responses with HTTP metadata like headers + */ + public AsyncRawBatchesClient withRawResponse() { + return this.rawClient; + } + + /** + * List the batches for the current user + */ + public CompletableFuture list() { + return this.rawClient.list().thenApply(response -> response.body()); + } + + /** + * List the batches for the current user + */ + public CompletableFuture list(BatchesListBatchesRequest request) { + return this.rawClient.list(request).thenApply(response -> response.body()); + } + + /** + * List the batches for the current user + */ + public CompletableFuture list( + BatchesListBatchesRequest request, RequestOptions requestOptions) { + return this.rawClient.list(request, requestOptions).thenApply(response -> response.body()); + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CompletableFuture create(Batch request) { + return this.rawClient.create(request).thenApply(response -> response.body()); + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CompletableFuture create(Batch request, RequestOptions requestOptions) { + return this.rawClient.create(request, requestOptions).thenApply(response -> response.body()); + } + + /** + * Retrieves a batch + */ + public CompletableFuture retrieve(String id) { + return this.rawClient.retrieve(id).thenApply(response -> response.body()); + } + + /** + * Retrieves a batch + */ + public CompletableFuture retrieve(String id, RequestOptions requestOptions) { + return this.rawClient.retrieve(id, requestOptions).thenApply(response -> response.body()); + } + + /** + * Cancels an in-progress batch + */ + public CompletableFuture> cancel(String id) { + return this.rawClient.cancel(id).thenApply(response -> response.body()); + } + + /** + * Cancels an in-progress batch + */ + public CompletableFuture> cancel(String id, RequestOptions requestOptions) { + return this.rawClient.cancel(id, requestOptions).thenApply(response -> response.body()); + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java new file mode 100644 index 0000000..8983224 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/AsyncRawBatchesClient.java @@ -0,0 +1,447 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches; + +import com.cohere.api.core.ClientOptions; +import com.cohere.api.core.CohereApiException; +import com.cohere.api.core.CohereException; +import com.cohere.api.core.CohereHttpResponse; +import com.cohere.api.core.MediaTypes; +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.core.QueryStringMapper; +import com.cohere.api.core.RequestOptions; +import com.cohere.api.errors.BadRequestError; +import com.cohere.api.errors.ForbiddenError; +import com.cohere.api.errors.InternalServerError; +import com.cohere.api.errors.NotFoundError; +import com.cohere.api.errors.ServiceUnavailableError; +import com.cohere.api.errors.UnauthorizedError; +import com.cohere.api.resources.batches.requests.BatchesListBatchesRequest; +import com.cohere.api.resources.batches.types.Batch; +import com.cohere.api.resources.batches.types.CreateBatchResponse; +import com.cohere.api.resources.batches.types.GetBatchResponse; +import com.cohere.api.resources.batches.types.ListBatchesResponse; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.ResponseBody; +import org.jetbrains.annotations.NotNull; + +public class AsyncRawBatchesClient { + protected final ClientOptions clientOptions; + + public AsyncRawBatchesClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + /** + * List the batches for the current user + */ + public CompletableFuture> list() { + return list(BatchesListBatchesRequest.builder().build()); + } + + /** + * List the batches for the current user + */ + public CompletableFuture> list(BatchesListBatchesRequest request) { + return list(request, null); + } + + /** + * List the batches for the current user + */ + public CompletableFuture> list( + BatchesListBatchesRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches"); + if (request.getPageSize().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "page_size", request.getPageSize().get(), false); + } + if (request.getPageToken().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "page_token", request.getPageToken().get(), false); + } + if (request.getOrderBy().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "order_by", request.getOrderBy().get(), false); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + if (response.isSuccessful()) { + future.complete(new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBatchesResponse.class), + response)); + return; + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + future.completeExceptionally(new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 403: + future.completeExceptionally(new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + future.completeExceptionally(new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } catch (IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + }); + return future; + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CompletableFuture> create(Batch request) { + return create(request, null); + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CompletableFuture> create( + Batch request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new CohereException("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .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()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + if (response.isSuccessful()) { + future.complete(new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateBatchResponse.class), + response)); + return; + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + future.completeExceptionally(new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 403: + future.completeExceptionally(new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + future.completeExceptionally(new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } catch (IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + }); + return future; + } + + /** + * Retrieves a batch + */ + public CompletableFuture> retrieve(String id) { + return retrieve(id, null); + } + + /** + * Retrieves a batch + */ + public CompletableFuture> retrieve(String id, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches") + .addPathSegment(id) + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + if (response.isSuccessful()) { + future.complete(new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBatchResponse.class), + response)); + return; + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + future.completeExceptionally(new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 403: + future.completeExceptionally(new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + future.completeExceptionally(new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } catch (IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + }); + return future; + } + + /** + * Cancels an in-progress batch + */ + public CompletableFuture>> cancel(String id) { + return cancel(id, null); + } + + /** + * Cancels an in-progress batch + */ + public CompletableFuture>> cancel(String id, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches") + .addPathSegment(id) + .addPathSegments(":cancel") + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", RequestBody.create("", null)) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture>> future = new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + if (response.isSuccessful()) { + future.complete(new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), new TypeReference>() {}), + response)); + return; + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + future.completeExceptionally(new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 403: + future.completeExceptionally(new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 404: + future.completeExceptionally(new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 503: + future.completeExceptionally(new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + future.completeExceptionally(new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } catch (IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new CohereException("Network error executing HTTP request", e)); + } + }); + return future; + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/BatchesClient.java b/src/main/java/com/cohere/api/resources/batches/BatchesClient.java new file mode 100644 index 0000000..82f4fd0 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/BatchesClient.java @@ -0,0 +1,94 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches; + +import com.cohere.api.core.ClientOptions; +import com.cohere.api.core.RequestOptions; +import com.cohere.api.resources.batches.requests.BatchesListBatchesRequest; +import com.cohere.api.resources.batches.types.Batch; +import com.cohere.api.resources.batches.types.CreateBatchResponse; +import com.cohere.api.resources.batches.types.GetBatchResponse; +import com.cohere.api.resources.batches.types.ListBatchesResponse; +import java.util.Map; + +public class BatchesClient { + protected final ClientOptions clientOptions; + + private final RawBatchesClient rawClient; + + public BatchesClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + this.rawClient = new RawBatchesClient(clientOptions); + } + + /** + * Get responses with HTTP metadata like headers + */ + public RawBatchesClient withRawResponse() { + return this.rawClient; + } + + /** + * List the batches for the current user + */ + public ListBatchesResponse list() { + return this.rawClient.list().body(); + } + + /** + * List the batches for the current user + */ + public ListBatchesResponse list(BatchesListBatchesRequest request) { + return this.rawClient.list(request).body(); + } + + /** + * List the batches for the current user + */ + public ListBatchesResponse list(BatchesListBatchesRequest request, RequestOptions requestOptions) { + return this.rawClient.list(request, requestOptions).body(); + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CreateBatchResponse create(Batch request) { + return this.rawClient.create(request).body(); + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CreateBatchResponse create(Batch request, RequestOptions requestOptions) { + return this.rawClient.create(request, requestOptions).body(); + } + + /** + * Retrieves a batch + */ + public GetBatchResponse retrieve(String id) { + return this.rawClient.retrieve(id).body(); + } + + /** + * Retrieves a batch + */ + public GetBatchResponse retrieve(String id, RequestOptions requestOptions) { + return this.rawClient.retrieve(id, requestOptions).body(); + } + + /** + * Cancels an in-progress batch + */ + public Map cancel(String id) { + return this.rawClient.cancel(id).body(); + } + + /** + * Cancels an in-progress batch + */ + public Map cancel(String id, RequestOptions requestOptions) { + return this.rawClient.cancel(id, requestOptions).body(); + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java b/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java new file mode 100644 index 0000000..374cf81 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/RawBatchesClient.java @@ -0,0 +1,341 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches; + +import com.cohere.api.core.ClientOptions; +import com.cohere.api.core.CohereApiException; +import com.cohere.api.core.CohereException; +import com.cohere.api.core.CohereHttpResponse; +import com.cohere.api.core.MediaTypes; +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.core.QueryStringMapper; +import com.cohere.api.core.RequestOptions; +import com.cohere.api.errors.BadRequestError; +import com.cohere.api.errors.ForbiddenError; +import com.cohere.api.errors.InternalServerError; +import com.cohere.api.errors.NotFoundError; +import com.cohere.api.errors.ServiceUnavailableError; +import com.cohere.api.errors.UnauthorizedError; +import com.cohere.api.resources.batches.requests.BatchesListBatchesRequest; +import com.cohere.api.resources.batches.types.Batch; +import com.cohere.api.resources.batches.types.CreateBatchResponse; +import com.cohere.api.resources.batches.types.GetBatchResponse; +import com.cohere.api.resources.batches.types.ListBatchesResponse; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Map; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.ResponseBody; + +public class RawBatchesClient { + protected final ClientOptions clientOptions; + + public RawBatchesClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + /** + * List the batches for the current user + */ + public CohereHttpResponse list() { + return list(BatchesListBatchesRequest.builder().build()); + } + + /** + * List the batches for the current user + */ + public CohereHttpResponse list(BatchesListBatchesRequest request) { + return list(request, null); + } + + /** + * List the batches for the current user + */ + public CohereHttpResponse list( + BatchesListBatchesRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches"); + if (request.getPageSize().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "page_size", request.getPageSize().get(), false); + } + if (request.getPageToken().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "page_token", request.getPageToken().get(), false); + } + if (request.getOrderBy().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "order_by", request.getOrderBy().get(), false); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json"); + Request okhttpRequest = _requestBuilder.build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBatchesResponse.class), + response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 403: + throw new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); + } catch (IOException e) { + throw new CohereException("Network error executing HTTP request", e); + } + } + + /** + * Creates and executes a batch from an uploaded dataset of requests + */ + public CohereHttpResponse create(Batch request) { + return create(request, null); + } + + /** + * 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()) + .newBuilder() + .addPathSegments("v2/batches") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new CohereException("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .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()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateBatchResponse.class), + response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 403: + throw new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); + } catch (IOException e) { + throw new CohereException("Network error executing HTTP request", e); + } + } + + /** + * Retrieves a batch + */ + public CohereHttpResponse retrieve(String id) { + return retrieve(id, null); + } + + /** + * Retrieves a batch + */ + public CohereHttpResponse retrieve(String id, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches") + .addPathSegment(id) + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBatchResponse.class), response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 403: + throw new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); + } catch (IOException e) { + throw new CohereException("Network error executing HTTP request", e); + } + } + + /** + * Cancels an in-progress batch + */ + public CohereHttpResponse> cancel(String id) { + return cancel(id, null); + } + + /** + * Cancels an in-progress batch + */ + public CohereHttpResponse> cancel(String id, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/batches") + .addPathSegment(id) + .addPathSegments(":cancel") + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", RequestBody.create("", null)) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new CohereHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), new TypeReference>() {}), + response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 403: + throw new ForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 404: + throw new NotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 503: + throw new ServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); + } catch (IOException e) { + throw new CohereException("Network error executing HTTP request", e); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/requests/BatchesListBatchesRequest.java b/src/main/java/com/cohere/api/resources/batches/requests/BatchesListBatchesRequest.java new file mode 100644 index 0000000..7f1220e --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/requests/BatchesListBatchesRequest.java @@ -0,0 +1,171 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.requests; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = BatchesListBatchesRequest.Builder.class) +public final class BatchesListBatchesRequest { + private final Optional pageSize; + + private final Optional pageToken; + + private final Optional orderBy; + + private final Map additionalProperties; + + private BatchesListBatchesRequest( + Optional pageSize, + Optional pageToken, + Optional orderBy, + Map additionalProperties) { + this.pageSize = pageSize; + this.pageToken = pageToken; + this.orderBy = orderBy; + this.additionalProperties = additionalProperties; + } + + /** + * @return The maximum number of batches to return. The service may return fewer than + * this value. + * If unspecified, at most 50 batches will be returned. + * The maximum value is 1000; values above 1000 will be coerced to 1000. + */ + @JsonProperty("page_size") + public Optional getPageSize() { + return pageSize; + } + + /** + * @return A page token, received from a previous ListBatches call. + * Provide this to retrieve the subsequent page. + */ + @JsonProperty("page_token") + public Optional getPageToken() { + return pageToken; + } + + /** + * @return Batches can be ordered by creation time or last updated time. + * Use created_at for creation time or updated_at for last updated time. + */ + @JsonProperty("order_by") + public Optional getOrderBy() { + return orderBy; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof BatchesListBatchesRequest && equalTo((BatchesListBatchesRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(BatchesListBatchesRequest other) { + return pageSize.equals(other.pageSize) && pageToken.equals(other.pageToken) && orderBy.equals(other.orderBy); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.pageSize, this.pageToken, this.orderBy); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder { + private Optional pageSize = Optional.empty(); + + private Optional pageToken = Optional.empty(); + + private Optional orderBy = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(BatchesListBatchesRequest other) { + pageSize(other.getPageSize()); + pageToken(other.getPageToken()); + orderBy(other.getOrderBy()); + return this; + } + + /** + *

The maximum number of batches to return. The service may return fewer than + * this value. + * If unspecified, at most 50 batches will be returned. + * The maximum value is 1000; values above 1000 will be coerced to 1000.

+ */ + @JsonSetter(value = "page_size", nulls = Nulls.SKIP) + public Builder pageSize(Optional pageSize) { + this.pageSize = pageSize; + return this; + } + + public Builder pageSize(Integer pageSize) { + this.pageSize = Optional.ofNullable(pageSize); + return this; + } + + /** + *

A page token, received from a previous ListBatches call. + * Provide this to retrieve the subsequent page.

+ */ + @JsonSetter(value = "page_token", nulls = Nulls.SKIP) + public Builder pageToken(Optional pageToken) { + this.pageToken = pageToken; + return this; + } + + public Builder pageToken(String pageToken) { + this.pageToken = Optional.ofNullable(pageToken); + return this; + } + + /** + *

Batches can be ordered by creation time or last updated time. + * Use created_at for creation time or updated_at for last updated time.

+ */ + @JsonSetter(value = "order_by", nulls = Nulls.SKIP) + public Builder orderBy(Optional orderBy) { + this.orderBy = orderBy; + return this; + } + + public Builder orderBy(String orderBy) { + this.orderBy = Optional.ofNullable(orderBy); + return this; + } + + public BatchesListBatchesRequest build() { + return new BatchesListBatchesRequest(pageSize, pageToken, orderBy, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/types/Batch.java b/src/main/java/com/cohere/api/resources/batches/types/Batch.java new file mode 100644 index 0000000..5d53b12 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/types/Batch.java @@ -0,0 +1,767 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = Batch.Builder.class) +public final class Batch { + private final Optional id; + + private final String name; + + private final Optional creatorId; + + private final Optional orgId; + + private final Optional status; + + private final Optional createdAt; + + private final Optional updatedAt; + + private final String inputDatasetId; + + private final Optional outputDatasetId; + + private final Optional inputTokens; + + private final Optional outputTokens; + + private final String model; + + private final Optional numRecords; + + private final Optional numSuccessfulRecords; + + private final Optional numFailedRecords; + + private final Optional statusReason; + + private final Map additionalProperties; + + private Batch( + Optional id, + String name, + Optional creatorId, + Optional orgId, + Optional status, + Optional createdAt, + Optional updatedAt, + String inputDatasetId, + Optional outputDatasetId, + Optional inputTokens, + Optional outputTokens, + String model, + Optional numRecords, + Optional numSuccessfulRecords, + Optional numFailedRecords, + Optional statusReason, + Map additionalProperties) { + this.id = id; + this.name = name; + this.creatorId = creatorId; + this.orgId = orgId; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.inputDatasetId = inputDatasetId; + this.outputDatasetId = outputDatasetId; + this.inputTokens = inputTokens; + this.outputTokens = outputTokens; + this.model = model; + this.numRecords = numRecords; + this.numSuccessfulRecords = numSuccessfulRecords; + this.numFailedRecords = numFailedRecords; + this.statusReason = statusReason; + this.additionalProperties = additionalProperties; + } + + /** + * @return read-only. Batch ID. + */ + @JsonProperty("id") + public Optional getId() { + return id; + } + + /** + * @return Batch name (e.g. foobar). + */ + @JsonProperty("name") + public String getName() { + return name; + } + + /** + * @return read-only. User ID of the creator. + */ + @JsonProperty("creator_id") + public Optional getCreatorId() { + return creatorId; + } + + /** + * @return read-only. Organization ID. + */ + @JsonProperty("org_id") + public Optional getOrgId() { + return orgId; + } + + /** + * @return read-only. Current stage in the life-cycle of the batch. + */ + @JsonProperty("status") + public Optional getStatus() { + return status; + } + + /** + * @return read-only. Creation timestamp. + */ + @JsonProperty("created_at") + public Optional getCreatedAt() { + return createdAt; + } + + /** + * @return read-only. Latest update timestamp. + */ + @JsonProperty("updated_at") + public Optional getUpdatedAt() { + return updatedAt; + } + + /** + * @return ID of the dataset the batch reads inputs from. + */ + @JsonProperty("input_dataset_id") + public String getInputDatasetId() { + return inputDatasetId; + } + + @JsonProperty("output_dataset_id") + public Optional getOutputDatasetId() { + return outputDatasetId; + } + + /** + * @return read-only. The total number of input tokens in the batch. + */ + @JsonProperty("input_tokens") + public Optional getInputTokens() { + return inputTokens; + } + + /** + * @return read-only. The total number of output tokens in the batch. + */ + @JsonProperty("output_tokens") + public Optional getOutputTokens() { + return outputTokens; + } + + /** + * @return The name of the model the batch uses. + */ + @JsonProperty("model") + public String getModel() { + return model; + } + + /** + * @return read-only. The total number of records in the batch. + */ + @JsonProperty("num_records") + public Optional getNumRecords() { + return numRecords; + } + + /** + * @return read-only. The current number of successful records in the batch. + */ + @JsonProperty("num_successful_records") + public Optional getNumSuccessfulRecords() { + return numSuccessfulRecords; + } + + /** + * @return read-only. The current number of failed records in the batch. + */ + @JsonProperty("num_failed_records") + public Optional getNumFailedRecords() { + return numFailedRecords; + } + + /** + * @return read-only. More details about the reason for the status of a batch job. + */ + @JsonProperty("status_reason") + public Optional getStatusReason() { + return statusReason; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Batch && equalTo((Batch) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Batch other) { + return id.equals(other.id) + && name.equals(other.name) + && creatorId.equals(other.creatorId) + && orgId.equals(other.orgId) + && status.equals(other.status) + && createdAt.equals(other.createdAt) + && updatedAt.equals(other.updatedAt) + && inputDatasetId.equals(other.inputDatasetId) + && outputDatasetId.equals(other.outputDatasetId) + && inputTokens.equals(other.inputTokens) + && outputTokens.equals(other.outputTokens) + && model.equals(other.model) + && numRecords.equals(other.numRecords) + && numSuccessfulRecords.equals(other.numSuccessfulRecords) + && numFailedRecords.equals(other.numFailedRecords) + && statusReason.equals(other.statusReason); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash( + this.id, + this.name, + this.creatorId, + this.orgId, + this.status, + this.createdAt, + this.updatedAt, + this.inputDatasetId, + this.outputDatasetId, + this.inputTokens, + this.outputTokens, + this.model, + this.numRecords, + this.numSuccessfulRecords, + this.numFailedRecords, + this.statusReason); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static NameStage builder() { + return new Builder(); + } + + public interface NameStage { + /** + *

Batch name (e.g. foobar).

+ */ + InputDatasetIdStage name(@NotNull String name); + + Builder from(Batch other); + } + + public interface InputDatasetIdStage { + /** + *

ID of the dataset the batch reads inputs from.

+ */ + ModelStage inputDatasetId(@NotNull String inputDatasetId); + } + + public interface ModelStage { + /** + *

The name of the model the batch uses.

+ */ + _FinalStage model(@NotNull String model); + } + + public interface _FinalStage { + Batch build(); + + /** + *

read-only. Batch ID.

+ */ + _FinalStage id(Optional id); + + _FinalStage id(String id); + + /** + *

read-only. User ID of the creator.

+ */ + _FinalStage creatorId(Optional creatorId); + + _FinalStage creatorId(String creatorId); + + /** + *

read-only. Organization ID.

+ */ + _FinalStage orgId(Optional orgId); + + _FinalStage orgId(String orgId); + + /** + *

read-only. Current stage in the life-cycle of the batch.

+ */ + _FinalStage status(Optional status); + + _FinalStage status(BatchStatus status); + + /** + *

read-only. Creation timestamp.

+ */ + _FinalStage createdAt(Optional createdAt); + + _FinalStage createdAt(OffsetDateTime createdAt); + + /** + *

read-only. Latest update timestamp.

+ */ + _FinalStage updatedAt(Optional updatedAt); + + _FinalStage updatedAt(OffsetDateTime updatedAt); + + _FinalStage outputDatasetId(Optional outputDatasetId); + + _FinalStage outputDatasetId(String outputDatasetId); + + /** + *

read-only. The total number of input tokens in the batch.

+ */ + _FinalStage inputTokens(Optional inputTokens); + + _FinalStage inputTokens(String inputTokens); + + /** + *

read-only. The total number of output tokens in the batch.

+ */ + _FinalStage outputTokens(Optional outputTokens); + + _FinalStage outputTokens(String outputTokens); + + /** + *

read-only. The total number of records in the batch.

+ */ + _FinalStage numRecords(Optional numRecords); + + _FinalStage numRecords(Integer numRecords); + + /** + *

read-only. The current number of successful records in the batch.

+ */ + _FinalStage numSuccessfulRecords(Optional numSuccessfulRecords); + + _FinalStage numSuccessfulRecords(Integer numSuccessfulRecords); + + /** + *

read-only. The current number of failed records in the batch.

+ */ + _FinalStage numFailedRecords(Optional numFailedRecords); + + _FinalStage numFailedRecords(Integer numFailedRecords); + + /** + *

read-only. More details about the reason for the status of a batch job.

+ */ + _FinalStage statusReason(Optional statusReason); + + _FinalStage statusReason(String statusReason); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements NameStage, InputDatasetIdStage, ModelStage, _FinalStage { + private String name; + + private String inputDatasetId; + + private String model; + + private Optional statusReason = Optional.empty(); + + private Optional numFailedRecords = Optional.empty(); + + private Optional numSuccessfulRecords = Optional.empty(); + + private Optional numRecords = Optional.empty(); + + private Optional outputTokens = Optional.empty(); + + private Optional inputTokens = Optional.empty(); + + private Optional outputDatasetId = Optional.empty(); + + private Optional updatedAt = Optional.empty(); + + private Optional createdAt = Optional.empty(); + + private Optional status = Optional.empty(); + + private Optional orgId = Optional.empty(); + + private Optional creatorId = Optional.empty(); + + private Optional id = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(Batch other) { + id(other.getId()); + name(other.getName()); + creatorId(other.getCreatorId()); + orgId(other.getOrgId()); + status(other.getStatus()); + createdAt(other.getCreatedAt()); + updatedAt(other.getUpdatedAt()); + inputDatasetId(other.getInputDatasetId()); + outputDatasetId(other.getOutputDatasetId()); + inputTokens(other.getInputTokens()); + outputTokens(other.getOutputTokens()); + model(other.getModel()); + numRecords(other.getNumRecords()); + numSuccessfulRecords(other.getNumSuccessfulRecords()); + numFailedRecords(other.getNumFailedRecords()); + statusReason(other.getStatusReason()); + return this; + } + + /** + *

Batch name (e.g. foobar).

+ *

Batch name (e.g. foobar).

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("name") + public InputDatasetIdStage name(@NotNull String name) { + this.name = Objects.requireNonNull(name, "name must not be null"); + return this; + } + + /** + *

ID of the dataset the batch reads inputs from.

+ *

ID of the dataset the batch reads inputs from.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("input_dataset_id") + public ModelStage inputDatasetId(@NotNull String inputDatasetId) { + this.inputDatasetId = Objects.requireNonNull(inputDatasetId, "inputDatasetId must not be null"); + return this; + } + + /** + *

The name of the model the batch uses.

+ *

The name of the model the batch uses.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("model") + public _FinalStage model(@NotNull String model) { + this.model = Objects.requireNonNull(model, "model must not be null"); + return this; + } + + /** + *

read-only. More details about the reason for the status of a batch job.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage statusReason(String statusReason) { + this.statusReason = Optional.ofNullable(statusReason); + return this; + } + + /** + *

read-only. More details about the reason for the status of a batch job.

+ */ + @java.lang.Override + @JsonSetter(value = "status_reason", nulls = Nulls.SKIP) + public _FinalStage statusReason(Optional statusReason) { + this.statusReason = statusReason; + return this; + } + + /** + *

read-only. The current number of failed records in the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage numFailedRecords(Integer numFailedRecords) { + this.numFailedRecords = Optional.ofNullable(numFailedRecords); + return this; + } + + /** + *

read-only. The current number of failed records in the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "num_failed_records", nulls = Nulls.SKIP) + public _FinalStage numFailedRecords(Optional numFailedRecords) { + this.numFailedRecords = numFailedRecords; + return this; + } + + /** + *

read-only. The current number of successful records in the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage numSuccessfulRecords(Integer numSuccessfulRecords) { + this.numSuccessfulRecords = Optional.ofNullable(numSuccessfulRecords); + return this; + } + + /** + *

read-only. The current number of successful records in the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "num_successful_records", nulls = Nulls.SKIP) + public _FinalStage numSuccessfulRecords(Optional numSuccessfulRecords) { + this.numSuccessfulRecords = numSuccessfulRecords; + return this; + } + + /** + *

read-only. The total number of records in the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage numRecords(Integer numRecords) { + this.numRecords = Optional.ofNullable(numRecords); + return this; + } + + /** + *

read-only. The total number of records in the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "num_records", nulls = Nulls.SKIP) + public _FinalStage numRecords(Optional numRecords) { + this.numRecords = numRecords; + return this; + } + + /** + *

read-only. The total number of output tokens in the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage outputTokens(String outputTokens) { + this.outputTokens = Optional.ofNullable(outputTokens); + return this; + } + + /** + *

read-only. The total number of output tokens in the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "output_tokens", nulls = Nulls.SKIP) + public _FinalStage outputTokens(Optional outputTokens) { + this.outputTokens = outputTokens; + return this; + } + + /** + *

read-only. The total number of input tokens in the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage inputTokens(String inputTokens) { + this.inputTokens = Optional.ofNullable(inputTokens); + return this; + } + + /** + *

read-only. The total number of input tokens in the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "input_tokens", nulls = Nulls.SKIP) + public _FinalStage inputTokens(Optional inputTokens) { + this.inputTokens = inputTokens; + return this; + } + + @java.lang.Override + public _FinalStage outputDatasetId(String outputDatasetId) { + this.outputDatasetId = Optional.ofNullable(outputDatasetId); + return this; + } + + @java.lang.Override + @JsonSetter(value = "output_dataset_id", nulls = Nulls.SKIP) + public _FinalStage outputDatasetId(Optional outputDatasetId) { + this.outputDatasetId = outputDatasetId; + return this; + } + + /** + *

read-only. Latest update timestamp.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage updatedAt(OffsetDateTime updatedAt) { + this.updatedAt = Optional.ofNullable(updatedAt); + return this; + } + + /** + *

read-only. Latest update timestamp.

+ */ + @java.lang.Override + @JsonSetter(value = "updated_at", nulls = Nulls.SKIP) + public _FinalStage updatedAt(Optional updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + /** + *

read-only. Creation timestamp.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage createdAt(OffsetDateTime createdAt) { + this.createdAt = Optional.ofNullable(createdAt); + return this; + } + + /** + *

read-only. Creation timestamp.

+ */ + @java.lang.Override + @JsonSetter(value = "created_at", nulls = Nulls.SKIP) + public _FinalStage createdAt(Optional createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + *

read-only. Current stage in the life-cycle of the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage status(BatchStatus status) { + this.status = Optional.ofNullable(status); + return this; + } + + /** + *

read-only. Current stage in the life-cycle of the batch.

+ */ + @java.lang.Override + @JsonSetter(value = "status", nulls = Nulls.SKIP) + public _FinalStage status(Optional status) { + this.status = status; + return this; + } + + /** + *

read-only. Organization ID.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage orgId(String orgId) { + this.orgId = Optional.ofNullable(orgId); + return this; + } + + /** + *

read-only. Organization ID.

+ */ + @java.lang.Override + @JsonSetter(value = "org_id", nulls = Nulls.SKIP) + public _FinalStage orgId(Optional orgId) { + this.orgId = orgId; + return this; + } + + /** + *

read-only. User ID of the creator.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage creatorId(String creatorId) { + this.creatorId = Optional.ofNullable(creatorId); + return this; + } + + /** + *

read-only. User ID of the creator.

+ */ + @java.lang.Override + @JsonSetter(value = "creator_id", nulls = Nulls.SKIP) + public _FinalStage creatorId(Optional creatorId) { + this.creatorId = creatorId; + return this; + } + + /** + *

read-only. Batch ID.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage id(String id) { + this.id = Optional.ofNullable(id); + return this; + } + + /** + *

read-only. Batch ID.

+ */ + @java.lang.Override + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public _FinalStage id(Optional id) { + this.id = id; + return this; + } + + @java.lang.Override + public Batch build() { + return new Batch( + id, + name, + creatorId, + orgId, + status, + createdAt, + updatedAt, + inputDatasetId, + outputDatasetId, + inputTokens, + outputTokens, + model, + numRecords, + numSuccessfulRecords, + numFailedRecords, + statusReason, + additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/types/BatchStatus.java b/src/main/java/com/cohere/api/resources/batches/types/BatchStatus.java new file mode 100644 index 0000000..e0dd5f1 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/types/BatchStatus.java @@ -0,0 +1,34 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum BatchStatus { + BATCH_STATUS_UNSPECIFIED("BATCH_STATUS_UNSPECIFIED"), + + BATCH_STATUS_QUEUED("BATCH_STATUS_QUEUED"), + + BATCH_STATUS_IN_PROGRESS("BATCH_STATUS_IN_PROGRESS"), + + BATCH_STATUS_CANCELING("BATCH_STATUS_CANCELING"), + + BATCH_STATUS_COMPLETED("BATCH_STATUS_COMPLETED"), + + BATCH_STATUS_FAILED("BATCH_STATUS_FAILED"), + + BATCH_STATUS_CANCELED("BATCH_STATUS_CANCELED"); + + private final String value; + + BatchStatus(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/types/CreateBatchResponse.java b/src/main/java/com/cohere/api/resources/batches/types/CreateBatchResponse.java new file mode 100644 index 0000000..6ace36c --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/types/CreateBatchResponse.java @@ -0,0 +1,113 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = CreateBatchResponse.Builder.class) +public final class CreateBatchResponse { + private final Batch batch; + + private final Map additionalProperties; + + private CreateBatchResponse(Batch batch, Map additionalProperties) { + this.batch = batch; + this.additionalProperties = additionalProperties; + } + + /** + * @return Information about the batch. + */ + @JsonProperty("batch") + public Batch getBatch() { + return batch; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CreateBatchResponse && equalTo((CreateBatchResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CreateBatchResponse other) { + return batch.equals(other.batch); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.batch); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static BatchStage builder() { + return new Builder(); + } + + public interface BatchStage { + /** + *

Information about the batch.

+ */ + _FinalStage batch(@NotNull Batch batch); + + Builder from(CreateBatchResponse other); + } + + public interface _FinalStage { + CreateBatchResponse build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements BatchStage, _FinalStage { + private Batch batch; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(CreateBatchResponse other) { + batch(other.getBatch()); + return this; + } + + /** + *

Information about the batch.

+ *

Information about the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("batch") + public _FinalStage batch(@NotNull Batch batch) { + this.batch = Objects.requireNonNull(batch, "batch must not be null"); + return this; + } + + @java.lang.Override + public CreateBatchResponse build() { + return new CreateBatchResponse(batch, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/types/GetBatchResponse.java b/src/main/java/com/cohere/api/resources/batches/types/GetBatchResponse.java new file mode 100644 index 0000000..a2cfed9 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/types/GetBatchResponse.java @@ -0,0 +1,113 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = GetBatchResponse.Builder.class) +public final class GetBatchResponse { + private final Batch batch; + + private final Map additionalProperties; + + private GetBatchResponse(Batch batch, Map additionalProperties) { + this.batch = batch; + this.additionalProperties = additionalProperties; + } + + /** + * @return Information about the batch. + */ + @JsonProperty("batch") + public Batch getBatch() { + return batch; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof GetBatchResponse && equalTo((GetBatchResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(GetBatchResponse other) { + return batch.equals(other.batch); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.batch); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static BatchStage builder() { + return new Builder(); + } + + public interface BatchStage { + /** + *

Information about the batch.

+ */ + _FinalStage batch(@NotNull Batch batch); + + Builder from(GetBatchResponse other); + } + + public interface _FinalStage { + GetBatchResponse build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements BatchStage, _FinalStage { + private Batch batch; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(GetBatchResponse other) { + batch(other.getBatch()); + return this; + } + + /** + *

Information about the batch.

+ *

Information about the batch.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("batch") + public _FinalStage batch(@NotNull Batch batch) { + this.batch = Objects.requireNonNull(batch, "batch must not be null"); + return this; + } + + @java.lang.Override + public GetBatchResponse build() { + return new GetBatchResponse(batch, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/batches/types/ListBatchesResponse.java b/src/main/java/com/cohere/api/resources/batches/types/ListBatchesResponse.java new file mode 100644 index 0000000..bb265ac --- /dev/null +++ b/src/main/java/com/cohere/api/resources/batches/types/ListBatchesResponse.java @@ -0,0 +1,133 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.batches.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = ListBatchesResponse.Builder.class) +public final class ListBatchesResponse { + private final Optional> batches; + + private final Optional nextPageToken; + + private final Map additionalProperties; + + private ListBatchesResponse( + Optional> batches, Optional nextPageToken, Map additionalProperties) { + this.batches = batches; + this.nextPageToken = nextPageToken; + this.additionalProperties = additionalProperties; + } + + /** + * @return The batches that belong to the authenticated user. + */ + @JsonProperty("batches") + public Optional> getBatches() { + return batches; + } + + /** + * @return A token, which can be sent as page_token to retrieve the next page. + * If this field is omitted, there are no subsequent pages. + */ + @JsonProperty("next_page_token") + public Optional getNextPageToken() { + return nextPageToken; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ListBatchesResponse && equalTo((ListBatchesResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ListBatchesResponse other) { + return batches.equals(other.batches) && nextPageToken.equals(other.nextPageToken); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.batches, this.nextPageToken); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder { + private Optional> batches = Optional.empty(); + + private Optional nextPageToken = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ListBatchesResponse other) { + batches(other.getBatches()); + nextPageToken(other.getNextPageToken()); + return this; + } + + /** + *

The batches that belong to the authenticated user.

+ */ + @JsonSetter(value = "batches", nulls = Nulls.SKIP) + public Builder batches(Optional> batches) { + this.batches = batches; + return this; + } + + public Builder batches(List batches) { + this.batches = Optional.ofNullable(batches); + return this; + } + + /** + *

A token, which can be sent as page_token to retrieve the next page. + * If this field is omitted, there are no subsequent pages.

+ */ + @JsonSetter(value = "next_page_token", nulls = Nulls.SKIP) + public Builder nextPageToken(Optional nextPageToken) { + this.nextPageToken = nextPageToken; + return this; + } + + public Builder nextPageToken(String nextPageToken) { + this.nextPageToken = Optional.ofNullable(nextPageToken); + return this; + } + + public ListBatchesResponse build() { + return new ListBatchesResponse(batches, nextPageToken, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/datasets/requests/DatasetsCreateRequest.java b/src/main/java/com/cohere/api/resources/datasets/requests/DatasetsCreateRequest.java index fda96a8..882a935 100644 --- a/src/main/java/com/cohere/api/resources/datasets/requests/DatasetsCreateRequest.java +++ b/src/main/java/com/cohere/api/resources/datasets/requests/DatasetsCreateRequest.java @@ -88,7 +88,7 @@ public String getName() { } /** - * @return The dataset type, which is used to validate the data. Valid types are embed-input, reranker-finetune-input, single-label-classification-finetune-input, chat-finetune-input, and multi-label-classification-finetune-input. + * @return The dataset type, which is used to validate the data. The only valid type is embed-input used in conjunction with the Embed Jobs API. */ @JsonProperty("type") public DatasetType getType() { @@ -182,7 +182,7 @@ public interface NameStage { public interface TypeStage { /** - *

The dataset type, which is used to validate the data. Valid types are embed-input, reranker-finetune-input, single-label-classification-finetune-input, chat-finetune-input, and multi-label-classification-finetune-input.

+ *

The dataset type, which is used to validate the data. The only valid type is embed-input used in conjunction with the Embed Jobs API.

*/ _FinalStage type(@NotNull DatasetType type); } @@ -286,8 +286,8 @@ public TypeStage name(@NotNull String name) { } /** - *

The dataset type, which is used to validate the data. Valid types are embed-input, reranker-finetune-input, single-label-classification-finetune-input, chat-finetune-input, and multi-label-classification-finetune-input.

- *

The dataset type, which is used to validate the data. Valid types are embed-input, reranker-finetune-input, single-label-classification-finetune-input, chat-finetune-input, and multi-label-classification-finetune-input.

+ *

The dataset type, which is used to validate the data. The only valid type is embed-input used in conjunction with the Embed Jobs API.

+ *

The dataset type, which is used to validate the data. The only valid type is embed-input used in conjunction with the Embed Jobs API.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override 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 a5ec2e9..135c199 100644 --- a/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/AsyncModelsClient.java @@ -42,21 +42,21 @@ public CompletableFuture get(String model, RequestOptions requ } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture list() { return this.rawClient.list().thenApply(response -> response.body()); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture list(ModelsListRequest request) { return this.rawClient.list(request).thenApply(response -> response.body()); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture list(ModelsListRequest request, RequestOptions requestOptions) { return this.rawClient.list(request, requestOptions).thenApply(response -> response.body()); 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 0a3801a..1746203 100644 --- a/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/AsyncRawModelsClient.java @@ -169,21 +169,21 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture> list() { return list(ModelsListRequest.builder().build()); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture> list(ModelsListRequest request) { return list(request, null); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CompletableFuture> list( ModelsListRequest request, RequestOptions requestOptions) { 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 b73cf49..237e9ff 100644 --- a/src/main/java/com/cohere/api/resources/models/ModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/ModelsClient.java @@ -41,21 +41,21 @@ public GetModelResponse get(String model, RequestOptions requestOptions) { } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public ListModelsResponse list() { return this.rawClient.list().body(); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public ListModelsResponse list(ModelsListRequest request) { return this.rawClient.list(request).body(); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public ListModelsResponse list(ModelsListRequest request, RequestOptions requestOptions) { return this.rawClient.list(request, requestOptions).body(); 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 a094ca9..861f471 100644 --- a/src/main/java/com/cohere/api/resources/models/RawModelsClient.java +++ b/src/main/java/com/cohere/api/resources/models/RawModelsClient.java @@ -127,21 +127,21 @@ public CohereHttpResponse get(String model, RequestOptions req } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CohereHttpResponse list() { return list(ModelsListRequest.builder().build()); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CohereHttpResponse list(ModelsListRequest request) { return list(request, null); } /** - * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. + * Returns a list of models available for use. */ public CohereHttpResponse list(ModelsListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java index 1d6b6b8..04007e7 100644 --- a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java @@ -69,6 +69,8 @@ public final class V2ChatRequest { private final Optional thinking; + private final Optional priority; + private final Map additionalProperties; private V2ChatRequest( @@ -91,6 +93,7 @@ private V2ChatRequest( Optional logprobs, Optional toolChoice, Optional thinking, + Optional priority, Map additionalProperties) { this.model = model; this.messages = messages; @@ -111,6 +114,7 @@ private V2ChatRequest( this.logprobs = logprobs; this.toolChoice = toolChoice; this.thinking = thinking; + this.priority = priority; this.additionalProperties = additionalProperties; } @@ -125,7 +129,7 @@ public Boolean getStream() { } /** - * @return The name of a compatible Cohere model or the ID of a fine-tuned model. + * @return The name of a compatible Cohere model. */ @JsonProperty("model") public String getModel() { @@ -284,6 +288,15 @@ public Optional getThinking() { return thinking; } + /** + * @return The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load. + */ + @JsonProperty("priority") + public Optional getPriority() { + return priority; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -314,7 +327,8 @@ private boolean equalTo(V2ChatRequest other) { && p.equals(other.p) && logprobs.equals(other.logprobs) && toolChoice.equals(other.toolChoice) - && thinking.equals(other.thinking); + && thinking.equals(other.thinking) + && priority.equals(other.priority); } @java.lang.Override @@ -338,7 +352,8 @@ public int hashCode() { this.p, this.logprobs, this.toolChoice, - this.thinking); + this.thinking, + this.priority); } @java.lang.Override @@ -352,7 +367,7 @@ public static ModelStage builder() { public interface ModelStage { /** - *

The name of a compatible Cohere model or the ID of a fine-tuned model.

+ *

The name of a compatible Cohere model.

*/ _FinalStage model(@NotNull String model); @@ -497,12 +512,22 @@ public interface _FinalStage { _FinalStage thinking(Optional thinking); _FinalStage thinking(Thinking thinking); + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + _FinalStage priority(Optional priority); + + _FinalStage priority(Integer priority); } @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder implements ModelStage, _FinalStage { private String model; + private Optional priority = Optional.empty(); + private Optional thinking = Optional.empty(); private Optional toolChoice = Optional.empty(); @@ -565,12 +590,13 @@ public Builder from(V2ChatRequest other) { logprobs(other.getLogprobs()); toolChoice(other.getToolChoice()); thinking(other.getThinking()); + priority(other.getPriority()); return this; } /** - *

The name of a compatible Cohere model or the ID of a fine-tuned model.

- *

The name of a compatible Cohere model or the ID of a fine-tuned model.

+ *

The name of a compatible Cohere model.

+ *

The name of a compatible Cohere model.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @@ -580,6 +606,28 @@ public _FinalStage model(@NotNull String model) { return this; } + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage priority(Integer priority) { + this.priority = Optional.ofNullable(priority); + return this; + } + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + @java.lang.Override + @JsonSetter(value = "priority", nulls = Nulls.SKIP) + public _FinalStage priority(Optional priority) { + this.priority = priority; + return this; + } + @java.lang.Override public _FinalStage thinking(Thinking thinking) { this.thinking = Optional.ofNullable(thinking); @@ -981,6 +1029,7 @@ public V2ChatRequest build() { logprobs, toolChoice, thinking, + priority, additionalProperties); } } diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java index 8bae398..2e6ab7b 100644 --- a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java @@ -69,6 +69,8 @@ public final class V2ChatStreamRequest { private final Optional thinking; + private final Optional priority; + private final Map additionalProperties; private V2ChatStreamRequest( @@ -91,6 +93,7 @@ private V2ChatStreamRequest( Optional logprobs, Optional toolChoice, Optional thinking, + Optional priority, Map additionalProperties) { this.model = model; this.messages = messages; @@ -111,6 +114,7 @@ private V2ChatStreamRequest( this.logprobs = logprobs; this.toolChoice = toolChoice; this.thinking = thinking; + this.priority = priority; this.additionalProperties = additionalProperties; } @@ -125,7 +129,7 @@ public Boolean getStream() { } /** - * @return The name of a compatible Cohere model or the ID of a fine-tuned model. + * @return The name of a compatible Cohere model. */ @JsonProperty("model") public String getModel() { @@ -284,6 +288,15 @@ public Optional getThinking() { return thinking; } + /** + * @return The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load. + */ + @JsonProperty("priority") + public Optional getPriority() { + return priority; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -314,7 +327,8 @@ private boolean equalTo(V2ChatStreamRequest other) { && p.equals(other.p) && logprobs.equals(other.logprobs) && toolChoice.equals(other.toolChoice) - && thinking.equals(other.thinking); + && thinking.equals(other.thinking) + && priority.equals(other.priority); } @java.lang.Override @@ -338,7 +352,8 @@ public int hashCode() { this.p, this.logprobs, this.toolChoice, - this.thinking); + this.thinking, + this.priority); } @java.lang.Override @@ -352,7 +367,7 @@ public static ModelStage builder() { public interface ModelStage { /** - *

The name of a compatible Cohere model or the ID of a fine-tuned model.

+ *

The name of a compatible Cohere model.

*/ _FinalStage model(@NotNull String model); @@ -497,12 +512,22 @@ public interface _FinalStage { _FinalStage thinking(Optional thinking); _FinalStage thinking(Thinking thinking); + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + _FinalStage priority(Optional priority); + + _FinalStage priority(Integer priority); } @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder implements ModelStage, _FinalStage { private String model; + private Optional priority = Optional.empty(); + private Optional thinking = Optional.empty(); private Optional toolChoice = Optional.empty(); @@ -565,12 +590,13 @@ public Builder from(V2ChatStreamRequest other) { logprobs(other.getLogprobs()); toolChoice(other.getToolChoice()); thinking(other.getThinking()); + priority(other.getPriority()); return this; } /** - *

The name of a compatible Cohere model or the ID of a fine-tuned model.

- *

The name of a compatible Cohere model or the ID of a fine-tuned model.

+ *

The name of a compatible Cohere model.

+ *

The name of a compatible Cohere model.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @@ -580,6 +606,28 @@ public _FinalStage model(@NotNull String model) { return this; } + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage priority(Integer priority) { + this.priority = Optional.ofNullable(priority); + return this; + } + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + @java.lang.Override + @JsonSetter(value = "priority", nulls = Nulls.SKIP) + public _FinalStage priority(Optional priority) { + this.priority = priority; + return this; + } + @java.lang.Override public _FinalStage thinking(Thinking thinking) { this.thinking = Optional.ofNullable(thinking); @@ -981,6 +1029,7 @@ public V2ChatStreamRequest build() { logprobs, toolChoice, thinking, + priority, additionalProperties); } } diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2EmbedRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2EmbedRequest.java index aeb1df6..d7cf1a7 100644 --- a/src/main/java/com/cohere/api/resources/v2/requests/V2EmbedRequest.java +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2EmbedRequest.java @@ -44,6 +44,8 @@ public final class V2EmbedRequest { private final Optional truncate; + private final Optional priority; + private final Map additionalProperties; private V2EmbedRequest( @@ -56,6 +58,7 @@ private V2EmbedRequest( Optional outputDimension, Optional> embeddingTypes, Optional truncate, + Optional priority, Map additionalProperties) { this.texts = texts; this.images = images; @@ -66,6 +69,7 @@ private V2EmbedRequest( this.outputDimension = outputDimension; this.embeddingTypes = embeddingTypes; this.truncate = truncate; + this.priority = priority; this.additionalProperties = additionalProperties; } @@ -79,7 +83,7 @@ public Optional> getTexts() { /** * @return An array of image data URIs for the model to embed. Maximum number of images per call is 1. - *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Image embeddings are supported with Embed v3.0 and newer models.

*/ @JsonProperty("images") @@ -151,6 +155,15 @@ public Optional getTruncate() { return truncate; } + /** + * @return The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load. + */ + @JsonProperty("priority") + public Optional getPriority() { + return priority; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -171,7 +184,8 @@ private boolean equalTo(V2EmbedRequest other) { && maxTokens.equals(other.maxTokens) && outputDimension.equals(other.outputDimension) && embeddingTypes.equals(other.embeddingTypes) - && truncate.equals(other.truncate); + && truncate.equals(other.truncate) + && priority.equals(other.priority); } @java.lang.Override @@ -185,7 +199,8 @@ public int hashCode() { this.maxTokens, this.outputDimension, this.embeddingTypes, - this.truncate); + this.truncate, + this.priority); } @java.lang.Override @@ -222,7 +237,7 @@ public interface _FinalStage { /** *

An array of image data URIs for the model to embed. Maximum number of images per call is 1.

- *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Image embeddings are supported with Embed v3.0 and newer models.

*/ _FinalStage images(Optional> images); @@ -274,6 +289,14 @@ public interface _FinalStage { _FinalStage truncate(Optional truncate); _FinalStage truncate(V2EmbedRequestTruncate truncate); + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + _FinalStage priority(Optional priority); + + _FinalStage priority(Integer priority); } @JsonIgnoreProperties(ignoreUnknown = true) @@ -282,6 +305,8 @@ public static final class Builder implements ModelStage, InputTypeStage, _FinalS private EmbedInputType inputType; + private Optional priority = Optional.empty(); + private Optional truncate = Optional.empty(); private Optional> embeddingTypes = Optional.empty(); @@ -312,6 +337,7 @@ public Builder from(V2EmbedRequest other) { outputDimension(other.getOutputDimension()); embeddingTypes(other.getEmbeddingTypes()); truncate(other.getTruncate()); + priority(other.getPriority()); return this; } @@ -334,6 +360,28 @@ public _FinalStage inputType(@NotNull EmbedInputType inputType) { return this; } + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage priority(Integer priority) { + this.priority = Optional.ofNullable(priority); + return this; + } + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + @java.lang.Override + @JsonSetter(value = "priority", nulls = Nulls.SKIP) + public _FinalStage priority(Optional priority) { + this.priority = priority; + return this; + } + /** *

One of NONE|START|END to specify how the API will handle inputs longer than the maximum token length.

*

Passing START will discard the start of the input. END will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.

@@ -458,7 +506,7 @@ public _FinalStage inputs(Optional> inputs) { /** *

An array of image data URIs for the model to embed. Maximum number of images per call is 1.

- *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Image embeddings are supported with Embed v3.0 and newer models.

* @return Reference to {@code this} so that method calls can be chained together. */ @@ -470,7 +518,7 @@ public _FinalStage images(List images) { /** *

An array of image data URIs for the model to embed. Maximum number of images per call is 1.

- *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ *

The image must be a valid data URI. The image must be in either image/jpeg, image/png, image/webp, or image/gif format and has a maximum size of 5MB.

*

Image embeddings are supported with Embed v3.0 and newer models.

*/ @java.lang.Override @@ -512,6 +560,7 @@ public V2EmbedRequest build() { outputDimension, embeddingTypes, truncate, + priority, additionalProperties); } } diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2RerankRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2RerankRequest.java index 0089220..53d5108 100644 --- a/src/main/java/com/cohere/api/resources/v2/requests/V2RerankRequest.java +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2RerankRequest.java @@ -33,6 +33,8 @@ public final class V2RerankRequest { private final Optional maxTokensPerDoc; + private final Optional priority; + private final Map additionalProperties; private V2RerankRequest( @@ -41,12 +43,14 @@ private V2RerankRequest( List documents, Optional topN, Optional maxTokensPerDoc, + Optional priority, Map additionalProperties) { this.model = model; this.query = query; this.documents = documents; this.topN = topN; this.maxTokensPerDoc = maxTokensPerDoc; + this.priority = priority; this.additionalProperties = additionalProperties; } @@ -93,6 +97,15 @@ public Optional getMaxTokensPerDoc() { return maxTokensPerDoc; } + /** + * @return The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load. + */ + @JsonProperty("priority") + public Optional getPriority() { + return priority; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -109,12 +122,13 @@ private boolean equalTo(V2RerankRequest other) { && query.equals(other.query) && documents.equals(other.documents) && topN.equals(other.topN) - && maxTokensPerDoc.equals(other.maxTokensPerDoc); + && maxTokensPerDoc.equals(other.maxTokensPerDoc) + && priority.equals(other.priority); } @java.lang.Override public int hashCode() { - return Objects.hash(this.model, this.query, this.documents, this.topN, this.maxTokensPerDoc); + return Objects.hash(this.model, this.query, this.documents, this.topN, this.maxTokensPerDoc, this.priority); } @java.lang.Override @@ -170,6 +184,14 @@ public interface _FinalStage { _FinalStage maxTokensPerDoc(Optional maxTokensPerDoc); _FinalStage maxTokensPerDoc(Integer maxTokensPerDoc); + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + _FinalStage priority(Optional priority); + + _FinalStage priority(Integer priority); } @JsonIgnoreProperties(ignoreUnknown = true) @@ -178,6 +200,8 @@ public static final class Builder implements ModelStage, QueryStage, _FinalStage private String query; + private Optional priority = Optional.empty(); + private Optional maxTokensPerDoc = Optional.empty(); private Optional topN = Optional.empty(); @@ -196,6 +220,7 @@ public Builder from(V2RerankRequest other) { documents(other.getDocuments()); topN(other.getTopN()); maxTokensPerDoc(other.getMaxTokensPerDoc()); + priority(other.getPriority()); return this; } @@ -223,6 +248,28 @@ public _FinalStage query(@NotNull String query) { return this; } + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage priority(Integer priority) { + this.priority = Optional.ofNullable(priority); + return this; + } + + /** + *

The priority of the request (lower means earlier handling; default 0 highest priority). + * Higher priority requests are handled first, and dropped last when the system is under load.

+ */ + @java.lang.Override + @JsonSetter(value = "priority", nulls = Nulls.SKIP) + public _FinalStage priority(Optional priority) { + this.priority = priority; + return this; + } + /** *

Defaults to 4096. Long documents will be automatically truncated to the specified number of tokens.

* @return Reference to {@code this} so that method calls can be chained together. @@ -305,7 +352,7 @@ public _FinalStage documents(List documents) { @java.lang.Override public V2RerankRequest build() { - return new V2RerankRequest(model, query, documents, topN, maxTokensPerDoc, additionalProperties); + return new V2RerankRequest(model, query, documents, topN, maxTokensPerDoc, priority, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/types/ApiMeta.java b/src/main/java/com/cohere/api/types/ApiMeta.java index a10d9da..2efc6a9 100644 --- a/src/main/java/com/cohere/api/types/ApiMeta.java +++ b/src/main/java/com/cohere/api/types/ApiMeta.java @@ -27,6 +27,8 @@ public final class ApiMeta { private final Optional tokens; + private final Optional cachedTokens; + private final Optional> warnings; private final Map additionalProperties; @@ -35,11 +37,13 @@ private ApiMeta( Optional apiVersion, Optional billedUnits, Optional tokens, + Optional cachedTokens, Optional> warnings, Map additionalProperties) { this.apiVersion = apiVersion; this.billedUnits = billedUnits; this.tokens = tokens; + this.cachedTokens = cachedTokens; this.warnings = warnings; this.additionalProperties = additionalProperties; } @@ -59,6 +63,14 @@ public Optional getTokens() { return tokens; } + /** + * @return The number of prompt tokens that hit the inference cache. + */ + @JsonProperty("cached_tokens") + public Optional getCachedTokens() { + return cachedTokens; + } + @JsonProperty("warnings") public Optional> getWarnings() { return warnings; @@ -79,12 +91,13 @@ private boolean equalTo(ApiMeta other) { return apiVersion.equals(other.apiVersion) && billedUnits.equals(other.billedUnits) && tokens.equals(other.tokens) + && cachedTokens.equals(other.cachedTokens) && warnings.equals(other.warnings); } @java.lang.Override public int hashCode() { - return Objects.hash(this.apiVersion, this.billedUnits, this.tokens, this.warnings); + return Objects.hash(this.apiVersion, this.billedUnits, this.tokens, this.cachedTokens, this.warnings); } @java.lang.Override @@ -104,6 +117,8 @@ public static final class Builder { private Optional tokens = Optional.empty(); + private Optional cachedTokens = Optional.empty(); + private Optional> warnings = Optional.empty(); @JsonAnySetter @@ -115,6 +130,7 @@ public Builder from(ApiMeta other) { apiVersion(other.getApiVersion()); billedUnits(other.getBilledUnits()); tokens(other.getTokens()); + cachedTokens(other.getCachedTokens()); warnings(other.getWarnings()); return this; } @@ -152,6 +168,20 @@ public Builder tokens(ApiMetaTokens tokens) { return this; } + /** + *

The number of prompt tokens that hit the inference cache.

+ */ + @JsonSetter(value = "cached_tokens", nulls = Nulls.SKIP) + public Builder cachedTokens(Optional cachedTokens) { + this.cachedTokens = cachedTokens; + return this; + } + + public Builder cachedTokens(Double cachedTokens) { + this.cachedTokens = Optional.ofNullable(cachedTokens); + return this; + } + @JsonSetter(value = "warnings", nulls = Nulls.SKIP) public Builder warnings(Optional> warnings) { this.warnings = warnings; @@ -164,7 +194,7 @@ public Builder warnings(List warnings) { } public ApiMeta build() { - return new ApiMeta(apiVersion, billedUnits, tokens, warnings, additionalProperties); + return new ApiMeta(apiVersion, billedUnits, tokens, cachedTokens, warnings, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/types/ChatFinishReason.java b/src/main/java/com/cohere/api/types/ChatFinishReason.java index e289f1b..a692121 100644 --- a/src/main/java/com/cohere/api/types/ChatFinishReason.java +++ b/src/main/java/com/cohere/api/types/ChatFinishReason.java @@ -14,7 +14,9 @@ public enum ChatFinishReason { TOOL_CALL("TOOL_CALL"), - ERROR("ERROR"); + ERROR("ERROR"), + + TIMEOUT("TIMEOUT"); private final String value; diff --git a/src/main/java/com/cohere/api/types/ChatRequestCitationQuality.java b/src/main/java/com/cohere/api/types/ChatRequestCitationQuality.java index 214309f..77abb7f 100644 --- a/src/main/java/com/cohere/api/types/ChatRequestCitationQuality.java +++ b/src/main/java/com/cohere/api/types/ChatRequestCitationQuality.java @@ -6,11 +6,15 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ChatRequestCitationQuality { - FAST("fast"), + ENABLED("ENABLED"), - ACCURATE("accurate"), + DISABLED("DISABLED"), - OFF("off"); + FAST("FAST"), + + ACCURATE("ACCURATE"), + + OFF("OFF"); private final String value; diff --git a/src/main/java/com/cohere/api/types/ChatStreamRequestCitationQuality.java b/src/main/java/com/cohere/api/types/ChatStreamRequestCitationQuality.java index 3fca8b3..7a3c415 100644 --- a/src/main/java/com/cohere/api/types/ChatStreamRequestCitationQuality.java +++ b/src/main/java/com/cohere/api/types/ChatStreamRequestCitationQuality.java @@ -6,11 +6,15 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ChatStreamRequestCitationQuality { - FAST("fast"), + ENABLED("ENABLED"), - ACCURATE("accurate"), + DISABLED("DISABLED"), - OFF("off"); + FAST("FAST"), + + ACCURATE("ACCURATE"), + + OFF("OFF"); private final String value; diff --git a/src/main/java/com/cohere/api/types/CitationOptions.java b/src/main/java/com/cohere/api/types/CitationOptions.java index f6f2ade..dd7153c 100644 --- a/src/main/java/com/cohere/api/types/CitationOptions.java +++ b/src/main/java/com/cohere/api/types/CitationOptions.java @@ -30,9 +30,8 @@ private CitationOptions(Optional mode, Map } /** - * @return Defaults to "accurate". - * Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results. - *

Note: command-r7b-12-2024 and command-a-03-2025 only support "fast" and "off" modes. The default is "fast".

+ * @return Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled". */ @JsonProperty("mode") public Optional getMode() { @@ -83,9 +82,8 @@ public Builder from(CitationOptions other) { } /** - *

Defaults to "accurate". - * Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results, "fast" results or no results.

- *

Note: command-r7b-12-2024 and command-a-03-2025 only support "fast" and "off" modes. The default is "fast".

+ *

Defaults to "enabled". + * Citations are enabled by default for models that support it, but can be turned off by setting "type": "disabled".

*/ @JsonSetter(value = "mode", nulls = Nulls.SKIP) public Builder mode(Optional mode) { diff --git a/src/main/java/com/cohere/api/types/CitationOptionsMode.java b/src/main/java/com/cohere/api/types/CitationOptionsMode.java index a07df70..12e8edd 100644 --- a/src/main/java/com/cohere/api/types/CitationOptionsMode.java +++ b/src/main/java/com/cohere/api/types/CitationOptionsMode.java @@ -6,6 +6,10 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum CitationOptionsMode { + ENABLED("ENABLED"), + + DISABLED("DISABLED"), + FAST("FAST"), ACCURATE("ACCURATE"), diff --git a/src/main/java/com/cohere/api/types/DatasetType.java b/src/main/java/com/cohere/api/types/DatasetType.java index a2dc4e7..59c2173 100644 --- a/src/main/java/com/cohere/api/types/DatasetType.java +++ b/src/main/java/com/cohere/api/types/DatasetType.java @@ -20,7 +20,15 @@ public enum DatasetType { CHAT_FINETUNE_INPUT("chat-finetune-input"), - MULTI_LABEL_CLASSIFICATION_FINETUNE_INPUT("multi-label-classification-finetune-input"); + MULTI_LABEL_CLASSIFICATION_FINETUNE_INPUT("multi-label-classification-finetune-input"), + + BATCH_CHAT_INPUT("batch-chat-input"), + + BATCH_OPENAI_CHAT_INPUT("batch-openai-chat-input"), + + BATCH_EMBED_V_2_INPUT("batch-embed-v2-input"), + + BATCH_CHAT_V_2_INPUT("batch-chat-v2-input"); private final String value; diff --git a/src/main/java/com/cohere/api/types/FinishReason.java b/src/main/java/com/cohere/api/types/FinishReason.java index 951b334..f07a3e4 100644 --- a/src/main/java/com/cohere/api/types/FinishReason.java +++ b/src/main/java/com/cohere/api/types/FinishReason.java @@ -18,7 +18,9 @@ public enum FinishReason { USER_CANCEL("USER_CANCEL"), - MAX_TOKENS("MAX_TOKENS"); + MAX_TOKENS("MAX_TOKENS"), + + TIMEOUT("TIMEOUT"); private final String value; diff --git a/src/main/java/com/cohere/api/types/GetModelResponse.java b/src/main/java/com/cohere/api/types/GetModelResponse.java index bd067c6..da79af7 100644 --- a/src/main/java/com/cohere/api/types/GetModelResponse.java +++ b/src/main/java/com/cohere/api/types/GetModelResponse.java @@ -33,8 +33,6 @@ public final class GetModelResponse { private final Optional tokenizerUrl; - private final Optional supportsVision; - private final Optional> defaultEndpoints; private final Optional> features; @@ -48,7 +46,6 @@ private GetModelResponse( Optional finetuned, Optional contextLength, Optional tokenizerUrl, - Optional supportsVision, Optional> defaultEndpoints, Optional> features, Map additionalProperties) { @@ -58,7 +55,6 @@ private GetModelResponse( this.finetuned = finetuned; this.contextLength = contextLength; this.tokenizerUrl = tokenizerUrl; - this.supportsVision = supportsVision; this.defaultEndpoints = defaultEndpoints; this.features = features; this.additionalProperties = additionalProperties; @@ -112,14 +108,6 @@ public Optional getTokenizerUrl() { return tokenizerUrl; } - /** - * @return Whether the model supports image inputs or not. - */ - @JsonProperty("supports_vision") - public Optional getSupportsVision() { - return supportsVision; - } - /** * @return The API endpoints that the model is default to. */ @@ -154,7 +142,6 @@ private boolean equalTo(GetModelResponse other) { && finetuned.equals(other.finetuned) && contextLength.equals(other.contextLength) && tokenizerUrl.equals(other.tokenizerUrl) - && supportsVision.equals(other.supportsVision) && defaultEndpoints.equals(other.defaultEndpoints) && features.equals(other.features); } @@ -168,7 +155,6 @@ public int hashCode() { this.finetuned, this.contextLength, this.tokenizerUrl, - this.supportsVision, this.defaultEndpoints, this.features); } @@ -196,8 +182,6 @@ public static final class Builder { private Optional tokenizerUrl = Optional.empty(); - private Optional supportsVision = Optional.empty(); - private Optional> defaultEndpoints = Optional.empty(); private Optional> features = Optional.empty(); @@ -214,7 +198,6 @@ public Builder from(GetModelResponse other) { finetuned(other.getFinetuned()); contextLength(other.getContextLength()); tokenizerUrl(other.getTokenizerUrl()); - supportsVision(other.getSupportsVision()); defaultEndpoints(other.getDefaultEndpoints()); features(other.getFeatures()); return this; @@ -304,20 +287,6 @@ public Builder tokenizerUrl(String tokenizerUrl) { return this; } - /** - *

Whether the model supports image inputs or not.

- */ - @JsonSetter(value = "supports_vision", nulls = Nulls.SKIP) - public Builder supportsVision(Optional supportsVision) { - this.supportsVision = supportsVision; - return this; - } - - public Builder supportsVision(Boolean supportsVision) { - this.supportsVision = Optional.ofNullable(supportsVision); - return this; - } - /** *

The API endpoints that the model is default to.

*/ @@ -354,7 +323,6 @@ public GetModelResponse build() { finetuned, contextLength, tokenizerUrl, - supportsVision, defaultEndpoints, features, additionalProperties); diff --git a/src/main/java/com/cohere/api/types/ToolCallV2.java b/src/main/java/com/cohere/api/types/ToolCallV2.java index ac097ab..9181ce9 100644 --- a/src/main/java/com/cohere/api/types/ToolCallV2.java +++ b/src/main/java/com/cohere/api/types/ToolCallV2.java @@ -16,37 +16,31 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import org.jetbrains.annotations.NotNull; @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = ToolCallV2.Builder.class) public final class ToolCallV2 { - private final Optional id; - - private final Optional type; + private final String id; private final Optional function; private final Map additionalProperties; - private ToolCallV2( - Optional id, - Optional type, - Optional function, - Map additionalProperties) { + private ToolCallV2(String id, Optional function, Map additionalProperties) { this.id = id; - this.type = type; this.function = function; this.additionalProperties = additionalProperties; } @JsonProperty("id") - public Optional getId() { + public String getId() { return id; } @JsonProperty("type") - public Optional getType() { - return type; + public String getType() { + return "function"; } @JsonProperty("function") @@ -66,12 +60,12 @@ public Map getAdditionalProperties() { } private boolean equalTo(ToolCallV2 other) { - return id.equals(other.id) && type.equals(other.type) && function.equals(other.function); + return id.equals(other.id) && function.equals(other.function); } @java.lang.Override public int hashCode() { - return Objects.hash(this.id, this.type, this.function); + return Objects.hash(this.id, this.function); } @java.lang.Override @@ -79,15 +73,27 @@ public String toString() { return ObjectMappers.stringify(this); } - public static Builder builder() { + public static IdStage builder() { return new Builder(); } - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional id = Optional.empty(); + public interface IdStage { + _FinalStage id(@NotNull String id); + + Builder from(ToolCallV2 other); + } + + public interface _FinalStage { + ToolCallV2 build(); - private Optional type = Optional.empty(); + _FinalStage function(Optional function); + + _FinalStage function(ToolCallV2Function function); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements IdStage, _FinalStage { + private String id; private Optional function = Optional.empty(); @@ -96,48 +102,36 @@ public static final class Builder { private Builder() {} + @java.lang.Override public Builder from(ToolCallV2 other) { id(other.getId()); - type(other.getType()); function(other.getFunction()); return this; } - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; + @java.lang.Override + @JsonSetter("id") + public _FinalStage id(@NotNull String id) { + this.id = Objects.requireNonNull(id, "id must not be null"); return this; } - public Builder type(String type) { - this.type = Optional.ofNullable(type); + @java.lang.Override + public _FinalStage function(ToolCallV2Function function) { + this.function = Optional.ofNullable(function); return this; } + @java.lang.Override @JsonSetter(value = "function", nulls = Nulls.SKIP) - public Builder function(Optional function) { + public _FinalStage function(Optional function) { this.function = function; return this; } - public Builder function(ToolCallV2Function function) { - this.function = Optional.ofNullable(function); - return this; - } - + @java.lang.Override public ToolCallV2 build() { - return new ToolCallV2(id, type, function, additionalProperties); + return new ToolCallV2(id, function, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/types/ToolV2.java b/src/main/java/com/cohere/api/types/ToolV2.java index 38c6063..e3b09dd 100644 --- a/src/main/java/com/cohere/api/types/ToolV2.java +++ b/src/main/java/com/cohere/api/types/ToolV2.java @@ -20,21 +20,18 @@ @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = ToolV2.Builder.class) public final class ToolV2 { - private final Optional type; - private final Optional function; private final Map additionalProperties; - private ToolV2(Optional type, Optional function, Map additionalProperties) { - this.type = type; + private ToolV2(Optional function, Map additionalProperties) { this.function = function; this.additionalProperties = additionalProperties; } @JsonProperty("type") - public Optional getType() { - return type; + public String getType() { + return "function"; } /** @@ -57,12 +54,12 @@ public Map getAdditionalProperties() { } private boolean equalTo(ToolV2 other) { - return type.equals(other.type) && function.equals(other.function); + return function.equals(other.function); } @java.lang.Override public int hashCode() { - return Objects.hash(this.type, this.function); + return Objects.hash(this.function); } @java.lang.Override @@ -76,8 +73,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - private Optional type = Optional.empty(); - private Optional function = Optional.empty(); @JsonAnySetter @@ -86,22 +81,10 @@ public static final class Builder { private Builder() {} public Builder from(ToolV2 other) { - type(other.getType()); function(other.getFunction()); return this; } - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - /** *

The function to be executed.

*/ @@ -117,7 +100,7 @@ public Builder function(ToolV2Function function) { } public ToolV2 build() { - return new ToolV2(type, function, additionalProperties); + return new ToolV2(function, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/types/Usage.java b/src/main/java/com/cohere/api/types/Usage.java index 331d08b..ab9464e 100644 --- a/src/main/java/com/cohere/api/types/Usage.java +++ b/src/main/java/com/cohere/api/types/Usage.java @@ -24,14 +24,18 @@ public final class Usage { private final Optional tokens; + private final Optional cachedTokens; + private final Map additionalProperties; private Usage( Optional billedUnits, Optional tokens, + Optional cachedTokens, Map additionalProperties) { this.billedUnits = billedUnits; this.tokens = tokens; + this.cachedTokens = cachedTokens; this.additionalProperties = additionalProperties; } @@ -45,6 +49,14 @@ public Optional getTokens() { return tokens; } + /** + * @return The number of prompt tokens that hit the inference cache. + */ + @JsonProperty("cached_tokens") + public Optional getCachedTokens() { + return cachedTokens; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -57,12 +69,14 @@ public Map getAdditionalProperties() { } private boolean equalTo(Usage other) { - return billedUnits.equals(other.billedUnits) && tokens.equals(other.tokens); + return billedUnits.equals(other.billedUnits) + && tokens.equals(other.tokens) + && cachedTokens.equals(other.cachedTokens); } @java.lang.Override public int hashCode() { - return Objects.hash(this.billedUnits, this.tokens); + return Objects.hash(this.billedUnits, this.tokens, this.cachedTokens); } @java.lang.Override @@ -80,6 +94,8 @@ public static final class Builder { private Optional tokens = Optional.empty(); + private Optional cachedTokens = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -88,6 +104,7 @@ private Builder() {} public Builder from(Usage other) { billedUnits(other.getBilledUnits()); tokens(other.getTokens()); + cachedTokens(other.getCachedTokens()); return this; } @@ -113,8 +130,22 @@ public Builder tokens(UsageTokens tokens) { return this; } + /** + *

The number of prompt tokens that hit the inference cache.

+ */ + @JsonSetter(value = "cached_tokens", nulls = Nulls.SKIP) + public Builder cachedTokens(Optional cachedTokens) { + this.cachedTokens = cachedTokens; + return this; + } + + public Builder cachedTokens(Double cachedTokens) { + this.cachedTokens = Optional.ofNullable(cachedTokens); + return this; + } + public Usage build() { - return new Usage(billedUnits, tokens, additionalProperties); + return new Usage(billedUnits, tokens, cachedTokens, additionalProperties); } } }