From 93023da50a242d0a341cae1c9316e18a6b9c5d25 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 12:23:09 +0000 Subject: [PATCH] SDK regeneration --- build.gradle | 2 +- .../com/cohere/api/core/ClientOptions.java | 2 +- .../com/cohere/api/requests/EmbedRequest.java | 38 ++- .../connectors/ConnectorsClient.java | 8 +- ...equest.java => ConnectorsListRequest.java} | 17 +- .../connectors/requests/CreateRequest.java | 12 +- .../connectors/requests/UpdateRequest.java | 10 +- .../java/com/cohere/api/types/Connector.java | 24 +- .../cohere/api/types/EmbedByTypeResponse.java | 218 ++++++++++++++ .../types/EmbedByTypeResponseEmbeddings.java | 209 +++++++++++++ .../cohere/api/types/EmbedFloatsResponse.java | 237 +++++++++++++++ .../com/cohere/api/types/EmbedResponse.java | 281 ++++++++---------- 12 files changed, 862 insertions(+), 196 deletions(-) rename src/main/java/com/cohere/api/resources/connectors/requests/{ListRequest.java => ConnectorsListRequest.java} (83%) create mode 100644 src/main/java/com/cohere/api/types/EmbedByTypeResponse.java create mode 100644 src/main/java/com/cohere/api/types/EmbedByTypeResponseEmbeddings.java create mode 100644 src/main/java/com/cohere/api/types/EmbedFloatsResponse.java diff --git a/build.gradle b/build.gradle index 3817b36..9b09169 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ publishing { maven(MavenPublication) { groupId = 'com.cohere' artifactId = 'cohere-java' - version = '1.0.1' + version = '1.0.2' from components.java } } diff --git a/src/main/java/com/cohere/api/core/ClientOptions.java b/src/main/java/com/cohere/api/core/ClientOptions.java index 3ea3ff2..a3b6478 100644 --- a/src/main/java/com/cohere/api/core/ClientOptions.java +++ b/src/main/java/com/cohere/api/core/ClientOptions.java @@ -29,7 +29,7 @@ private ClientOptions( "X-Fern-SDK-Name", "com.cohere.fern:api-sdk", "X-Fern-SDK-Version", - "1.0.1", + "1.0.2", "X-Fern-Language", "JAVA")); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/cohere/api/requests/EmbedRequest.java b/src/main/java/com/cohere/api/requests/EmbedRequest.java index df6ee2e..a3c91ed 100644 --- a/src/main/java/com/cohere/api/requests/EmbedRequest.java +++ b/src/main/java/com/cohere/api/requests/EmbedRequest.java @@ -29,6 +29,8 @@ public final class EmbedRequest { private final Optional inputType; + private final Optional> embeddingTypes; + private final Optional truncate; private final Map additionalProperties; @@ -37,11 +39,13 @@ private EmbedRequest( List texts, Optional model, Optional inputType, + Optional> embeddingTypes, Optional truncate, Map additionalProperties) { this.texts = texts; this.model = model; this.inputType = inputType; + this.embeddingTypes = embeddingTypes; this.truncate = truncate; this.additionalProperties = additionalProperties; } @@ -101,6 +105,21 @@ public Optional getInputType() { return inputType; } + /** + * @return Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. + *
    + *
  • "float": Use this when you want to get back the default float embeddings. Valid for all models.
  • + *
  • "int8": Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
  • + *
  • "uint8": Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
  • + *
  • "binary": Use this when you want to get back signed binary embeddings. Valid for only v3 models.
  • + *
  • "ubinary": Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
  • + *
+ */ + @JsonProperty("embedding_types") + public Optional> getEmbeddingTypes() { + return embeddingTypes; + } + /** * @return 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.

@@ -126,12 +145,13 @@ private boolean equalTo(EmbedRequest other) { return texts.equals(other.texts) && model.equals(other.model) && inputType.equals(other.inputType) + && embeddingTypes.equals(other.embeddingTypes) && truncate.equals(other.truncate); } @Override public int hashCode() { - return Objects.hash(this.texts, this.model, this.inputType, this.truncate); + return Objects.hash(this.texts, this.model, this.inputType, this.embeddingTypes, this.truncate); } @Override @@ -151,6 +171,8 @@ public static final class Builder { private Optional inputType = Optional.empty(); + private Optional> embeddingTypes = Optional.empty(); + private Optional truncate = Optional.empty(); @JsonAnySetter @@ -162,6 +184,7 @@ public Builder from(EmbedRequest other) { texts(other.getTexts()); model(other.getModel()); inputType(other.getInputType()); + embeddingTypes(other.getEmbeddingTypes()); truncate(other.getTruncate()); return this; } @@ -205,6 +228,17 @@ public Builder inputType(String inputType) { return this; } + @JsonSetter(value = "embedding_types", nulls = Nulls.SKIP) + public Builder embeddingTypes(Optional> embeddingTypes) { + this.embeddingTypes = embeddingTypes; + return this; + } + + public Builder embeddingTypes(List embeddingTypes) { + this.embeddingTypes = Optional.of(embeddingTypes); + return this; + } + @JsonSetter(value = "truncate", nulls = Nulls.SKIP) public Builder truncate(Optional truncate) { this.truncate = truncate; @@ -217,7 +251,7 @@ public Builder truncate(EmbedRequestTruncate truncate) { } public EmbedRequest build() { - return new EmbedRequest(texts, model, inputType, truncate, additionalProperties); + return new EmbedRequest(texts, model, inputType, embeddingTypes, truncate, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java b/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java index d2de576..d7115e9 100644 --- a/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java +++ b/src/main/java/com/cohere/api/resources/connectors/ConnectorsClient.java @@ -7,8 +7,8 @@ import com.cohere.api.core.ClientOptions; import com.cohere.api.core.ObjectMappers; import com.cohere.api.core.RequestOptions; +import com.cohere.api.resources.connectors.requests.ConnectorsListRequest; import com.cohere.api.resources.connectors.requests.CreateRequest; -import com.cohere.api.resources.connectors.requests.ListRequest; import com.cohere.api.resources.connectors.requests.UpdateRequest; import com.cohere.api.types.CreateResponse; import com.cohere.api.types.GetResponse; @@ -36,13 +36,13 @@ public ConnectorsClient(ClientOptions clientOptions) { * Returns a list of connectors ordered by descending creation date (newer first). */ public ListResponse list() { - return list(ListRequest.builder().build()); + return list(ConnectorsListRequest.builder().build()); } /** * Returns a list of connectors ordered by descending creation date (newer first). */ - public ListResponse list(ListRequest request, RequestOptions requestOptions) { + public ListResponse list(ConnectorsListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/connectors"); @@ -75,7 +75,7 @@ public ListResponse list(ListRequest request, RequestOptions requestOptions) { /** * Returns a list of connectors ordered by descending creation date (newer first). */ - public ListResponse list(ListRequest request) { + public ListResponse list(ConnectorsListRequest request) { return list(request, null); } diff --git a/src/main/java/com/cohere/api/resources/connectors/requests/ListRequest.java b/src/main/java/com/cohere/api/resources/connectors/requests/ConnectorsListRequest.java similarity index 83% rename from src/main/java/com/cohere/api/resources/connectors/requests/ListRequest.java rename to src/main/java/com/cohere/api/resources/connectors/requests/ConnectorsListRequest.java index 41eb2e2..179db53 100644 --- a/src/main/java/com/cohere/api/resources/connectors/requests/ListRequest.java +++ b/src/main/java/com/cohere/api/resources/connectors/requests/ConnectorsListRequest.java @@ -18,15 +18,16 @@ import java.util.Optional; @JsonInclude(JsonInclude.Include.NON_EMPTY) -@JsonDeserialize(builder = ListRequest.Builder.class) -public final class ListRequest { +@JsonDeserialize(builder = ConnectorsListRequest.Builder.class) +public final class ConnectorsListRequest { private final Optional limit; private final Optional offset; private final Map additionalProperties; - private ListRequest(Optional limit, Optional offset, Map additionalProperties) { + private ConnectorsListRequest( + Optional limit, Optional offset, Map additionalProperties) { this.limit = limit; this.offset = offset; this.additionalProperties = additionalProperties; @@ -51,7 +52,7 @@ public Optional getOffset() { @Override public boolean equals(Object other) { if (this == other) return true; - return other instanceof ListRequest && equalTo((ListRequest) other); + return other instanceof ConnectorsListRequest && equalTo((ConnectorsListRequest) other); } @JsonAnyGetter @@ -59,7 +60,7 @@ public Map getAdditionalProperties() { return this.additionalProperties; } - private boolean equalTo(ListRequest other) { + private boolean equalTo(ConnectorsListRequest other) { return limit.equals(other.limit) && offset.equals(other.offset); } @@ -88,7 +89,7 @@ public static final class Builder { private Builder() {} - public Builder from(ListRequest other) { + public Builder from(ConnectorsListRequest other) { limit(other.getLimit()); offset(other.getOffset()); return this; @@ -116,8 +117,8 @@ public Builder offset(Double offset) { return this; } - public ListRequest build() { - return new ListRequest(limit, offset, additionalProperties); + public ConnectorsListRequest build() { + return new ConnectorsListRequest(limit, offset, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/resources/connectors/requests/CreateRequest.java b/src/main/java/com/cohere/api/resources/connectors/requests/CreateRequest.java index 36a6aa0..557d196 100644 --- a/src/main/java/com/cohere/api/resources/connectors/requests/CreateRequest.java +++ b/src/main/java/com/cohere/api/resources/connectors/requests/CreateRequest.java @@ -95,7 +95,7 @@ public Optional> getExcludes() { } /** - * @return The OAuth 2.0 configuration for the connector. Cannot be specified if serviceAuth is specified. + * @return The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. */ @JsonProperty("oauth") public Optional getOauth() { @@ -113,7 +113,7 @@ public Optional getActive() { /** * @return Whether a chat request should continue or not if the request to this connector fails. */ - @JsonProperty("continueOnFailure") + @JsonProperty("continue_on_failure") public Optional getContinueOnFailure() { return continueOnFailure; } @@ -121,7 +121,7 @@ public Optional getContinueOnFailure() { /** * @return The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. */ - @JsonProperty("serviceAuth") + @JsonProperty("service_auth") public Optional getServiceAuth() { return serviceAuth; } @@ -277,7 +277,7 @@ public _FinalStage serviceAuth(CreateConnectorServiceAuth serviceAuth) { } @Override - @JsonSetter(value = "serviceAuth", nulls = Nulls.SKIP) + @JsonSetter(value = "service_auth", nulls = Nulls.SKIP) public _FinalStage serviceAuth(Optional serviceAuth) { this.serviceAuth = serviceAuth; return this; @@ -294,7 +294,7 @@ public _FinalStage continueOnFailure(Boolean continueOnFailure) { } @Override - @JsonSetter(value = "continueOnFailure", nulls = Nulls.SKIP) + @JsonSetter(value = "continue_on_failure", nulls = Nulls.SKIP) public _FinalStage continueOnFailure(Optional continueOnFailure) { this.continueOnFailure = continueOnFailure; return this; @@ -318,7 +318,7 @@ public _FinalStage active(Optional active) { } /** - *

The OAuth 2.0 configuration for the connector. Cannot be specified if serviceAuth is specified.

+ *

The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified.

* @return Reference to {@code this} so that method calls can be chained together. */ @Override diff --git a/src/main/java/com/cohere/api/resources/connectors/requests/UpdateRequest.java b/src/main/java/com/cohere/api/resources/connectors/requests/UpdateRequest.java index 1ab08dc..19b9547 100644 --- a/src/main/java/com/cohere/api/resources/connectors/requests/UpdateRequest.java +++ b/src/main/java/com/cohere/api/resources/connectors/requests/UpdateRequest.java @@ -83,7 +83,7 @@ public Optional> getExcludes() { } /** - * @return The OAuth 2.0 configuration for the connector. Cannot be specified if serviceAuth is specified. + * @return The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. */ @JsonProperty("oauth") public Optional getOauth() { @@ -95,7 +95,7 @@ public Optional getActive() { return active; } - @JsonProperty("continueOnFailure") + @JsonProperty("continue_on_failure") public Optional getContinueOnFailure() { return continueOnFailure; } @@ -103,7 +103,7 @@ public Optional getContinueOnFailure() { /** * @return The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. */ - @JsonProperty("serviceAuth") + @JsonProperty("service_auth") public Optional getServiceAuth() { return serviceAuth; } @@ -231,7 +231,7 @@ public Builder active(Boolean active) { return this; } - @JsonSetter(value = "continueOnFailure", nulls = Nulls.SKIP) + @JsonSetter(value = "continue_on_failure", nulls = Nulls.SKIP) public Builder continueOnFailure(Optional continueOnFailure) { this.continueOnFailure = continueOnFailure; return this; @@ -242,7 +242,7 @@ public Builder continueOnFailure(Boolean continueOnFailure) { return this; } - @JsonSetter(value = "serviceAuth", nulls = Nulls.SKIP) + @JsonSetter(value = "service_auth", nulls = Nulls.SKIP) public Builder serviceAuth(Optional serviceAuth) { this.serviceAuth = serviceAuth; return this; diff --git a/src/main/java/com/cohere/api/types/Connector.java b/src/main/java/com/cohere/api/types/Connector.java index beb6f25..978ca83 100644 --- a/src/main/java/com/cohere/api/types/Connector.java +++ b/src/main/java/com/cohere/api/types/Connector.java @@ -94,7 +94,7 @@ public String getId() { * @return The organization to which this connector belongs. This is automatically set to * the organization of the user who created the connector. */ - @JsonProperty("organizationId") + @JsonProperty("organization_id") public Optional getOrganizationId() { return organizationId; } @@ -126,7 +126,7 @@ public Optional getUrl() { /** * @return The UTC time at which the connector was created. */ - @JsonProperty("createdAt") + @JsonProperty("created_at") public OffsetDateTime getCreatedAt() { return createdAt; } @@ -134,7 +134,7 @@ public OffsetDateTime getCreatedAt() { /** * @return The UTC time at which the connector was last updated. */ - @JsonProperty("updatedAt") + @JsonProperty("updated_at") public OffsetDateTime getUpdatedAt() { return updatedAt; } @@ -150,7 +150,7 @@ public Optional> getExcludes() { /** * @return The type of authentication/authorization used by the connector. Possible values: [oauth, service_auth] */ - @JsonProperty("authType") + @JsonProperty("auth_type") public Optional getAuthType() { return authType; } @@ -166,7 +166,7 @@ public Optional getOauth() { /** * @return The OAuth status for the user making the request. One of ["valid", "expired", ""]. Empty string (field is omitted) means the user has not authorized the connector yet. */ - @JsonProperty("authStatus") + @JsonProperty("auth_status") public Optional getAuthStatus() { return authStatus; } @@ -182,7 +182,7 @@ public Optional getActive() { /** * @return Whether a chat request should continue or not if the request to this connector fails. */ - @JsonProperty("continueOnFailure") + @JsonProperty("continue_on_failure") public Optional getContinueOnFailure() { return continueOnFailure; } @@ -378,7 +378,7 @@ public CreatedAtStage name(String name) { * @return Reference to {@code this} so that method calls can be chained together. */ @Override - @JsonSetter("createdAt") + @JsonSetter("created_at") public UpdatedAtStage createdAt(OffsetDateTime createdAt) { this.createdAt = createdAt; return this; @@ -389,7 +389,7 @@ public UpdatedAtStage createdAt(OffsetDateTime createdAt) { * @return Reference to {@code this} so that method calls can be chained together. */ @Override - @JsonSetter("updatedAt") + @JsonSetter("updated_at") public _FinalStage updatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; return this; @@ -406,7 +406,7 @@ public _FinalStage continueOnFailure(Boolean continueOnFailure) { } @Override - @JsonSetter(value = "continueOnFailure", nulls = Nulls.SKIP) + @JsonSetter(value = "continue_on_failure", nulls = Nulls.SKIP) public _FinalStage continueOnFailure(Optional continueOnFailure) { this.continueOnFailure = continueOnFailure; return this; @@ -440,7 +440,7 @@ public _FinalStage authStatus(ConnectorAuthStatus authStatus) { } @Override - @JsonSetter(value = "authStatus", nulls = Nulls.SKIP) + @JsonSetter(value = "auth_status", nulls = Nulls.SKIP) public _FinalStage authStatus(Optional authStatus) { this.authStatus = authStatus; return this; @@ -474,7 +474,7 @@ public _FinalStage authType(String authType) { } @Override - @JsonSetter(value = "authType", nulls = Nulls.SKIP) + @JsonSetter(value = "auth_type", nulls = Nulls.SKIP) public _FinalStage authType(Optional authType) { this.authType = authType; return this; @@ -543,7 +543,7 @@ public _FinalStage organizationId(String organizationId) { } @Override - @JsonSetter(value = "organizationId", nulls = Nulls.SKIP) + @JsonSetter(value = "organization_id", nulls = Nulls.SKIP) public _FinalStage organizationId(Optional organizationId) { this.organizationId = organizationId; return this; diff --git a/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java b/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java new file mode 100644 index 0000000..79ea844 --- /dev/null +++ b/src/main/java/com/cohere/api/types/EmbedByTypeResponse.java @@ -0,0 +1,218 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = EmbedByTypeResponse.Builder.class) +public final class EmbedByTypeResponse { + private final String id; + + private final EmbedByTypeResponseEmbeddings embeddings; + + private final List texts; + + private final Optional meta; + + private final Map additionalProperties; + + private EmbedByTypeResponse( + String id, + EmbedByTypeResponseEmbeddings embeddings, + List texts, + Optional meta, + Map additionalProperties) { + this.id = id; + this.embeddings = embeddings; + this.texts = texts; + this.meta = meta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("id") + public String getId() { + return id; + } + + /** + * @return An object with different embedding types. The length of each embedding type array will be the same as the length of the original texts array. + */ + @JsonProperty("embeddings") + public EmbedByTypeResponseEmbeddings getEmbeddings() { + return embeddings; + } + + /** + * @return The text entries for which embeddings were returned. + */ + @JsonProperty("texts") + public List getTexts() { + return texts; + } + + @JsonProperty("meta") + public Optional getMeta() { + return meta; + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof EmbedByTypeResponse && equalTo((EmbedByTypeResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(EmbedByTypeResponse other) { + return id.equals(other.id) + && embeddings.equals(other.embeddings) + && texts.equals(other.texts) + && meta.equals(other.meta); + } + + @Override + public int hashCode() { + return Objects.hash(this.id, this.embeddings, this.texts, this.meta); + } + + @Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static IdStage builder() { + return new Builder(); + } + + public interface IdStage { + EmbeddingsStage id(String id); + + Builder from(EmbedByTypeResponse other); + } + + public interface EmbeddingsStage { + _FinalStage embeddings(EmbedByTypeResponseEmbeddings embeddings); + } + + public interface _FinalStage { + EmbedByTypeResponse build(); + + _FinalStage texts(List texts); + + _FinalStage addTexts(String texts); + + _FinalStage addAllTexts(List texts); + + _FinalStage meta(Optional meta); + + _FinalStage meta(ApiMeta meta); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements IdStage, EmbeddingsStage, _FinalStage { + private String id; + + private EmbedByTypeResponseEmbeddings embeddings; + + private Optional meta = Optional.empty(); + + private List texts = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @Override + public Builder from(EmbedByTypeResponse other) { + id(other.getId()); + embeddings(other.getEmbeddings()); + texts(other.getTexts()); + meta(other.getMeta()); + return this; + } + + @Override + @JsonSetter("id") + public EmbeddingsStage id(String id) { + this.id = id; + return this; + } + + /** + *

An object with different embedding types. The length of each embedding type array will be the same as the length of the original texts array.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + @JsonSetter("embeddings") + public _FinalStage embeddings(EmbedByTypeResponseEmbeddings embeddings) { + this.embeddings = embeddings; + return this; + } + + @Override + public _FinalStage meta(ApiMeta meta) { + this.meta = Optional.of(meta); + return this; + } + + @Override + @JsonSetter(value = "meta", nulls = Nulls.SKIP) + public _FinalStage meta(Optional meta) { + this.meta = meta; + return this; + } + + /** + *

The text entries for which embeddings were returned.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addAllTexts(List texts) { + this.texts.addAll(texts); + return this; + } + + /** + *

The text entries for which embeddings were returned.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addTexts(String texts) { + this.texts.add(texts); + return this; + } + + @Override + @JsonSetter(value = "texts", nulls = Nulls.SKIP) + public _FinalStage texts(List texts) { + this.texts.clear(); + this.texts.addAll(texts); + return this; + } + + @Override + public EmbedByTypeResponse build() { + return new EmbedByTypeResponse(id, embeddings, texts, meta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/types/EmbedByTypeResponseEmbeddings.java b/src/main/java/com/cohere/api/types/EmbedByTypeResponseEmbeddings.java new file mode 100644 index 0000000..566a0f2 --- /dev/null +++ b/src/main/java/com/cohere/api/types/EmbedByTypeResponseEmbeddings.java @@ -0,0 +1,209 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.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_EMPTY) +@JsonDeserialize(builder = EmbedByTypeResponseEmbeddings.Builder.class) +public final class EmbedByTypeResponseEmbeddings { + private final Optional>> float_; + + private final Optional>> int8; + + private final Optional>> uint8; + + private final Optional>> binary; + + private final Optional>> ubinary; + + private final Map additionalProperties; + + private EmbedByTypeResponseEmbeddings( + Optional>> float_, + Optional>> int8, + Optional>> uint8, + Optional>> binary, + Optional>> ubinary, + Map additionalProperties) { + this.float_ = float_; + this.int8 = int8; + this.uint8 = uint8; + this.binary = binary; + this.ubinary = ubinary; + this.additionalProperties = additionalProperties; + } + + /** + * @return An array of float embeddings. + */ + @JsonProperty("float") + public Optional>> getFloat() { + return float_; + } + + /** + * @return An array of signed int8 embeddings. Each value is between -128 and 127. + */ + @JsonProperty("int8") + public Optional>> getInt8() { + return int8; + } + + /** + * @return An array of unsigned int8 embeddings. Each value is between 0 and 255. + */ + @JsonProperty("uint8") + public Optional>> getUint8() { + return uint8; + } + + /** + * @return An array of packed signed binary embeddings. The length of each binary embedding is 1/8 the length of the float embeddings of the provided model. Each value is between -128 and 127. + */ + @JsonProperty("binary") + public Optional>> getBinary() { + return binary; + } + + /** + * @return An array of packed unsigned binary embeddings. The length of each binary embedding is 1/8 the length of the float embeddings of the provided model. Each value is between 0 and 255. + */ + @JsonProperty("ubinary") + public Optional>> getUbinary() { + return ubinary; + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof EmbedByTypeResponseEmbeddings && equalTo((EmbedByTypeResponseEmbeddings) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(EmbedByTypeResponseEmbeddings other) { + return float_.equals(other.float_) + && int8.equals(other.int8) + && uint8.equals(other.uint8) + && binary.equals(other.binary) + && ubinary.equals(other.ubinary); + } + + @Override + public int hashCode() { + return Objects.hash(this.float_, this.int8, this.uint8, this.binary, this.ubinary); + } + + @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>> float_ = Optional.empty(); + + private Optional>> int8 = Optional.empty(); + + private Optional>> uint8 = Optional.empty(); + + private Optional>> binary = Optional.empty(); + + private Optional>> ubinary = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(EmbedByTypeResponseEmbeddings other) { + float_(other.getFloat()); + int8(other.getInt8()); + uint8(other.getUint8()); + binary(other.getBinary()); + ubinary(other.getUbinary()); + return this; + } + + @JsonSetter(value = "float", nulls = Nulls.SKIP) + public Builder float_(Optional>> float_) { + this.float_ = float_; + return this; + } + + public Builder float_(List> float_) { + this.float_ = Optional.of(float_); + return this; + } + + @JsonSetter(value = "int8", nulls = Nulls.SKIP) + public Builder int8(Optional>> int8) { + this.int8 = int8; + return this; + } + + public Builder int8(List> int8) { + this.int8 = Optional.of(int8); + return this; + } + + @JsonSetter(value = "uint8", nulls = Nulls.SKIP) + public Builder uint8(Optional>> uint8) { + this.uint8 = uint8; + return this; + } + + public Builder uint8(List> uint8) { + this.uint8 = Optional.of(uint8); + return this; + } + + @JsonSetter(value = "binary", nulls = Nulls.SKIP) + public Builder binary(Optional>> binary) { + this.binary = binary; + return this; + } + + public Builder binary(List> binary) { + this.binary = Optional.of(binary); + return this; + } + + @JsonSetter(value = "ubinary", nulls = Nulls.SKIP) + public Builder ubinary(Optional>> ubinary) { + this.ubinary = ubinary; + return this; + } + + public Builder ubinary(List> ubinary) { + this.ubinary = Optional.of(ubinary); + return this; + } + + public EmbedByTypeResponseEmbeddings build() { + return new EmbedByTypeResponseEmbeddings(float_, int8, uint8, binary, ubinary, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/types/EmbedFloatsResponse.java b/src/main/java/com/cohere/api/types/EmbedFloatsResponse.java new file mode 100644 index 0000000..7f3970d --- /dev/null +++ b/src/main/java/com/cohere/api/types/EmbedFloatsResponse.java @@ -0,0 +1,237 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = EmbedFloatsResponse.Builder.class) +public final class EmbedFloatsResponse { + private final String id; + + private final List> embeddings; + + private final List texts; + + private final Optional meta; + + private final Map additionalProperties; + + private EmbedFloatsResponse( + String id, + List> embeddings, + List texts, + Optional meta, + Map additionalProperties) { + this.id = id; + this.embeddings = embeddings; + this.texts = texts; + this.meta = meta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("id") + public String getId() { + return id; + } + + /** + * @return An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array. + */ + @JsonProperty("embeddings") + public List> getEmbeddings() { + return embeddings; + } + + /** + * @return The text entries for which embeddings were returned. + */ + @JsonProperty("texts") + public List getTexts() { + return texts; + } + + @JsonProperty("meta") + public Optional getMeta() { + return meta; + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof EmbedFloatsResponse && equalTo((EmbedFloatsResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(EmbedFloatsResponse other) { + return id.equals(other.id) + && embeddings.equals(other.embeddings) + && texts.equals(other.texts) + && meta.equals(other.meta); + } + + @Override + public int hashCode() { + return Objects.hash(this.id, this.embeddings, this.texts, this.meta); + } + + @Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static IdStage builder() { + return new Builder(); + } + + public interface IdStage { + _FinalStage id(String id); + + Builder from(EmbedFloatsResponse other); + } + + public interface _FinalStage { + EmbedFloatsResponse build(); + + _FinalStage embeddings(List> embeddings); + + _FinalStage addEmbeddings(List embeddings); + + _FinalStage addAllEmbeddings(List> embeddings); + + _FinalStage texts(List texts); + + _FinalStage addTexts(String texts); + + _FinalStage addAllTexts(List texts); + + _FinalStage meta(Optional meta); + + _FinalStage meta(ApiMeta meta); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements IdStage, _FinalStage { + private String id; + + private Optional meta = Optional.empty(); + + private List texts = new ArrayList<>(); + + private List> embeddings = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @Override + public Builder from(EmbedFloatsResponse other) { + id(other.getId()); + embeddings(other.getEmbeddings()); + texts(other.getTexts()); + meta(other.getMeta()); + return this; + } + + @Override + @JsonSetter("id") + public _FinalStage id(String id) { + this.id = id; + return this; + } + + @Override + public _FinalStage meta(ApiMeta meta) { + this.meta = Optional.of(meta); + return this; + } + + @Override + @JsonSetter(value = "meta", nulls = Nulls.SKIP) + public _FinalStage meta(Optional meta) { + this.meta = meta; + return this; + } + + /** + *

The text entries for which embeddings were returned.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addAllTexts(List texts) { + this.texts.addAll(texts); + return this; + } + + /** + *

The text entries for which embeddings were returned.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addTexts(String texts) { + this.texts.add(texts); + return this; + } + + @Override + @JsonSetter(value = "texts", nulls = Nulls.SKIP) + public _FinalStage texts(List texts) { + this.texts.clear(); + this.texts.addAll(texts); + return this; + } + + /** + *

An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addAllEmbeddings(List> embeddings) { + this.embeddings.addAll(embeddings); + return this; + } + + /** + *

An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @Override + public _FinalStage addEmbeddings(List embeddings) { + this.embeddings.add(embeddings); + return this; + } + + @Override + @JsonSetter(value = "embeddings", nulls = Nulls.SKIP) + public _FinalStage embeddings(List> embeddings) { + this.embeddings.clear(); + this.embeddings.addAll(embeddings); + return this; + } + + @Override + public EmbedFloatsResponse build() { + return new EmbedFloatsResponse(id, embeddings, texts, meta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/types/EmbedResponse.java b/src/main/java/com/cohere/api/types/EmbedResponse.java index 6f81c36..6720e90 100644 --- a/src/main/java/com/cohere/api/types/EmbedResponse.java +++ b/src/main/java/com/cohere/api/types/EmbedResponse.java @@ -3,235 +3,202 @@ */ package com.cohere.api.types; -import com.cohere.api.core.ObjectMappers; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; 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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; import java.util.Objects; import java.util.Optional; -@JsonInclude(JsonInclude.Include.NON_EMPTY) -@JsonDeserialize(builder = EmbedResponse.Builder.class) public final class EmbedResponse { - private final String id; + private final Value value; - private final List> embeddings; - - private final List texts; - - private final Optional meta; - - private final Map additionalProperties; - - private EmbedResponse( - String id, - List> embeddings, - List texts, - Optional meta, - Map additionalProperties) { - this.id = id; - this.embeddings = embeddings; - this.texts = texts; - this.meta = meta; - this.additionalProperties = additionalProperties; + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private EmbedResponse(Value value) { + this.value = value; } - @JsonProperty("id") - public String getId() { - return id; + public T visit(Visitor visitor) { + return value.visit(visitor); } - /** - * @return An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array. - */ - @JsonProperty("embeddings") - public List> getEmbeddings() { - return embeddings; + public static EmbedResponse embeddingsFloats(EmbedFloatsResponse value) { + return new EmbedResponse(new EmbeddingsFloatsValue(value)); } - /** - * @return The text entries for which embeddings were returned. - */ - @JsonProperty("texts") - public List getTexts() { - return texts; + public static EmbedResponse embeddingsByType(EmbedByTypeResponse value) { + return new EmbedResponse(new EmbeddingsByTypeValue(value)); } - @JsonProperty("meta") - public Optional getMeta() { - return meta; + public boolean isEmbeddingsFloats() { + return value instanceof EmbeddingsFloatsValue; } - @Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof EmbedResponse && equalTo((EmbedResponse) other); + public boolean isEmbeddingsByType() { + return value instanceof EmbeddingsByTypeValue; } - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; + public boolean _isUnknown() { + return value instanceof _UnknownValue; } - private boolean equalTo(EmbedResponse other) { - return id.equals(other.id) - && embeddings.equals(other.embeddings) - && texts.equals(other.texts) - && meta.equals(other.meta); + public Optional getEmbeddingsFloats() { + if (isEmbeddingsFloats()) { + return Optional.of(((EmbeddingsFloatsValue) value).value); + } + return Optional.empty(); } - @Override - public int hashCode() { - return Objects.hash(this.id, this.embeddings, this.texts, this.meta); + public Optional getEmbeddingsByType() { + if (isEmbeddingsByType()) { + return Optional.of(((EmbeddingsByTypeValue) value).value); + } + return Optional.empty(); } - @Override - public String toString() { - return ObjectMappers.stringify(this); + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); } - public static IdStage builder() { - return new Builder(); + @JsonValue + private Value getValue() { + return this.value; } - public interface IdStage { - _FinalStage id(String id); + public interface Visitor { + T visitEmbeddingsFloats(EmbedFloatsResponse embeddingsFloats); + + T visitEmbeddingsByType(EmbedByTypeResponse embeddingsByType); - Builder from(EmbedResponse other); + T _visitUnknown(Object unknownType); } - public interface _FinalStage { - EmbedResponse build(); + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "response_type", + visible = true, + defaultImpl = _UnknownValue.class) + @JsonSubTypes({@JsonSubTypes.Type(EmbeddingsFloatsValue.class), @JsonSubTypes.Type(EmbeddingsByTypeValue.class)}) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } - _FinalStage embeddings(List> embeddings); + @JsonTypeName("embeddings_floats") + private static final class EmbeddingsFloatsValue implements Value { + @JsonUnwrapped + private EmbedFloatsResponse value; - _FinalStage addEmbeddings(List embeddings); + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private EmbeddingsFloatsValue() {} - _FinalStage addAllEmbeddings(List> embeddings); + private EmbeddingsFloatsValue(EmbedFloatsResponse value) { + this.value = value; + } - _FinalStage texts(List texts); + @Override + public T visit(Visitor visitor) { + return visitor.visitEmbeddingsFloats(value); + } - _FinalStage addTexts(String texts); + @Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof EmbeddingsFloatsValue && equalTo((EmbeddingsFloatsValue) other); + } - _FinalStage addAllTexts(List texts); + private boolean equalTo(EmbeddingsFloatsValue other) { + return value.equals(other.value); + } - _FinalStage meta(Optional meta); + @Override + public int hashCode() { + return Objects.hash(this.value); + } - _FinalStage meta(ApiMeta meta); + @Override + public String toString() { + return "EmbedResponse{" + "value: " + value + "}"; + } } - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements IdStage, _FinalStage { - private String id; - - private Optional meta = Optional.empty(); - - private List texts = new ArrayList<>(); - - private List> embeddings = new ArrayList<>(); + @JsonTypeName("embeddings_by_type") + private static final class EmbeddingsByTypeValue implements Value { + @JsonUnwrapped + private EmbedByTypeResponse value; - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private EmbeddingsByTypeValue() {} - private Builder() {} - - @Override - public Builder from(EmbedResponse other) { - id(other.getId()); - embeddings(other.getEmbeddings()); - texts(other.getTexts()); - meta(other.getMeta()); - return this; + private EmbeddingsByTypeValue(EmbedByTypeResponse value) { + this.value = value; } @Override - @JsonSetter("id") - public _FinalStage id(String id) { - this.id = id; - return this; + public T visit(Visitor visitor) { + return visitor.visitEmbeddingsByType(value); } @Override - public _FinalStage meta(ApiMeta meta) { - this.meta = Optional.of(meta); - return this; + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof EmbeddingsByTypeValue && equalTo((EmbeddingsByTypeValue) other); } - @Override - @JsonSetter(value = "meta", nulls = Nulls.SKIP) - public _FinalStage meta(Optional meta) { - this.meta = meta; - return this; + private boolean equalTo(EmbeddingsByTypeValue other) { + return value.equals(other.value); } - /** - *

The text entries for which embeddings were returned.

- * @return Reference to {@code this} so that method calls can be chained together. - */ @Override - public _FinalStage addAllTexts(List texts) { - this.texts.addAll(texts); - return this; + public int hashCode() { + return Objects.hash(this.value); } - /** - *

The text entries for which embeddings were returned.

- * @return Reference to {@code this} so that method calls can be chained together. - */ @Override - public _FinalStage addTexts(String texts) { - this.texts.add(texts); - return this; + public String toString() { + return "EmbedResponse{" + "value: " + value + "}"; } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} @Override - @JsonSetter(value = "texts", nulls = Nulls.SKIP) - public _FinalStage texts(List texts) { - this.texts.clear(); - this.texts.addAll(texts); - return this; + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); } - /** - *

An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array.

- * @return Reference to {@code this} so that method calls can be chained together. - */ @Override - public _FinalStage addAllEmbeddings(List> embeddings) { - this.embeddings.addAll(embeddings); - return this; + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); } - /** - *

An array of embeddings, where each embedding is an array of floats. The length of the embeddings array will be the same as the length of the original texts array.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @Override - public _FinalStage addEmbeddings(List embeddings) { - this.embeddings.add(embeddings); - return this; + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); } @Override - @JsonSetter(value = "embeddings", nulls = Nulls.SKIP) - public _FinalStage embeddings(List> embeddings) { - this.embeddings.clear(); - this.embeddings.addAll(embeddings); - return this; + public int hashCode() { + return Objects.hash(this.type, this.value); } @Override - public EmbedResponse build() { - return new EmbedResponse(id, embeddings, texts, meta, additionalProperties); + public String toString() { + return "EmbedResponse{" + "type: " + type + ", value: " + value + "}"; } } }