com.konfigthis.carbonai.client.model.DocumentResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carbonai-java-sdk Show documentation
Show all versions of carbonai-java-sdk Show documentation
Connect external data to LLMs, no matter the source.
This library was generated by https://konfigthis.com
/*
* Carbon
* Connect external data to LLMs, no matter the source.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
* Do not edit the class manually.
*/
package com.konfigthis.carbonai.client.model;
import java.util.Objects;
import java.util.Arrays;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.konfigthis.carbonai.client.model.DataSourceTypeNullable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.konfigthis.carbonai.client.JSON;
/**
* DocumentResponse
*/@javax.annotation.Generated(value = "Generated by https://konfigthis.com")
public class DocumentResponse {
public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private Map tags = new HashMap<>();
public static final String SERIALIZED_NAME_CONTENT = "content";
@SerializedName(SERIALIZED_NAME_CONTENT)
private String content;
public static final String SERIALIZED_NAME_FILE_ID = "file_id";
@SerializedName(SERIALIZED_NAME_FILE_ID)
private Integer fileId;
public static final String SERIALIZED_NAME_PARENT_FILE_ID = "parent_file_id";
@SerializedName(SERIALIZED_NAME_PARENT_FILE_ID)
private Integer parentFileId;
public static final String SERIALIZED_NAME_SOURCE = "source";
@SerializedName(SERIALIZED_NAME_SOURCE)
private String source;
public static final String SERIALIZED_NAME_SOURCE_URL = "source_url";
@SerializedName(SERIALIZED_NAME_SOURCE_URL)
private String sourceUrl;
public static final String SERIALIZED_NAME_SOURCE_TYPE = "source_type";
@SerializedName(SERIALIZED_NAME_SOURCE_TYPE)
private DataSourceTypeNullable sourceType;
public static final String SERIALIZED_NAME_PRESIGNED_URL = "presigned_url";
@SerializedName(SERIALIZED_NAME_PRESIGNED_URL)
private String presignedUrl;
public static final String SERIALIZED_NAME_VECTOR = "vector";
@SerializedName(SERIALIZED_NAME_VECTOR)
private List vector = new ArrayList<>();
public static final String SERIALIZED_NAME_SCORE = "score";
@SerializedName(SERIALIZED_NAME_SCORE)
private Double score;
public static final String SERIALIZED_NAME_RANK = "rank";
@SerializedName(SERIALIZED_NAME_RANK)
private Object rank = null;
public static final String SERIALIZED_NAME_CONTENT_METADATA = "content_metadata";
@SerializedName(SERIALIZED_NAME_CONTENT_METADATA)
private Object contentMetadata;
public static final String SERIALIZED_NAME_CHUNK_INDEX = "chunk_index";
@SerializedName(SERIALIZED_NAME_CHUNK_INDEX)
private Integer chunkIndex;
public DocumentResponse() {
}
public DocumentResponse tags(Map tags) {
this.tags = tags;
return this;
}
public DocumentResponse putTagsItem(String key, Object tagsItem) {
this.tags.put(key, tagsItem);
return this;
}
/**
* Get tags
* @return tags
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Map getTags() {
return tags;
}
public void setTags(Map tags) {
this.tags = tags;
}
public DocumentResponse content(String content) {
this.content = content;
return this;
}
/**
* Get content
* @return content
**/
@javax.annotation.Nonnull
@ApiModelProperty(required = true, value = "")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public DocumentResponse fileId(Integer fileId) {
this.fileId = fileId;
return this;
}
/**
* Get fileId
* @return fileId
**/
@javax.annotation.Nonnull
@ApiModelProperty(required = true, value = "")
public Integer getFileId() {
return fileId;
}
public void setFileId(Integer fileId) {
this.fileId = fileId;
}
public DocumentResponse parentFileId(Integer parentFileId) {
this.parentFileId = parentFileId;
return this;
}
/**
* Get parentFileId
* @return parentFileId
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Integer getParentFileId() {
return parentFileId;
}
public void setParentFileId(Integer parentFileId) {
this.parentFileId = parentFileId;
}
public DocumentResponse source(String source) {
this.source = source;
return this;
}
/**
* Get source
* @return source
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public DocumentResponse sourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
return this;
}
/**
* Get sourceUrl
* @return sourceUrl
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public String getSourceUrl() {
return sourceUrl;
}
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
public DocumentResponse sourceType(DataSourceTypeNullable sourceType) {
this.sourceType = sourceType;
return this;
}
/**
* Get sourceType
* @return sourceType
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public DataSourceTypeNullable getSourceType() {
return sourceType;
}
public void setSourceType(DataSourceTypeNullable sourceType) {
this.sourceType = sourceType;
}
public DocumentResponse presignedUrl(String presignedUrl) {
this.presignedUrl = presignedUrl;
return this;
}
/**
* Get presignedUrl
* @return presignedUrl
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public String getPresignedUrl() {
return presignedUrl;
}
public void setPresignedUrl(String presignedUrl) {
this.presignedUrl = presignedUrl;
}
public DocumentResponse vector(List vector) {
this.vector = vector;
return this;
}
public DocumentResponse addVectorItem(Double vectorItem) {
this.vector.add(vectorItem);
return this;
}
/**
* Get vector
* @return vector
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public List getVector() {
return vector;
}
public void setVector(List vector) {
this.vector = vector;
}
public DocumentResponse score(Double score) {
this.score = score;
return this;
}
public DocumentResponse score(Integer score) {
this.score = score.doubleValue();
return this;
}
/**
* Get score
* @return score
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
public DocumentResponse rank(Object rank) {
this.rank = rank;
return this;
}
/**
* Get rank
* @return rank
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Object getRank() {
return rank;
}
public void setRank(Object rank) {
this.rank = rank;
}
public DocumentResponse contentMetadata(Object contentMetadata) {
this.contentMetadata = contentMetadata;
return this;
}
/**
* Get contentMetadata
* @return contentMetadata
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Object getContentMetadata() {
return contentMetadata;
}
public void setContentMetadata(Object contentMetadata) {
this.contentMetadata = contentMetadata;
}
public DocumentResponse chunkIndex(Integer chunkIndex) {
this.chunkIndex = chunkIndex;
return this;
}
/**
* Get chunkIndex
* @return chunkIndex
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
public Integer getChunkIndex() {
return chunkIndex;
}
public void setChunkIndex(Integer chunkIndex) {
this.chunkIndex = chunkIndex;
}
/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map additionalProperties;
/**
* Set the additional (undeclared) property with the specified name and value.
* If the property does not already exist, create it otherwise replace it.
*
* @param key name of the property
* @param value value of the property
* @return the DocumentResponse instance itself
*/
public DocumentResponse putAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap();
}
this.additionalProperties.put(key, value);
return this;
}
/**
* Return the additional (undeclared) property.
*
* @return a map of objects
*/
public Map getAdditionalProperties() {
return additionalProperties;
}
/**
* Return the additional (undeclared) property with the specified name.
*
* @param key name of the property
* @return an object
*/
public Object getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DocumentResponse documentResponse = (DocumentResponse) o;
return Objects.equals(this.tags, documentResponse.tags) &&
Objects.equals(this.content, documentResponse.content) &&
Objects.equals(this.fileId, documentResponse.fileId) &&
Objects.equals(this.parentFileId, documentResponse.parentFileId) &&
Objects.equals(this.source, documentResponse.source) &&
Objects.equals(this.sourceUrl, documentResponse.sourceUrl) &&
Objects.equals(this.sourceType, documentResponse.sourceType) &&
Objects.equals(this.presignedUrl, documentResponse.presignedUrl) &&
Objects.equals(this.vector, documentResponse.vector) &&
Objects.equals(this.score, documentResponse.score) &&
Objects.equals(this.rank, documentResponse.rank) &&
Objects.equals(this.contentMetadata, documentResponse.contentMetadata) &&
Objects.equals(this.chunkIndex, documentResponse.chunkIndex)&&
Objects.equals(this.additionalProperties, documentResponse.additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(tags, content, fileId, parentFileId, source, sourceUrl, sourceType, presignedUrl, vector, score, rank, contentMetadata, chunkIndex, additionalProperties);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DocumentResponse {\n");
sb.append(" tags: ").append(toIndentedString(tags)).append("\n");
sb.append(" content: ").append(toIndentedString(content)).append("\n");
sb.append(" fileId: ").append(toIndentedString(fileId)).append("\n");
sb.append(" parentFileId: ").append(toIndentedString(parentFileId)).append("\n");
sb.append(" source: ").append(toIndentedString(source)).append("\n");
sb.append(" sourceUrl: ").append(toIndentedString(sourceUrl)).append("\n");
sb.append(" sourceType: ").append(toIndentedString(sourceType)).append("\n");
sb.append(" presignedUrl: ").append(toIndentedString(presignedUrl)).append("\n");
sb.append(" vector: ").append(toIndentedString(vector)).append("\n");
sb.append(" score: ").append(toIndentedString(score)).append("\n");
sb.append(" rank: ").append(toIndentedString(rank)).append("\n");
sb.append(" contentMetadata: ").append(toIndentedString(contentMetadata)).append("\n");
sb.append(" chunkIndex: ").append(toIndentedString(chunkIndex)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet openapiFields;
public static HashSet openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
openapiFields.add("tags");
openapiFields.add("content");
openapiFields.add("file_id");
openapiFields.add("parent_file_id");
openapiFields.add("source");
openapiFields.add("source_url");
openapiFields.add("source_type");
openapiFields.add("presigned_url");
openapiFields.add("vector");
openapiFields.add("score");
openapiFields.add("rank");
openapiFields.add("content_metadata");
openapiFields.add("chunk_index");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
openapiRequiredFields.add("tags");
openapiRequiredFields.add("content");
openapiRequiredFields.add("file_id");
openapiRequiredFields.add("parent_file_id");
openapiRequiredFields.add("source");
openapiRequiredFields.add("source_url");
openapiRequiredFields.add("source_type");
openapiRequiredFields.add("presigned_url");
openapiRequiredFields.add("vector");
openapiRequiredFields.add("score");
openapiRequiredFields.add("rank");
openapiRequiredFields.add("content_metadata");
openapiRequiredFields.add("chunk_index");
}
/**
* Validates the JSON Object and throws an exception if issues found
*
* @param jsonObj JSON Object
* @throws IOException if the JSON Object is invalid with respect to DocumentResponse
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (!DocumentResponse.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in DocumentResponse is not found in the empty JSON string", DocumentResponse.openapiRequiredFields.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : DocumentResponse.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
if (!jsonObj.get("content").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `content` to be a primitive type in the JSON string but got `%s`", jsonObj.get("content").toString()));
}
if (!jsonObj.get("source").isJsonNull() && !jsonObj.get("source").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `source` to be a primitive type in the JSON string but got `%s`", jsonObj.get("source").toString()));
}
if (!jsonObj.get("source_url").isJsonNull() && !jsonObj.get("source_url").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `source_url` to be a primitive type in the JSON string but got `%s`", jsonObj.get("source_url").toString()));
}
if (!jsonObj.get("presigned_url").isJsonNull() && !jsonObj.get("presigned_url").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `presigned_url` to be a primitive type in the JSON string but got `%s`", jsonObj.get("presigned_url").toString()));
}
// ensure the required json array is present
if (jsonObj.get("vector") == null) {
throw new IllegalArgumentException("Expected the field `linkedContent` to be an array in the JSON string but got `null`");
} else if (!jsonObj.get("vector").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `vector` to be an array in the JSON string but got `%s`", jsonObj.get("vector").toString()));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!DocumentResponse.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'DocumentResponse' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(DocumentResponse.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, DocumentResponse value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
obj.remove("additionalProperties");
// serialize additonal properties
if (value.getAdditionalProperties() != null) {
for (Map.Entry entry : value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(entry.getKey(), (Character) entry.getValue());
else if (entry.getValue() == null) {
obj.addProperty(entry.getKey(), (String) null);
} else {
obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject());
}
}
}
elementAdapter.write(out, obj);
}
@Override
public DocumentResponse read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
// store additional fields in the deserialized instance
DocumentResponse instance = thisAdapter.fromJsonTree(jsonObj);
for (Map.Entry entry : jsonObj.entrySet()) {
if (!openapiFields.contains(entry.getKey())) {
if (entry.getValue().isJsonPrimitive()) { // primitive type
if (entry.getValue().getAsJsonPrimitive().isString())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
else if (entry.getValue().getAsJsonPrimitive().isNumber())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
else
throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
} else if (entry.getValue().isJsonArray()) {
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
} else { // JSON object
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
}
}
}
return instance;
}
}.nullSafe();
}
}
/**
* Create an instance of DocumentResponse given an JSON string
*
* @param jsonString JSON string
* @return An instance of DocumentResponse
* @throws IOException if the JSON string is invalid with respect to DocumentResponse
*/
public static DocumentResponse fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, DocumentResponse.class);
}
/**
* Convert an instance of DocumentResponse to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}