diff --git a/README.md b/README.md index 947c8c4..f5d5985 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Maven Central](https://img.shields.io/maven-central/v/ai.llamaindex.llamacloud/llama-cloud)](https://central.sonatype.com/artifact/ai.llamaindex.llamacloud/llama-cloud/1.9.0) -[![javadoc](https://javadoc.io/badge2/ai.llamaindex.llamacloud/llama-cloud/1.9.0/javadoc.svg)](https://javadoc.io/doc/ai.llamaindex.llamacloud/llama-cloud/1.8.0) +[![javadoc](https://javadoc.io/badge2/ai.llamaindex.llamacloud/llama-cloud/1.9.0/javadoc.svg)](https://javadoc.io/doc/ai.llamaindex.llamacloud/llama-cloud/1.9.0) diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt index 36f3f95..380a0c8 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt @@ -9,6 +9,7 @@ import ai.llamaindex.llamacloud.core.JsonMissing import ai.llamaindex.llamacloud.core.JsonValue import ai.llamaindex.llamacloud.core.Params import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired import ai.llamaindex.llamacloud.core.http.Headers import ai.llamaindex.llamacloud.core.http.QueryParams import ai.llamaindex.llamacloud.core.toImmutable @@ -46,28 +47,20 @@ private constructor( fun projectId(): Optional = Optional.ofNullable(projectId) /** - * Configuration for a Verify job. - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun configuration(): Optional = body.configuration() - - /** - * Deprecated: use file_input instead + * File ID of the document to analyze * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - @Deprecated("deprecated") fun fileId(): Optional = body.fileId() + fun fileInput(): String = body.fileInput() /** - * File ID of the document to analyze + * Configuration for a Verify job. * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun fileInput(): Optional = body.fileInput() + fun configuration(): Optional = body.configuration() /** * Idempotency key scoped to the project. Reusing a key returns the original job; the new @@ -95,25 +88,18 @@ private constructor( fun webhookConfigurations(): Optional> = body.webhookConfigurations() /** - * Returns the raw JSON value of [configuration]. - * - * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _configuration(): JsonField = body._configuration() - - /** - * Returns the raw JSON value of [fileId]. + * Returns the raw JSON value of [fileInput]. * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. */ - @Deprecated("deprecated") fun _fileId(): JsonField = body._fileId() + fun _fileInput(): JsonField = body._fileInput() /** - * Returns the raw JSON value of [fileInput]. + * Returns the raw JSON value of [configuration]. * - * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. */ - fun _fileInput(): JsonField = body._fileInput() + fun _configuration(): JsonField = body._configuration() /** * Returns the raw JSON value of [transactionId]. @@ -151,9 +137,14 @@ private constructor( companion object { - @JvmStatic fun none(): VerifyCreateParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [VerifyCreateParams]. */ + /** + * Returns a mutable builder for constructing an instance of [VerifyCreateParams]. + * + * The following fields are required: + * ```java + * .fileInput() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -191,15 +182,27 @@ private constructor( * * This is generally only useful if you are already constructing the body separately. * Otherwise, it's more convenient to use the top-level setters instead: - * - [configuration] - * - [fileId] * - [fileInput] + * - [configuration] * - [transactionId] * - [webhookConfigurationIds] + * - [webhookConfigurations] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** File ID of the document to analyze */ + fun fileInput(fileInput: String) = apply { body.fileInput(fileInput) } + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { body.fileInput(fileInput) } + /** Configuration for a Verify job. */ fun configuration(configuration: Configuration?) = apply { body.configuration(configuration) @@ -220,36 +223,6 @@ private constructor( body.configuration(configuration) } - /** Deprecated: use file_input instead */ - @Deprecated("deprecated") fun fileId(fileId: String?) = apply { body.fileId(fileId) } - - /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ - @Deprecated("deprecated") fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun fileId(fileId: JsonField) = apply { body.fileId(fileId) } - - /** File ID of the document to analyze */ - fun fileInput(fileInput: String?) = apply { body.fileInput(fileInput) } - - /** Alias for calling [Builder.fileInput] with `fileInput.orElse(null)`. */ - fun fileInput(fileInput: Optional) = fileInput(fileInput.getOrNull()) - - /** - * Sets [Builder.fileInput] to an arbitrary JSON value. - * - * You should usually call [Builder.fileInput] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun fileInput(fileInput: JsonField) = apply { body.fileInput(fileInput) } - /** * Idempotency key scoped to the project. Reusing a key returns the original job; the new * request body is ignored. @@ -457,6 +430,13 @@ private constructor( * Returns an immutable instance of [VerifyCreateParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileInput() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): VerifyCreateParams = VerifyCreateParams( @@ -485,9 +465,8 @@ private constructor( class Body @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val configuration: JsonField, - private val fileId: JsonField, private val fileInput: JsonField, + private val configuration: JsonField, private val transactionId: JsonField, private val webhookConfigurationIds: JsonField>, private val webhookConfigurations: JsonField>, @@ -496,13 +475,12 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("configuration") - @ExcludeMissing - configuration: JsonField = JsonMissing.of(), - @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), @JsonProperty("file_input") @ExcludeMissing fileInput: JsonField = JsonMissing.of(), + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), @JsonProperty("transaction_id") @ExcludeMissing transactionId: JsonField = JsonMissing.of(), @@ -513,9 +491,8 @@ private constructor( @ExcludeMissing webhookConfigurations: JsonField> = JsonMissing.of(), ) : this( - configuration, - fileId, fileInput, + configuration, transactionId, webhookConfigurationIds, webhookConfigurations, @@ -523,28 +500,20 @@ private constructor( ) /** - * Configuration for a Verify job. - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun configuration(): Optional = configuration.getOptional("configuration") - - /** - * Deprecated: use file_input instead + * File ID of the document to analyze * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - @Deprecated("deprecated") fun fileId(): Optional = fileId.getOptional("file_id") + fun fileInput(): String = fileInput.getRequired("file_input") /** - * File ID of the document to analyze + * Configuration for a Verify job. * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun fileInput(): Optional = fileInput.getOptional("file_input") + fun configuration(): Optional = configuration.getOptional("configuration") /** * Idempotency key scoped to the project. Reusing a key returns the original job; the new @@ -573,6 +542,13 @@ private constructor( fun webhookConfigurations(): Optional> = webhookConfigurations.getOptional("webhook_configurations") + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + /** * Returns the raw JSON value of [configuration]. * @@ -583,23 +559,6 @@ private constructor( @ExcludeMissing fun _configuration(): JsonField = configuration - /** - * Returns the raw JSON value of [fileId]. - * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("file_id") - @ExcludeMissing - fun _fileId(): JsonField = fileId - - /** - * Returns the raw JSON value of [fileInput]. - * - * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput - /** * Returns the raw JSON value of [transactionId]. * @@ -644,16 +603,22 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .fileInput() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Body]. */ class Builder internal constructor() { + private var fileInput: JsonField? = null private var configuration: JsonField = JsonMissing.of() - private var fileId: JsonField = JsonMissing.of() - private var fileInput: JsonField = JsonMissing.of() private var transactionId: JsonField = JsonMissing.of() private var webhookConfigurationIds: JsonField>? = null private var webhookConfigurations: JsonField>? = null @@ -661,15 +626,26 @@ private constructor( @JvmSynthetic internal fun from(body: Body) = apply { - configuration = body.configuration - fileId = body.fileId fileInput = body.fileInput + configuration = body.configuration transactionId = body.transactionId webhookConfigurationIds = body.webhookConfigurationIds.map { it.toMutableList() } webhookConfigurations = body.webhookConfigurations.map { it.toMutableList() } additionalProperties = body.additionalProperties.toMutableMap() } + /** File ID of the document to analyze */ + fun fileInput(fileInput: String) = fileInput(JsonField.of(fileInput)) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + /** Configuration for a Verify job. */ fun configuration(configuration: Configuration?) = configuration(JsonField.ofNullable(configuration)) @@ -689,39 +665,6 @@ private constructor( this.configuration = configuration } - /** Deprecated: use file_input instead */ - @Deprecated("deprecated") - fun fileId(fileId: String?) = fileId(JsonField.ofNullable(fileId)) - - /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ - @Deprecated("deprecated") - fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun fileId(fileId: JsonField) = apply { this.fileId = fileId } - - /** File ID of the document to analyze */ - fun fileInput(fileInput: String?) = fileInput(JsonField.ofNullable(fileInput)) - - /** Alias for calling [Builder.fileInput] with `fileInput.orElse(null)`. */ - fun fileInput(fileInput: Optional) = fileInput(fileInput.getOrNull()) - - /** - * Sets [Builder.fileInput] to an arbitrary JSON value. - * - * You should usually call [Builder.fileInput] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } - /** * Idempotency key scoped to the project. Reusing a key returns the original job; the * new request body is ignored. @@ -837,12 +780,18 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileInput() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = Body( + checkRequired("fileInput", fileInput), configuration, - fileId, - fileInput, transactionId, (webhookConfigurationIds ?: JsonMissing.of()).map { it.toImmutable() }, (webhookConfigurations ?: JsonMissing.of()).map { it.toImmutable() }, @@ -866,9 +815,8 @@ private constructor( return@apply } - configuration().ifPresent { it.validate() } - fileId() fileInput() + configuration().ifPresent { it.validate() } transactionId() webhookConfigurationIds() webhookConfigurations().ifPresent { it.forEach { it.validate() } } @@ -891,9 +839,8 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (configuration.asKnown().getOrNull()?.validity() ?: 0) + - (if (fileId.asKnown().isPresent) 1 else 0) + - (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (configuration.asKnown().getOrNull()?.validity() ?: 0) + (if (transactionId.asKnown().isPresent) 1 else 0) + (webhookConfigurationIds.asKnown().getOrNull()?.size ?: 0) + (webhookConfigurations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) @@ -904,9 +851,8 @@ private constructor( } return other is Body && - configuration == other.configuration && - fileId == other.fileId && fileInput == other.fileInput && + configuration == other.configuration && transactionId == other.transactionId && webhookConfigurationIds == other.webhookConfigurationIds && webhookConfigurations == other.webhookConfigurations && @@ -915,9 +861,8 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( - configuration, - fileId, fileInput, + configuration, transactionId, webhookConfigurationIds, webhookConfigurations, @@ -928,7 +873,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{configuration=$configuration, fileId=$fileId, fileInput=$fileInput, transactionId=$transactionId, webhookConfigurationIds=$webhookConfigurationIds, webhookConfigurations=$webhookConfigurations, additionalProperties=$additionalProperties}" + "Body{fileInput=$fileInput, configuration=$configuration, transactionId=$transactionId, webhookConfigurationIds=$webhookConfigurationIds, webhookConfigurations=$webhookConfigurations, additionalProperties=$additionalProperties}" } /** Configuration for a Verify job. */ diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt index 49e242a..45b4820 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt @@ -699,8 +699,8 @@ private constructor( private val family: JsonField, private val score: JsonField, private val tool: JsonField, - private val data: JsonField, private val hard: JsonField, + private val metadata: JsonField, private val additionalProperties: MutableMap, ) { @@ -711,9 +711,11 @@ private constructor( @JsonProperty("family") @ExcludeMissing family: JsonField = JsonMissing.of(), @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), @JsonProperty("tool") @ExcludeMissing tool: JsonField = JsonMissing.of(), - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), @JsonProperty("hard") @ExcludeMissing hard: JsonField = JsonMissing.of(), - ) : this(code, detail, family, score, tool, data, hard, mutableMapOf()) + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(code, detail, family, score, tool, hard, metadata, mutableMapOf()) /** * Machine-readable evidence code @@ -756,20 +758,20 @@ private constructor( fun tool(): String = tool.getRequired("tool") /** - * Tool-specific structured payload + * Whether this is hard (conclusive) evidence * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun data(): Optional = data.getOptional("data") + fun hard(): Optional = hard.getOptional("hard") /** - * Whether this is hard (conclusive) evidence + * Raw values from the tool behind this finding; the shape varies by tool * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun hard(): Optional = hard.getOptional("hard") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [code]. @@ -807,18 +809,18 @@ private constructor( @JsonProperty("tool") @ExcludeMissing fun _tool(): JsonField = tool /** - * Returns the raw JSON value of [data]. + * Returns the raw JSON value of [hard]. * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [hard], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + @JsonProperty("hard") @ExcludeMissing fun _hard(): JsonField = hard /** - * Returns the raw JSON value of [hard]. + * Returns the raw JSON value of [metadata]. * - * Unlike [hard], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("hard") @ExcludeMissing fun _hard(): JsonField = hard + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -857,8 +859,8 @@ private constructor( private var family: JsonField? = null private var score: JsonField? = null private var tool: JsonField? = null - private var data: JsonField = JsonMissing.of() private var hard: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -868,8 +870,8 @@ private constructor( family = evidence.family score = evidence.score tool = evidence.tool - data = evidence.data hard = evidence.hard + metadata = evidence.metadata additionalProperties = evidence.additionalProperties.toMutableMap() } @@ -933,18 +935,6 @@ private constructor( */ fun tool(tool: JsonField) = apply { this.tool = tool } - /** Tool-specific structured payload */ - fun data(data: Data) = data(JsonField.of(data)) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed [Data] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun data(data: JsonField) = apply { this.data = data } - /** Whether this is hard (conclusive) evidence */ fun hard(hard: Boolean) = hard(JsonField.of(hard)) @@ -957,6 +947,18 @@ private constructor( */ fun hard(hard: JsonField) = apply { this.hard = hard } + /** Raw values from the tool behind this finding; the shape varies by tool */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -999,8 +1001,8 @@ private constructor( checkRequired("family", family), checkRequired("score", score), checkRequired("tool", tool), - data, hard, + metadata, additionalProperties.toMutableMap(), ) } @@ -1026,8 +1028,8 @@ private constructor( family() score() tool() - data().ifPresent { it.validate() } hard() + metadata().ifPresent { it.validate() } validated = true } @@ -1052,11 +1054,11 @@ private constructor( (if (family.asKnown().isPresent) 1 else 0) + (if (score.asKnown().isPresent) 1 else 0) + (if (tool.asKnown().isPresent) 1 else 0) + - (data.asKnown().getOrNull()?.validity() ?: 0) + - (if (hard.asKnown().isPresent) 1 else 0) + (if (hard.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) - /** Tool-specific structured payload */ - class Data + /** Raw values from the tool behind this finding; the shape varies by tool */ + class Metadata @JsonCreator private constructor( @com.fasterxml.jackson.annotation.JsonValue @@ -1071,18 +1073,18 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Data]. */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } - /** A builder for [Data]. */ + /** A builder for [Metadata]. */ class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(data: Data) = apply { - additionalProperties = data.additionalProperties.toMutableMap() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { @@ -1108,11 +1110,11 @@ private constructor( } /** - * Returns an immutable instance of [Data]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Data = Data(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -1127,7 +1129,7 @@ private constructor( * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): Data = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -1158,14 +1160,14 @@ private constructor( return true } - return other is Data && additionalProperties == other.additionalProperties + return other is Metadata && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { Objects.hash(additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "Data{additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1179,19 +1181,19 @@ private constructor( family == other.family && score == other.score && tool == other.tool && - data == other.data && hard == other.hard && + metadata == other.metadata && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(code, detail, family, score, tool, data, hard, additionalProperties) + Objects.hash(code, detail, family, score, tool, hard, metadata, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Evidence{code=$code, detail=$detail, family=$family, score=$score, tool=$tool, data=$data, hard=$hard, additionalProperties=$additionalProperties}" + "Evidence{code=$code, detail=$detail, family=$family, score=$score, tool=$tool, hard=$hard, metadata=$metadata, additionalProperties=$additionalProperties}" } /** A per-page forensic heatmap overlay, as a presigned image URL. */ diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCancelResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCancelResponse.kt index 7815a78..402a0df 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCancelResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCancelResponse.kt @@ -37,6 +37,7 @@ private constructor( private val result: JsonField, private val transactionId: JsonField, private val updatedAt: JsonField, + private val usage: JsonField, private val additionalProperties: MutableMap, ) { @@ -74,6 +75,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("usage") @ExcludeMissing usage: JsonField = JsonMissing.of(), ) : this( id, configuration, @@ -89,6 +91,7 @@ private constructor( result, transactionId, updatedAt, + usage, mutableMapOf(), ) @@ -205,6 +208,18 @@ private constructor( */ fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usage(): Optional = usage.getOptional("usage") + /** * Returns the raw JSON value of [id]. * @@ -318,6 +333,13 @@ private constructor( @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField = usage + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -366,6 +388,7 @@ private constructor( private var result: JsonField = JsonMissing.of() private var transactionId: JsonField = JsonMissing.of() private var updatedAt: JsonField = JsonMissing.of() + private var usage: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -384,6 +407,7 @@ private constructor( result = classifyCancelResponse.result transactionId = classifyCancelResponse.transactionId updatedAt = classifyCancelResponse.updatedAt + usage = classifyCancelResponse.usage additionalProperties = classifyCancelResponse.additionalProperties.toMutableMap() } @@ -589,6 +613,26 @@ private constructor( */ fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits + * are the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + fun usage(usage: Usage?) = usage(JsonField.ofNullable(usage)) + + /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */ + fun usage(usage: Optional) = usage(usage.getOrNull()) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed [Usage] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun usage(usage: JsonField) = apply { this.usage = usage } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -642,6 +686,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties.toMutableMap(), ) } @@ -675,6 +720,7 @@ private constructor( result().ifPresent { it.validate() } transactionId() updatedAt() + usage().ifPresent { it.validate() } validated = true } @@ -706,7 +752,8 @@ private constructor( (if (parseJobId.asKnown().isPresent) 1 else 0) + (result.asKnown().getOrNull()?.validity() ?: 0) + (if (transactionId.asKnown().isPresent) 1 else 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (usage.asKnown().getOrNull()?.validity() ?: 0) /** Whether the input was a file or parse job (FILE or PARSE_JOB) */ class DocumentInputType @JsonCreator private constructor(private val value: JsonField) : @@ -1010,6 +1057,230 @@ private constructor( override fun toString() = value.toString() } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val credits: JsonField, + private val parseCredits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credits") @ExcludeMissing credits: JsonField = JsonMissing.of(), + @JsonProperty("parse_credits") + @ExcludeMissing + parseCredits: JsonField = JsonMissing.of(), + ) : this(credits, parseCredits, mutableMapOf()) + + /** + * Total credits billed against this job. Null until billing has recorded it. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun credits(): Optional = credits.getOptional("credits") + + /** + * Credits billed against the parse job Classify ran on the input file + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parseCredits(): Optional = parseCredits.getOptional("parse_credits") + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credits") @ExcludeMissing fun _credits(): JsonField = credits + + /** + * Returns the raw JSON value of [parseCredits]. + * + * Unlike [parseCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("parse_credits") + @ExcludeMissing + fun _parseCredits(): JsonField = parseCredits + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Usage]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Usage]. */ + class Builder internal constructor() { + + private var credits: JsonField = JsonMissing.of() + private var parseCredits: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usage: Usage) = apply { + credits = usage.credits + parseCredits = usage.parseCredits + additionalProperties = usage.additionalProperties.toMutableMap() + } + + /** Total credits billed against this job. Null until billing has recorded it. */ + fun credits(credits: Double?) = credits(JsonField.ofNullable(credits)) + + /** + * Alias for [Builder.credits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun credits(credits: Double) = credits(credits as Double?) + + /** Alias for calling [Builder.credits] with `credits.orElse(null)`. */ + fun credits(credits: Optional) = credits(credits.getOrNull()) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun credits(credits: JsonField) = apply { this.credits = credits } + + /** Credits billed against the parse job Classify ran on the input file */ + fun parseCredits(parseCredits: Double?) = + parseCredits(JsonField.ofNullable(parseCredits)) + + /** + * Alias for [Builder.parseCredits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun parseCredits(parseCredits: Double) = parseCredits(parseCredits as Double?) + + /** Alias for calling [Builder.parseCredits] with `parseCredits.orElse(null)`. */ + fun parseCredits(parseCredits: Optional) = + parseCredits(parseCredits.getOrNull()) + + /** + * Sets [Builder.parseCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.parseCredits] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parseCredits(parseCredits: JsonField) = apply { + this.parseCredits = parseCredits + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Usage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Usage = Usage(credits, parseCredits, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Usage = apply { + if (validated) { + return@apply + } + + credits() + parseCredits() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (credits.asKnown().isPresent) 1 else 0) + + (if (parseCredits.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Usage && + credits == other.credits && + parseCredits == other.parseCredits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(credits, parseCredits, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Usage{credits=$credits, parseCredits=$parseCredits, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1030,6 +1301,7 @@ private constructor( result == other.result && transactionId == other.transactionId && updatedAt == other.updatedAt && + usage == other.usage && additionalProperties == other.additionalProperties } @@ -1049,6 +1321,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties, ) } @@ -1056,5 +1329,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ClassifyCancelResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "ClassifyCancelResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, usage=$usage, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateResponse.kt index 571e45d..2abe7da 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateResponse.kt @@ -37,6 +37,7 @@ private constructor( private val result: JsonField, private val transactionId: JsonField, private val updatedAt: JsonField, + private val usage: JsonField, private val additionalProperties: MutableMap, ) { @@ -74,6 +75,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("usage") @ExcludeMissing usage: JsonField = JsonMissing.of(), ) : this( id, configuration, @@ -89,6 +91,7 @@ private constructor( result, transactionId, updatedAt, + usage, mutableMapOf(), ) @@ -205,6 +208,18 @@ private constructor( */ fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usage(): Optional = usage.getOptional("usage") + /** * Returns the raw JSON value of [id]. * @@ -318,6 +333,13 @@ private constructor( @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField = usage + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -366,6 +388,7 @@ private constructor( private var result: JsonField = JsonMissing.of() private var transactionId: JsonField = JsonMissing.of() private var updatedAt: JsonField = JsonMissing.of() + private var usage: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -384,6 +407,7 @@ private constructor( result = classifyCreateResponse.result transactionId = classifyCreateResponse.transactionId updatedAt = classifyCreateResponse.updatedAt + usage = classifyCreateResponse.usage additionalProperties = classifyCreateResponse.additionalProperties.toMutableMap() } @@ -589,6 +613,26 @@ private constructor( */ fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits + * are the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + fun usage(usage: Usage?) = usage(JsonField.ofNullable(usage)) + + /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */ + fun usage(usage: Optional) = usage(usage.getOrNull()) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed [Usage] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun usage(usage: JsonField) = apply { this.usage = usage } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -642,6 +686,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties.toMutableMap(), ) } @@ -675,6 +720,7 @@ private constructor( result().ifPresent { it.validate() } transactionId() updatedAt() + usage().ifPresent { it.validate() } validated = true } @@ -706,7 +752,8 @@ private constructor( (if (parseJobId.asKnown().isPresent) 1 else 0) + (result.asKnown().getOrNull()?.validity() ?: 0) + (if (transactionId.asKnown().isPresent) 1 else 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (usage.asKnown().getOrNull()?.validity() ?: 0) /** Whether the input was a file or parse job (FILE or PARSE_JOB) */ class DocumentInputType @JsonCreator private constructor(private val value: JsonField) : @@ -1010,6 +1057,230 @@ private constructor( override fun toString() = value.toString() } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val credits: JsonField, + private val parseCredits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credits") @ExcludeMissing credits: JsonField = JsonMissing.of(), + @JsonProperty("parse_credits") + @ExcludeMissing + parseCredits: JsonField = JsonMissing.of(), + ) : this(credits, parseCredits, mutableMapOf()) + + /** + * Total credits billed against this job. Null until billing has recorded it. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun credits(): Optional = credits.getOptional("credits") + + /** + * Credits billed against the parse job Classify ran on the input file + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parseCredits(): Optional = parseCredits.getOptional("parse_credits") + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credits") @ExcludeMissing fun _credits(): JsonField = credits + + /** + * Returns the raw JSON value of [parseCredits]. + * + * Unlike [parseCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("parse_credits") + @ExcludeMissing + fun _parseCredits(): JsonField = parseCredits + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Usage]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Usage]. */ + class Builder internal constructor() { + + private var credits: JsonField = JsonMissing.of() + private var parseCredits: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usage: Usage) = apply { + credits = usage.credits + parseCredits = usage.parseCredits + additionalProperties = usage.additionalProperties.toMutableMap() + } + + /** Total credits billed against this job. Null until billing has recorded it. */ + fun credits(credits: Double?) = credits(JsonField.ofNullable(credits)) + + /** + * Alias for [Builder.credits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun credits(credits: Double) = credits(credits as Double?) + + /** Alias for calling [Builder.credits] with `credits.orElse(null)`. */ + fun credits(credits: Optional) = credits(credits.getOrNull()) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun credits(credits: JsonField) = apply { this.credits = credits } + + /** Credits billed against the parse job Classify ran on the input file */ + fun parseCredits(parseCredits: Double?) = + parseCredits(JsonField.ofNullable(parseCredits)) + + /** + * Alias for [Builder.parseCredits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun parseCredits(parseCredits: Double) = parseCredits(parseCredits as Double?) + + /** Alias for calling [Builder.parseCredits] with `parseCredits.orElse(null)`. */ + fun parseCredits(parseCredits: Optional) = + parseCredits(parseCredits.getOrNull()) + + /** + * Sets [Builder.parseCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.parseCredits] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parseCredits(parseCredits: JsonField) = apply { + this.parseCredits = parseCredits + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Usage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Usage = Usage(credits, parseCredits, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Usage = apply { + if (validated) { + return@apply + } + + credits() + parseCredits() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (credits.asKnown().isPresent) 1 else 0) + + (if (parseCredits.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Usage && + credits == other.credits && + parseCredits == other.parseCredits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(credits, parseCredits, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Usage{credits=$credits, parseCredits=$parseCredits, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1030,6 +1301,7 @@ private constructor( result == other.result && transactionId == other.transactionId && updatedAt == other.updatedAt && + usage == other.usage && additionalProperties == other.additionalProperties } @@ -1049,6 +1321,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties, ) } @@ -1056,5 +1329,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ClassifyCreateResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "ClassifyCreateResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, usage=$usage, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetParams.kt index fb2778e..cbfb7d4 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetParams.kt @@ -5,6 +5,7 @@ package ai.llamaindex.llamacloud.models.classify import ai.llamaindex.llamacloud.core.Params import ai.llamaindex.llamacloud.core.http.Headers import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -13,11 +14,13 @@ import kotlin.jvm.optionals.getOrNull * Get a classify job by ID. * * Returns the job status, configuration, and classify result when complete. The result includes the - * matched document type, confidence score, and reasoning. + * matched document type, confidence score, and reasoning. Use `expand=usage` for credits billed + * against the job. */ class ClassifyGetParams private constructor( private val jobId: String?, + private val expand: List?, private val organizationId: String?, private val projectId: String?, private val additionalHeaders: Headers, @@ -26,6 +29,9 @@ private constructor( fun jobId(): Optional = Optional.ofNullable(jobId) + /** Additional fields to include: usage */ + fun expand(): Optional> = Optional.ofNullable(expand) + fun organizationId(): Optional = Optional.ofNullable(organizationId) fun projectId(): Optional = Optional.ofNullable(projectId) @@ -50,6 +56,7 @@ private constructor( class Builder internal constructor() { private var jobId: String? = null + private var expand: MutableList? = null private var organizationId: String? = null private var projectId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -58,6 +65,7 @@ private constructor( @JvmSynthetic internal fun from(classifyGetParams: ClassifyGetParams) = apply { jobId = classifyGetParams.jobId + expand = classifyGetParams.expand?.toMutableList() organizationId = classifyGetParams.organizationId projectId = classifyGetParams.projectId additionalHeaders = classifyGetParams.additionalHeaders.toBuilder() @@ -69,6 +77,21 @@ private constructor( /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) + /** Additional fields to include: usage */ + fun expand(expand: List?) = apply { this.expand = expand?.toMutableList() } + + /** Alias for calling [Builder.expand] with `expand.orElse(null)`. */ + fun expand(expand: Optional>) = expand(expand.getOrNull()) + + /** + * Adds a single [String] to [Builder.expand]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpand(expand: String) = apply { + this.expand = (this.expand ?: mutableListOf()).apply { add(expand) } + } + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ @@ -186,6 +209,7 @@ private constructor( fun build(): ClassifyGetParams = ClassifyGetParams( jobId, + expand?.toImmutable(), organizationId, projectId, additionalHeaders.build(), @@ -204,6 +228,7 @@ private constructor( override fun _queryParams(): QueryParams = QueryParams.builder() .apply { + expand?.forEach { put("expand", it) } organizationId?.let { put("organization_id", it) } projectId?.let { put("project_id", it) } putAll(additionalQueryParams) @@ -217,6 +242,7 @@ private constructor( return other is ClassifyGetParams && jobId == other.jobId && + expand == other.expand && organizationId == other.organizationId && projectId == other.projectId && additionalHeaders == other.additionalHeaders && @@ -224,8 +250,15 @@ private constructor( } override fun hashCode(): Int = - Objects.hash(jobId, organizationId, projectId, additionalHeaders, additionalQueryParams) + Objects.hash( + jobId, + expand, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = - "ClassifyGetParams{jobId=$jobId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "ClassifyGetParams{jobId=$jobId, expand=$expand, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetResponse.kt index 7d3486f..7dbd24b 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyGetResponse.kt @@ -37,6 +37,7 @@ private constructor( private val result: JsonField, private val transactionId: JsonField, private val updatedAt: JsonField, + private val usage: JsonField, private val additionalProperties: MutableMap, ) { @@ -74,6 +75,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("usage") @ExcludeMissing usage: JsonField = JsonMissing.of(), ) : this( id, configuration, @@ -89,6 +91,7 @@ private constructor( result, transactionId, updatedAt, + usage, mutableMapOf(), ) @@ -205,6 +208,18 @@ private constructor( */ fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usage(): Optional = usage.getOptional("usage") + /** * Returns the raw JSON value of [id]. * @@ -318,6 +333,13 @@ private constructor( @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField = usage + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -366,6 +388,7 @@ private constructor( private var result: JsonField = JsonMissing.of() private var transactionId: JsonField = JsonMissing.of() private var updatedAt: JsonField = JsonMissing.of() + private var usage: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -384,6 +407,7 @@ private constructor( result = classifyGetResponse.result transactionId = classifyGetResponse.transactionId updatedAt = classifyGetResponse.updatedAt + usage = classifyGetResponse.usage additionalProperties = classifyGetResponse.additionalProperties.toMutableMap() } @@ -589,6 +613,26 @@ private constructor( */ fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits + * are the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + fun usage(usage: Usage?) = usage(JsonField.ofNullable(usage)) + + /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */ + fun usage(usage: Optional) = usage(usage.getOrNull()) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed [Usage] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun usage(usage: JsonField) = apply { this.usage = usage } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -642,6 +686,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties.toMutableMap(), ) } @@ -675,6 +720,7 @@ private constructor( result().ifPresent { it.validate() } transactionId() updatedAt() + usage().ifPresent { it.validate() } validated = true } @@ -706,7 +752,8 @@ private constructor( (if (parseJobId.asKnown().isPresent) 1 else 0) + (result.asKnown().getOrNull()?.validity() ?: 0) + (if (transactionId.asKnown().isPresent) 1 else 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (usage.asKnown().getOrNull()?.validity() ?: 0) /** Whether the input was a file or parse job (FILE or PARSE_JOB) */ class DocumentInputType @JsonCreator private constructor(private val value: JsonField) : @@ -1010,6 +1057,230 @@ private constructor( override fun toString() = value.toString() } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val credits: JsonField, + private val parseCredits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credits") @ExcludeMissing credits: JsonField = JsonMissing.of(), + @JsonProperty("parse_credits") + @ExcludeMissing + parseCredits: JsonField = JsonMissing.of(), + ) : this(credits, parseCredits, mutableMapOf()) + + /** + * Total credits billed against this job. Null until billing has recorded it. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun credits(): Optional = credits.getOptional("credits") + + /** + * Credits billed against the parse job Classify ran on the input file + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parseCredits(): Optional = parseCredits.getOptional("parse_credits") + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credits") @ExcludeMissing fun _credits(): JsonField = credits + + /** + * Returns the raw JSON value of [parseCredits]. + * + * Unlike [parseCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("parse_credits") + @ExcludeMissing + fun _parseCredits(): JsonField = parseCredits + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Usage]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Usage]. */ + class Builder internal constructor() { + + private var credits: JsonField = JsonMissing.of() + private var parseCredits: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usage: Usage) = apply { + credits = usage.credits + parseCredits = usage.parseCredits + additionalProperties = usage.additionalProperties.toMutableMap() + } + + /** Total credits billed against this job. Null until billing has recorded it. */ + fun credits(credits: Double?) = credits(JsonField.ofNullable(credits)) + + /** + * Alias for [Builder.credits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun credits(credits: Double) = credits(credits as Double?) + + /** Alias for calling [Builder.credits] with `credits.orElse(null)`. */ + fun credits(credits: Optional) = credits(credits.getOrNull()) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun credits(credits: JsonField) = apply { this.credits = credits } + + /** Credits billed against the parse job Classify ran on the input file */ + fun parseCredits(parseCredits: Double?) = + parseCredits(JsonField.ofNullable(parseCredits)) + + /** + * Alias for [Builder.parseCredits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun parseCredits(parseCredits: Double) = parseCredits(parseCredits as Double?) + + /** Alias for calling [Builder.parseCredits] with `parseCredits.orElse(null)`. */ + fun parseCredits(parseCredits: Optional) = + parseCredits(parseCredits.getOrNull()) + + /** + * Sets [Builder.parseCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.parseCredits] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parseCredits(parseCredits: JsonField) = apply { + this.parseCredits = parseCredits + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Usage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Usage = Usage(credits, parseCredits, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Usage = apply { + if (validated) { + return@apply + } + + credits() + parseCredits() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (credits.asKnown().isPresent) 1 else 0) + + (if (parseCredits.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Usage && + credits == other.credits && + parseCredits == other.parseCredits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(credits, parseCredits, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Usage{credits=$credits, parseCredits=$parseCredits, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1030,6 +1301,7 @@ private constructor( result == other.result && transactionId == other.transactionId && updatedAt == other.updatedAt && + usage == other.usage && additionalProperties == other.additionalProperties } @@ -1049,6 +1321,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties, ) } @@ -1056,5 +1329,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ClassifyGetResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "ClassifyGetResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, usage=$usage, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyListResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyListResponse.kt index 4b4ffc8..49d1279 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyListResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyListResponse.kt @@ -37,6 +37,7 @@ private constructor( private val result: JsonField, private val transactionId: JsonField, private val updatedAt: JsonField, + private val usage: JsonField, private val additionalProperties: MutableMap, ) { @@ -74,6 +75,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("usage") @ExcludeMissing usage: JsonField = JsonMissing.of(), ) : this( id, configuration, @@ -89,6 +91,7 @@ private constructor( result, transactionId, updatedAt, + usage, mutableMapOf(), ) @@ -205,6 +208,18 @@ private constructor( */ fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usage(): Optional = usage.getOptional("usage") + /** * Returns the raw JSON value of [id]. * @@ -318,6 +333,13 @@ private constructor( @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField = usage + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -366,6 +388,7 @@ private constructor( private var result: JsonField = JsonMissing.of() private var transactionId: JsonField = JsonMissing.of() private var updatedAt: JsonField = JsonMissing.of() + private var usage: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -384,6 +407,7 @@ private constructor( result = classifyListResponse.result transactionId = classifyListResponse.transactionId updatedAt = classifyListResponse.updatedAt + usage = classifyListResponse.usage additionalProperties = classifyListResponse.additionalProperties.toMutableMap() } @@ -589,6 +613,26 @@ private constructor( */ fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits + * are the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + fun usage(usage: Usage?) = usage(JsonField.ofNullable(usage)) + + /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */ + fun usage(usage: Optional) = usage(usage.getOrNull()) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed [Usage] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun usage(usage: JsonField) = apply { this.usage = usage } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -642,6 +686,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties.toMutableMap(), ) } @@ -675,6 +720,7 @@ private constructor( result().ifPresent { it.validate() } transactionId() updatedAt() + usage().ifPresent { it.validate() } validated = true } @@ -706,7 +752,8 @@ private constructor( (if (parseJobId.asKnown().isPresent) 1 else 0) + (result.asKnown().getOrNull()?.validity() ?: 0) + (if (transactionId.asKnown().isPresent) 1 else 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (usage.asKnown().getOrNull()?.validity() ?: 0) /** Whether the input was a file or parse job (FILE or PARSE_JOB) */ class DocumentInputType @JsonCreator private constructor(private val value: JsonField) : @@ -1010,6 +1057,230 @@ private constructor( override fun toString() = value.toString() } + /** + * Usage recorded against a classify job. + * + * Classify bills through the parse job it runs on a file input, so that parse job's credits are + * the whole total. A job run on a parse job you created bills nothing of its own: + * ``parse_credits`` is null and ``credits`` is 0. + */ + class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val credits: JsonField, + private val parseCredits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credits") @ExcludeMissing credits: JsonField = JsonMissing.of(), + @JsonProperty("parse_credits") + @ExcludeMissing + parseCredits: JsonField = JsonMissing.of(), + ) : this(credits, parseCredits, mutableMapOf()) + + /** + * Total credits billed against this job. Null until billing has recorded it. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun credits(): Optional = credits.getOptional("credits") + + /** + * Credits billed against the parse job Classify ran on the input file + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parseCredits(): Optional = parseCredits.getOptional("parse_credits") + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credits") @ExcludeMissing fun _credits(): JsonField = credits + + /** + * Returns the raw JSON value of [parseCredits]. + * + * Unlike [parseCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("parse_credits") + @ExcludeMissing + fun _parseCredits(): JsonField = parseCredits + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Usage]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Usage]. */ + class Builder internal constructor() { + + private var credits: JsonField = JsonMissing.of() + private var parseCredits: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usage: Usage) = apply { + credits = usage.credits + parseCredits = usage.parseCredits + additionalProperties = usage.additionalProperties.toMutableMap() + } + + /** Total credits billed against this job. Null until billing has recorded it. */ + fun credits(credits: Double?) = credits(JsonField.ofNullable(credits)) + + /** + * Alias for [Builder.credits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun credits(credits: Double) = credits(credits as Double?) + + /** Alias for calling [Builder.credits] with `credits.orElse(null)`. */ + fun credits(credits: Optional) = credits(credits.getOrNull()) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun credits(credits: JsonField) = apply { this.credits = credits } + + /** Credits billed against the parse job Classify ran on the input file */ + fun parseCredits(parseCredits: Double?) = + parseCredits(JsonField.ofNullable(parseCredits)) + + /** + * Alias for [Builder.parseCredits]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun parseCredits(parseCredits: Double) = parseCredits(parseCredits as Double?) + + /** Alias for calling [Builder.parseCredits] with `parseCredits.orElse(null)`. */ + fun parseCredits(parseCredits: Optional) = + parseCredits(parseCredits.getOrNull()) + + /** + * Sets [Builder.parseCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.parseCredits] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parseCredits(parseCredits: JsonField) = apply { + this.parseCredits = parseCredits + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Usage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Usage = Usage(credits, parseCredits, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Usage = apply { + if (validated) { + return@apply + } + + credits() + parseCredits() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (credits.asKnown().isPresent) 1 else 0) + + (if (parseCredits.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Usage && + credits == other.credits && + parseCredits == other.parseCredits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(credits, parseCredits, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Usage{credits=$credits, parseCredits=$parseCredits, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1030,6 +1301,7 @@ private constructor( result == other.result && transactionId == other.transactionId && updatedAt == other.updatedAt && + usage == other.usage && additionalProperties == other.additionalProperties } @@ -1049,6 +1321,7 @@ private constructor( result, transactionId, updatedAt, + usage, additionalProperties, ) } @@ -1056,5 +1329,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ClassifyListResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "ClassifyListResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, configurationId=$configurationId, createdAt=$createdAt, errorMessage=$errorMessage, parseJobId=$parseJobId, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, usage=$usage, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/configurations/ExtractV2Parameters.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/configurations/ExtractV2Parameters.kt index 3af6d57..2fcdb01 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/configurations/ExtractV2Parameters.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/configurations/ExtractV2Parameters.kt @@ -26,6 +26,7 @@ class ExtractV2Parameters private constructor( private val dataSchema: JsonField, private val productType: JsonValue, + private val advancedCitations: JsonField, private val citeSources: JsonField, private val confidenceScores: JsonField, private val disableCache: JsonField, @@ -48,6 +49,9 @@ private constructor( @ExcludeMissing dataSchema: JsonField = JsonMissing.of(), @JsonProperty("product_type") @ExcludeMissing productType: JsonValue = JsonMissing.of(), + @JsonProperty("advanced_citations") + @ExcludeMissing + advancedCitations: JsonField = JsonMissing.of(), @JsonProperty("cite_sources") @ExcludeMissing citeSources: JsonField = JsonMissing.of(), @@ -84,6 +88,7 @@ private constructor( ) : this( dataSchema, productType, + advancedCitations, citeSources, confidenceScores, disableCache, @@ -122,6 +127,15 @@ private constructor( */ @JsonProperty("product_type") @ExcludeMissing fun _productType(): JsonValue = productType + /** + * More precise citation bounding boxes. Set to false for faster extraction with less precise + * boxes. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun advancedCitations(): Optional = advancedCitations.getOptional("advanced_citations") + /** * Include citations in results. Returned under `extract_metadata` (auto-included when set). * Text-level on `turbo` (no bounding boxes). @@ -253,6 +267,16 @@ private constructor( @ExcludeMissing fun _dataSchema(): JsonField = dataSchema + /** + * Returns the raw JSON value of [advancedCitations]. + * + * Unlike [advancedCitations], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("advanced_citations") + @ExcludeMissing + fun _advancedCitations(): JsonField = advancedCitations + /** * Returns the raw JSON value of [citeSources]. * @@ -394,6 +418,7 @@ private constructor( private var dataSchema: JsonField? = null private var productType: JsonValue = JsonValue.from("extract_v2") + private var advancedCitations: JsonField = JsonMissing.of() private var citeSources: JsonField = JsonMissing.of() private var confidenceScores: JsonField = JsonMissing.of() private var disableCache: JsonField = JsonMissing.of() @@ -413,6 +438,7 @@ private constructor( internal fun from(extractV2Parameters: ExtractV2Parameters) = apply { dataSchema = extractV2Parameters.dataSchema productType = extractV2Parameters.productType + advancedCitations = extractV2Parameters.advancedCitations citeSources = extractV2Parameters.citeSources confidenceScores = extractV2Parameters.confidenceScores disableCache = extractV2Parameters.disableCache @@ -458,6 +484,24 @@ private constructor( */ fun productType(productType: JsonValue) = apply { this.productType = productType } + /** + * More precise citation bounding boxes. Set to false for faster extraction with less + * precise boxes. + */ + fun advancedCitations(advancedCitations: Boolean) = + advancedCitations(JsonField.of(advancedCitations)) + + /** + * Sets [Builder.advancedCitations] to an arbitrary JSON value. + * + * You should usually call [Builder.advancedCitations] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun advancedCitations(advancedCitations: JsonField) = apply { + this.advancedCitations = advancedCitations + } + /** * Include citations in results. Returned under `extract_metadata` (auto-included when set). * Text-level on `turbo` (no bounding boxes). @@ -741,6 +785,7 @@ private constructor( ExtractV2Parameters( checkRequired("dataSchema", dataSchema), productType, + advancedCitations, citeSources, confidenceScores, disableCache, @@ -779,6 +824,7 @@ private constructor( throw LlamaCloudInvalidDataException("'productType' is invalid, received $it") } } + advancedCitations() citeSources() confidenceScores() disableCache() @@ -812,6 +858,7 @@ private constructor( internal fun validity(): Int = (dataSchema.asKnown().getOrNull()?.validity() ?: 0) + productType.let { if (it == JsonValue.from("extract_v2")) 1 else 0 } + + (if (advancedCitations.asKnown().isPresent) 1 else 0) + (if (citeSources.asKnown().isPresent) 1 else 0) + (if (confidenceScores.asKnown().isPresent) 1 else 0) + (if (disableCache.asKnown().isPresent) 1 else 0) + @@ -1404,6 +1451,7 @@ private constructor( return other is ExtractV2Parameters && dataSchema == other.dataSchema && productType == other.productType && + advancedCitations == other.advancedCitations && citeSources == other.citeSources && confidenceScores == other.confidenceScores && disableCache == other.disableCache && @@ -1424,6 +1472,7 @@ private constructor( Objects.hash( dataSchema, productType, + advancedCitations, citeSources, confidenceScores, disableCache, @@ -1444,5 +1493,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ExtractV2Parameters{dataSchema=$dataSchema, productType=$productType, citeSources=$citeSources, confidenceScores=$confidenceScores, disableCache=$disableCache, extractionTarget=$extractionTarget, maxPages=$maxPages, parseConfigId=$parseConfigId, parseTier=$parseTier, sheetNames=$sheetNames, spreadsheetMode=$spreadsheetMode, systemPrompt=$systemPrompt, targetPages=$targetPages, tier=$tier, version=$version, additionalProperties=$additionalProperties}" + "ExtractV2Parameters{dataSchema=$dataSchema, productType=$productType, advancedCitations=$advancedCitations, citeSources=$citeSources, confidenceScores=$confidenceScores, disableCache=$disableCache, extractionTarget=$extractionTarget, maxPages=$maxPages, parseConfigId=$parseConfigId, parseTier=$parseTier, sheetNames=$sheetNames, spreadsheetMode=$spreadsheetMode, systemPrompt=$systemPrompt, targetPages=$targetPages, tier=$tier, version=$version, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractConfiguration.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractConfiguration.kt index 241749e..2ad6723 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractConfiguration.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractConfiguration.kt @@ -25,6 +25,7 @@ class ExtractConfiguration @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dataSchema: JsonField, + private val advancedCitations: JsonField, private val citeSources: JsonField, private val confidenceScores: JsonField, private val disableCache: JsonField, @@ -46,6 +47,9 @@ private constructor( @JsonProperty("data_schema") @ExcludeMissing dataSchema: JsonField = JsonMissing.of(), + @JsonProperty("advanced_citations") + @ExcludeMissing + advancedCitations: JsonField = JsonMissing.of(), @JsonProperty("cite_sources") @ExcludeMissing citeSources: JsonField = JsonMissing.of(), @@ -81,6 +85,7 @@ private constructor( @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), ) : this( dataSchema, + advancedCitations, citeSources, confidenceScores, disableCache, @@ -106,6 +111,15 @@ private constructor( */ fun dataSchema(): DataSchema = dataSchema.getRequired("data_schema") + /** + * More precise citation bounding boxes. Set to false for faster extraction with less precise + * boxes. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun advancedCitations(): Optional = advancedCitations.getOptional("advanced_citations") + /** * Include citations in results. Returned under `extract_metadata` (auto-included when set). * Text-level on `turbo` (no bounding boxes). @@ -237,6 +251,16 @@ private constructor( @ExcludeMissing fun _dataSchema(): JsonField = dataSchema + /** + * Returns the raw JSON value of [advancedCitations]. + * + * Unlike [advancedCitations], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("advanced_citations") + @ExcludeMissing + fun _advancedCitations(): JsonField = advancedCitations + /** * Returns the raw JSON value of [citeSources]. * @@ -377,6 +401,7 @@ private constructor( class Builder internal constructor() { private var dataSchema: JsonField? = null + private var advancedCitations: JsonField = JsonMissing.of() private var citeSources: JsonField = JsonMissing.of() private var confidenceScores: JsonField = JsonMissing.of() private var disableCache: JsonField = JsonMissing.of() @@ -395,6 +420,7 @@ private constructor( @JvmSynthetic internal fun from(extractConfiguration: ExtractConfiguration) = apply { dataSchema = extractConfiguration.dataSchema + advancedCitations = extractConfiguration.advancedCitations citeSources = extractConfiguration.citeSources confidenceScores = extractConfiguration.confidenceScores disableCache = extractConfiguration.disableCache @@ -426,6 +452,24 @@ private constructor( */ fun dataSchema(dataSchema: JsonField) = apply { this.dataSchema = dataSchema } + /** + * More precise citation bounding boxes. Set to false for faster extraction with less + * precise boxes. + */ + fun advancedCitations(advancedCitations: Boolean) = + advancedCitations(JsonField.of(advancedCitations)) + + /** + * Sets [Builder.advancedCitations] to an arbitrary JSON value. + * + * You should usually call [Builder.advancedCitations] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun advancedCitations(advancedCitations: JsonField) = apply { + this.advancedCitations = advancedCitations + } + /** * Include citations in results. Returned under `extract_metadata` (auto-included when set). * Text-level on `turbo` (no bounding boxes). @@ -708,6 +752,7 @@ private constructor( fun build(): ExtractConfiguration = ExtractConfiguration( checkRequired("dataSchema", dataSchema), + advancedCitations, citeSources, confidenceScores, disableCache, @@ -741,6 +786,7 @@ private constructor( } dataSchema().validate() + advancedCitations() citeSources() confidenceScores() disableCache() @@ -773,6 +819,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (dataSchema.asKnown().getOrNull()?.validity() ?: 0) + + (if (advancedCitations.asKnown().isPresent) 1 else 0) + (if (citeSources.asKnown().isPresent) 1 else 0) + (if (confidenceScores.asKnown().isPresent) 1 else 0) + (if (disableCache.asKnown().isPresent) 1 else 0) + @@ -1364,6 +1411,7 @@ private constructor( return other is ExtractConfiguration && dataSchema == other.dataSchema && + advancedCitations == other.advancedCitations && citeSources == other.citeSources && confidenceScores == other.confidenceScores && disableCache == other.disableCache && @@ -1383,6 +1431,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( dataSchema, + advancedCitations, citeSources, confidenceScores, disableCache, @@ -1403,5 +1452,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ExtractConfiguration{dataSchema=$dataSchema, citeSources=$citeSources, confidenceScores=$confidenceScores, disableCache=$disableCache, extractionTarget=$extractionTarget, maxPages=$maxPages, parseConfigId=$parseConfigId, parseTier=$parseTier, sheetNames=$sheetNames, spreadsheetMode=$spreadsheetMode, systemPrompt=$systemPrompt, targetPages=$targetPages, tier=$tier, version=$version, additionalProperties=$additionalProperties}" + "ExtractConfiguration{dataSchema=$dataSchema, advancedCitations=$advancedCitations, citeSources=$citeSources, confidenceScores=$confidenceScores, disableCache=$disableCache, extractionTarget=$extractionTarget, maxPages=$maxPages, parseConfigId=$parseConfigId, parseTier=$parseTier, sheetNames=$sheetNames, spreadsheetMode=$spreadsheetMode, systemPrompt=$systemPrompt, targetPages=$targetPages, tier=$tier, version=$version, additionalProperties=$additionalProperties}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/parsing/Form.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/parsing/Form.kt index 829db40..a34443d 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/parsing/Form.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/parsing/Form.kt @@ -4,7 +4,6 @@ package ai.llamaindex.llamacloud.models.parsing import ai.llamaindex.llamacloud.core.BaseDeserializer import ai.llamaindex.llamacloud.core.BaseSerializer -import ai.llamaindex.llamacloud.core.Enum import ai.llamaindex.llamacloud.core.ExcludeMissing import ai.llamaindex.llamacloud.core.JsonField import ai.llamaindex.llamacloud.core.JsonMissing @@ -46,7 +45,7 @@ private constructor( ) : this(json, list, mutableMapOf()) /** - * Structured representation: an ordered tree of sections, fields, and tables + * Structured representation: an ordered tree of sections, fields, tables, and text * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -115,7 +114,7 @@ private constructor( additionalProperties = form.additionalProperties.toMutableMap() } - /** Structured representation: an ordered tree of sections, fields, and tables */ + /** Structured representation: an ordered tree of sections, fields, tables, and text */ fun json(json: List) = json(JsonField.of(json)) /** @@ -186,19 +185,19 @@ private constructor( addJson(FormTable.builder().type(FormTable.Type.TABLE).rows(rows).build()) /** Alias for calling [addJson] with `Json.ofText(text)`. */ - fun addJson(text: Json.Text) = addJson(Json.ofText(text)) + fun addJson(text: FormText) = addJson(Json.ofText(text)) /** * Alias for calling [addJson] with the following: * ```java - * Json.Text.builder() - * .type(Form.Json.Text.Type.TEXT) + * FormText.builder() + * .type(FormText.Type.TEXT) * .value(value) * .build() * ``` */ fun addTextJson(value: String) = - addJson(Json.Text.builder().type(Form.Json.Text.Type.TEXT).value(value).build()) + addJson(FormText.builder().type(FormText.Type.TEXT).value(value).build()) /** Flattened list representation of the same content */ fun list(list: FormListItem) = list(JsonField.of(list)) @@ -298,7 +297,7 @@ private constructor( private val field: FormField? = null, private val section: FormSection? = null, private val table: FormTable? = null, - private val text: Text? = null, + private val text: FormText? = null, private val _json: JsonValue? = null, ) { @@ -315,7 +314,7 @@ private constructor( * Printed text that is not part of a field, section heading or table: a title, an * instruction, a note. With it the form JSON holds every printed word of its region. */ - fun text(): Optional = Optional.ofNullable(text) + fun text(): Optional = Optional.ofNullable(text) fun isField(): Boolean = field != null @@ -338,7 +337,7 @@ private constructor( * Printed text that is not part of a field, section heading or table: a title, an * instruction, a note. With it the form JSON holds every printed word of its region. */ - fun asText(): Text = text.getOrThrow("text") + fun asText(): FormText = text.getOrThrow("text") fun _json(): Optional = Optional.ofNullable(_json) @@ -410,7 +409,7 @@ private constructor( table.validate() } - override fun visitText(text: Text) { + override fun visitText(text: FormText) { text.validate() } } @@ -442,7 +441,7 @@ private constructor( override fun visitTable(table: FormTable) = table.validity() - override fun visitText(text: Text) = text.validity() + override fun visitText(text: FormText) = text.validity() override fun unknown(json: JsonValue?) = 0 } @@ -487,7 +486,7 @@ private constructor( * Printed text that is not part of a field, section heading or table: a title, an * instruction, a note. With it the form JSON holds every printed word of its region. */ - @JvmStatic fun ofText(text: Text) = Json(text = text) + @JvmStatic fun ofText(text: FormText) = Json(text = text) } /** An interface that defines how to map each variant of [Json] to a value of type [T]. */ @@ -506,7 +505,7 @@ private constructor( * Printed text that is not part of a field, section heading or table: a title, an * instruction, a note. With it the form JSON holds every printed word of its region. */ - fun visitText(text: Text): T + fun visitText(text: FormText): T /** * Maps an unknown variant of [Json] to a value of type [T]. @@ -545,7 +544,7 @@ private constructor( } ?: Json(_json = json) } "text" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Json(text = it, _json = json) } ?: Json(_json = json) } @@ -572,2972 +571,6 @@ private constructor( } } } - - /** - * Printed text that is not part of a field, section heading or table: a title, an - * instruction, a note. With it the form JSON holds every printed word of its region. - */ - class Text - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val value: JsonField, - private val bbox: JsonField>, - private val grounding: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), - @JsonProperty("bbox") - @ExcludeMissing - bbox: JsonField> = JsonMissing.of(), - @JsonProperty("grounding") - @ExcludeMissing - grounding: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(value, bbox, grounding, type, mutableMapOf()) - - /** - * The printed text, verbatim - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun value(): String = value.getRequired("value") - - /** - * Bounding boxes of the text on the page, if attributed. - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun bbox(): Optional> = bbox.getOptional("bbox") - - /** - * Optional grounding for a field's printed text; boolean states have no text spans. - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun grounding(): Optional = grounding.getOptional("grounding") - - /** - * Form text node - * - * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun type(): Optional = type.getOptional("type") - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - /** - * Returns the raw JSON value of [bbox]. - * - * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox - - /** - * Returns the raw JSON value of [grounding]. - * - * Unlike [grounding], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("grounding") - @ExcludeMissing - fun _grounding(): JsonField = grounding - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Text]. - * - * The following fields are required: - * ```java - * .value() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Text]. */ - class Builder internal constructor() { - - private var value: JsonField? = null - private var bbox: JsonField>? = null - private var grounding: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(text: Text) = apply { - value = text.value - bbox = text.bbox.map { it.toMutableList() } - grounding = text.grounding - type = text.type - additionalProperties = text.additionalProperties.toMutableMap() - } - - /** The printed text, verbatim */ - fun value(value: String) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Bounding boxes of the text on the page, if attributed. */ - fun bbox(bbox: List?) = bbox(JsonField.ofNullable(bbox)) - - /** Alias for calling [Builder.bbox] with `bbox.orElse(null)`. */ - fun bbox(bbox: Optional>) = bbox(bbox.getOrNull()) - - /** - * Sets [Builder.bbox] to an arbitrary JSON value. - * - * You should usually call [Builder.bbox] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun bbox(bbox: JsonField>) = apply { - this.bbox = bbox.map { it.toMutableList() } - } - - /** - * Adds a single [BBox] to [Builder.bbox]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addBbox(bbox: BBox) = apply { - this.bbox = - (this.bbox ?: JsonField.of(mutableListOf())).also { - checkKnown("bbox", it).add(bbox) - } - } - - /** - * Optional grounding for a field's printed text; boolean states have no text spans. - */ - fun grounding(grounding: Grounding?) = grounding(JsonField.ofNullable(grounding)) - - /** Alias for calling [Builder.grounding] with `grounding.orElse(null)`. */ - fun grounding(grounding: Optional) = grounding(grounding.getOrNull()) - - /** - * Sets [Builder.grounding] to an arbitrary JSON value. - * - * You should usually call [Builder.grounding] with a well-typed [Grounding] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun grounding(grounding: JsonField) = apply { - this.grounding = grounding - } - - /** Form text node */ - fun type(type: Type) = type(JsonField.of(type)) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [Type] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Text]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .value() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Text = - Text( - checkRequired("value", value), - (bbox ?: JsonMissing.of()).map { it.toImmutable() }, - grounding, - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws LlamaCloudInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Text = apply { - if (validated) { - return@apply - } - - value() - bbox().ifPresent { it.forEach { it.validate() } } - grounding().ifPresent { it.validate() } - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LlamaCloudInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (if (value.asKnown().isPresent) 1 else 0) + - (bbox.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (grounding.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - /** Optional grounding for a field's printed text; boolean states have no text spans. */ - class Grounding - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val label: JsonField