diff --git a/langsmith-java-core/src/main/kotlin/com/langchain/smith/models/sessions/CustomChartsSection.kt b/langsmith-java-core/src/main/kotlin/com/langchain/smith/models/sessions/CustomChartsSection.kt index 0d7e32b7..094d6dd0 100644 --- a/langsmith-java-core/src/main/kotlin/com/langchain/smith/models/sessions/CustomChartsSection.kt +++ b/langsmith-java-core/src/main/kotlin/com/langchain/smith/models/sessions/CustomChartsSection.kt @@ -256,6 +256,16 @@ private constructor( } } + /** + * Alias for calling [addChart] with + * `Chart.ofSingleCustomChartResponse(singleCustomChartResponse)`. + */ + fun addChart(singleCustomChartResponse: Chart.SingleCustomChartResponse) = + addChart(Chart.ofSingleCustomChartResponse(singleCustomChartResponse)) + + /** Alias for calling [addChart] with `Chart.ofText(text)`. */ + fun addChart(text: Chart.Text) = addChart(Chart.ofText(text)) + fun title(title: String) = title(JsonField.of(title)) /** @@ -454,433 +464,68 @@ private constructor( (if (sessionId.asKnown().isPresent) 1 else 0) + (subSections.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + @JsonDeserialize(using = Chart.Deserializer::class) + @JsonSerialize(using = Chart.Serializer::class) class Chart - @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val id: JsonField, - private val chartType: JsonField, - private val data: JsonField>, - private val index: JsonField, - private val series: JsonField>, - private val title: JsonField, - private val commonFilters: JsonField, - private val description: JsonField, - private val metadata: JsonField, - private val additionalProperties: MutableMap, + private val singleCustomChartResponse: SingleCustomChartResponse? = null, + private val text: Text? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("chart_type") - @ExcludeMissing - chartType: JsonField = JsonMissing.of(), - @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), - @JsonProperty("index") @ExcludeMissing index: JsonField = JsonMissing.of(), - @JsonProperty("series") - @ExcludeMissing - series: JsonField> = JsonMissing.of(), - @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), - @JsonProperty("common_filters") - @ExcludeMissing - commonFilters: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of(), - ) : this( - id, - chartType, - data, - index, - series, - title, - commonFilters, - description, - metadata, - mutableMapOf(), - ) + fun singleCustomChartResponse(): Optional = + Optional.ofNullable(singleCustomChartResponse) + + fun text(): Optional = Optional.ofNullable(text) + + fun isSingleCustomChartResponse(): Boolean = singleCustomChartResponse != null + + fun isText(): Boolean = text != null + + fun asSingleCustomChartResponse(): SingleCustomChartResponse = + singleCustomChartResponse.getOrThrow("singleCustomChartResponse") + + fun asText(): Text = text.getOrThrow("text") + + fun _json(): Optional = Optional.ofNullable(_json) /** - * @throws LangChainInvalidDataException 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 id(): String = id.getRequired("id") - - /** - * Enum for custom chart types. + * Maps this instance's current variant to a value of type [T] using the given [visitor]. * - * @throws LangChainInvalidDataException 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 chartType(): ChartType = chartType.getRequired("chart_type") - - /** - * @throws LangChainInvalidDataException 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 data(): List = data.getRequired("data") - - /** - * @throws LangChainInvalidDataException 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 index(): Long = index.getRequired("index") - - /** - * @throws LangChainInvalidDataException 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 series(): List = series.getRequired("series") - - /** - * @throws LangChainInvalidDataException 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 title(): String = title.getRequired("title") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun commonFilters(): Optional = commonFilters.getOptional("common_filters") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = description.getOptional("description") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun metadata(): Optional = metadata.getOptional("metadata") - - /** - * Returns the raw JSON value of [id]. + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - - /** - * Returns the raw JSON value of [chartType]. + * Optional result = chart.accept(new Chart.Visitor>() { + * @Override + * public Optional visitSingleCustomChartResponse(SingleCustomChartResponse singleCustomChartResponse) { + * return Optional.of(singleCustomChartResponse.toString()); + * } * - * Unlike [chartType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("chart_type") - @ExcludeMissing - fun _chartType(): JsonField = chartType - - /** - * Returns the raw JSON value of [data]. + * // ... * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data - - /** - * Returns the raw JSON value of [index]. + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` * - * Unlike [index], this method doesn't throw if the JSON field has an unexpected type. + * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. */ - @JsonProperty("index") @ExcludeMissing fun _index(): JsonField = index - - /** - * Returns the raw JSON value of [series]. - * - * Unlike [series], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("series") @ExcludeMissing fun _series(): JsonField> = series - - /** - * Returns the raw JSON value of [title]. - * - * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title - - /** - * Returns the raw JSON value of [commonFilters]. - * - * Unlike [commonFilters], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("common_filters") - @ExcludeMissing - fun _commonFilters(): JsonField = commonFilters - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - @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 [Chart]. - * - * The following fields are required: - * ```java - * .id() - * .chartType() - * .data() - * .index() - * .series() - * .title() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Chart]. */ - class Builder internal constructor() { - - private var id: JsonField? = null - private var chartType: JsonField? = null - private var data: JsonField>? = null - private var index: JsonField? = null - private var series: JsonField>? = null - private var title: JsonField? = null - private var commonFilters: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(chart: Chart) = apply { - id = chart.id - chartType = chart.chartType - data = chart.data.map { it.toMutableList() } - index = chart.index - series = chart.series.map { it.toMutableList() } - title = chart.title - commonFilters = chart.commonFilters - description = chart.description - metadata = chart.metadata - additionalProperties = chart.additionalProperties.toMutableMap() + fun accept(visitor: Visitor): T = + when { + singleCustomChartResponse != null -> + visitor.visitSingleCustomChartResponse(singleCustomChartResponse) + text != null -> visitor.visitText(text) + else -> visitor.unknown(_json) } - fun id(id: String) = id(JsonField.of(id)) - - /** - * Sets [Builder.id] to an arbitrary JSON value. - * - * You should usually call [Builder.id] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun id(id: JsonField) = apply { this.id = id } - - /** Enum for custom chart types. */ - fun chartType(chartType: ChartType) = chartType(JsonField.of(chartType)) - - /** - * Sets [Builder.chartType] to an arbitrary JSON value. - * - * You should usually call [Builder.chartType] with a well-typed [ChartType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun chartType(chartType: JsonField) = apply { this.chartType = chartType } - - fun data(data: List) = data(JsonField.of(data)) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed `List` 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.map { it.toMutableList() } - } - - /** - * Adds a single [Data] to [Builder.data]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addData(data: Data) = apply { - this.data = - (this.data ?: JsonField.of(mutableListOf())).also { - checkKnown("data", it).add(data) - } - } - - fun index(index: Long) = index(JsonField.of(index)) - - /** - * Sets [Builder.index] to an arbitrary JSON value. - * - * You should usually call [Builder.index] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun index(index: JsonField) = apply { this.index = index } - - fun series(series: List) = series(JsonField.of(series)) - - /** - * Sets [Builder.series] to an arbitrary JSON value. - * - * You should usually call [Builder.series] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun series(series: JsonField>) = apply { - this.series = series.map { it.toMutableList() } - } - - /** - * Adds a single [Series] to [Builder.series]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addSeries(series: Series) = apply { - this.series = - (this.series ?: JsonField.of(mutableListOf())).also { - checkKnown("series", it).add(series) - } - } - - fun title(title: String) = title(JsonField.of(title)) - - /** - * Sets [Builder.title] to an arbitrary JSON value. - * - * You should usually call [Builder.title] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun title(title: JsonField) = apply { this.title = title } - - fun commonFilters(commonFilters: CommonFilters?) = - commonFilters(JsonField.ofNullable(commonFilters)) - - /** Alias for calling [Builder.commonFilters] with `commonFilters.orElse(null)`. */ - fun commonFilters(commonFilters: Optional) = - commonFilters(commonFilters.getOrNull()) - - /** - * Sets [Builder.commonFilters] to an arbitrary JSON value. - * - * You should usually call [Builder.commonFilters] with a well-typed [CommonFilters] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun commonFilters(commonFilters: JsonField) = apply { - this.commonFilters = commonFilters - } - - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * 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) - } - - 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 [Chart]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .id() - * .chartType() - * .data() - * .index() - * .series() - * .title() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Chart = - Chart( - checkRequired("id", id), - checkRequired("chartType", chartType), - checkRequired("data", data).map { it.toImmutable() }, - checkRequired("index", index), - checkRequired("series", series).map { it.toImmutable() }, - checkRequired("title", title), - commonFilters, - description, - metadata, - additionalProperties.toMutableMap(), - ) - } - private var validated: Boolean = false /** @@ -897,15 +542,19 @@ private constructor( return@apply } - id() - chartType().validate() - data().forEach { it.validate() } - index() - series().forEach { it.validate() } - title() - commonFilters().ifPresent { it.validate() } - description() - metadata().ifPresent { it.validate() } + accept( + object : Visitor { + override fun visitSingleCustomChartResponse( + singleCustomChartResponse: SingleCustomChartResponse + ) { + singleCustomChartResponse.validate() + } + + override fun visitText(text: Text) { + text.validate() + } + } + ) validated = true } @@ -925,882 +574,156 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (id.asKnown().isPresent) 1 else 0) + - (chartType.asKnown().getOrNull()?.validity() ?: 0) + - (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (index.asKnown().isPresent) 1 else 0) + - (series.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (title.asKnown().isPresent) 1 else 0) + - (commonFilters.asKnown().getOrNull()?.validity() ?: 0) + - (if (description.asKnown().isPresent) 1 else 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + accept( + object : Visitor { + override fun visitSingleCustomChartResponse( + singleCustomChartResponse: SingleCustomChartResponse + ) = singleCustomChartResponse.validity() - /** Enum for custom chart types. */ - class ChartType @JsonCreator private constructor(private val value: JsonField) : - Enum { + override fun visitText(text: Text) = text.validity() - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + override fun unknown(json: JsonValue?) = 0 + } + ) - companion object { - - @JvmField val LINE = of("line") - - @JvmField val BAR = of("bar") - - @JvmField val TABLE = of("table") - - @JvmField val KPI = of("kpi") - - @JvmField val TOP_K = of("top-k") - - @JvmField val PIE = of("pie") - - @JvmStatic fun of(value: String) = ChartType(JsonField.of(value)) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - /** An enum containing [ChartType]'s known values. */ - enum class Known { - LINE, - BAR, - TABLE, - KPI, - TOP_K, - PIE, - } - - /** - * An enum containing [ChartType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ChartType] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - LINE, - BAR, - TABLE, - KPI, - TOP_K, - PIE, - /** - * An enum member indicating that [ChartType] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LINE -> Value.LINE - BAR -> Value.BAR - TABLE -> Value.TABLE - KPI -> Value.KPI - TOP_K -> Value.TOP_K - PIE -> Value.PIE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - LINE -> Known.LINE - BAR -> Known.BAR - TABLE -> Known.TABLE - KPI -> Known.KPI - TOP_K -> Known.TOP_K - PIE -> Known.PIE - else -> throw LangChainInvalidDataException("Unknown ChartType: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): ChartType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ChartType && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() + return other is Chart && + singleCustomChartResponse == other.singleCustomChartResponse && + text == other.text } - class Data - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val seriesId: JsonField, - private val timestamp: JsonField, - private val value: JsonField, - private val group: JsonField, - private val additionalProperties: MutableMap, - ) { + override fun hashCode(): Int = Objects.hash(singleCustomChartResponse, text) - @JsonCreator - private constructor( - @JsonProperty("series_id") - @ExcludeMissing - seriesId: JsonField = JsonMissing.of(), - @JsonProperty("timestamp") - @ExcludeMissing - timestamp: JsonField = JsonMissing.of(), - @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), - @JsonProperty("group") @ExcludeMissing group: JsonField = JsonMissing.of(), - ) : this(seriesId, timestamp, value, group, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 seriesId(): String = seriesId.getRequired("series_id") - - /** - * @throws LangChainInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun group(): Optional = group.getOptional("group") - - /** - * Returns the raw JSON value of [seriesId]. - * - * Unlike [seriesId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("series_id") @ExcludeMissing fun _seriesId(): JsonField = seriesId - - /** - * Returns the raw JSON value of [timestamp]. - * - * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("timestamp") - @ExcludeMissing - fun _timestamp(): JsonField = timestamp - - /** - * 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 [group]. - * - * Unlike [group], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) + override fun toString(): String = + when { + singleCustomChartResponse != null -> + "Chart{singleCustomChartResponse=$singleCustomChartResponse}" + text != null -> "Chart{text=$text}" + _json != null -> "Chart{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Chart") } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + companion object { - fun toBuilder() = Builder().from(this) + @JvmStatic + fun ofSingleCustomChartResponse(singleCustomChartResponse: SingleCustomChartResponse) = + Chart(singleCustomChartResponse = singleCustomChartResponse) - companion object { + @JvmStatic fun ofText(text: Text) = Chart(text = text) + } - /** - * Returns a mutable builder for constructing an instance of [Data]. - * - * The following fields are required: - * ```java - * .seriesId() - * .timestamp() - * .value() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** An interface that defines how to map each variant of [Chart] to a value of type [T]. */ + interface Visitor { - /** A builder for [Data]. */ - class Builder internal constructor() { + fun visitSingleCustomChartResponse( + singleCustomChartResponse: SingleCustomChartResponse + ): T - private var seriesId: JsonField? = null - private var timestamp: JsonField? = null - private var value: JsonField? = null - private var group: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(data: Data) = apply { - seriesId = data.seriesId - timestamp = data.timestamp - value = data.value - group = data.group - additionalProperties = data.additionalProperties.toMutableMap() - } - - fun seriesId(seriesId: String) = seriesId(JsonField.of(seriesId)) - - /** - * Sets [Builder.seriesId] to an arbitrary JSON value. - * - * You should usually call [Builder.seriesId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun seriesId(seriesId: JsonField) = apply { this.seriesId = seriesId } - - fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) - - /** - * Sets [Builder.timestamp] to an arbitrary JSON value. - * - * You should usually call [Builder.timestamp] with a well-typed [OffsetDateTime] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun timestamp(timestamp: JsonField) = apply { - this.timestamp = timestamp - } - - fun value(value: Value?) = value(JsonField.ofNullable(value)) - - /** Alias for calling [Builder.value] with `value.orElse(null)`. */ - fun value(value: Optional) = value(value.getOrNull()) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] 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 } - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Double) = value(Value.ofNumber(number)) - - /** Alias for calling [value] with `Value.ofUnionMember1(unionMember1)`. */ - fun value(unionMember1: Value.UnionMember1) = - value(Value.ofUnionMember1(unionMember1)) - - fun group(group: String?) = group(JsonField.ofNullable(group)) - - /** Alias for calling [Builder.group] with `group.orElse(null)`. */ - fun group(group: Optional) = group(group.getOrNull()) - - /** - * Sets [Builder.group] to an arbitrary JSON value. - * - * You should usually call [Builder.group] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun group(group: JsonField) = apply { this.group = group } - - 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 [Data]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .seriesId() - * .timestamp() - * .value() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Data = - Data( - checkRequired("seriesId", seriesId), - checkRequired("timestamp", timestamp), - checkRequired("value", value), - group, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false + fun visitText(text: Text): T /** - * Validates that the types of all values in this object match their expected types - * recursively. + * Maps an unknown variant of [Chart] to a value of type [T]. * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. + * An instance of [Chart] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. * - * @throws LangChainInvalidDataException if any value type in this object doesn't match - * its expected type. + * @throws LangChainInvalidDataException in the default implementation. */ - fun validate(): Data = apply { - if (validated) { - return@apply - } - - seriesId() - timestamp() - value().ifPresent { it.validate() } - group() - validated = true + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown Chart: $json") } + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - false + internal class Deserializer : BaseDeserializer(Chart::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Chart { + val json = JsonValue.fromJsonNode(node) + val chartType = + json.asObject().getOrNull()?.get("chart_type")?.asString()?.getOrNull() + + if (chartType == "text") { + return tryDeserialize(node, jacksonTypeRef())?.let { + Chart(text = it, _json = json) + } ?: Chart(_json = json) } - /** - * 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 (seriesId.asKnown().isPresent) 1 else 0) + - (if (timestamp.asKnown().isPresent) 1 else 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) + - (if (group.asKnown().isPresent) 1 else 0) + return tryDeserialize(node, jacksonTypeRef())?.let { + Chart(singleCustomChartResponse = it, _json = json) + } ?: Chart(_json = json) + } + } - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val number: Double? = null, - private val unionMember1: UnionMember1? = null, - private val _json: JsonValue? = null, + internal class Serializer : BaseSerializer(Chart::class) { + + override fun serialize( + value: Chart, + generator: JsonGenerator, + provider: SerializerProvider, ) { - - fun number(): Optional = Optional.ofNullable(number) - - fun unionMember1(): Optional = Optional.ofNullable(unionMember1) - - fun isNumber(): Boolean = number != null - - fun isUnionMember1(): Boolean = unionMember1 != null - - fun asNumber(): Double = number.getOrThrow("number") - - fun asUnionMember1(): UnionMember1 = unionMember1.getOrThrow("unionMember1") - - fun _json(): Optional = Optional.ofNullable(_json) - - /** - * Maps this instance's current variant to a value of type [T] using the given - * [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from the - * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not known - * to this version of the SDK gracefully, consider overriding [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = value.accept(new Value.Visitor>() { - * @Override - * public Optional visitNumber(Double number) { - * return Optional.of(number.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden in - * [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - number != null -> visitor.visitNumber(number) - unionMember1 != null -> visitor.visitUnionMember1(unionMember1) - else -> visitor.unknown(_json) - } - - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitNumber(number: Double) {} - - override fun visitUnionMember1(unionMember1: UnionMember1) { - unionMember1.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - accept( - object : Visitor { - override fun visitNumber(number: Double) = 1 - - override fun visitUnionMember1(unionMember1: UnionMember1) = - unionMember1.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - number == other.number && - unionMember1 == other.unionMember1 - } - - override fun hashCode(): Int = Objects.hash(number, unionMember1) - - override fun toString(): String = - when { - number != null -> "Value{number=$number}" - unionMember1 != null -> "Value{unionMember1=$unionMember1}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - @JvmStatic fun ofNumber(number: Double) = Value(number = number) - - @JvmStatic - fun ofUnionMember1(unionMember1: UnionMember1) = - Value(unionMember1 = unionMember1) - } - - /** - * An interface that defines how to map each variant of [Value] to a value of type - * [T]. - */ - interface Visitor { - - fun visitNumber(number: Double): T - - fun visitUnionMember1(unionMember1: UnionMember1): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on - * an older version than the API, then the API may respond with new variants - * that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(unionMember1 = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing from - // boolean). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use - // the first completely valid match, or simply the first match if none - // are completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.number != null -> generator.writeObject(value.number) - value.unionMember1 != null -> generator.writeObject(value.unionMember1) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - - class UnionMember1 - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [UnionMember1]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [UnionMember1]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(unionMember1: UnionMember1) = apply { - additionalProperties = unionMember1.additionalProperties.toMutableMap() - } - - 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 [UnionMember1]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): UnionMember1 = UnionMember1(additionalProperties.toImmutable()) - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): UnionMember1 = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - additionalProperties.count { (_, value) -> - !value.isNull() && !value.isMissing() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is UnionMember1 && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "UnionMember1{additionalProperties=$additionalProperties}" + when { + value.singleCustomChartResponse != null -> + generator.writeObject(value.singleCustomChartResponse) + value.text != null -> generator.writeObject(value.text) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Chart") } } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Data && - seriesId == other.seriesId && - timestamp == other.timestamp && - value == other.value && - group == other.group && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(seriesId, timestamp, value, group, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Data{seriesId=$seriesId, timestamp=$timestamp, value=$value, group=$group, additionalProperties=$additionalProperties}" } - class Series + class SingleCustomChartResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, - private val name: JsonField, - private val feedbackKey: JsonField, - private val filterDefinition: JsonField, - private val filters: JsonField, - private val groupBy: JsonField, - private val groupByDefinitions: JsonField>, + private val chartType: JsonField, + private val data: JsonField>, + private val index: JsonField, + private val series: JsonField>, + private val title: JsonField, + private val commonFilters: JsonField, + private val description: JsonField, private val metadata: JsonField, - private val metric: JsonField, - private val metricDefinition: JsonField, - private val projectMetric: JsonField, - private val workspaceId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("feedback_key") + @JsonProperty("chart_type") @ExcludeMissing - feedbackKey: JsonField = JsonMissing.of(), - @JsonProperty("filter_definition") + chartType: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing - filterDefinition: JsonField = JsonMissing.of(), - @JsonProperty("filters") + data: JsonField> = JsonMissing.of(), + @JsonProperty("index") @ExcludeMissing index: JsonField = JsonMissing.of(), + @JsonProperty("series") @ExcludeMissing - filters: JsonField = JsonMissing.of(), - @JsonProperty("group_by") + series: JsonField> = JsonMissing.of(), + @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), + @JsonProperty("common_filters") @ExcludeMissing - groupBy: JsonField = JsonMissing.of(), - @JsonProperty("group_by_definitions") + commonFilters: JsonField = JsonMissing.of(), + @JsonProperty("description") @ExcludeMissing - groupByDefinitions: JsonField> = JsonMissing.of(), + description: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("metric") - @ExcludeMissing - metric: JsonField = JsonMissing.of(), - @JsonProperty("metric_definition") - @ExcludeMissing - metricDefinition: JsonField = JsonMissing.of(), - @JsonProperty("project_metric") - @ExcludeMissing - projectMetric: JsonField = JsonMissing.of(), - @JsonProperty("workspace_id") - @ExcludeMissing - workspaceId: JsonField = JsonMissing.of(), ) : this( id, - name, - feedbackKey, - filterDefinition, - filters, - groupBy, - groupByDefinitions, + chartType, + data, + index, + series, + title, + commonFilters, + description, metadata, - metric, - metricDefinition, - projectMetric, - workspaceId, mutableMapOf(), ) @@ -1816,41 +739,48 @@ private constructor( * unexpectedly missing or null (e.g. if the server responded with an unexpected * value). */ - fun name(): String = name.getRequired("name") + fun chartType(): ChartType = chartType.getRequired("chart_type") + + /** + * @throws LangChainInvalidDataException 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 data(): List = data.getRequired("data") + + /** + * @throws LangChainInvalidDataException 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 index(): Long = index.getRequired("index") + + /** + * @throws LangChainInvalidDataException 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 series(): List = series.getRequired("series") + + /** + * @throws LangChainInvalidDataException 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 title(): String = title.getRequired("title") /** * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun feedbackKey(): Optional = feedbackKey.getOptional("feedback_key") + fun commonFilters(): Optional = + commonFilters.getOptional("common_filters") /** * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun filterDefinition(): Optional = - filterDefinition.getOptional("filter_definition") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun filters(): Optional = filters.getOptional("filters") - - /** - * Include additional information about where the group_by param was set. - * - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun groupBy(): Optional = groupBy.getOptional("group_by") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun groupByDefinitions(): Optional> = - groupByDefinitions.getOptional("group_by_definitions") + fun description(): Optional = description.getOptional("description") /** * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. @@ -1858,37 +788,6 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") - /** - * Metrics you can chart. Feedback metrics are not available for organization-scoped - * charts. - * - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun metric(): Optional = metric.getOptional("metric") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun metricDefinition(): Optional = - metricDefinition.getOptional("metric_definition") - - /** - * LGP Metrics you can chart. - * - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun projectMetric(): Optional = - projectMetric.getOptional("project_metric") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun workspaceId(): Optional = workspaceId.getOptional("workspace_id") - /** * Returns the raw JSON value of [id]. * @@ -1897,55 +796,62 @@ private constructor( @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id /** - * Returns the raw JSON value of [name]. + * Returns the raw JSON value of [chartType]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [feedbackKey]. - * - * Unlike [feedbackKey], this method doesn't throw if the JSON field has an unexpected + * Unlike [chartType], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("feedback_key") + @JsonProperty("chart_type") @ExcludeMissing - fun _feedbackKey(): JsonField = feedbackKey + fun _chartType(): JsonField = chartType /** - * Returns the raw JSON value of [filterDefinition]. + * Returns the raw JSON value of [data]. * - * Unlike [filterDefinition], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filter_definition") + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [index]. + * + * Unlike [index], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index") @ExcludeMissing fun _index(): JsonField = index + + /** + * Returns the raw JSON value of [series]. + * + * Unlike [series], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("series") @ExcludeMissing fun _series(): JsonField> = series + + /** + * Returns the raw JSON value of [title]. + * + * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title + + /** + * Returns the raw JSON value of [commonFilters]. + * + * Unlike [commonFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("common_filters") @ExcludeMissing - fun _filterDefinition(): JsonField = filterDefinition + fun _commonFilters(): JsonField = commonFilters /** - * Returns the raw JSON value of [filters]. + * Returns the raw JSON value of [description]. * - * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField = filters - - /** - * Returns the raw JSON value of [groupBy]. - * - * Unlike [groupBy], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("group_by") @ExcludeMissing fun _groupBy(): JsonField = groupBy - - /** - * Returns the raw JSON value of [groupByDefinitions]. - * - * Unlike [groupByDefinitions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("group_by_definitions") + @JsonProperty("description") @ExcludeMissing - fun _groupByDefinitions(): JsonField> = groupByDefinitions + fun _description(): JsonField = description /** * Returns the raw JSON value of [metadata]. @@ -1957,43 +863,6 @@ private constructor( @ExcludeMissing fun _metadata(): JsonField = metadata - /** - * Returns the raw JSON value of [metric]. - * - * Unlike [metric], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metric") @ExcludeMissing fun _metric(): JsonField = metric - - /** - * Returns the raw JSON value of [metricDefinition]. - * - * Unlike [metricDefinition], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("metric_definition") - @ExcludeMissing - fun _metricDefinition(): JsonField = metricDefinition - - /** - * Returns the raw JSON value of [projectMetric]. - * - * Unlike [projectMetric], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("project_metric") - @ExcludeMissing - fun _projectMetric(): JsonField = projectMetric - - /** - * Returns the raw JSON value of [workspaceId]. - * - * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("workspace_id") - @ExcludeMissing - fun _workspaceId(): JsonField = workspaceId - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2009,49 +878,49 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Series]. + * Returns a mutable builder for constructing an instance of + * [SingleCustomChartResponse]. * * The following fields are required: * ```java * .id() - * .name() + * .chartType() + * .data() + * .index() + * .series() + * .title() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [Series]. */ + /** A builder for [SingleCustomChartResponse]. */ class Builder internal constructor() { private var id: JsonField? = null - private var name: JsonField? = null - private var feedbackKey: JsonField = JsonMissing.of() - private var filterDefinition: JsonField = JsonMissing.of() - private var filters: JsonField = JsonMissing.of() - private var groupBy: JsonField = JsonMissing.of() - private var groupByDefinitions: JsonField>? = null + private var chartType: JsonField? = null + private var data: JsonField>? = null + private var index: JsonField? = null + private var series: JsonField>? = null + private var title: JsonField? = null + private var commonFilters: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() - private var metric: JsonField = JsonMissing.of() - private var metricDefinition: JsonField = JsonMissing.of() - private var projectMetric: JsonField = JsonMissing.of() - private var workspaceId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(series: Series) = apply { - id = series.id - name = series.name - feedbackKey = series.feedbackKey - filterDefinition = series.filterDefinition - filters = series.filters - groupBy = series.groupBy - groupByDefinitions = series.groupByDefinitions.map { it.toMutableList() } - metadata = series.metadata - metric = series.metric - metricDefinition = series.metricDefinition - projectMetric = series.projectMetric - workspaceId = series.workspaceId - additionalProperties = series.additionalProperties.toMutableMap() + internal fun from(singleCustomChartResponse: SingleCustomChartResponse) = apply { + id = singleCustomChartResponse.id + chartType = singleCustomChartResponse.chartType + data = singleCustomChartResponse.data.map { it.toMutableList() } + index = singleCustomChartResponse.index + series = singleCustomChartResponse.series.map { it.toMutableList() } + title = singleCustomChartResponse.title + commonFilters = singleCustomChartResponse.commonFilters + description = singleCustomChartResponse.description + metadata = singleCustomChartResponse.metadata + additionalProperties = + singleCustomChartResponse.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -2065,165 +934,126 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } - fun name(name: String) = name(JsonField.of(name)) + fun chartType(chartType: ChartType) = chartType(JsonField.of(chartType)) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Sets [Builder.chartType] to an arbitrary JSON value. * - * You should usually call [Builder.name] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun name(name: JsonField) = apply { this.name = name } - - fun feedbackKey(feedbackKey: String?) = - feedbackKey(JsonField.ofNullable(feedbackKey)) - - /** Alias for calling [Builder.feedbackKey] with `feedbackKey.orElse(null)`. */ - fun feedbackKey(feedbackKey: Optional) = - feedbackKey(feedbackKey.getOrNull()) - - /** - * Sets [Builder.feedbackKey] to an arbitrary JSON value. - * - * You should usually call [Builder.feedbackKey] with a well-typed [String] value + * You should usually call [Builder.chartType] with a well-typed [ChartType] value * instead. This method is primarily for setting the field to an undocumented or not * yet supported value. */ - fun feedbackKey(feedbackKey: JsonField) = apply { - this.feedbackKey = feedbackKey + fun chartType(chartType: JsonField) = apply { + this.chartType = chartType } - fun filterDefinition(filterDefinition: FilterDefinition?) = - filterDefinition(JsonField.ofNullable(filterDefinition)) + fun data(data: List) = data(JsonField.of(data)) /** - * Alias for calling [Builder.filterDefinition] with - * `filterDefinition.orElse(null)`. - */ - fun filterDefinition(filterDefinition: Optional) = - filterDefinition(filterDefinition.getOrNull()) - - /** - * Sets [Builder.filterDefinition] to an arbitrary JSON value. + * Sets [Builder.data] to an arbitrary JSON value. * - * You should usually call [Builder.filterDefinition] with a well-typed - * [FilterDefinition] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun filterDefinition(filterDefinition: JsonField) = apply { - this.filterDefinition = filterDefinition + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } } /** - * Alias for calling [filterDefinition] with - * `FilterDefinition.ofCustomChartFilterByTracingProject(customChartFilterByTracingProject)`. - */ - fun filterDefinition( - customChartFilterByTracingProject: - FilterDefinition.CustomChartFilterByTracingProject - ) = - filterDefinition( - FilterDefinition.ofCustomChartFilterByTracingProject( - customChartFilterByTracingProject - ) - ) - - /** - * Alias for calling [filterDefinition] with - * `FilterDefinition.ofCustomChartFilterByDataset(customChartFilterByDataset)`. - */ - fun filterDefinition( - customChartFilterByDataset: FilterDefinition.CustomChartFilterByDataset - ) = - filterDefinition( - FilterDefinition.ofCustomChartFilterByDataset(customChartFilterByDataset) - ) - - fun filters(filters: Filters?) = filters(JsonField.ofNullable(filters)) - - /** Alias for calling [Builder.filters] with `filters.orElse(null)`. */ - fun filters(filters: Optional) = filters(filters.getOrNull()) - - /** - * Sets [Builder.filters] to an arbitrary JSON value. - * - * You should usually call [Builder.filters] with a well-typed [Filters] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun filters(filters: JsonField) = apply { this.filters = filters } - - /** Include additional information about where the group_by param was set. */ - fun groupBy(groupBy: GroupBy?) = groupBy(JsonField.ofNullable(groupBy)) - - /** Alias for calling [Builder.groupBy] with `groupBy.orElse(null)`. */ - fun groupBy(groupBy: Optional) = groupBy(groupBy.getOrNull()) - - /** - * Sets [Builder.groupBy] to an arbitrary JSON value. - * - * You should usually call [Builder.groupBy] with a well-typed [GroupBy] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun groupBy(groupBy: JsonField) = apply { this.groupBy = groupBy } - - fun groupByDefinitions(groupByDefinitions: List?) = - groupByDefinitions(JsonField.ofNullable(groupByDefinitions)) - - /** - * Alias for calling [Builder.groupByDefinitions] with - * `groupByDefinitions.orElse(null)`. - */ - fun groupByDefinitions(groupByDefinitions: Optional>) = - groupByDefinitions(groupByDefinitions.getOrNull()) - - /** - * Sets [Builder.groupByDefinitions] to an arbitrary JSON value. - * - * You should usually call [Builder.groupByDefinitions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun groupByDefinitions(groupByDefinitions: JsonField>) = - apply { - this.groupByDefinitions = groupByDefinitions.map { it.toMutableList() } - } - - /** - * Adds a single [GroupByDefinition] to [groupByDefinitions]. + * Adds a single [Data] to [Builder.data]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addGroupByDefinition(groupByDefinition: GroupByDefinition) = apply { - groupByDefinitions = - (groupByDefinitions ?: JsonField.of(mutableListOf())).also { - checkKnown("groupByDefinitions", it).add(groupByDefinition) + fun addData(data: Data) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) } } - /** - * Alias for calling [addGroupByDefinition] with - * `GroupByDefinition.ofCustomChartGroupByPlain(customChartGroupByPlain)`. - */ - fun addGroupByDefinition( - customChartGroupByPlain: GroupByDefinition.CustomChartGroupByPlain - ) = - addGroupByDefinition( - GroupByDefinition.ofCustomChartGroupByPlain(customChartGroupByPlain) - ) + fun index(index: Long) = index(JsonField.of(index)) /** - * Alias for calling [addGroupByDefinition] with - * `GroupByDefinition.ofCustomChartGroupByComplex(customChartGroupByComplex)`. + * Sets [Builder.index] to an arbitrary JSON value. + * + * You should usually call [Builder.index] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun addGroupByDefinition( - customChartGroupByComplex: GroupByDefinition.CustomChartGroupByComplex - ) = - addGroupByDefinition( - GroupByDefinition.ofCustomChartGroupByComplex(customChartGroupByComplex) - ) + fun index(index: JsonField) = apply { this.index = index } + + fun series(series: List) = series(JsonField.of(series)) + + /** + * Sets [Builder.series] to an arbitrary JSON value. + * + * You should usually call [Builder.series] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun series(series: JsonField>) = apply { + this.series = series.map { it.toMutableList() } + } + + /** + * Adds a single [Series] to [Builder.series]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSeries(series: Series) = apply { + this.series = + (this.series ?: JsonField.of(mutableListOf())).also { + checkKnown("series", it).add(series) + } + } + + fun title(title: String) = title(JsonField.of(title)) + + /** + * Sets [Builder.title] to an arbitrary JSON value. + * + * You should usually call [Builder.title] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun title(title: JsonField) = apply { this.title = title } + + fun commonFilters(commonFilters: CommonFilters?) = + commonFilters(JsonField.ofNullable(commonFilters)) + + /** Alias for calling [Builder.commonFilters] with `commonFilters.orElse(null)`. */ + fun commonFilters(commonFilters: Optional) = + commonFilters(commonFilters.getOrNull()) + + /** + * Sets [Builder.commonFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.commonFilters] with a well-typed [CommonFilters] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun commonFilters(commonFilters: JsonField) = apply { + this.commonFilters = commonFilters + } + + fun description(description: String?) = + description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = + description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) @@ -2239,142 +1069,6 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** - * Metrics you can chart. Feedback metrics are not available for organization-scoped - * charts. - */ - fun metric(metric: Metric?) = metric(JsonField.ofNullable(metric)) - - /** Alias for calling [Builder.metric] with `metric.orElse(null)`. */ - fun metric(metric: Optional) = metric(metric.getOrNull()) - - /** - * Sets [Builder.metric] to an arbitrary JSON value. - * - * You should usually call [Builder.metric] with a well-typed [Metric] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun metric(metric: JsonField) = apply { this.metric = metric } - - fun metricDefinition(metricDefinition: MetricDefinition?) = - metricDefinition(JsonField.ofNullable(metricDefinition)) - - /** - * Alias for calling [Builder.metricDefinition] with - * `metricDefinition.orElse(null)`. - */ - fun metricDefinition(metricDefinition: Optional) = - metricDefinition(metricDefinition.getOrNull()) - - /** - * Sets [Builder.metricDefinition] to an arbitrary JSON value. - * - * You should usually call [Builder.metricDefinition] with a well-typed - * [MetricDefinition] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun metricDefinition(metricDefinition: JsonField) = apply { - this.metricDefinition = metricDefinition - } - - /** - * Alias for calling [metricDefinition] with - * `MetricDefinition.ofCustomChartMetricCount(customChartMetricCount)`. - */ - fun metricDefinition( - customChartMetricCount: MetricDefinition.CustomChartMetricCount - ) = - metricDefinition( - MetricDefinition.ofCustomChartMetricCount(customChartMetricCount) - ) - - /** - * Alias for calling [metricDefinition] with - * `MetricDefinition.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. - */ - fun metricDefinition( - customChartFeedbackScoreMetricScalar: - MetricDefinition.CustomChartFeedbackScoreMetricScalar - ) = - metricDefinition( - MetricDefinition.ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - ) - - /** - * Alias for calling [metricDefinition] with - * `MetricDefinition.ofCustomChartMetricScalar(customChartMetricScalar)`. - */ - fun metricDefinition( - customChartMetricScalar: MetricDefinition.CustomChartMetricScalar - ) = - metricDefinition( - MetricDefinition.ofCustomChartMetricScalar(customChartMetricScalar) - ) - - /** - * Alias for calling [metricDefinition] with - * `MetricDefinition.ofCustomChartMetricPercentile(customChartMetricPercentile)`. - */ - fun metricDefinition( - customChartMetricPercentile: MetricDefinition.CustomChartMetricPercentile - ) = - metricDefinition( - MetricDefinition.ofCustomChartMetricPercentile(customChartMetricPercentile) - ) - - /** - * Alias for calling [metricDefinition] with - * `MetricDefinition.ofCustomChartMetricRatioOutput(customChartMetricRatioOutput)`. - */ - fun metricDefinition( - customChartMetricRatioOutput: MetricDefinition.CustomChartMetricRatioOutput - ) = - metricDefinition( - MetricDefinition.ofCustomChartMetricRatioOutput( - customChartMetricRatioOutput - ) - ) - - /** LGP Metrics you can chart. */ - fun projectMetric(projectMetric: ProjectMetric?) = - projectMetric(JsonField.ofNullable(projectMetric)) - - /** Alias for calling [Builder.projectMetric] with `projectMetric.orElse(null)`. */ - fun projectMetric(projectMetric: Optional) = - projectMetric(projectMetric.getOrNull()) - - /** - * Sets [Builder.projectMetric] to an arbitrary JSON value. - * - * You should usually call [Builder.projectMetric] with a well-typed [ProjectMetric] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun projectMetric(projectMetric: JsonField) = apply { - this.projectMetric = projectMetric - } - - fun workspaceId(workspaceId: String?) = - workspaceId(JsonField.ofNullable(workspaceId)) - - /** Alias for calling [Builder.workspaceId] with `workspaceId.orElse(null)`. */ - fun workspaceId(workspaceId: Optional) = - workspaceId(workspaceId.getOrNull()) - - /** - * Sets [Builder.workspaceId] to an arbitrary JSON value. - * - * You should usually call [Builder.workspaceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun workspaceId(workspaceId: JsonField) = apply { - this.workspaceId = workspaceId - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -2398,32 +1092,33 @@ private constructor( } /** - * Returns an immutable instance of [Series]. + * Returns an immutable instance of [SingleCustomChartResponse]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .id() - * .name() + * .chartType() + * .data() + * .index() + * .series() + * .title() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Series = - Series( + fun build(): SingleCustomChartResponse = + SingleCustomChartResponse( checkRequired("id", id), - checkRequired("name", name), - feedbackKey, - filterDefinition, - filters, - groupBy, - (groupByDefinitions ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("chartType", chartType), + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("index", index), + checkRequired("series", series).map { it.toImmutable() }, + checkRequired("title", title), + commonFilters, + description, metadata, - metric, - metricDefinition, - projectMetric, - workspaceId, additionalProperties.toMutableMap(), ) } @@ -2440,23 +1135,20 @@ private constructor( * @throws LangChainInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): Series = apply { + fun validate(): SingleCustomChartResponse = apply { if (validated) { return@apply } id() - name() - feedbackKey() - filterDefinition().ifPresent { it.validate() } - filters().ifPresent { it.validate() } - groupBy().ifPresent { it.validate() } - groupByDefinitions().ifPresent { it.forEach { it.validate() } } + chartType().validate() + data().forEach { it.validate() } + index() + series().forEach { it.validate() } + title() + commonFilters().ifPresent { it.validate() } + description() metadata().ifPresent { it.validate() } - metric().ifPresent { it.validate() } - metricDefinition().ifPresent { it.validate() } - projectMetric().ifPresent { it.validate() } - workspaceId() validated = true } @@ -2477,90 +1169,128 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (if (feedbackKey.asKnown().isPresent) 1 else 0) + - (filterDefinition.asKnown().getOrNull()?.validity() ?: 0) + - (filters.asKnown().getOrNull()?.validity() ?: 0) + - (groupBy.asKnown().getOrNull()?.validity() ?: 0) + - (groupByDefinitions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } - ?: 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + - (metric.asKnown().getOrNull()?.validity() ?: 0) + - (metricDefinition.asKnown().getOrNull()?.validity() ?: 0) + - (projectMetric.asKnown().getOrNull()?.validity() ?: 0) + - (if (workspaceId.asKnown().isPresent) 1 else 0) + (chartType.asKnown().getOrNull()?.validity() ?: 0) + + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (index.asKnown().isPresent) 1 else 0) + + (series.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (title.asKnown().isPresent) 1 else 0) + + (commonFilters.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) - @JsonDeserialize(using = FilterDefinition.Deserializer::class) - @JsonSerialize(using = FilterDefinition.Serializer::class) - class FilterDefinition - private constructor( - private val customChartFilterByTracingProject: CustomChartFilterByTracingProject? = - null, - private val customChartFilterByDataset: CustomChartFilterByDataset? = null, - private val _json: JsonValue? = null, - ) { - - fun customChartFilterByTracingProject(): - Optional = - Optional.ofNullable(customChartFilterByTracingProject) - - fun customChartFilterByDataset(): Optional = - Optional.ofNullable(customChartFilterByDataset) - - fun isCustomChartFilterByTracingProject(): Boolean = - customChartFilterByTracingProject != null - - fun isCustomChartFilterByDataset(): Boolean = customChartFilterByDataset != null - - fun asCustomChartFilterByTracingProject(): CustomChartFilterByTracingProject = - customChartFilterByTracingProject.getOrThrow( - "customChartFilterByTracingProject" - ) - - fun asCustomChartFilterByDataset(): CustomChartFilterByDataset = - customChartFilterByDataset.getOrThrow("customChartFilterByDataset") - - fun _json(): Optional = Optional.ofNullable(_json) + class ChartType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps this instance's current variant to a value of type [T] using the given - * [visitor]. + * Returns this class instance's raw value. * - * Note that this method is _not_ forwards compatible with new variants from the - * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not known - * to this version of the SDK gracefully, consider overriding [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = filterDefinition.accept(new FilterDefinition.Visitor>() { - * @Override - * public Optional visitCustomChartFilterByTracingProject(CustomChartFilterByTracingProject customChartFilterByTracingProject) { - * return Optional.of(customChartFilterByTracingProject.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden in - * [visitor] and the current variant is unknown. + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. */ - fun accept(visitor: Visitor): T = - when { - customChartFilterByTracingProject != null -> - visitor.visitCustomChartFilterByTracingProject( - customChartFilterByTracingProject - ) - customChartFilterByDataset != null -> - visitor.visitCustomChartFilterByDataset(customChartFilterByDataset) - else -> visitor.unknown(_json) + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val LINE = of("line") + + @JvmField val BAR = of("bar") + + @JvmField val TABLE = of("table") + + @JvmField val KPI = of("kpi") + + @JvmField val TOP_K = of("top-k") + + @JvmField val PIE = of("pie") + + @JvmStatic fun of(value: String) = ChartType(JsonField.of(value)) + } + + /** An enum containing [ChartType]'s known values. */ + enum class Known { + LINE, + BAR, + TABLE, + KPI, + TOP_K, + PIE, + } + + /** + * An enum containing [ChartType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ChartType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + LINE, + BAR, + TABLE, + KPI, + TOP_K, + PIE, + /** + * An enum member indicating that [ChartType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LINE -> Value.LINE + BAR -> Value.BAR + TABLE -> Value.TABLE + KPI -> Value.KPI + TOP_K -> Value.TOP_K + PIE -> Value.PIE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + LINE -> Known.LINE + BAR -> Known.BAR + TABLE -> Known.TABLE + KPI -> Known.KPI + TOP_K -> Known.TOP_K + PIE -> Known.PIE + else -> throw LangChainInvalidDataException("Unknown ChartType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") } private var validated: Boolean = false @@ -2575,26 +1305,303 @@ private constructor( * @throws LangChainInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): FilterDefinition = apply { + fun validate(): ChartType = apply { if (validated) { return@apply } - accept( - object : Visitor { - override fun visitCustomChartFilterByTracingProject( - customChartFilterByTracingProject: CustomChartFilterByTracingProject - ) { - customChartFilterByTracingProject.validate() - } + known() + validated = true + } - override fun visitCustomChartFilterByDataset( - customChartFilterByDataset: CustomChartFilterByDataset - ) { - customChartFilterByDataset.validate() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChartType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val seriesId: JsonField, + private val timestamp: JsonField, + private val value: JsonField, + private val group: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("series_id") + @ExcludeMissing + seriesId: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + @JsonProperty("group") + @ExcludeMissing + group: JsonField = JsonMissing.of(), + ) : this(seriesId, timestamp, value, group, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 seriesId(): String = seriesId.getRequired("series_id") + + /** + * @throws LangChainInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun value(): Optional = value.getOptional("value") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun group(): Optional = group.getOptional("group") + + /** + * Returns the raw JSON value of [seriesId]. + * + * Unlike [seriesId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("series_id") + @ExcludeMissing + fun _seriesId(): JsonField = seriesId + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * 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 [group]. + * + * Unlike [group], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group + + @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 [Data]. + * + * The following fields are required: + * ```java + * .seriesId() + * .timestamp() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var seriesId: JsonField? = null + private var timestamp: JsonField? = null + private var value: JsonField? = null + private var group: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + seriesId = data.seriesId + timestamp = data.timestamp + value = data.value + group = data.group + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun seriesId(seriesId: String) = seriesId(JsonField.of(seriesId)) + + /** + * Sets [Builder.seriesId] to an arbitrary JSON value. + * + * You should usually call [Builder.seriesId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun seriesId(seriesId: JsonField) = apply { this.seriesId = seriesId } + + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun value(value: Value?) = value(JsonField.ofNullable(value)) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofNumber(number)`. */ + fun value(number: Double) = value(Value.ofNumber(number)) + + /** Alias for calling [value] with `Value.ofUnionMember1(unionMember1)`. */ + fun value(unionMember1: Value.UnionMember1) = + value(Value.ofUnionMember1(unionMember1)) + + fun group(group: String?) = group(JsonField.ofNullable(group)) + + /** Alias for calling [Builder.group] with `group.orElse(null)`. */ + fun group(group: Optional) = group(group.getOrNull()) + + /** + * Sets [Builder.group] to an arbitrary JSON value. + * + * You should usually call [Builder.group] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun group(group: JsonField) = apply { this.group = group } + + 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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .seriesId() + * .timestamp() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data( + checkRequired("seriesId", seriesId), + checkRequired("timestamp", timestamp), + checkRequired("value", value), + group, + 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 LangChainInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + seriesId() + timestamp() + value().ifPresent { it.validate() } + group() validated = true } @@ -2614,160 +1621,2094 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - accept( - object : Visitor { - override fun visitCustomChartFilterByTracingProject( - customChartFilterByTracingProject: CustomChartFilterByTracingProject - ) = customChartFilterByTracingProject.validity() + (if (seriesId.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + (if (group.asKnown().isPresent) 1 else 0) - override fun visitCustomChartFilterByDataset( - customChartFilterByDataset: CustomChartFilterByDataset - ) = customChartFilterByDataset.validity() + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val number: Double? = null, + private val unionMember1: UnionMember1? = null, + private val _json: JsonValue? = null, + ) { - override fun unknown(json: JsonValue?) = 0 + fun number(): Optional = Optional.ofNullable(number) + + fun unionMember1(): Optional = Optional.ofNullable(unionMember1) + + fun isNumber(): Boolean = number != null + + fun isUnionMember1(): Boolean = unionMember1 != null + + fun asNumber(): Double = number.getOrThrow("number") + + fun asUnionMember1(): UnionMember1 = unionMember1.getOrThrow("unionMember1") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the + * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not + * known to this version of the SDK gracefully, consider overriding + * [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = value.accept(new Value.Visitor>() { + * @Override + * public Optional visitNumber(Double number) { + * return Optional.of(number.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden + * in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + number != null -> visitor.visitNumber(number) + unionMember1 != null -> visitor.visitUnionMember1(unionMember1) + else -> visitor.unknown(_json) } - ) + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitNumber(number: Double) {} + + override fun visitUnionMember1(unionMember1: UnionMember1) { + unionMember1.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitNumber(number: Double) = 1 + + override fun visitUnionMember1(unionMember1: UnionMember1) = + unionMember1.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + number == other.number && + unionMember1 == other.unionMember1 + } + + override fun hashCode(): Int = Objects.hash(number, unionMember1) + + override fun toString(): String = + when { + number != null -> "Value{number=$number}" + unionMember1 != null -> "Value{unionMember1=$unionMember1}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + + @JvmStatic + fun ofUnionMember1(unionMember1: UnionMember1) = + Value(unionMember1 = unionMember1) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of + * type [T]. + */ + interface Visitor { + + fun visitNumber(number: Double): T + + fun visitUnionMember1(unionMember1: UnionMember1): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, + * if the SDK is on an older version than the API, then the API may respond + * with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(unionMember1 = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from boolean). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.number != null -> generator.writeObject(value.number) + value.unionMember1 != null -> + generator.writeObject(value.unionMember1) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + + class UnionMember1 + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [UnionMember1]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnionMember1]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(unionMember1: UnionMember1) = apply { + additionalProperties = + unionMember1.additionalProperties.toMutableMap() + } + + 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 [UnionMember1]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): UnionMember1 = + UnionMember1(additionalProperties.toImmutable()) + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): UnionMember1 = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnionMember1 && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnionMember1{additionalProperties=$additionalProperties}" + } + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is FilterDefinition && - customChartFilterByTracingProject == - other.customChartFilterByTracingProject && - customChartFilterByDataset == other.customChartFilterByDataset + return other is Data && + seriesId == other.seriesId && + timestamp == other.timestamp && + value == other.value && + group == other.group && + additionalProperties == other.additionalProperties } - override fun hashCode(): Int = - Objects.hash(customChartFilterByTracingProject, customChartFilterByDataset) + private val hashCode: Int by lazy { + Objects.hash(seriesId, timestamp, value, group, additionalProperties) + } - override fun toString(): String = - when { - customChartFilterByTracingProject != null -> - "FilterDefinition{customChartFilterByTracingProject=$customChartFilterByTracingProject}" - customChartFilterByDataset != null -> - "FilterDefinition{customChartFilterByDataset=$customChartFilterByDataset}" - _json != null -> "FilterDefinition{_unknown=$_json}" - else -> throw IllegalStateException("Invalid FilterDefinition") - } + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{seriesId=$seriesId, timestamp=$timestamp, value=$value, group=$group, additionalProperties=$additionalProperties}" + } + + class Series + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val feedbackKey: JsonField, + private val filterDefinition: JsonField, + private val filters: JsonField, + private val groupBy: JsonField, + private val groupByDefinitions: JsonField>, + private val metadata: JsonField, + private val metric: JsonField, + private val metricDefinition: JsonField, + private val projectMetric: JsonField, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("feedback_key") + @ExcludeMissing + feedbackKey: JsonField = JsonMissing.of(), + @JsonProperty("filter_definition") + @ExcludeMissing + filterDefinition: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField = JsonMissing.of(), + @JsonProperty("group_by") + @ExcludeMissing + groupBy: JsonField = JsonMissing.of(), + @JsonProperty("group_by_definitions") + @ExcludeMissing + groupByDefinitions: JsonField> = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("metric") + @ExcludeMissing + metric: JsonField = JsonMissing.of(), + @JsonProperty("metric_definition") + @ExcludeMissing + metricDefinition: JsonField = JsonMissing.of(), + @JsonProperty("project_metric") + @ExcludeMissing + projectMetric: JsonField = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this( + id, + name, + feedbackKey, + filterDefinition, + filters, + groupBy, + groupByDefinitions, + metadata, + metric, + metricDefinition, + projectMetric, + workspaceId, + mutableMapOf(), + ) + + /** + * @throws LangChainInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * @throws LangChainInvalidDataException 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 name(): String = name.getRequired("name") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun feedbackKey(): Optional = feedbackKey.getOptional("feedback_key") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun filterDefinition(): Optional = + filterDefinition.getOptional("filter_definition") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun filters(): Optional = filters.getOptional("filters") + + /** + * Include additional information about where the group_by param was set. + * + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupBy(): Optional = groupBy.getOptional("group_by") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupByDefinitions(): Optional> = + groupByDefinitions.getOptional("group_by_definitions") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Metrics you can chart. Feedback metrics are not available for organization-scoped + * charts. + * + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun metric(): Optional = metric.getOptional("metric") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun metricDefinition(): Optional = + metricDefinition.getOptional("metric_definition") + + /** + * LGP Metrics you can chart. + * + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun projectMetric(): Optional = + projectMetric.getOptional("project_metric") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): Optional = workspaceId.getOptional("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [feedbackKey]. + * + * Unlike [feedbackKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("feedback_key") + @ExcludeMissing + fun _feedbackKey(): JsonField = feedbackKey + + /** + * Returns the raw JSON value of [filterDefinition]. + * + * Unlike [filterDefinition], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filter_definition") + @ExcludeMissing + fun _filterDefinition(): JsonField = filterDefinition + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField = filters + + /** + * Returns the raw JSON value of [groupBy]. + * + * Unlike [groupBy], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("group_by") + @ExcludeMissing + fun _groupBy(): JsonField = groupBy + + /** + * Returns the raw JSON value of [groupByDefinitions]. + * + * Unlike [groupByDefinitions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_by_definitions") + @ExcludeMissing + fun _groupByDefinitions(): JsonField> = groupByDefinitions + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [metric]. + * + * Unlike [metric], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metric") @ExcludeMissing fun _metric(): JsonField = metric + + /** + * Returns the raw JSON value of [metricDefinition]. + * + * Unlike [metricDefinition], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("metric_definition") + @ExcludeMissing + fun _metricDefinition(): JsonField = metricDefinition + + /** + * Returns the raw JSON value of [projectMetric]. + * + * Unlike [projectMetric], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("project_metric") + @ExcludeMissing + fun _projectMetric(): JsonField = projectMetric + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 { - @JvmStatic - fun ofCustomChartFilterByTracingProject( - customChartFilterByTracingProject: CustomChartFilterByTracingProject - ) = - FilterDefinition( - customChartFilterByTracingProject = customChartFilterByTracingProject - ) - - @JvmStatic - fun ofCustomChartFilterByDataset( - customChartFilterByDataset: CustomChartFilterByDataset - ) = FilterDefinition(customChartFilterByDataset = customChartFilterByDataset) + /** + * Returns a mutable builder for constructing an instance of [Series]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() } - /** - * An interface that defines how to map each variant of [FilterDefinition] to a - * value of type [T]. - */ - interface Visitor { + /** A builder for [Series]. */ + class Builder internal constructor() { - fun visitCustomChartFilterByTracingProject( - customChartFilterByTracingProject: CustomChartFilterByTracingProject - ): T + private var id: JsonField? = null + private var name: JsonField? = null + private var feedbackKey: JsonField = JsonMissing.of() + private var filterDefinition: JsonField = JsonMissing.of() + private var filters: JsonField = JsonMissing.of() + private var groupBy: JsonField = JsonMissing.of() + private var groupByDefinitions: JsonField>? = + null + private var metadata: JsonField = JsonMissing.of() + private var metric: JsonField = JsonMissing.of() + private var metricDefinition: JsonField = JsonMissing.of() + private var projectMetric: JsonField = JsonMissing.of() + private var workspaceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun visitCustomChartFilterByDataset( - customChartFilterByDataset: CustomChartFilterByDataset - ): T + @JvmSynthetic + internal fun from(series: Series) = apply { + id = series.id + name = series.name + feedbackKey = series.feedbackKey + filterDefinition = series.filterDefinition + filters = series.filters + groupBy = series.groupBy + groupByDefinitions = series.groupByDefinitions.map { it.toMutableList() } + metadata = series.metadata + metric = series.metric + metricDefinition = series.metricDefinition + projectMetric = series.projectMetric + workspaceId = series.workspaceId + additionalProperties = series.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) /** - * Maps an unknown variant of [FilterDefinition] to a value of type [T]. + * Sets [Builder.id] to an arbitrary JSON value. * - * An instance of [FilterDefinition] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if - * the SDK is on an older version than the API, then the API may respond with - * new variants that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown FilterDefinition: $json") + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun feedbackKey(feedbackKey: String?) = + feedbackKey(JsonField.ofNullable(feedbackKey)) + + /** Alias for calling [Builder.feedbackKey] with `feedbackKey.orElse(null)`. */ + fun feedbackKey(feedbackKey: Optional) = + feedbackKey(feedbackKey.getOrNull()) + + /** + * Sets [Builder.feedbackKey] to an arbitrary JSON value. + * + * You should usually call [Builder.feedbackKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun feedbackKey(feedbackKey: JsonField) = apply { + this.feedbackKey = feedbackKey } - } - internal class Deserializer : - BaseDeserializer(FilterDefinition::class) { + fun filterDefinition(filterDefinition: FilterDefinition?) = + filterDefinition(JsonField.ofNullable(filterDefinition)) - override fun ObjectCodec.deserialize(node: JsonNode): FilterDefinition { - val json = JsonValue.fromJsonNode(node) + /** + * Alias for calling [Builder.filterDefinition] with + * `filterDefinition.orElse(null)`. + */ + fun filterDefinition(filterDefinition: Optional) = + filterDefinition(filterDefinition.getOrNull()) - val bestMatches = - sequenceOf( - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - FilterDefinition( - customChartFilterByTracingProject = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - FilterDefinition( - customChartFilterByDataset = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing from - // boolean). - 0 -> FilterDefinition(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use - // the first completely valid match, or simply the first match if none - // are completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + /** + * Sets [Builder.filterDefinition] to an arbitrary JSON value. + * + * You should usually call [Builder.filterDefinition] with a well-typed + * [FilterDefinition] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filterDefinition(filterDefinition: JsonField) = apply { + this.filterDefinition = filterDefinition + } + + /** + * Alias for calling [filterDefinition] with + * `FilterDefinition.ofCustomChartFilterByTracingProject(customChartFilterByTracingProject)`. + */ + fun filterDefinition( + customChartFilterByTracingProject: + FilterDefinition.CustomChartFilterByTracingProject + ) = + filterDefinition( + FilterDefinition.ofCustomChartFilterByTracingProject( + customChartFilterByTracingProject + ) + ) + + /** + * Alias for calling [filterDefinition] with + * `FilterDefinition.ofCustomChartFilterByDataset(customChartFilterByDataset)`. + */ + fun filterDefinition( + customChartFilterByDataset: FilterDefinition.CustomChartFilterByDataset + ) = + filterDefinition( + FilterDefinition.ofCustomChartFilterByDataset( + customChartFilterByDataset + ) + ) + + fun filters(filters: Filters?) = filters(JsonField.ofNullable(filters)) + + /** Alias for calling [Builder.filters] with `filters.orElse(null)`. */ + fun filters(filters: Optional) = filters(filters.getOrNull()) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed [Filters] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun filters(filters: JsonField) = apply { this.filters = filters } + + /** Include additional information about where the group_by param was set. */ + fun groupBy(groupBy: GroupBy?) = groupBy(JsonField.ofNullable(groupBy)) + + /** Alias for calling [Builder.groupBy] with `groupBy.orElse(null)`. */ + fun groupBy(groupBy: Optional) = groupBy(groupBy.getOrNull()) + + /** + * Sets [Builder.groupBy] to an arbitrary JSON value. + * + * You should usually call [Builder.groupBy] with a well-typed [GroupBy] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun groupBy(groupBy: JsonField) = apply { this.groupBy = groupBy } + + fun groupByDefinitions(groupByDefinitions: List?) = + groupByDefinitions(JsonField.ofNullable(groupByDefinitions)) + + /** + * Alias for calling [Builder.groupByDefinitions] with + * `groupByDefinitions.orElse(null)`. + */ + fun groupByDefinitions(groupByDefinitions: Optional>) = + groupByDefinitions(groupByDefinitions.getOrNull()) + + /** + * Sets [Builder.groupByDefinitions] to an arbitrary JSON value. + * + * You should usually call [Builder.groupByDefinitions] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun groupByDefinitions(groupByDefinitions: JsonField>) = + apply { + this.groupByDefinitions = groupByDefinitions.map { it.toMutableList() } } + + /** + * Adds a single [GroupByDefinition] to [groupByDefinitions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupByDefinition(groupByDefinition: GroupByDefinition) = apply { + groupByDefinitions = + (groupByDefinitions ?: JsonField.of(mutableListOf())).also { + checkKnown("groupByDefinitions", it).add(groupByDefinition) + } } + + /** + * Alias for calling [addGroupByDefinition] with + * `GroupByDefinition.ofCustomChartGroupByPlain(customChartGroupByPlain)`. + */ + fun addGroupByDefinition( + customChartGroupByPlain: GroupByDefinition.CustomChartGroupByPlain + ) = + addGroupByDefinition( + GroupByDefinition.ofCustomChartGroupByPlain(customChartGroupByPlain) + ) + + /** + * Alias for calling [addGroupByDefinition] with + * `GroupByDefinition.ofCustomChartGroupByComplex(customChartGroupByComplex)`. + */ + fun addGroupByDefinition( + customChartGroupByComplex: GroupByDefinition.CustomChartGroupByComplex + ) = + addGroupByDefinition( + GroupByDefinition.ofCustomChartGroupByComplex(customChartGroupByComplex) + ) + + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * 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 } + + /** + * Metrics you can chart. Feedback metrics are not available for + * organization-scoped charts. + */ + fun metric(metric: Metric?) = metric(JsonField.ofNullable(metric)) + + /** Alias for calling [Builder.metric] with `metric.orElse(null)`. */ + fun metric(metric: Optional) = metric(metric.getOrNull()) + + /** + * Sets [Builder.metric] to an arbitrary JSON value. + * + * You should usually call [Builder.metric] with a well-typed [Metric] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metric(metric: JsonField) = apply { this.metric = metric } + + fun metricDefinition(metricDefinition: MetricDefinition?) = + metricDefinition(JsonField.ofNullable(metricDefinition)) + + /** + * Alias for calling [Builder.metricDefinition] with + * `metricDefinition.orElse(null)`. + */ + fun metricDefinition(metricDefinition: Optional) = + metricDefinition(metricDefinition.getOrNull()) + + /** + * Sets [Builder.metricDefinition] to an arbitrary JSON value. + * + * You should usually call [Builder.metricDefinition] with a well-typed + * [MetricDefinition] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun metricDefinition(metricDefinition: JsonField) = apply { + this.metricDefinition = metricDefinition + } + + /** + * Alias for calling [metricDefinition] with + * `MetricDefinition.ofCustomChartMetricCount(customChartMetricCount)`. + */ + fun metricDefinition( + customChartMetricCount: MetricDefinition.CustomChartMetricCount + ) = + metricDefinition( + MetricDefinition.ofCustomChartMetricCount(customChartMetricCount) + ) + + /** + * Alias for calling [metricDefinition] with + * `MetricDefinition.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. + */ + fun metricDefinition( + customChartFeedbackScoreMetricScalar: + MetricDefinition.CustomChartFeedbackScoreMetricScalar + ) = + metricDefinition( + MetricDefinition.ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + ) + + /** + * Alias for calling [metricDefinition] with + * `MetricDefinition.ofCustomChartMetricScalar(customChartMetricScalar)`. + */ + fun metricDefinition( + customChartMetricScalar: MetricDefinition.CustomChartMetricScalar + ) = + metricDefinition( + MetricDefinition.ofCustomChartMetricScalar(customChartMetricScalar) + ) + + /** + * Alias for calling [metricDefinition] with + * `MetricDefinition.ofCustomChartMetricPercentile(customChartMetricPercentile)`. + */ + fun metricDefinition( + customChartMetricPercentile: MetricDefinition.CustomChartMetricPercentile + ) = + metricDefinition( + MetricDefinition.ofCustomChartMetricPercentile( + customChartMetricPercentile + ) + ) + + /** + * Alias for calling [metricDefinition] with + * `MetricDefinition.ofCustomChartMetricRatioOutput(customChartMetricRatioOutput)`. + */ + fun metricDefinition( + customChartMetricRatioOutput: MetricDefinition.CustomChartMetricRatioOutput + ) = + metricDefinition( + MetricDefinition.ofCustomChartMetricRatioOutput( + customChartMetricRatioOutput + ) + ) + + /** LGP Metrics you can chart. */ + fun projectMetric(projectMetric: ProjectMetric?) = + projectMetric(JsonField.ofNullable(projectMetric)) + + /** + * Alias for calling [Builder.projectMetric] with `projectMetric.orElse(null)`. + */ + fun projectMetric(projectMetric: Optional) = + projectMetric(projectMetric.getOrNull()) + + /** + * Sets [Builder.projectMetric] to an arbitrary JSON value. + * + * You should usually call [Builder.projectMetric] with a well-typed + * [ProjectMetric] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun projectMetric(projectMetric: JsonField) = apply { + this.projectMetric = projectMetric + } + + fun workspaceId(workspaceId: String?) = + workspaceId(JsonField.ofNullable(workspaceId)) + + /** Alias for calling [Builder.workspaceId] with `workspaceId.orElse(null)`. */ + fun workspaceId(workspaceId: Optional) = + workspaceId(workspaceId.getOrNull()) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun workspaceId(workspaceId: JsonField) = apply { + this.workspaceId = workspaceId + } + + 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 [Series]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Series = + Series( + checkRequired("id", id), + checkRequired("name", name), + feedbackKey, + filterDefinition, + filters, + groupBy, + (groupByDefinitions ?: JsonMissing.of()).map { it.toImmutable() }, + metadata, + metric, + metricDefinition, + projectMetric, + workspaceId, + additionalProperties.toMutableMap(), + ) } - internal class Serializer : - BaseSerializer(FilterDefinition::class) { + private var validated: Boolean = false - override fun serialize( - value: FilterDefinition, - generator: JsonGenerator, - provider: SerializerProvider, - ) { + /** + * 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 LangChainInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Series = apply { + if (validated) { + return@apply + } + + id() + name() + feedbackKey() + filterDefinition().ifPresent { it.validate() } + filters().ifPresent { it.validate() } + groupBy().ifPresent { it.validate() } + groupByDefinitions().ifPresent { it.forEach { it.validate() } } + metadata().ifPresent { it.validate() } + metric().ifPresent { it.validate() } + metricDefinition().ifPresent { it.validate() } + projectMetric().ifPresent { it.validate() } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (feedbackKey.asKnown().isPresent) 1 else 0) + + (filterDefinition.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.validity() ?: 0) + + (groupBy.asKnown().getOrNull()?.validity() ?: 0) + + (groupByDefinitions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metric.asKnown().getOrNull()?.validity() ?: 0) + + (metricDefinition.asKnown().getOrNull()?.validity() ?: 0) + + (projectMetric.asKnown().getOrNull()?.validity() ?: 0) + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + @JsonDeserialize(using = FilterDefinition.Deserializer::class) + @JsonSerialize(using = FilterDefinition.Serializer::class) + class FilterDefinition + private constructor( + private val customChartFilterByTracingProject: + CustomChartFilterByTracingProject? = + null, + private val customChartFilterByDataset: CustomChartFilterByDataset? = null, + private val _json: JsonValue? = null, + ) { + + fun customChartFilterByTracingProject(): + Optional = + Optional.ofNullable(customChartFilterByTracingProject) + + fun customChartFilterByDataset(): Optional = + Optional.ofNullable(customChartFilterByDataset) + + fun isCustomChartFilterByTracingProject(): Boolean = + customChartFilterByTracingProject != null + + fun isCustomChartFilterByDataset(): Boolean = customChartFilterByDataset != null + + fun asCustomChartFilterByTracingProject(): CustomChartFilterByTracingProject = + customChartFilterByTracingProject.getOrThrow( + "customChartFilterByTracingProject" + ) + + fun asCustomChartFilterByDataset(): CustomChartFilterByDataset = + customChartFilterByDataset.getOrThrow("customChartFilterByDataset") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the + * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not + * known to this version of the SDK gracefully, consider overriding + * [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = filterDefinition.accept(new FilterDefinition.Visitor>() { + * @Override + * public Optional visitCustomChartFilterByTracingProject(CustomChartFilterByTracingProject customChartFilterByTracingProject) { + * return Optional.of(customChartFilterByTracingProject.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden + * in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = when { - value.customChartFilterByTracingProject != null -> - generator.writeObject(value.customChartFilterByTracingProject) - value.customChartFilterByDataset != null -> - generator.writeObject(value.customChartFilterByDataset) - value._json != null -> generator.writeObject(value._json) + customChartFilterByTracingProject != null -> + visitor.visitCustomChartFilterByTracingProject( + customChartFilterByTracingProject + ) + customChartFilterByDataset != null -> + visitor.visitCustomChartFilterByDataset(customChartFilterByDataset) + else -> visitor.unknown(_json) + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): FilterDefinition = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustomChartFilterByTracingProject( + customChartFilterByTracingProject: + CustomChartFilterByTracingProject + ) { + customChartFilterByTracingProject.validate() + } + + override fun visitCustomChartFilterByDataset( + customChartFilterByDataset: CustomChartFilterByDataset + ) { + customChartFilterByDataset.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitCustomChartFilterByTracingProject( + customChartFilterByTracingProject: + CustomChartFilterByTracingProject + ) = customChartFilterByTracingProject.validity() + + override fun visitCustomChartFilterByDataset( + customChartFilterByDataset: CustomChartFilterByDataset + ) = customChartFilterByDataset.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FilterDefinition && + customChartFilterByTracingProject == + other.customChartFilterByTracingProject && + customChartFilterByDataset == other.customChartFilterByDataset + } + + override fun hashCode(): Int = + Objects.hash(customChartFilterByTracingProject, customChartFilterByDataset) + + override fun toString(): String = + when { + customChartFilterByTracingProject != null -> + "FilterDefinition{customChartFilterByTracingProject=$customChartFilterByTracingProject}" + customChartFilterByDataset != null -> + "FilterDefinition{customChartFilterByDataset=$customChartFilterByDataset}" + _json != null -> "FilterDefinition{_unknown=$_json}" else -> throw IllegalStateException("Invalid FilterDefinition") } + + companion object { + + @JvmStatic + fun ofCustomChartFilterByTracingProject( + customChartFilterByTracingProject: CustomChartFilterByTracingProject + ) = + FilterDefinition( + customChartFilterByTracingProject = + customChartFilterByTracingProject + ) + + @JvmStatic + fun ofCustomChartFilterByDataset( + customChartFilterByDataset: CustomChartFilterByDataset + ) = + FilterDefinition( + customChartFilterByDataset = customChartFilterByDataset + ) + } + + /** + * An interface that defines how to map each variant of [FilterDefinition] to a + * value of type [T]. + */ + interface Visitor { + + fun visitCustomChartFilterByTracingProject( + customChartFilterByTracingProject: CustomChartFilterByTracingProject + ): T + + fun visitCustomChartFilterByDataset( + customChartFilterByDataset: CustomChartFilterByDataset + ): T + + /** + * Maps an unknown variant of [FilterDefinition] to a value of type [T]. + * + * An instance of [FilterDefinition] can contain an unknown variant if it + * was deserialized from data that doesn't match any known variant. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown FilterDefinition: $json") + } + } + + internal class Deserializer : + BaseDeserializer(FilterDefinition::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FilterDefinition { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + FilterDefinition( + customChartFilterByTracingProject = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + FilterDefinition( + customChartFilterByDataset = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from boolean). + 0 -> FilterDefinition(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(FilterDefinition::class) { + + override fun serialize( + value: FilterDefinition, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.customChartFilterByTracingProject != null -> + generator.writeObject(value.customChartFilterByTracingProject) + value.customChartFilterByDataset != null -> + generator.writeObject(value.customChartFilterByDataset) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FilterDefinition") + } + } + } + + class CustomChartFilterByTracingProject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val projectIds: JsonField>, + private val sourceType: JsonValue, + private val runFilter: JsonField, + private val traceFilter: JsonField, + private val treeFilter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("project_ids") + @ExcludeMissing + projectIds: JsonField> = JsonMissing.of(), + @JsonProperty("source_type") + @ExcludeMissing + sourceType: JsonValue = JsonMissing.of(), + @JsonProperty("run_filter") + @ExcludeMissing + runFilter: JsonField = JsonMissing.of(), + @JsonProperty("trace_filter") + @ExcludeMissing + traceFilter: JsonField = JsonMissing.of(), + @JsonProperty("tree_filter") + @ExcludeMissing + treeFilter: JsonField = JsonMissing.of(), + ) : this( + projectIds, + sourceType, + runFilter, + traceFilter, + treeFilter, + mutableMapOf(), + ) + + /** + * @throws LangChainInvalidDataException 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 projectIds(): List = projectIds.getRequired("project_ids") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tracing_project") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the + * server responded with an unexpected value). + */ + @JsonProperty("source_type") + @ExcludeMissing + fun _sourceType(): JsonValue = sourceType + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun runFilter(): Optional = runFilter.getOptional("run_filter") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun traceFilter(): Optional = + traceFilter.getOptional("trace_filter") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun treeFilter(): Optional = treeFilter.getOptional("tree_filter") + + /** + * Returns the raw JSON value of [projectIds]. + * + * Unlike [projectIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("project_ids") + @ExcludeMissing + fun _projectIds(): JsonField> = projectIds + + /** + * Returns the raw JSON value of [runFilter]. + * + * Unlike [runFilter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("run_filter") + @ExcludeMissing + fun _runFilter(): JsonField = runFilter + + /** + * Returns the raw JSON value of [traceFilter]. + * + * Unlike [traceFilter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("trace_filter") + @ExcludeMissing + fun _traceFilter(): JsonField = traceFilter + + /** + * Returns the raw JSON value of [treeFilter]. + * + * Unlike [treeFilter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tree_filter") + @ExcludeMissing + fun _treeFilter(): JsonField = treeFilter + + @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 + * [CustomChartFilterByTracingProject]. + * + * The following fields are required: + * ```java + * .projectIds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartFilterByTracingProject]. */ + class Builder internal constructor() { + + private var projectIds: JsonField>? = null + private var sourceType: JsonValue = JsonValue.from("tracing_project") + private var runFilter: JsonField = JsonMissing.of() + private var traceFilter: JsonField = JsonMissing.of() + private var treeFilter: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartFilterByTracingProject: CustomChartFilterByTracingProject + ) = apply { + projectIds = + customChartFilterByTracingProject.projectIds.map { + it.toMutableList() + } + sourceType = customChartFilterByTracingProject.sourceType + runFilter = customChartFilterByTracingProject.runFilter + traceFilter = customChartFilterByTracingProject.traceFilter + treeFilter = customChartFilterByTracingProject.treeFilter + additionalProperties = + customChartFilterByTracingProject.additionalProperties + .toMutableMap() + } + + fun projectIds(projectIds: List) = + projectIds(JsonField.of(projectIds)) + + /** + * Sets [Builder.projectIds] to an arbitrary JSON value. + * + * You should usually call [Builder.projectIds] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun projectIds(projectIds: JsonField>) = apply { + this.projectIds = projectIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [projectIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addProjectId(projectId: String) = apply { + projectIds = + (projectIds ?: JsonField.of(mutableListOf())).also { + checkKnown("projectIds", it).add(projectId) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field + * defaults to the following: + * ```java + * JsonValue.from("tracing_project") + * ``` + * + * This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun sourceType(sourceType: JsonValue) = apply { + this.sourceType = sourceType + } + + fun runFilter(runFilter: String?) = + runFilter(JsonField.ofNullable(runFilter)) + + /** + * Alias for calling [Builder.runFilter] with `runFilter.orElse(null)`. + */ + fun runFilter(runFilter: Optional) = + runFilter(runFilter.getOrNull()) + + /** + * Sets [Builder.runFilter] to an arbitrary JSON value. + * + * You should usually call [Builder.runFilter] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun runFilter(runFilter: JsonField) = apply { + this.runFilter = runFilter + } + + fun traceFilter(traceFilter: String?) = + traceFilter(JsonField.ofNullable(traceFilter)) + + /** + * Alias for calling [Builder.traceFilter] with + * `traceFilter.orElse(null)`. + */ + fun traceFilter(traceFilter: Optional) = + traceFilter(traceFilter.getOrNull()) + + /** + * Sets [Builder.traceFilter] to an arbitrary JSON value. + * + * You should usually call [Builder.traceFilter] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun traceFilter(traceFilter: JsonField) = apply { + this.traceFilter = traceFilter + } + + fun treeFilter(treeFilter: String?) = + treeFilter(JsonField.ofNullable(treeFilter)) + + /** + * Alias for calling [Builder.treeFilter] with + * `treeFilter.orElse(null)`. + */ + fun treeFilter(treeFilter: Optional) = + treeFilter(treeFilter.getOrNull()) + + /** + * Sets [Builder.treeFilter] to an arbitrary JSON value. + * + * You should usually call [Builder.treeFilter] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun treeFilter(treeFilter: JsonField) = apply { + this.treeFilter = treeFilter + } + + 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 [CustomChartFilterByTracingProject]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .projectIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartFilterByTracingProject = + CustomChartFilterByTracingProject( + checkRequired("projectIds", projectIds).map { + it.toImmutable() + }, + sourceType, + runFilter, + traceFilter, + treeFilter, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartFilterByTracingProject = apply { + if (validated) { + return@apply + } + + projectIds() + _sourceType().let { + if (it != JsonValue.from("tracing_project")) { + throw LangChainInvalidDataException( + "'sourceType' is invalid, received $it" + ) + } + } + runFilter() + traceFilter() + treeFilter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (projectIds.asKnown().getOrNull()?.size ?: 0) + + sourceType.let { + if (it == JsonValue.from("tracing_project")) 1 else 0 + } + + (if (runFilter.asKnown().isPresent) 1 else 0) + + (if (traceFilter.asKnown().isPresent) 1 else 0) + + (if (treeFilter.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartFilterByTracingProject && + projectIds == other.projectIds && + sourceType == other.sourceType && + runFilter == other.runFilter && + traceFilter == other.traceFilter && + treeFilter == other.treeFilter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + projectIds, + sourceType, + runFilter, + traceFilter, + treeFilter, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartFilterByTracingProject{projectIds=$projectIds, sourceType=$sourceType, runFilter=$runFilter, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" + } + + class CustomChartFilterByDataset + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val datasetIds: JsonField>, + private val sourceType: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dataset_ids") + @ExcludeMissing + datasetIds: JsonField> = JsonMissing.of(), + @JsonProperty("source_type") + @ExcludeMissing + sourceType: JsonValue = JsonMissing.of(), + ) : this(datasetIds, sourceType, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 datasetIds(): List = datasetIds.getRequired("dataset_ids") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("dataset") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the + * server responded with an unexpected value). + */ + @JsonProperty("source_type") + @ExcludeMissing + fun _sourceType(): JsonValue = sourceType + + /** + * Returns the raw JSON value of [datasetIds]. + * + * Unlike [datasetIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dataset_ids") + @ExcludeMissing + fun _datasetIds(): JsonField> = datasetIds + + @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 + * [CustomChartFilterByDataset]. + * + * The following fields are required: + * ```java + * .datasetIds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartFilterByDataset]. */ + class Builder internal constructor() { + + private var datasetIds: JsonField>? = null + private var sourceType: JsonValue = JsonValue.from("dataset") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartFilterByDataset: CustomChartFilterByDataset + ) = apply { + datasetIds = + customChartFilterByDataset.datasetIds.map { it.toMutableList() } + sourceType = customChartFilterByDataset.sourceType + additionalProperties = + customChartFilterByDataset.additionalProperties.toMutableMap() + } + + fun datasetIds(datasetIds: List) = + datasetIds(JsonField.of(datasetIds)) + + /** + * Sets [Builder.datasetIds] to an arbitrary JSON value. + * + * You should usually call [Builder.datasetIds] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun datasetIds(datasetIds: JsonField>) = apply { + this.datasetIds = datasetIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [datasetIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addDatasetId(datasetId: String) = apply { + datasetIds = + (datasetIds ?: JsonField.of(mutableListOf())).also { + checkKnown("datasetIds", it).add(datasetId) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field + * defaults to the following: + * ```java + * JsonValue.from("dataset") + * ``` + * + * This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun sourceType(sourceType: JsonValue) = apply { + this.sourceType = sourceType + } + + 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 [CustomChartFilterByDataset]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .datasetIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartFilterByDataset = + CustomChartFilterByDataset( + checkRequired("datasetIds", datasetIds).map { + it.toImmutable() + }, + sourceType, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartFilterByDataset = apply { + if (validated) { + return@apply + } + + datasetIds() + _sourceType().let { + if (it != JsonValue.from("dataset")) { + throw LangChainInvalidDataException( + "'sourceType' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (datasetIds.asKnown().getOrNull()?.size ?: 0) + + sourceType.let { if (it == JsonValue.from("dataset")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartFilterByDataset && + datasetIds == other.datasetIds && + sourceType == other.sourceType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(datasetIds, sourceType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartFilterByDataset{datasetIds=$datasetIds, sourceType=$sourceType, additionalProperties=$additionalProperties}" } } - class CustomChartFilterByTracingProject + class Filters @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val projectIds: JsonField>, - private val sourceType: JsonValue, - private val runFilter: JsonField, + private val filter: JsonField, + private val session: JsonField>, private val traceFilter: JsonField, private val treeFilter: JsonField, private val additionalProperties: MutableMap, @@ -2775,55 +3716,31 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("project_ids") + @JsonProperty("filter") @ExcludeMissing - projectIds: JsonField> = JsonMissing.of(), - @JsonProperty("source_type") + filter: JsonField = JsonMissing.of(), + @JsonProperty("session") @ExcludeMissing - sourceType: JsonValue = JsonMissing.of(), - @JsonProperty("run_filter") - @ExcludeMissing - runFilter: JsonField = JsonMissing.of(), + session: JsonField> = JsonMissing.of(), @JsonProperty("trace_filter") @ExcludeMissing traceFilter: JsonField = JsonMissing.of(), @JsonProperty("tree_filter") @ExcludeMissing treeFilter: JsonField = JsonMissing.of(), - ) : this( - projectIds, - sourceType, - runFilter, - traceFilter, - treeFilter, - mutableMapOf(), - ) - - /** - * @throws LangChainInvalidDataException 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 projectIds(): List = projectIds.getRequired("project_ids") - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("tracing_project") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). - */ - @JsonProperty("source_type") - @ExcludeMissing - fun _sourceType(): JsonValue = sourceType + ) : this(filter, session, traceFilter, treeFilter, mutableMapOf()) /** * @throws LangChainInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun runFilter(): Optional = runFilter.getOptional("run_filter") + fun filter(): Optional = filter.getOptional("filter") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun session(): Optional> = session.getOptional("session") /** * @throws LangChainInvalidDataException if the JSON field has an unexpected @@ -2838,24 +3755,24 @@ private constructor( fun treeFilter(): Optional = treeFilter.getOptional("tree_filter") /** - * Returns the raw JSON value of [projectIds]. + * Returns the raw JSON value of [filter]. * - * Unlike [projectIds], this method doesn't throw if the JSON field has an + * Unlike [filter], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("project_ids") + @JsonProperty("filter") @ExcludeMissing - fun _projectIds(): JsonField> = projectIds + fun _filter(): JsonField = filter /** - * Returns the raw JSON value of [runFilter]. + * Returns the raw JSON value of [session]. * - * Unlike [runFilter], this method doesn't throw if the JSON field has an + * Unlike [session], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("run_filter") + @JsonProperty("session") @ExcludeMissing - fun _runFilter(): JsonField = runFilter + fun _session(): JsonField> = session /** * Returns the raw JSON value of [traceFilter]. @@ -2891,107 +3808,72 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of - * [CustomChartFilterByTracingProject]. - * - * The following fields are required: - * ```java - * .projectIds() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Filters]. */ @JvmStatic fun builder() = Builder() } - /** A builder for [CustomChartFilterByTracingProject]. */ + /** A builder for [Filters]. */ class Builder internal constructor() { - private var projectIds: JsonField>? = null - private var sourceType: JsonValue = JsonValue.from("tracing_project") - private var runFilter: JsonField = JsonMissing.of() + private var filter: JsonField = JsonMissing.of() + private var session: JsonField>? = null private var traceFilter: JsonField = JsonMissing.of() private var treeFilter: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from( - customChartFilterByTracingProject: CustomChartFilterByTracingProject - ) = apply { - projectIds = - customChartFilterByTracingProject.projectIds.map { - it.toMutableList() - } - sourceType = customChartFilterByTracingProject.sourceType - runFilter = customChartFilterByTracingProject.runFilter - traceFilter = customChartFilterByTracingProject.traceFilter - treeFilter = customChartFilterByTracingProject.treeFilter - additionalProperties = - customChartFilterByTracingProject.additionalProperties - .toMutableMap() + internal fun from(filters: Filters) = apply { + filter = filters.filter + session = filters.session.map { it.toMutableList() } + traceFilter = filters.traceFilter + treeFilter = filters.treeFilter + additionalProperties = filters.additionalProperties.toMutableMap() } - fun projectIds(projectIds: List) = - projectIds(JsonField.of(projectIds)) + fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) /** - * Sets [Builder.projectIds] to an arbitrary JSON value. + * Sets [Builder.filter] to an arbitrary JSON value. * - * You should usually call [Builder.projectIds] with a well-typed + * You should usually call [Builder.filter] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + fun session(session: List?) = session(JsonField.ofNullable(session)) + + /** Alias for calling [Builder.session] with `session.orElse(null)`. */ + fun session(session: Optional>) = session(session.getOrNull()) + + /** + * Sets [Builder.session] to an arbitrary JSON value. + * + * You should usually call [Builder.session] with a well-typed * `List` value instead. This method is primarily for setting the * field to an undocumented or not yet supported value. */ - fun projectIds(projectIds: JsonField>) = apply { - this.projectIds = projectIds.map { it.toMutableList() } + fun session(session: JsonField>) = apply { + this.session = session.map { it.toMutableList() } } /** - * Adds a single [String] to [projectIds]. + * Adds a single [String] to [Builder.session]. * * @throws IllegalStateException if the field was previously set to a * non-list. */ - fun addProjectId(projectId: String) = apply { - projectIds = - (projectIds ?: JsonField.of(mutableListOf())).also { - checkKnown("projectIds", it).add(projectId) + fun addSession(session: String) = apply { + this.session = + (this.session ?: JsonField.of(mutableListOf())).also { + checkKnown("session", it).add(session) } } - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field defaults - * to the following: - * ```java - * JsonValue.from("tracing_project") - * ``` - * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun sourceType(sourceType: JsonValue) = apply { - this.sourceType = sourceType - } - - fun runFilter(runFilter: String?) = - runFilter(JsonField.ofNullable(runFilter)) - - /** Alias for calling [Builder.runFilter] with `runFilter.orElse(null)`. */ - fun runFilter(runFilter: Optional) = - runFilter(runFilter.getOrNull()) - - /** - * Sets [Builder.runFilter] to an arbitrary JSON value. - * - * You should usually call [Builder.runFilter] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun runFilter(runFilter: JsonField) = apply { - this.runFilter = runFilter - } - fun traceFilter(traceFilter: String?) = traceFilter(JsonField.ofNullable(traceFilter)) @@ -3055,22 +3937,14 @@ private constructor( } /** - * Returns an immutable instance of [CustomChartFilterByTracingProject]. + * Returns an immutable instance of [Filters]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectIds() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): CustomChartFilterByTracingProject = - CustomChartFilterByTracingProject( - checkRequired("projectIds", projectIds).map { it.toImmutable() }, - sourceType, - runFilter, + fun build(): Filters = + Filters( + filter, + (session ?: JsonMissing.of()).map { it.toImmutable() }, traceFilter, treeFilter, additionalProperties.toMutableMap(), @@ -3089,20 +3963,13 @@ private constructor( * @throws LangChainInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): CustomChartFilterByTracingProject = apply { + fun validate(): Filters = apply { if (validated) { return@apply } - projectIds() - _sourceType().let { - if (it != JsonValue.from("tracing_project")) { - throw LangChainInvalidDataException( - "'sourceType' is invalid, received $it" - ) - } - } - runFilter() + filter() + session() traceFilter() treeFilter() validated = true @@ -3124,11 +3991,8 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (projectIds.asKnown().getOrNull()?.size ?: 0) + - sourceType.let { - if (it == JsonValue.from("tracing_project")) 1 else 0 - } + - (if (runFilter.asKnown().isPresent) 1 else 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + (session.asKnown().getOrNull()?.size ?: 0) + (if (traceFilter.asKnown().isPresent) 1 else 0) + (if (treeFilter.asKnown().isPresent) 1 else 0) @@ -3137,79 +4001,111 @@ private constructor( return true } - return other is CustomChartFilterByTracingProject && - projectIds == other.projectIds && - sourceType == other.sourceType && - runFilter == other.runFilter && + return other is Filters && + filter == other.filter && + session == other.session && traceFilter == other.traceFilter && treeFilter == other.treeFilter && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash( - projectIds, - sourceType, - runFilter, - traceFilter, - treeFilter, - additionalProperties, - ) + Objects.hash(filter, session, traceFilter, treeFilter, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "CustomChartFilterByTracingProject{projectIds=$projectIds, sourceType=$sourceType, runFilter=$runFilter, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" + "Filters{filter=$filter, session=$session, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" } - class CustomChartFilterByDataset + /** Include additional information about where the group_by param was set. */ + class GroupBy @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val datasetIds: JsonField>, - private val sourceType: JsonValue, + private val attribute: JsonField, + private val maxGroups: JsonField, + private val path: JsonField, + private val setBy: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("dataset_ids") + @JsonProperty("attribute") @ExcludeMissing - datasetIds: JsonField> = JsonMissing.of(), - @JsonProperty("source_type") + attribute: JsonField = JsonMissing.of(), + @JsonProperty("max_groups") @ExcludeMissing - sourceType: JsonValue = JsonMissing.of(), - ) : this(datasetIds, sourceType, mutableMapOf()) + maxGroups: JsonField = JsonMissing.of(), + @JsonProperty("path") + @ExcludeMissing + path: JsonField = JsonMissing.of(), + @JsonProperty("set_by") + @ExcludeMissing + setBy: JsonField = JsonMissing.of(), + ) : this(attribute, maxGroups, path, setBy, mutableMapOf()) /** * @throws LangChainInvalidDataException 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 datasetIds(): List = datasetIds.getRequired("dataset_ids") + fun attribute(): Attribute = attribute.getRequired("attribute") /** - * Expected to always return the following: - * ```java - * JsonValue.from("dataset") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). */ - @JsonProperty("source_type") - @ExcludeMissing - fun _sourceType(): JsonValue = sourceType + fun maxGroups(): Optional = maxGroups.getOptional("max_groups") /** - * Returns the raw JSON value of [datasetIds]. + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun path(): Optional = path.getOptional("path") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun setBy(): Optional = setBy.getOptional("set_by") + + /** + * Returns the raw JSON value of [attribute]. * - * Unlike [datasetIds], this method doesn't throw if the JSON field has an + * Unlike [attribute], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("dataset_ids") + @JsonProperty("attribute") @ExcludeMissing - fun _datasetIds(): JsonField> = datasetIds + fun _attribute(): JsonField = attribute + + /** + * Returns the raw JSON value of [maxGroups]. + * + * Unlike [maxGroups], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("max_groups") + @ExcludeMissing + fun _maxGroups(): JsonField = maxGroups + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + /** + * Returns the raw JSON value of [setBy]. + * + * Unlike [setBy], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("set_by") @ExcludeMissing fun _setBy(): JsonField = setBy @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -3226,76 +4122,1526 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [CustomChartFilterByDataset]. + * Returns a mutable builder for constructing an instance of [GroupBy]. * * The following fields are required: * ```java - * .datasetIds() + * .attribute() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [CustomChartFilterByDataset]. */ + /** A builder for [GroupBy]. */ class Builder internal constructor() { - private var datasetIds: JsonField>? = null - private var sourceType: JsonValue = JsonValue.from("dataset") + private var attribute: JsonField? = null + private var maxGroups: JsonField = JsonMissing.of() + private var path: JsonField = JsonMissing.of() + private var setBy: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(customChartFilterByDataset: CustomChartFilterByDataset) = + internal fun from(groupBy: GroupBy) = apply { + attribute = groupBy.attribute + maxGroups = groupBy.maxGroups + path = groupBy.path + setBy = groupBy.setBy + additionalProperties = groupBy.additionalProperties.toMutableMap() + } + + fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) + + /** + * Sets [Builder.attribute] to an arbitrary JSON value. + * + * You should usually call [Builder.attribute] with a well-typed [Attribute] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun attribute(attribute: JsonField) = apply { + this.attribute = attribute + } + + fun maxGroups(maxGroups: Long) = maxGroups(JsonField.of(maxGroups)) + + /** + * Sets [Builder.maxGroups] to an arbitrary JSON value. + * + * You should usually call [Builder.maxGroups] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun maxGroups(maxGroups: JsonField) = apply { + this.maxGroups = maxGroups + } + + fun path(path: String?) = path(JsonField.ofNullable(path)) + + /** Alias for calling [Builder.path] with `path.orElse(null)`. */ + fun path(path: Optional) = path(path.getOrNull()) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + fun setBy(setBy: SetBy?) = setBy(JsonField.ofNullable(setBy)) + + /** Alias for calling [Builder.setBy] with `setBy.orElse(null)`. */ + fun setBy(setBy: Optional) = setBy(setBy.getOrNull()) + + /** + * Sets [Builder.setBy] to an arbitrary JSON value. + * + * You should usually call [Builder.setBy] with a well-typed [SetBy] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun setBy(setBy: JsonField) = apply { this.setBy = setBy } + + fun additionalProperties(additionalProperties: Map) = apply { - datasetIds = - customChartFilterByDataset.datasetIds.map { it.toMutableList() } - sourceType = customChartFilterByDataset.sourceType - additionalProperties = - customChartFilterByDataset.additionalProperties.toMutableMap() + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun datasetIds(datasetIds: List) = - datasetIds(JsonField.of(datasetIds)) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * Sets [Builder.datasetIds] to an arbitrary JSON value. - * - * You should usually call [Builder.datasetIds] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun datasetIds(datasetIds: JsonField>) = apply { - this.datasetIds = datasetIds.map { it.toMutableList() } + 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) } /** - * Adds a single [String] to [datasetIds]. + * Returns an immutable instance of [GroupBy]. * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addDatasetId(datasetId: String) = apply { - datasetIds = - (datasetIds ?: JsonField.of(mutableListOf())).also { - checkKnown("datasetIds", it).add(datasetId) - } - } - - /** - * Sets the field to an arbitrary JSON value. + * Further updates to this [Builder] will not mutate the returned instance. * - * It is usually unnecessary to call this method because the field defaults - * to the following: + * The following fields are required: * ```java - * JsonValue.from("dataset") + * .attribute() * ``` * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. + * @throws IllegalStateException if any required field is unset. */ - fun sourceType(sourceType: JsonValue) = apply { - this.sourceType = sourceType + fun build(): GroupBy = + GroupBy( + checkRequired("attribute", attribute), + maxGroups, + path, + setBy, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): GroupBy = apply { + if (validated) { + return@apply + } + + attribute().validate() + maxGroups() + path() + setBy().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (attribute.asKnown().getOrNull()?.validity() ?: 0) + + (if (maxGroups.asKnown().isPresent) 1 else 0) + + (if (path.asKnown().isPresent) 1 else 0) + + (setBy.asKnown().getOrNull()?.validity() ?: 0) + + class Attribute + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val NAME = of("name") + + @JvmField val RUN_TYPE = of("run_type") + + @JvmField val TAG = of("tag") + + @JvmField val METADATA = of("metadata") + + @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) + } + + /** An enum containing [Attribute]'s known values. */ + enum class Known { + NAME, + RUN_TYPE, + TAG, + METADATA, + } + + /** + * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Attribute] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + NAME, + RUN_TYPE, + TAG, + METADATA, + /** + * An enum member indicating that [Attribute] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + NAME -> Value.NAME + RUN_TYPE -> Value.RUN_TYPE + TAG -> Value.TAG + METADATA -> Value.METADATA + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + NAME -> Known.NAME + RUN_TYPE -> Known.RUN_TYPE + TAG -> Known.TAG + METADATA -> Known.METADATA + else -> + throw LangChainInvalidDataException("Unknown Attribute: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Attribute = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Attribute && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SetBy + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val SECTION = of("section") + + @JvmField val SERIES = of("series") + + @JvmStatic fun of(value: String) = SetBy(JsonField.of(value)) + } + + /** An enum containing [SetBy]'s known values. */ + enum class Known { + SECTION, + SERIES, + } + + /** + * An enum containing [SetBy]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [SetBy] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SECTION, + SERIES, + /** + * An enum member indicating that [SetBy] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SECTION -> Value.SECTION + SERIES -> Value.SERIES + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + SECTION -> Known.SECTION + SERIES -> Known.SERIES + else -> throw LangChainInvalidDataException("Unknown SetBy: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): SetBy = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SetBy && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupBy && + attribute == other.attribute && + maxGroups == other.maxGroups && + path == other.path && + setBy == other.setBy && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attribute, maxGroups, path, setBy, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupBy{attribute=$attribute, maxGroups=$maxGroups, path=$path, setBy=$setBy, additionalProperties=$additionalProperties}" + } + + @JsonDeserialize(using = GroupByDefinition.Deserializer::class) + @JsonSerialize(using = GroupByDefinition.Serializer::class) + class GroupByDefinition + private constructor( + private val customChartGroupByPlain: CustomChartGroupByPlain? = null, + private val customChartGroupByComplex: CustomChartGroupByComplex? = null, + private val _json: JsonValue? = null, + ) { + + fun customChartGroupByPlain(): Optional = + Optional.ofNullable(customChartGroupByPlain) + + fun customChartGroupByComplex(): Optional = + Optional.ofNullable(customChartGroupByComplex) + + fun isCustomChartGroupByPlain(): Boolean = customChartGroupByPlain != null + + fun isCustomChartGroupByComplex(): Boolean = customChartGroupByComplex != null + + fun asCustomChartGroupByPlain(): CustomChartGroupByPlain = + customChartGroupByPlain.getOrThrow("customChartGroupByPlain") + + fun asCustomChartGroupByComplex(): CustomChartGroupByComplex = + customChartGroupByComplex.getOrThrow("customChartGroupByComplex") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the + * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not + * known to this version of the SDK gracefully, consider overriding + * [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = groupByDefinition.accept(new GroupByDefinition.Visitor>() { + * @Override + * public Optional visitCustomChartGroupByPlain(CustomChartGroupByPlain customChartGroupByPlain) { + * return Optional.of(customChartGroupByPlain.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden + * in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + customChartGroupByPlain != null -> + visitor.visitCustomChartGroupByPlain(customChartGroupByPlain) + customChartGroupByComplex != null -> + visitor.visitCustomChartGroupByComplex(customChartGroupByComplex) + else -> visitor.unknown(_json) + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): GroupByDefinition = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustomChartGroupByPlain( + customChartGroupByPlain: CustomChartGroupByPlain + ) { + customChartGroupByPlain.validate() + } + + override fun visitCustomChartGroupByComplex( + customChartGroupByComplex: CustomChartGroupByComplex + ) { + customChartGroupByComplex.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitCustomChartGroupByPlain( + customChartGroupByPlain: CustomChartGroupByPlain + ) = customChartGroupByPlain.validity() + + override fun visitCustomChartGroupByComplex( + customChartGroupByComplex: CustomChartGroupByComplex + ) = customChartGroupByComplex.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupByDefinition && + customChartGroupByPlain == other.customChartGroupByPlain && + customChartGroupByComplex == other.customChartGroupByComplex + } + + override fun hashCode(): Int = + Objects.hash(customChartGroupByPlain, customChartGroupByComplex) + + override fun toString(): String = + when { + customChartGroupByPlain != null -> + "GroupByDefinition{customChartGroupByPlain=$customChartGroupByPlain}" + customChartGroupByComplex != null -> + "GroupByDefinition{customChartGroupByComplex=$customChartGroupByComplex}" + _json != null -> "GroupByDefinition{_unknown=$_json}" + else -> throw IllegalStateException("Invalid GroupByDefinition") + } + + companion object { + + @JvmStatic + fun ofCustomChartGroupByPlain( + customChartGroupByPlain: CustomChartGroupByPlain + ) = GroupByDefinition(customChartGroupByPlain = customChartGroupByPlain) + + @JvmStatic + fun ofCustomChartGroupByComplex( + customChartGroupByComplex: CustomChartGroupByComplex + ) = GroupByDefinition(customChartGroupByComplex = customChartGroupByComplex) + } + + /** + * An interface that defines how to map each variant of [GroupByDefinition] to a + * value of type [T]. + */ + interface Visitor { + + fun visitCustomChartGroupByPlain( + customChartGroupByPlain: CustomChartGroupByPlain + ): T + + fun visitCustomChartGroupByComplex( + customChartGroupByComplex: CustomChartGroupByComplex + ): T + + /** + * Maps an unknown variant of [GroupByDefinition] to a value of type [T]. + * + * An instance of [GroupByDefinition] can contain an unknown variant if it + * was deserialized from data that doesn't match any known variant. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown GroupByDefinition: $json") + } + } + + internal class Deserializer : + BaseDeserializer(GroupByDefinition::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): GroupByDefinition { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + GroupByDefinition( + customChartGroupByPlain = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + GroupByDefinition( + customChartGroupByComplex = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from boolean). + 0 -> GroupByDefinition(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(GroupByDefinition::class) { + + override fun serialize( + value: GroupByDefinition, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.customChartGroupByPlain != null -> + generator.writeObject(value.customChartGroupByPlain) + value.customChartGroupByComplex != null -> + generator.writeObject(value.customChartGroupByComplex) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid GroupByDefinition") + } + } + } + + class CustomChartGroupByPlain + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attribute: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attribute") + @ExcludeMissing + attribute: JsonField = JsonMissing.of() + ) : this(attribute, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 attribute(): Attribute = attribute.getRequired("attribute") + + /** + * Returns the raw JSON value of [attribute]. + * + * Unlike [attribute], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("attribute") + @ExcludeMissing + fun _attribute(): JsonField = attribute + + @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 + * [CustomChartGroupByPlain]. + * + * The following fields are required: + * ```java + * .attribute() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartGroupByPlain]. */ + class Builder internal constructor() { + + private var attribute: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customChartGroupByPlain: CustomChartGroupByPlain) = + apply { + attribute = customChartGroupByPlain.attribute + additionalProperties = + customChartGroupByPlain.additionalProperties.toMutableMap() + } + + fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) + + /** + * Sets [Builder.attribute] to an arbitrary JSON value. + * + * You should usually call [Builder.attribute] with a well-typed + * [Attribute] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun attribute(attribute: JsonField) = apply { + this.attribute = attribute + } + + 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 [CustomChartGroupByPlain]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .attribute() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartGroupByPlain = + CustomChartGroupByPlain( + checkRequired("attribute", attribute), + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartGroupByPlain = apply { + if (validated) { + return@apply + } + + attribute().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (attribute.asKnown().getOrNull()?.validity() ?: 0) + + class Attribute + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val NAME = of("name") + + @JvmField val RUN_TYPE = of("run_type") + + @JvmField val TAG = of("tag") + + @JvmField val PROJECT = of("project") + + @JvmField val STATUS = of("status") + + @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) + } + + /** An enum containing [Attribute]'s known values. */ + enum class Known { + NAME, + RUN_TYPE, + TAG, + PROJECT, + STATUS, + } + + /** + * An enum containing [Attribute]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Attribute] can contain an unknown value in a couple + * of cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + NAME, + RUN_TYPE, + TAG, + PROJECT, + STATUS, + /** + * An enum member indicating that [Attribute] was instantiated with + * an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + NAME -> Value.NAME + RUN_TYPE -> Value.RUN_TYPE + TAG -> Value.TAG + PROJECT -> Value.PROJECT + STATUS -> Value.STATUS + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + NAME -> Known.NAME + RUN_TYPE -> Known.RUN_TYPE + TAG -> Known.TAG + PROJECT -> Known.PROJECT + STATUS -> Known.STATUS + else -> + throw LangChainInvalidDataException( + "Unknown Attribute: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Attribute = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Attribute && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartGroupByPlain && + attribute == other.attribute && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attribute, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartGroupByPlain{attribute=$attribute, additionalProperties=$additionalProperties}" + } + + class CustomChartGroupByComplex + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attribute: JsonField, + private val path: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attribute") + @ExcludeMissing + attribute: JsonField = JsonMissing.of(), + @JsonProperty("path") + @ExcludeMissing + path: JsonField = JsonMissing.of(), + ) : this(attribute, path, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 attribute(): Attribute = attribute.getRequired("attribute") + + /** + * @throws LangChainInvalidDataException 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 path(): String = path.getRequired("path") + + /** + * Returns the raw JSON value of [attribute]. + * + * Unlike [attribute], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("attribute") + @ExcludeMissing + fun _attribute(): JsonField = attribute + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + @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 + * [CustomChartGroupByComplex]. + * + * The following fields are required: + * ```java + * .attribute() + * .path() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartGroupByComplex]. */ + class Builder internal constructor() { + + private var attribute: JsonField? = null + private var path: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartGroupByComplex: CustomChartGroupByComplex + ) = apply { + attribute = customChartGroupByComplex.attribute + path = customChartGroupByComplex.path + additionalProperties = + customChartGroupByComplex.additionalProperties.toMutableMap() + } + + fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) + + /** + * Sets [Builder.attribute] to an arbitrary JSON value. + * + * You should usually call [Builder.attribute] with a well-typed + * [Attribute] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun attribute(attribute: JsonField) = apply { + this.attribute = attribute + } + + fun path(path: String) = path(JsonField.of(path)) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + 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 [CustomChartGroupByComplex]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .attribute() + * .path() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartGroupByComplex = + CustomChartGroupByComplex( + checkRequired("attribute", attribute), + checkRequired("path", path), + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartGroupByComplex = apply { + if (validated) { + return@apply + } + + attribute().validate() + path() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (attribute.asKnown().getOrNull()?.validity() ?: 0) + + (if (path.asKnown().isPresent) 1 else 0) + + class Attribute + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val METADATA = of("metadata") + + @JvmField val FEEDBACK_LABEL = of("feedback_label") + + @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) + } + + /** An enum containing [Attribute]'s known values. */ + enum class Known { + METADATA, + FEEDBACK_LABEL, + } + + /** + * An enum containing [Attribute]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Attribute] can contain an unknown value in a couple + * of cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + METADATA, + FEEDBACK_LABEL, + /** + * An enum member indicating that [Attribute] was instantiated with + * an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + METADATA -> Value.METADATA + FEEDBACK_LABEL -> Value.FEEDBACK_LABEL + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + METADATA -> Known.METADATA + FEEDBACK_LABEL -> Known.FEEDBACK_LABEL + else -> + throw LangChainInvalidDataException( + "Unknown Attribute: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Attribute = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Attribute && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartGroupByComplex && + attribute == other.attribute && + path == other.path && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attribute, path, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartGroupByComplex{attribute=$attribute, path=$path, additionalProperties=$additionalProperties}" + } + } + + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = @@ -3321,23 +5667,11 @@ private constructor( } /** - * Returns an immutable instance of [CustomChartFilterByDataset]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetIds() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): CustomChartFilterByDataset = - CustomChartFilterByDataset( - checkRequired("datasetIds", datasetIds).map { it.toImmutable() }, - sourceType, - additionalProperties.toMutableMap(), - ) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -3352,19 +5686,11 @@ private constructor( * @throws LangChainInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): CustomChartFilterByDataset = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } - datasetIds() - _sourceType().let { - if (it != JsonValue.from("dataset")) { - throw LangChainInvalidDataException( - "'sourceType' is invalid, received $it" - ) - } - } validated = true } @@ -3384,32 +5710,9316 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (datasetIds.asKnown().getOrNull()?.size ?: 0) + - sourceType.let { if (it == JsonValue.from("dataset")) 1 else 0 } + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is CustomChartFilterByDataset && - datasetIds == other.datasetIds && - sourceType == other.sourceType && + return other is Metadata && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { - Objects.hash(datasetIds, sourceType, additionalProperties) - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = - "CustomChartFilterByDataset{datasetIds=$datasetIds, sourceType=$sourceType, additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + + /** + * Metrics you can chart. Feedback metrics are not available for organization-scoped + * charts. + */ + class Metric + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val RUN_COUNT = of("run_count") + + @JvmField val LATENCY_P50 = of("latency_p50") + + @JvmField val LATENCY_P99 = of("latency_p99") + + @JvmField val LATENCY_AVG = of("latency_avg") + + @JvmField val FIRST_TOKEN_P50 = of("first_token_p50") + + @JvmField val FIRST_TOKEN_P99 = of("first_token_p99") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val MEDIAN_TOKENS = of("median_tokens") + + @JvmField val COMPLETION_TOKENS_P50 = of("completion_tokens_p50") + + @JvmField val PROMPT_TOKENS_P50 = of("prompt_tokens_p50") + + @JvmField val TOKENS_P99 = of("tokens_p99") + + @JvmField val COMPLETION_TOKENS_P99 = of("completion_tokens_p99") + + @JvmField val PROMPT_TOKENS_P99 = of("prompt_tokens_p99") + + @JvmField val FEEDBACK = of("feedback") + + @JvmField val FEEDBACK_SCORE_AVG = of("feedback_score_avg") + + @JvmField val FEEDBACK_VALUES = of("feedback_values") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val ERROR_RATE = of("error_rate") + + @JvmField val STREAMING_RATE = of("streaming_rate") + + @JvmField val COST_P50 = of("cost_p50") + + @JvmField val COST_P99 = of("cost_p99") + + @JvmStatic fun of(value: String) = Metric(JsonField.of(value)) + } + + /** An enum containing [Metric]'s known values. */ + enum class Known { + RUN_COUNT, + LATENCY_P50, + LATENCY_P99, + LATENCY_AVG, + FIRST_TOKEN_P50, + FIRST_TOKEN_P99, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + MEDIAN_TOKENS, + COMPLETION_TOKENS_P50, + PROMPT_TOKENS_P50, + TOKENS_P99, + COMPLETION_TOKENS_P99, + PROMPT_TOKENS_P99, + FEEDBACK, + FEEDBACK_SCORE_AVG, + FEEDBACK_VALUES, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + ERROR_RATE, + STREAMING_RATE, + COST_P50, + COST_P99, + } + + /** + * An enum containing [Metric]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Metric] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + RUN_COUNT, + LATENCY_P50, + LATENCY_P99, + LATENCY_AVG, + FIRST_TOKEN_P50, + FIRST_TOKEN_P99, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + MEDIAN_TOKENS, + COMPLETION_TOKENS_P50, + PROMPT_TOKENS_P50, + TOKENS_P99, + COMPLETION_TOKENS_P99, + PROMPT_TOKENS_P99, + FEEDBACK, + FEEDBACK_SCORE_AVG, + FEEDBACK_VALUES, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + ERROR_RATE, + STREAMING_RATE, + COST_P50, + COST_P99, + /** + * An enum member indicating that [Metric] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + RUN_COUNT -> Value.RUN_COUNT + LATENCY_P50 -> Value.LATENCY_P50 + LATENCY_P99 -> Value.LATENCY_P99 + LATENCY_AVG -> Value.LATENCY_AVG + FIRST_TOKEN_P50 -> Value.FIRST_TOKEN_P50 + FIRST_TOKEN_P99 -> Value.FIRST_TOKEN_P99 + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + MEDIAN_TOKENS -> Value.MEDIAN_TOKENS + COMPLETION_TOKENS_P50 -> Value.COMPLETION_TOKENS_P50 + PROMPT_TOKENS_P50 -> Value.PROMPT_TOKENS_P50 + TOKENS_P99 -> Value.TOKENS_P99 + COMPLETION_TOKENS_P99 -> Value.COMPLETION_TOKENS_P99 + PROMPT_TOKENS_P99 -> Value.PROMPT_TOKENS_P99 + FEEDBACK -> Value.FEEDBACK + FEEDBACK_SCORE_AVG -> Value.FEEDBACK_SCORE_AVG + FEEDBACK_VALUES -> Value.FEEDBACK_VALUES + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + ERROR_RATE -> Value.ERROR_RATE + STREAMING_RATE -> Value.STREAMING_RATE + COST_P50 -> Value.COST_P50 + COST_P99 -> Value.COST_P99 + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + RUN_COUNT -> Known.RUN_COUNT + LATENCY_P50 -> Known.LATENCY_P50 + LATENCY_P99 -> Known.LATENCY_P99 + LATENCY_AVG -> Known.LATENCY_AVG + FIRST_TOKEN_P50 -> Known.FIRST_TOKEN_P50 + FIRST_TOKEN_P99 -> Known.FIRST_TOKEN_P99 + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + MEDIAN_TOKENS -> Known.MEDIAN_TOKENS + COMPLETION_TOKENS_P50 -> Known.COMPLETION_TOKENS_P50 + PROMPT_TOKENS_P50 -> Known.PROMPT_TOKENS_P50 + TOKENS_P99 -> Known.TOKENS_P99 + COMPLETION_TOKENS_P99 -> Known.COMPLETION_TOKENS_P99 + PROMPT_TOKENS_P99 -> Known.PROMPT_TOKENS_P99 + FEEDBACK -> Known.FEEDBACK + FEEDBACK_SCORE_AVG -> Known.FEEDBACK_SCORE_AVG + FEEDBACK_VALUES -> Known.FEEDBACK_VALUES + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + ERROR_RATE -> Known.ERROR_RATE + STREAMING_RATE -> Known.STREAMING_RATE + COST_P50 -> Known.COST_P50 + COST_P99 -> Known.COST_P99 + else -> throw LangChainInvalidDataException("Unknown Metric: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Metric = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metric && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = MetricDefinition.Deserializer::class) + @JsonSerialize(using = MetricDefinition.Serializer::class) + class MetricDefinition + private constructor( + private val customChartMetricCount: CustomChartMetricCount? = null, + private val customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar? = + null, + private val customChartMetricScalar: CustomChartMetricScalar? = null, + private val customChartMetricPercentile: CustomChartMetricPercentile? = null, + private val customChartMetricRatioOutput: CustomChartMetricRatioOutput? = null, + private val _json: JsonValue? = null, + ) { + + fun customChartMetricCount(): Optional = + Optional.ofNullable(customChartMetricCount) + + fun customChartFeedbackScoreMetricScalar(): + Optional = + Optional.ofNullable(customChartFeedbackScoreMetricScalar) + + fun customChartMetricScalar(): Optional = + Optional.ofNullable(customChartMetricScalar) + + fun customChartMetricPercentile(): Optional = + Optional.ofNullable(customChartMetricPercentile) + + fun customChartMetricRatioOutput(): Optional = + Optional.ofNullable(customChartMetricRatioOutput) + + fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null + + fun isCustomChartFeedbackScoreMetricScalar(): Boolean = + customChartFeedbackScoreMetricScalar != null + + fun isCustomChartMetricScalar(): Boolean = customChartMetricScalar != null + + fun isCustomChartMetricPercentile(): Boolean = + customChartMetricPercentile != null + + fun isCustomChartMetricRatioOutput(): Boolean = + customChartMetricRatioOutput != null + + fun asCustomChartMetricCount(): CustomChartMetricCount = + customChartMetricCount.getOrThrow("customChartMetricCount") + + fun asCustomChartFeedbackScoreMetricScalar(): + CustomChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar.getOrThrow( + "customChartFeedbackScoreMetricScalar" + ) + + fun asCustomChartMetricScalar(): CustomChartMetricScalar = + customChartMetricScalar.getOrThrow("customChartMetricScalar") + + fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = + customChartMetricPercentile.getOrThrow("customChartMetricPercentile") + + fun asCustomChartMetricRatioOutput(): CustomChartMetricRatioOutput = + customChartMetricRatioOutput.getOrThrow("customChartMetricRatioOutput") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the + * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not + * known to this version of the SDK gracefully, consider overriding + * [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = metricDefinition.accept(new MetricDefinition.Visitor>() { + * @Override + * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { + * return Optional.of(customChartMetricCount.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden + * in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + customChartMetricCount != null -> + visitor.visitCustomChartMetricCount(customChartMetricCount) + customChartFeedbackScoreMetricScalar != null -> + visitor.visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + customChartMetricScalar != null -> + visitor.visitCustomChartMetricScalar(customChartMetricScalar) + customChartMetricPercentile != null -> + visitor.visitCustomChartMetricPercentile( + customChartMetricPercentile + ) + customChartMetricRatioOutput != null -> + visitor.visitCustomChartMetricRatioOutput( + customChartMetricRatioOutput + ) + else -> visitor.unknown(_json) + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): MetricDefinition = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) { + customChartMetricCount.validate() + } + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) { + customChartFeedbackScoreMetricScalar.validate() + } + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) { + customChartMetricScalar.validate() + } + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) { + customChartMetricPercentile.validate() + } + + override fun visitCustomChartMetricRatioOutput( + customChartMetricRatioOutput: CustomChartMetricRatioOutput + ) { + customChartMetricRatioOutput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = customChartMetricCount.validity() + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = customChartFeedbackScoreMetricScalar.validity() + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = customChartMetricScalar.validity() + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = customChartMetricPercentile.validity() + + override fun visitCustomChartMetricRatioOutput( + customChartMetricRatioOutput: CustomChartMetricRatioOutput + ) = customChartMetricRatioOutput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MetricDefinition && + customChartMetricCount == other.customChartMetricCount && + customChartFeedbackScoreMetricScalar == + other.customChartFeedbackScoreMetricScalar && + customChartMetricScalar == other.customChartMetricScalar && + customChartMetricPercentile == other.customChartMetricPercentile && + customChartMetricRatioOutput == other.customChartMetricRatioOutput + } + + override fun hashCode(): Int = + Objects.hash( + customChartMetricCount, + customChartFeedbackScoreMetricScalar, + customChartMetricScalar, + customChartMetricPercentile, + customChartMetricRatioOutput, + ) + + override fun toString(): String = + when { + customChartMetricCount != null -> + "MetricDefinition{customChartMetricCount=$customChartMetricCount}" + customChartFeedbackScoreMetricScalar != null -> + "MetricDefinition{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" + customChartMetricScalar != null -> + "MetricDefinition{customChartMetricScalar=$customChartMetricScalar}" + customChartMetricPercentile != null -> + "MetricDefinition{customChartMetricPercentile=$customChartMetricPercentile}" + customChartMetricRatioOutput != null -> + "MetricDefinition{customChartMetricRatioOutput=$customChartMetricRatioOutput}" + _json != null -> "MetricDefinition{_unknown=$_json}" + else -> throw IllegalStateException("Invalid MetricDefinition") + } + + companion object { + + @JvmStatic + fun ofCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = MetricDefinition(customChartMetricCount = customChartMetricCount) + + @JvmStatic + fun ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = + MetricDefinition( + customChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar + ) + + @JvmStatic + fun ofCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = MetricDefinition(customChartMetricScalar = customChartMetricScalar) + + @JvmStatic + fun ofCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = + MetricDefinition( + customChartMetricPercentile = customChartMetricPercentile + ) + + @JvmStatic + fun ofCustomChartMetricRatioOutput( + customChartMetricRatioOutput: CustomChartMetricRatioOutput + ) = + MetricDefinition( + customChartMetricRatioOutput = customChartMetricRatioOutput + ) + } + + /** + * An interface that defines how to map each variant of [MetricDefinition] to a + * value of type [T]. + */ + interface Visitor { + + fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ): T + + fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ): T + + fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ): T + + fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ): T + + fun visitCustomChartMetricRatioOutput( + customChartMetricRatioOutput: CustomChartMetricRatioOutput + ): T + + /** + * Maps an unknown variant of [MetricDefinition] to a value of type [T]. + * + * An instance of [MetricDefinition] can contain an unknown variant if it + * was deserialized from data that doesn't match any known variant. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown MetricDefinition: $json") + } + } + + internal class Deserializer : + BaseDeserializer(MetricDefinition::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): MetricDefinition { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + MetricDefinition( + customChartMetricCount = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + CustomChartFeedbackScoreMetricScalar + >(), + ) + ?.let { + MetricDefinition( + customChartFeedbackScoreMetricScalar = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + MetricDefinition( + customChartMetricScalar = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + MetricDefinition( + customChartMetricPercentile = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + MetricDefinition( + customChartMetricRatioOutput = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from boolean). + 0 -> MetricDefinition(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(MetricDefinition::class) { + + override fun serialize( + value: MetricDefinition, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.customChartMetricCount != null -> + generator.writeObject(value.customChartMetricCount) + value.customChartFeedbackScoreMetricScalar != null -> + generator.writeObject( + value.customChartFeedbackScoreMetricScalar + ) + value.customChartMetricScalar != null -> + generator.writeObject(value.customChartMetricScalar) + value.customChartMetricPercentile != null -> + generator.writeObject(value.customChartMetricPercentile) + value.customChartMetricRatioOutput != null -> + generator.writeObject(value.customChartMetricRatioOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid MetricDefinition") + } + } + } + + class CustomChartMetricCount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filter: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(filter, type, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * @throws LangChainInvalidDataException 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 [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + /** + * 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 + * [CustomChartMetricCount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricCount]. */ + class Builder internal constructor() { + + private var filter: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customChartMetricCount: CustomChartMetricCount) = + apply { + filter = customChartMetricCount.filter + type = customChartMetricCount.type + additionalProperties = + customChartMetricCount.additionalProperties.toMutableMap() + } + + fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + 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 [CustomChartMetricCount]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): CustomChartMetricCount = + CustomChartMetricCount( + filter, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartMetricCount = apply { + if (validated) { + return@apply + } + + filter() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (filter.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val COUNT = of("count") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COUNT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + COUNT, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + COUNT -> Value.COUNT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + COUNT -> Known.COUNT + else -> + throw LangChainInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricCount && + filter == other.filter && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filter, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" + } + + class CustomChartFeedbackScoreMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonValue, + private val params: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonValue = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the + * server responded with an unexpected value). + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonValue = field + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonValue = JsonValue.from("feedback_score") + private var params: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = apply { + field = customChartFeedbackScoreMetricScalar.field + params = customChartFeedbackScoreMetricScalar.params + type = customChartFeedbackScoreMetricScalar.type + filter = customChartFeedbackScoreMetricScalar.filter + additionalProperties = + customChartFeedbackScoreMetricScalar.additionalProperties + .toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field + * defaults to the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun field(field: JsonValue) = apply { this.field = field } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed [Params] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { this.params = params } + + 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + 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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartFeedbackScoreMetricScalar = + CustomChartFeedbackScoreMetricScalar( + field, + checkRequired("params", params), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartFeedbackScoreMetricScalar = apply { + if (validated) { + return@apply + } + + _field().let { + if (it != JsonValue.from("feedback_score")) { + throw LangChainInvalidDataException( + "'field' is invalid, received $it" + ) + } + } + params().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + field.let { if (it == JsonValue.from("feedback_score")) 1 else 0 } + + (params.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val feedbackKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback_key") + @ExcludeMissing + feedbackKey: JsonField = JsonMissing.of() + ) : this(feedbackKey, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 feedbackKey(): String = feedbackKey.getRequired("feedback_key") + + /** + * Returns the raw JSON value of [feedbackKey]. + * + * Unlike [feedbackKey], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("feedback_key") + @ExcludeMissing + fun _feedbackKey(): JsonField = feedbackKey + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var feedbackKey: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + feedbackKey = params.feedbackKey + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun feedbackKey(feedbackKey: String) = + feedbackKey(JsonField.of(feedbackKey)) + + /** + * Sets [Builder.feedbackKey] to an arbitrary JSON value. + * + * You should usually call [Builder.feedbackKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun feedbackKey(feedbackKey: JsonField) = apply { + this.feedbackKey = feedbackKey + } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Params = + Params( + checkRequired("feedbackKey", feedbackKey), + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + feedbackKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (feedbackKey.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + feedbackKey == other.feedbackKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(feedbackKey, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartFeedbackScoreMetricScalar && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricScalar]. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customChartMetricScalar: CustomChartMetricScalar) = + apply { + field = customChartMetricScalar.field + type = customChartMetricScalar.type + filter = customChartMetricScalar.filter + additionalProperties = + customChartMetricScalar.additionalProperties.toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + 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 [CustomChartMetricScalar]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricScalar = + CustomChartMetricScalar( + checkRequired("field", field), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartMetricScalar = apply { + if (validated) { + return@apply + } + + field().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Field] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException("Unknown Field: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val SUM = of("sum") + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SUM, + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SUM, + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SUM -> Value.SUM + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + SUM -> Known.SUM + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricScalar && + field == other.field && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricPercentile + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val params: JsonField, + private val type: JsonValue, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonValue = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the + * server responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricPercentile]. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricPercentile]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var params: JsonField? = null + private var type: JsonValue = JsonValue.from("percentile") + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricPercentile: CustomChartMetricPercentile + ) = apply { + field = customChartMetricPercentile.field + params = customChartMetricPercentile.params + type = customChartMetricPercentile.type + filter = customChartMetricPercentile.filter + additionalProperties = + customChartMetricPercentile.additionalProperties.toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed [Params] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { this.params = params } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field + * defaults to the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ + fun filter(filter: Optional) = filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + 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 [CustomChartMetricPercentile]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricPercentile = + CustomChartMetricPercentile( + checkRequired("field", field), + checkRequired("params", params), + type, + filter, + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartMetricPercentile = apply { + if (validated) { + return@apply + } + + field().validate() + params().validate() + _type().let { + if (it != JsonValue.from("percentile")) { + throw LangChainInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (params.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("percentile")) 1 else 0 } + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Field] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException("Unknown Field: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val p: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("p") + @ExcludeMissing + p: JsonField = JsonMissing.of() + ) : this(p, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") + + /** + * Returns the raw JSON value of [p]. + * + * Unlike [p], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("p") @ExcludeMissing fun _p(): JsonField = p + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .p() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var p: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + p = params.p + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun p(p: Double) = p(JsonField.of(p)) + + /** + * Sets [Builder.p] to an arbitrary JSON value. + * + * You should usually call [Builder.p] with a well-typed [Double] + * value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun p(p: JsonField) = apply { this.p = p } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .p() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Params = + Params( + checkRequired("p", p), + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + p() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (p.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + p == other.p && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(p, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{p=$p, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricPercentile && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricRatioOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val denominator: JsonField, + private val numerator: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("denominator") + @ExcludeMissing + denominator: JsonField = JsonMissing.of(), + @JsonProperty("numerator") + @ExcludeMissing + numerator: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(denominator, numerator, type, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 denominator(): Denominator = denominator.getRequired("denominator") + + /** + * @throws LangChainInvalidDataException 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 numerator(): Numerator = numerator.getRequired("numerator") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("ratio") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the + * server responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [denominator]. + * + * Unlike [denominator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("denominator") + @ExcludeMissing + fun _denominator(): JsonField = denominator + + /** + * Returns the raw JSON value of [numerator]. + * + * Unlike [numerator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("numerator") + @ExcludeMissing + fun _numerator(): JsonField = numerator + + @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 + * [CustomChartMetricRatioOutput]. + * + * The following fields are required: + * ```java + * .denominator() + * .numerator() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricRatioOutput]. */ + class Builder internal constructor() { + + private var denominator: JsonField? = null + private var numerator: JsonField? = null + private var type: JsonValue = JsonValue.from("ratio") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricRatioOutput: CustomChartMetricRatioOutput + ) = apply { + denominator = customChartMetricRatioOutput.denominator + numerator = customChartMetricRatioOutput.numerator + type = customChartMetricRatioOutput.type + additionalProperties = + customChartMetricRatioOutput.additionalProperties.toMutableMap() + } + + fun denominator(denominator: Denominator) = + denominator(JsonField.of(denominator)) + + /** + * Sets [Builder.denominator] to an arbitrary JSON value. + * + * You should usually call [Builder.denominator] with a well-typed + * [Denominator] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun denominator(denominator: JsonField) = apply { + this.denominator = denominator + } + + /** + * Alias for calling [denominator] with + * `Denominator.ofCustomChartMetricCount(customChartMetricCount)`. + */ + fun denominator( + customChartMetricCount: Denominator.CustomChartMetricCount + ) = + denominator( + Denominator.ofCustomChartMetricCount(customChartMetricCount) + ) + + /** + * Alias for calling [denominator] with + * `Denominator.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. + */ + fun denominator( + customChartFeedbackScoreMetricScalar: + Denominator.CustomChartFeedbackScoreMetricScalar + ) = + denominator( + Denominator.ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + ) + + /** + * Alias for calling [denominator] with + * `Denominator.ofCustomChartMetricScalar(customChartMetricScalar)`. + */ + fun denominator( + customChartMetricScalar: Denominator.CustomChartMetricScalar + ) = + denominator( + Denominator.ofCustomChartMetricScalar(customChartMetricScalar) + ) + + /** + * Alias for calling [denominator] with + * `Denominator.ofCustomChartMetricPercentile(customChartMetricPercentile)`. + */ + fun denominator( + customChartMetricPercentile: Denominator.CustomChartMetricPercentile + ) = + denominator( + Denominator.ofCustomChartMetricPercentile( + customChartMetricPercentile + ) + ) + + fun numerator(numerator: Numerator) = numerator(JsonField.of(numerator)) + + /** + * Sets [Builder.numerator] to an arbitrary JSON value. + * + * You should usually call [Builder.numerator] with a well-typed + * [Numerator] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun numerator(numerator: JsonField) = apply { + this.numerator = numerator + } + + /** + * Alias for calling [numerator] with + * `Numerator.ofCustomChartMetricCount(customChartMetricCount)`. + */ + fun numerator( + customChartMetricCount: Numerator.CustomChartMetricCount + ) = + numerator( + Numerator.ofCustomChartMetricCount(customChartMetricCount) + ) + + /** + * Alias for calling [numerator] with + * `Numerator.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. + */ + fun numerator( + customChartFeedbackScoreMetricScalar: + Numerator.CustomChartFeedbackScoreMetricScalar + ) = + numerator( + Numerator.ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + ) + + /** + * Alias for calling [numerator] with + * `Numerator.ofCustomChartMetricScalar(customChartMetricScalar)`. + */ + fun numerator( + customChartMetricScalar: Numerator.CustomChartMetricScalar + ) = + numerator( + Numerator.ofCustomChartMetricScalar(customChartMetricScalar) + ) + + /** + * Alias for calling [numerator] with + * `Numerator.ofCustomChartMetricPercentile(customChartMetricPercentile)`. + */ + fun numerator( + customChartMetricPercentile: Numerator.CustomChartMetricPercentile + ) = + numerator( + Numerator.ofCustomChartMetricPercentile( + customChartMetricPercentile + ) + ) + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field + * defaults to the following: + * ```java + * JsonValue.from("ratio") + * ``` + * + * This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonValue) = 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 [CustomChartMetricRatioOutput]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .denominator() + * .numerator() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricRatioOutput = + CustomChartMetricRatioOutput( + checkRequired("denominator", denominator), + checkRequired("numerator", numerator), + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomChartMetricRatioOutput = apply { + if (validated) { + return@apply + } + + denominator().validate() + numerator().validate() + _type().let { + if (it != JsonValue.from("ratio")) { + throw LangChainInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (denominator.asKnown().getOrNull()?.validity() ?: 0) + + (numerator.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("ratio")) 1 else 0 } + + @JsonDeserialize(using = Denominator.Deserializer::class) + @JsonSerialize(using = Denominator.Serializer::class) + class Denominator + private constructor( + private val customChartMetricCount: CustomChartMetricCount? = null, + private val customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar? = + null, + private val customChartMetricScalar: CustomChartMetricScalar? = null, + private val customChartMetricPercentile: CustomChartMetricPercentile? = + null, + private val _json: JsonValue? = null, + ) { + + fun customChartMetricCount(): Optional = + Optional.ofNullable(customChartMetricCount) + + fun customChartFeedbackScoreMetricScalar(): + Optional = + Optional.ofNullable(customChartFeedbackScoreMetricScalar) + + fun customChartMetricScalar(): Optional = + Optional.ofNullable(customChartMetricScalar) + + fun customChartMetricPercentile(): + Optional = + Optional.ofNullable(customChartMetricPercentile) + + fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null + + fun isCustomChartFeedbackScoreMetricScalar(): Boolean = + customChartFeedbackScoreMetricScalar != null + + fun isCustomChartMetricScalar(): Boolean = + customChartMetricScalar != null + + fun isCustomChartMetricPercentile(): Boolean = + customChartMetricPercentile != null + + fun asCustomChartMetricCount(): CustomChartMetricCount = + customChartMetricCount.getOrThrow("customChartMetricCount") + + fun asCustomChartFeedbackScoreMetricScalar(): + CustomChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar.getOrThrow( + "customChartFeedbackScoreMetricScalar" + ) + + fun asCustomChartMetricScalar(): CustomChartMetricScalar = + customChartMetricScalar.getOrThrow("customChartMetricScalar") + + fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = + customChartMetricPercentile.getOrThrow( + "customChartMetricPercentile" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the + * given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants + * from the API, unless [visitor] overrides [Visitor.unknown]. To handle + * variants not known to this version of the SDK gracefully, consider + * overriding [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = denominator.accept(new Denominator.Visitor>() { + * @Override + * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { + * return Optional.of(customChartMetricCount.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not + * overridden in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + customChartMetricCount != null -> + visitor.visitCustomChartMetricCount(customChartMetricCount) + customChartFeedbackScoreMetricScalar != null -> + visitor.visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + customChartMetricScalar != null -> + visitor.visitCustomChartMetricScalar( + customChartMetricScalar + ) + customChartMetricPercentile != null -> + visitor.visitCustomChartMetricPercentile( + customChartMetricPercentile + ) + else -> visitor.unknown(_json) + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Denominator = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) { + customChartMetricCount.validate() + } + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) { + customChartFeedbackScoreMetricScalar.validate() + } + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) { + customChartMetricScalar.validate() + } + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) { + customChartMetricPercentile.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = customChartMetricCount.validity() + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = customChartFeedbackScoreMetricScalar.validity() + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = customChartMetricScalar.validity() + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = customChartMetricPercentile.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Denominator && + customChartMetricCount == other.customChartMetricCount && + customChartFeedbackScoreMetricScalar == + other.customChartFeedbackScoreMetricScalar && + customChartMetricScalar == other.customChartMetricScalar && + customChartMetricPercentile == other.customChartMetricPercentile + } + + override fun hashCode(): Int = + Objects.hash( + customChartMetricCount, + customChartFeedbackScoreMetricScalar, + customChartMetricScalar, + customChartMetricPercentile, + ) + + override fun toString(): String = + when { + customChartMetricCount != null -> + "Denominator{customChartMetricCount=$customChartMetricCount}" + customChartFeedbackScoreMetricScalar != null -> + "Denominator{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" + customChartMetricScalar != null -> + "Denominator{customChartMetricScalar=$customChartMetricScalar}" + customChartMetricPercentile != null -> + "Denominator{customChartMetricPercentile=$customChartMetricPercentile}" + _json != null -> "Denominator{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Denominator") + } + + companion object { + + @JvmStatic + fun ofCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = Denominator(customChartMetricCount = customChartMetricCount) + + @JvmStatic + fun ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = + Denominator( + customChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar + ) + + @JvmStatic + fun ofCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = Denominator(customChartMetricScalar = customChartMetricScalar) + + @JvmStatic + fun ofCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = + Denominator( + customChartMetricPercentile = customChartMetricPercentile + ) + } + + /** + * An interface that defines how to map each variant of [Denominator] to + * a value of type [T]. + */ + interface Visitor { + + fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ): T + + fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ): T + + fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ): T + + fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ): T + + /** + * Maps an unknown variant of [Denominator] to a value of type [T]. + * + * An instance of [Denominator] can contain an unknown variant if it + * was deserialized from data that doesn't match any known variant. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default + * implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException( + "Unknown Denominator: $json" + ) + } + } + + internal class Deserializer : + BaseDeserializer(Denominator::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Denominator { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Denominator( + customChartMetricCount = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + CustomChartFeedbackScoreMetricScalar + >(), + ) + ?.let { + Denominator( + customChartFeedbackScoreMetricScalar = + it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Denominator( + customChartMetricScalar = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + CustomChartMetricPercentile + >(), + ) + ?.let { + Denominator( + customChartMetricPercentile = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from boolean). + 0 -> Denominator(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(Denominator::class) { + + override fun serialize( + value: Denominator, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.customChartMetricCount != null -> + generator.writeObject(value.customChartMetricCount) + value.customChartFeedbackScoreMetricScalar != null -> + generator.writeObject( + value.customChartFeedbackScoreMetricScalar + ) + value.customChartMetricScalar != null -> + generator.writeObject(value.customChartMetricScalar) + value.customChartMetricPercentile != null -> + generator.writeObject(value.customChartMetricPercentile) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Denominator") + } + } + } + + class CustomChartMetricCount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filter: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(filter, type, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * @throws LangChainInvalidDataException 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 [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + /** + * 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 + * [CustomChartMetricCount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricCount]. */ + class Builder internal constructor() { + + private var filter: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricCount: CustomChartMetricCount + ) = apply { + filter = customChartMetricCount.filter + type = customChartMetricCount.type + additionalProperties = + customChartMetricCount.additionalProperties + .toMutableMap() + } + + fun filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 [CustomChartMetricCount]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + */ + fun build(): CustomChartMetricCount = + CustomChartMetricCount( + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricCount = apply { + if (validated) { + return@apply + } + + filter() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (filter.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val COUNT = of("count") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COUNT + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + COUNT, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + COUNT -> Value.COUNT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + COUNT -> Known.COUNT + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricCount && + filter == other.filter && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filter, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" + } + + class CustomChartFeedbackScoreMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonValue, + private val params: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonValue = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * However, this method can be useful for debugging and logging + * (e.g. if the server responded with an unexpected value). + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonValue = field + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonValue = JsonValue.from("feedback_score") + private var params: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = apply { + field = customChartFeedbackScoreMetricScalar.field + params = customChartFeedbackScoreMetricScalar.params + type = customChartFeedbackScoreMetricScalar.type + filter = customChartFeedbackScoreMetricScalar.filter + additionalProperties = + customChartFeedbackScoreMetricScalar + .additionalProperties + .toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the + * field defaults to the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun field(field: JsonValue) = apply { this.field = field } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed + * [Params] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { + this.params = params + } + + 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 filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartFeedbackScoreMetricScalar = + CustomChartFeedbackScoreMetricScalar( + field, + checkRequired("params", params), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartFeedbackScoreMetricScalar = apply { + if (validated) { + return@apply + } + + _field().let { + if (it != JsonValue.from("feedback_score")) { + throw LangChainInvalidDataException( + "'field' is invalid, received $it" + ) + } + } + params().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + field.let { + if (it == JsonValue.from("feedback_score")) 1 else 0 + } + + (params.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val feedbackKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback_key") + @ExcludeMissing + feedbackKey: JsonField = JsonMissing.of() + ) : this(feedbackKey, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 feedbackKey(): String = + feedbackKey.getRequired("feedback_key") + + /** + * Returns the raw JSON value of [feedbackKey]. + * + * Unlike [feedbackKey], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("feedback_key") + @ExcludeMissing + fun _feedbackKey(): JsonField = feedbackKey + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var feedbackKey: JsonField? = null + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + feedbackKey = params.feedbackKey + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun feedbackKey(feedbackKey: String) = + feedbackKey(JsonField.of(feedbackKey)) + + /** + * Sets [Builder.feedbackKey] to an arbitrary JSON value. + * + * You should usually call [Builder.feedbackKey] with a + * well-typed [String] value instead. This method is + * primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun feedbackKey(feedbackKey: JsonField) = apply { + this.feedbackKey = feedbackKey + } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + * + * @throws IllegalStateException if any required field is + * unset. + */ + fun build(): Params = + Params( + checkRequired("feedbackKey", feedbackKey), + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + feedbackKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (feedbackKey.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + feedbackKey == other.feedbackKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(feedbackKey, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartFeedbackScoreMetricScalar && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricScalar]. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricScalar: CustomChartMetricScalar + ) = apply { + field = customChartMetricScalar.field + type = customChartMetricScalar.type + filter = customChartMetricScalar.filter + additionalProperties = + customChartMetricScalar.additionalProperties + .toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed + * [Field] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { + this.field = field + } + + 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 filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 [CustomChartMetricScalar]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricScalar = + CustomChartMetricScalar( + checkRequired("field", field), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricScalar = apply { + if (validated) { + return@apply + } + + field().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField + val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Field] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException( + "Unknown Field: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val SUM = of("sum") + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SUM, + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + SUM, + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SUM -> Value.SUM + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + SUM -> Known.SUM + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricScalar && + field == other.field && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricPercentile + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val params: JsonField, + private val type: JsonValue, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonValue = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * However, this method can be useful for debugging and logging + * (e.g. if the server responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricPercentile]. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricPercentile]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var params: JsonField? = null + private var type: JsonValue = JsonValue.from("percentile") + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricPercentile: CustomChartMetricPercentile + ) = apply { + field = customChartMetricPercentile.field + params = customChartMetricPercentile.params + type = customChartMetricPercentile.type + filter = customChartMetricPercentile.filter + additionalProperties = + customChartMetricPercentile.additionalProperties + .toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed + * [Field] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { + this.field = field + } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed + * [Params] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { + this.params = params + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the + * field defaults to the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 + * [CustomChartMetricPercentile]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricPercentile = + CustomChartMetricPercentile( + checkRequired("field", field), + checkRequired("params", params), + type, + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricPercentile = apply { + if (validated) { + return@apply + } + + field().validate() + params().validate() + _type().let { + if (it != JsonValue.from("percentile")) { + throw LangChainInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (params.asKnown().getOrNull()?.validity() ?: 0) + + type.let { + if (it == JsonValue.from("percentile")) 1 else 0 + } + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField + val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Field] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException( + "Unknown Field: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val p: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("p") + @ExcludeMissing + p: JsonField = JsonMissing.of() + ) : this(p, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") + + /** + * Returns the raw JSON value of [p]. + * + * Unlike [p], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("p") + @ExcludeMissing + fun _p(): JsonField = p + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .p() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var p: JsonField? = null + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + p = params.p + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun p(p: Double) = p(JsonField.of(p)) + + /** + * Sets [Builder.p] to an arbitrary JSON value. + * + * You should usually call [Builder.p] with a well-typed + * [Double] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported + * value. + */ + fun p(p: JsonField) = apply { this.p = p } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .p() + * ``` + * + * @throws IllegalStateException if any required field is + * unset. + */ + fun build(): Params = + Params( + checkRequired("p", p), + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + p() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (p.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + p == other.p && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(p, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{p=$p, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricPercentile && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + } + + @JsonDeserialize(using = Numerator.Deserializer::class) + @JsonSerialize(using = Numerator.Serializer::class) + class Numerator + private constructor( + private val customChartMetricCount: CustomChartMetricCount? = null, + private val customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar? = + null, + private val customChartMetricScalar: CustomChartMetricScalar? = null, + private val customChartMetricPercentile: CustomChartMetricPercentile? = + null, + private val _json: JsonValue? = null, + ) { + + fun customChartMetricCount(): Optional = + Optional.ofNullable(customChartMetricCount) + + fun customChartFeedbackScoreMetricScalar(): + Optional = + Optional.ofNullable(customChartFeedbackScoreMetricScalar) + + fun customChartMetricScalar(): Optional = + Optional.ofNullable(customChartMetricScalar) + + fun customChartMetricPercentile(): + Optional = + Optional.ofNullable(customChartMetricPercentile) + + fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null + + fun isCustomChartFeedbackScoreMetricScalar(): Boolean = + customChartFeedbackScoreMetricScalar != null + + fun isCustomChartMetricScalar(): Boolean = + customChartMetricScalar != null + + fun isCustomChartMetricPercentile(): Boolean = + customChartMetricPercentile != null + + fun asCustomChartMetricCount(): CustomChartMetricCount = + customChartMetricCount.getOrThrow("customChartMetricCount") + + fun asCustomChartFeedbackScoreMetricScalar(): + CustomChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar.getOrThrow( + "customChartFeedbackScoreMetricScalar" + ) + + fun asCustomChartMetricScalar(): CustomChartMetricScalar = + customChartMetricScalar.getOrThrow("customChartMetricScalar") + + fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = + customChartMetricPercentile.getOrThrow( + "customChartMetricPercentile" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the + * given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants + * from the API, unless [visitor] overrides [Visitor.unknown]. To handle + * variants not known to this version of the SDK gracefully, consider + * overriding [Visitor.unknown]: + * ```java + * import com.langchain.smith.core.JsonValue; + * import java.util.Optional; + * + * Optional result = numerator.accept(new Numerator.Visitor>() { + * @Override + * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { + * return Optional.of(customChartMetricCount.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LangChainInvalidDataException if [Visitor.unknown] is not + * overridden in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + customChartMetricCount != null -> + visitor.visitCustomChartMetricCount(customChartMetricCount) + customChartFeedbackScoreMetricScalar != null -> + visitor.visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar + ) + customChartMetricScalar != null -> + visitor.visitCustomChartMetricScalar( + customChartMetricScalar + ) + customChartMetricPercentile != null -> + visitor.visitCustomChartMetricPercentile( + customChartMetricPercentile + ) + else -> visitor.unknown(_json) + } + + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Numerator = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) { + customChartMetricCount.validate() + } + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) { + customChartFeedbackScoreMetricScalar.validate() + } + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) { + customChartMetricScalar.validate() + } + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) { + customChartMetricPercentile.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = customChartMetricCount.validity() + + override fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = customChartFeedbackScoreMetricScalar.validity() + + override fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = customChartMetricScalar.validity() + + override fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = customChartMetricPercentile.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Numerator && + customChartMetricCount == other.customChartMetricCount && + customChartFeedbackScoreMetricScalar == + other.customChartFeedbackScoreMetricScalar && + customChartMetricScalar == other.customChartMetricScalar && + customChartMetricPercentile == other.customChartMetricPercentile + } + + override fun hashCode(): Int = + Objects.hash( + customChartMetricCount, + customChartFeedbackScoreMetricScalar, + customChartMetricScalar, + customChartMetricPercentile, + ) + + override fun toString(): String = + when { + customChartMetricCount != null -> + "Numerator{customChartMetricCount=$customChartMetricCount}" + customChartFeedbackScoreMetricScalar != null -> + "Numerator{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" + customChartMetricScalar != null -> + "Numerator{customChartMetricScalar=$customChartMetricScalar}" + customChartMetricPercentile != null -> + "Numerator{customChartMetricPercentile=$customChartMetricPercentile}" + _json != null -> "Numerator{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Numerator") + } + + companion object { + + @JvmStatic + fun ofCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ) = Numerator(customChartMetricCount = customChartMetricCount) + + @JvmStatic + fun ofCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = + Numerator( + customChartFeedbackScoreMetricScalar = + customChartFeedbackScoreMetricScalar + ) + + @JvmStatic + fun ofCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ) = Numerator(customChartMetricScalar = customChartMetricScalar) + + @JvmStatic + fun ofCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ) = + Numerator( + customChartMetricPercentile = customChartMetricPercentile + ) + } + + /** + * An interface that defines how to map each variant of [Numerator] to a + * value of type [T]. + */ + interface Visitor { + + fun visitCustomChartMetricCount( + customChartMetricCount: CustomChartMetricCount + ): T + + fun visitCustomChartFeedbackScoreMetricScalar( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ): T + + fun visitCustomChartMetricScalar( + customChartMetricScalar: CustomChartMetricScalar + ): T + + fun visitCustomChartMetricPercentile( + customChartMetricPercentile: CustomChartMetricPercentile + ): T + + /** + * Maps an unknown variant of [Numerator] to a value of type [T]. + * + * An instance of [Numerator] can contain an unknown variant if it + * was deserialized from data that doesn't match any known variant. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new variants that the SDK is unaware of. + * + * @throws LangChainInvalidDataException in the default + * implementation. + */ + fun unknown(json: JsonValue?): T { + throw LangChainInvalidDataException("Unknown Numerator: $json") + } + } + + internal class Deserializer : + BaseDeserializer(Numerator::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Numerator { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Numerator( + customChartMetricCount = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + CustomChartFeedbackScoreMetricScalar + >(), + ) + ?.let { + Numerator( + customChartFeedbackScoreMetricScalar = + it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Numerator( + customChartMetricScalar = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + CustomChartMetricPercentile + >(), + ) + ?.let { + Numerator( + customChartMetricPercentile = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from boolean). + 0 -> Numerator(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(Numerator::class) { + + override fun serialize( + value: Numerator, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.customChartMetricCount != null -> + generator.writeObject(value.customChartMetricCount) + value.customChartFeedbackScoreMetricScalar != null -> + generator.writeObject( + value.customChartFeedbackScoreMetricScalar + ) + value.customChartMetricScalar != null -> + generator.writeObject(value.customChartMetricScalar) + value.customChartMetricPercentile != null -> + generator.writeObject(value.customChartMetricPercentile) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Numerator") + } + } + } + + class CustomChartMetricCount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filter: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(filter, type, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * @throws LangChainInvalidDataException 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 [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + /** + * 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 + * [CustomChartMetricCount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricCount]. */ + class Builder internal constructor() { + + private var filter: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricCount: CustomChartMetricCount + ) = apply { + filter = customChartMetricCount.filter + type = customChartMetricCount.type + additionalProperties = + customChartMetricCount.additionalProperties + .toMutableMap() + } + + fun filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 [CustomChartMetricCount]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + */ + fun build(): CustomChartMetricCount = + CustomChartMetricCount( + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricCount = apply { + if (validated) { + return@apply + } + + filter() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (filter.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val COUNT = of("count") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COUNT + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + COUNT, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + COUNT -> Value.COUNT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + COUNT -> Known.COUNT + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricCount && + filter == other.filter && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filter, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" + } + + class CustomChartFeedbackScoreMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonValue, + private val params: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonValue = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * However, this method can be useful for debugging and logging + * (e.g. if the server responded with an unexpected value). + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonValue = field + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonValue = JsonValue.from("feedback_score") + private var params: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartFeedbackScoreMetricScalar: + CustomChartFeedbackScoreMetricScalar + ) = apply { + field = customChartFeedbackScoreMetricScalar.field + params = customChartFeedbackScoreMetricScalar.params + type = customChartFeedbackScoreMetricScalar.type + filter = customChartFeedbackScoreMetricScalar.filter + additionalProperties = + customChartFeedbackScoreMetricScalar + .additionalProperties + .toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the + * field defaults to the following: + * ```java + * JsonValue.from("feedback_score") + * ``` + * + * This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun field(field: JsonValue) = apply { this.field = field } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed + * [Params] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { + this.params = params + } + + 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 filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 + * [CustomChartFeedbackScoreMetricScalar]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .params() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartFeedbackScoreMetricScalar = + CustomChartFeedbackScoreMetricScalar( + field, + checkRequired("params", params), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartFeedbackScoreMetricScalar = apply { + if (validated) { + return@apply + } + + _field().let { + if (it != JsonValue.from("feedback_score")) { + throw LangChainInvalidDataException( + "'field' is invalid, received $it" + ) + } + } + params().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + field.let { + if (it == JsonValue.from("feedback_score")) 1 else 0 + } + + (params.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val feedbackKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback_key") + @ExcludeMissing + feedbackKey: JsonField = JsonMissing.of() + ) : this(feedbackKey, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 feedbackKey(): String = + feedbackKey.getRequired("feedback_key") + + /** + * Returns the raw JSON value of [feedbackKey]. + * + * Unlike [feedbackKey], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("feedback_key") + @ExcludeMissing + fun _feedbackKey(): JsonField = feedbackKey + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var feedbackKey: JsonField? = null + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + feedbackKey = params.feedbackKey + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun feedbackKey(feedbackKey: String) = + feedbackKey(JsonField.of(feedbackKey)) + + /** + * Sets [Builder.feedbackKey] to an arbitrary JSON value. + * + * You should usually call [Builder.feedbackKey] with a + * well-typed [String] value instead. This method is + * primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun feedbackKey(feedbackKey: JsonField) = apply { + this.feedbackKey = feedbackKey + } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .feedbackKey() + * ``` + * + * @throws IllegalStateException if any required field is + * unset. + */ + fun build(): Params = + Params( + checkRequired("feedbackKey", feedbackKey), + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + feedbackKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (feedbackKey.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + feedbackKey == other.feedbackKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(feedbackKey, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartFeedbackScoreMetricScalar && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricScalar + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val type: JsonField, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * 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 + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricScalar]. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricScalar]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var type: JsonField? = null + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricScalar: CustomChartMetricScalar + ) = apply { + field = customChartMetricScalar.field + type = customChartMetricScalar.type + filter = customChartMetricScalar.filter + additionalProperties = + customChartMetricScalar.additionalProperties + .toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed + * [Field] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { + this.field = field + } + + 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 filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 [CustomChartMetricScalar]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .field() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricScalar = + CustomChartMetricScalar( + checkRequired("field", field), + checkRequired("type", type), + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricScalar = apply { + if (validated) { + return@apply + } + + field().validate() + type().validate() + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField + val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Field] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException( + "Unknown Field: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val SUM = of("sum") + + @JvmField val MAX = of("max") + + @JvmField val MIN = of("min") + + @JvmField val AVG = of("avg") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SUM, + MAX, + MIN, + AVG, + } + + /** + * An enum containing [Type]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + SUM, + MAX, + MIN, + AVG, + /** + * An enum member indicating that [Type] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SUM -> Value.SUM + MAX -> Value.MAX + MIN -> Value.MIN + AVG -> Value.AVG + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + SUM -> Known.SUM + MAX -> Known.MAX + MIN -> Known.MIN + AVG -> Known.AVG + else -> + throw LangChainInvalidDataException( + "Unknown Type: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricScalar && + field == other.field && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + + class CustomChartMetricPercentile + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val params: JsonField, + private val type: JsonValue, + private val filter: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("params") + @ExcludeMissing + params: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonValue = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + ) : this(field, params, type, filter, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") + + /** + * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * However, this method can be useful for debugging and logging + * (e.g. if the server responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws LangChainInvalidDataException if the JSON field has an + * unexpected type (e.g. if the server responded with an + * unexpected value). + */ + fun filter(): Optional = filter.getOptional("filter") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("field") + @ExcludeMissing + fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [params]. + * + * Unlike [params], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("params") + @ExcludeMissing + fun _params(): JsonField = params + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("filter") + @ExcludeMissing + fun _filter(): JsonField = filter + + @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 + * [CustomChartMetricPercentile]. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomChartMetricPercentile]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var params: JsonField? = null + private var type: JsonValue = JsonValue.from("percentile") + private var filter: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from( + customChartMetricPercentile: CustomChartMetricPercentile + ) = apply { + field = customChartMetricPercentile.field + params = customChartMetricPercentile.params + type = customChartMetricPercentile.type + filter = customChartMetricPercentile.filter + additionalProperties = + customChartMetricPercentile.additionalProperties + .toMutableMap() + } + + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed + * [Field] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun field(field: JsonField) = apply { + this.field = field + } + + fun params(params: Params) = params(JsonField.of(params)) + + /** + * Sets [Builder.params] to an arbitrary JSON value. + * + * You should usually call [Builder.params] with a well-typed + * [Params] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun params(params: JsonField) = apply { + this.params = params + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the + * field defaults to the following: + * ```java + * JsonValue.from("percentile") + * ``` + * + * This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun filter(filter: String?) = + filter(JsonField.ofNullable(filter)) + + /** + * Alias for calling [Builder.filter] with + * `filter.orElse(null)`. + */ + fun filter(filter: Optional) = + filter(filter.getOrNull()) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed + * [String] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun filter(filter: JsonField) = apply { + this.filter = filter + } + + 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 + * [CustomChartMetricPercentile]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .field() + * .params() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomChartMetricPercentile = + CustomChartMetricPercentile( + checkRequired("field", field), + checkRequired("params", params), + type, + filter, + 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 LangChainInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomChartMetricPercentile = apply { + if (validated) { + return@apply + } + + field().validate() + params().validate() + _type().let { + if (it != JsonValue.from("percentile")) { + throw LangChainInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + filter() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 = + (field.asKnown().getOrNull()?.validity() ?: 0) + + (params.asKnown().getOrNull()?.validity() ?: 0) + + type.let { + if (it == JsonValue.from("percentile")) 1 else 0 + } + + (if (filter.asKnown().isPresent) 1 else 0) + + class Field + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized + * from data that doesn't match any known member, and you want + * to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val LATENCY_SECONDS = of("latency_seconds") + + @JvmField + val FIRST_TOKEN_SECONDS = of("first_token_seconds") + + @JvmField val TOTAL_TOKENS = of("total_tokens") + + @JvmField val PROMPT_TOKENS = of("prompt_tokens") + + @JvmField val COMPLETION_TOKENS = of("completion_tokens") + + @JvmField val TOTAL_COST = of("total_cost") + + @JvmField val PROMPT_COST = of("prompt_cost") + + @JvmField val COMPLETION_COST = of("completion_cost") + + @JvmField val FEEDBACK_SCORE = of("feedback_score") + + @JvmStatic + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + } + + /** + * An enum containing [Field]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Field] can contain an unknown value in a + * couple of cases: + * - It was deserialized from data that doesn't match any known + * member. For example, if the SDK is on an older version than + * the API, then the API may respond with new members that the + * SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] + * method. + */ + enum class Value { + LATENCY_SECONDS, + FIRST_TOKEN_SECONDS, + TOTAL_TOKENS, + PROMPT_TOKENS, + COMPLETION_TOKENS, + TOTAL_COST, + PROMPT_COST, + COMPLETION_COST, + FEEDBACK_SCORE, + /** + * An enum member indicating that [Field] was instantiated + * with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's + * value, or [Value._UNKNOWN] if the class was instantiated with + * an unknown value. + * + * Use the [known] method instead if you're certain the value is + * always known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LATENCY_SECONDS -> Value.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Value.TOTAL_TOKENS + PROMPT_TOKENS -> Value.PROMPT_TOKENS + COMPLETION_TOKENS -> Value.COMPLETION_TOKENS + TOTAL_COST -> Value.TOTAL_COST + PROMPT_COST -> Value.PROMPT_COST + COMPLETION_COST -> Value.COMPLETION_COST + FEEDBACK_SCORE -> Value.FEEDBACK_SCORE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's + * value. + * + * Use the [value] method instead if you're uncertain the value + * is always known and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class + * instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + LATENCY_SECONDS -> Known.LATENCY_SECONDS + FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS + TOTAL_TOKENS -> Known.TOTAL_TOKENS + PROMPT_TOKENS -> Known.PROMPT_TOKENS + COMPLETION_TOKENS -> Known.COMPLETION_TOKENS + TOTAL_COST -> Known.TOTAL_COST + PROMPT_COST -> Known.PROMPT_COST + COMPLETION_COST -> Known.COMPLETION_COST + FEEDBACK_SCORE -> Known.FEEDBACK_SCORE + else -> + throw LangChainInvalidDataException( + "Unknown Field: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method + * is primarily for debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class + * instance's value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Params + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val p: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("p") + @ExcludeMissing + p: JsonField = JsonMissing.of() + ) : this(p, mutableMapOf()) + + /** + * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") + + /** + * Returns the raw JSON value of [p]. + * + * Unlike [p], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("p") + @ExcludeMissing + fun _p(): JsonField = p + + @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 + * [Params]. + * + * The following fields are required: + * ```java + * .p() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Params]. */ + class Builder internal constructor() { + + private var p: JsonField? = null + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(params: Params) = apply { + p = params.p + additionalProperties = + params.additionalProperties.toMutableMap() + } + + fun p(p: Double) = p(JsonField.of(p)) + + /** + * Sets [Builder.p] to an arbitrary JSON value. + * + * You should usually call [Builder.p] with a well-typed + * [Double] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported + * value. + */ + fun p(p: JsonField) = apply { this.p = p } + + 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 [Params]. + * + * Further updates to this [Builder] will not mutate the + * returned instance. + * + * The following fields are required: + * ```java + * .p() + * ``` + * + * @throws IllegalStateException if any required field is + * unset. + */ + fun build(): Params = + Params( + checkRequired("p", p), + 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 LangChainInvalidDataException if any value type in + * this object doesn't match its expected type. + */ + fun validate(): Params = apply { + if (validated) { + return@apply + } + + p() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (p.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + p == other.p && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(p, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Params{p=$p, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricPercentile && + field == other.field && + params == other.params && + type == other.type && + filter == other.filter && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, params, type, filter, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomChartMetricRatioOutput && + denominator == other.denominator && + numerator == other.numerator && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(denominator, numerator, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomChartMetricRatioOutput{denominator=$denominator, numerator=$numerator, type=$type, additionalProperties=$additionalProperties}" + } + } + + /** LGP Metrics you can chart. */ + class ProjectMetric + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MEMORY_USAGE = of("memory_usage") + + @JvmField val CPU_USAGE = of("cpu_usage") + + @JvmField val DISK_USAGE = of("disk_usage") + + @JvmField val RESTART_COUNT = of("restart_count") + + @JvmField val REPLICA_COUNT = of("replica_count") + + @JvmField val WORKER_COUNT = of("worker_count") + + @JvmField val LG_RUN_COUNT = of("lg_run_count") + + @JvmField val RESPONSES_PER_SECOND = of("responses_per_second") + + @JvmField val ERROR_RESPONSES_PER_SECOND = of("error_responses_per_second") + + @JvmField val P95_LATENCY = of("p95_latency") + + @JvmField val RUN_QUEUE_WAIT_TIME = of("run_queue_wait_time") + + @JvmStatic fun of(value: String) = ProjectMetric(JsonField.of(value)) + } + + /** An enum containing [ProjectMetric]'s known values. */ + enum class Known { + MEMORY_USAGE, + CPU_USAGE, + DISK_USAGE, + RESTART_COUNT, + REPLICA_COUNT, + WORKER_COUNT, + LG_RUN_COUNT, + RESPONSES_PER_SECOND, + ERROR_RESPONSES_PER_SECOND, + P95_LATENCY, + RUN_QUEUE_WAIT_TIME, + } + + /** + * An enum containing [ProjectMetric]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ProjectMetric] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MEMORY_USAGE, + CPU_USAGE, + DISK_USAGE, + RESTART_COUNT, + REPLICA_COUNT, + WORKER_COUNT, + LG_RUN_COUNT, + RESPONSES_PER_SECOND, + ERROR_RESPONSES_PER_SECOND, + P95_LATENCY, + RUN_QUEUE_WAIT_TIME, + /** + * An enum member indicating that [ProjectMetric] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MEMORY_USAGE -> Value.MEMORY_USAGE + CPU_USAGE -> Value.CPU_USAGE + DISK_USAGE -> Value.DISK_USAGE + RESTART_COUNT -> Value.RESTART_COUNT + REPLICA_COUNT -> Value.REPLICA_COUNT + WORKER_COUNT -> Value.WORKER_COUNT + LG_RUN_COUNT -> Value.LG_RUN_COUNT + RESPONSES_PER_SECOND -> Value.RESPONSES_PER_SECOND + ERROR_RESPONSES_PER_SECOND -> Value.ERROR_RESPONSES_PER_SECOND + P95_LATENCY -> Value.P95_LATENCY + RUN_QUEUE_WAIT_TIME -> Value.RUN_QUEUE_WAIT_TIME + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws LangChainInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MEMORY_USAGE -> Known.MEMORY_USAGE + CPU_USAGE -> Known.CPU_USAGE + DISK_USAGE -> Known.DISK_USAGE + RESTART_COUNT -> Known.RESTART_COUNT + REPLICA_COUNT -> Known.REPLICA_COUNT + WORKER_COUNT -> Known.WORKER_COUNT + LG_RUN_COUNT -> Known.LG_RUN_COUNT + RESPONSES_PER_SECOND -> Known.RESPONSES_PER_SECOND + ERROR_RESPONSES_PER_SECOND -> Known.ERROR_RESPONSES_PER_SECOND + P95_LATENCY -> Known.P95_LATENCY + RUN_QUEUE_WAIT_TIME -> Known.RUN_QUEUE_WAIT_TIME + else -> + throw LangChainInvalidDataException("Unknown ProjectMetric: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LangChainInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LangChainInvalidDataException("Value is not a String") + } + + 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 LangChainInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProjectMetric = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectMetric && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Series && + id == other.id && + name == other.name && + feedbackKey == other.feedbackKey && + filterDefinition == other.filterDefinition && + filters == other.filters && + groupBy == other.groupBy && + groupByDefinitions == other.groupByDefinitions && + metadata == other.metadata && + metric == other.metric && + metricDefinition == other.metricDefinition && + projectMetric == other.projectMetric && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + feedbackKey, + filterDefinition, + filters, + groupBy, + groupByDefinitions, + metadata, + metric, + metricDefinition, + projectMetric, + workspaceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Series{id=$id, name=$name, feedbackKey=$feedbackKey, filterDefinition=$filterDefinition, filters=$filters, groupBy=$groupBy, groupByDefinitions=$groupByDefinitions, metadata=$metadata, metric=$metric, metricDefinition=$metricDefinition, projectMetric=$projectMetric, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" } - class Filters + class CommonFilters @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val filter: JsonField, @@ -3511,11 +15121,13 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Filters]. */ + /** + * Returns a mutable builder for constructing an instance of [CommonFilters]. + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Filters]. */ + /** A builder for [CommonFilters]. */ class Builder internal constructor() { private var filter: JsonField = JsonMissing.of() @@ -3525,12 +15137,12 @@ private constructor( private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(filters: Filters) = apply { - filter = filters.filter - session = filters.session.map { it.toMutableList() } - traceFilter = filters.traceFilter - treeFilter = filters.treeFilter - additionalProperties = filters.additionalProperties.toMutableMap() + internal fun from(commonFilters: CommonFilters) = apply { + filter = commonFilters.filter + session = commonFilters.session.map { it.toMutableList() } + traceFilter = commonFilters.traceFilter + treeFilter = commonFilters.treeFilter + additionalProperties = commonFilters.additionalProperties.toMutableMap() } fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) @@ -3634,12 +15246,12 @@ private constructor( } /** - * Returns an immutable instance of [Filters]. + * Returns an immutable instance of [CommonFilters]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Filters = - Filters( + fun build(): CommonFilters = + CommonFilters( filter, (session ?: JsonMissing.of()).map { it.toImmutable() }, traceFilter, @@ -3660,7 +15272,7 @@ private constructor( * @throws LangChainInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): Filters = apply { + fun validate(): CommonFilters = apply { if (validated) { return@apply } @@ -3698,7 +15310,7 @@ private constructor( return true } - return other is Filters && + return other is CommonFilters && filter == other.filter && session == other.session && traceFilter == other.traceFilter && @@ -3713,1581 +15325,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Filters{filter=$filter, session=$session, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" - } - - /** Include additional information about where the group_by param was set. */ - class GroupBy - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val maxGroups: JsonField, - private val path: JsonField, - private val setBy: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("max_groups") - @ExcludeMissing - maxGroups: JsonField = JsonMissing.of(), - @JsonProperty("path") - @ExcludeMissing - path: JsonField = JsonMissing.of(), - @JsonProperty("set_by") - @ExcludeMissing - setBy: JsonField = JsonMissing.of(), - ) : this(attribute, maxGroups, path, setBy, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 attribute(): Attribute = attribute.getRequired("attribute") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun maxGroups(): Optional = maxGroups.getOptional("max_groups") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun path(): Optional = path.getOptional("path") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun setBy(): Optional = setBy.getOptional("set_by") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [maxGroups]. - * - * Unlike [maxGroups], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("max_groups") - @ExcludeMissing - fun _maxGroups(): JsonField = maxGroups - - /** - * Returns the raw JSON value of [path]. - * - * Unlike [path], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path - - /** - * Returns the raw JSON value of [setBy]. - * - * Unlike [setBy], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("set_by") @ExcludeMissing fun _setBy(): JsonField = setBy - - @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 [GroupBy]. - * - * The following fields are required: - * ```java - * .attribute() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [GroupBy]. */ - class Builder internal constructor() { - - private var attribute: JsonField? = null - private var maxGroups: JsonField = JsonMissing.of() - private var path: JsonField = JsonMissing.of() - private var setBy: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(groupBy: GroupBy) = apply { - attribute = groupBy.attribute - maxGroups = groupBy.maxGroups - path = groupBy.path - setBy = groupBy.setBy - additionalProperties = groupBy.additionalProperties.toMutableMap() - } - - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - fun maxGroups(maxGroups: Long) = maxGroups(JsonField.of(maxGroups)) - - /** - * Sets [Builder.maxGroups] to an arbitrary JSON value. - * - * You should usually call [Builder.maxGroups] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun maxGroups(maxGroups: JsonField) = apply { this.maxGroups = maxGroups } - - fun path(path: String?) = path(JsonField.ofNullable(path)) - - /** Alias for calling [Builder.path] with `path.orElse(null)`. */ - fun path(path: Optional) = path(path.getOrNull()) - - /** - * Sets [Builder.path] to an arbitrary JSON value. - * - * You should usually call [Builder.path] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun path(path: JsonField) = apply { this.path = path } - - fun setBy(setBy: SetBy?) = setBy(JsonField.ofNullable(setBy)) - - /** Alias for calling [Builder.setBy] with `setBy.orElse(null)`. */ - fun setBy(setBy: Optional) = setBy(setBy.getOrNull()) - - /** - * Sets [Builder.setBy] to an arbitrary JSON value. - * - * You should usually call [Builder.setBy] with a well-typed [SetBy] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun setBy(setBy: JsonField) = apply { this.setBy = setBy } - - 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 [GroupBy]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .attribute() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): GroupBy = - GroupBy( - checkRequired("attribute", attribute), - maxGroups, - path, - setBy, - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): GroupBy = apply { - if (validated) { - return@apply - } - - attribute().validate() - maxGroups() - path() - setBy().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (if (maxGroups.asKnown().isPresent) 1 else 0) + - (if (path.asKnown().isPresent) 1 else 0) + - (setBy.asKnown().getOrNull()?.validity() ?: 0) - - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val NAME = of("name") - - @JvmField val RUN_TYPE = of("run_type") - - @JvmField val TAG = of("tag") - - @JvmField val METADATA = of("metadata") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - NAME, - RUN_TYPE, - TAG, - METADATA, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - NAME, - RUN_TYPE, - TAG, - METADATA, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - NAME -> Value.NAME - RUN_TYPE -> Value.RUN_TYPE - TAG -> Value.TAG - METADATA -> Value.METADATA - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a not - * a known member. - */ - fun known(): Known = - when (this) { - NAME -> Known.NAME - RUN_TYPE -> Known.RUN_TYPE - TAG -> Known.TAG - METADATA -> Known.METADATA - else -> throw LangChainInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class SetBy @JsonCreator private constructor(private val value: JsonField) : - Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val SECTION = of("section") - - @JvmField val SERIES = of("series") - - @JvmStatic fun of(value: String) = SetBy(JsonField.of(value)) - } - - /** An enum containing [SetBy]'s known values. */ - enum class Known { - SECTION, - SERIES, - } - - /** - * An enum containing [SetBy]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [SetBy] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - SECTION, - SERIES, - /** - * An enum member indicating that [SetBy] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - SECTION -> Value.SECTION - SERIES -> Value.SERIES - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a not - * a known member. - */ - fun known(): Known = - when (this) { - SECTION -> Known.SECTION - SERIES -> Known.SERIES - else -> throw LangChainInvalidDataException("Unknown SetBy: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): SetBy = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is SetBy && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is GroupBy && - attribute == other.attribute && - maxGroups == other.maxGroups && - path == other.path && - setBy == other.setBy && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, maxGroups, path, setBy, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "GroupBy{attribute=$attribute, maxGroups=$maxGroups, path=$path, setBy=$setBy, additionalProperties=$additionalProperties}" - } - - @JsonDeserialize(using = GroupByDefinition.Deserializer::class) - @JsonSerialize(using = GroupByDefinition.Serializer::class) - class GroupByDefinition - private constructor( - private val customChartGroupByPlain: CustomChartGroupByPlain? = null, - private val customChartGroupByComplex: CustomChartGroupByComplex? = null, - private val _json: JsonValue? = null, - ) { - - fun customChartGroupByPlain(): Optional = - Optional.ofNullable(customChartGroupByPlain) - - fun customChartGroupByComplex(): Optional = - Optional.ofNullable(customChartGroupByComplex) - - fun isCustomChartGroupByPlain(): Boolean = customChartGroupByPlain != null - - fun isCustomChartGroupByComplex(): Boolean = customChartGroupByComplex != null - - fun asCustomChartGroupByPlain(): CustomChartGroupByPlain = - customChartGroupByPlain.getOrThrow("customChartGroupByPlain") - - fun asCustomChartGroupByComplex(): CustomChartGroupByComplex = - customChartGroupByComplex.getOrThrow("customChartGroupByComplex") - - fun _json(): Optional = Optional.ofNullable(_json) - - /** - * Maps this instance's current variant to a value of type [T] using the given - * [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from the - * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not known - * to this version of the SDK gracefully, consider overriding [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = groupByDefinition.accept(new GroupByDefinition.Visitor>() { - * @Override - * public Optional visitCustomChartGroupByPlain(CustomChartGroupByPlain customChartGroupByPlain) { - * return Optional.of(customChartGroupByPlain.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden in - * [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - customChartGroupByPlain != null -> - visitor.visitCustomChartGroupByPlain(customChartGroupByPlain) - customChartGroupByComplex != null -> - visitor.visitCustomChartGroupByComplex(customChartGroupByComplex) - else -> visitor.unknown(_json) - } - - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): GroupByDefinition = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitCustomChartGroupByPlain( - customChartGroupByPlain: CustomChartGroupByPlain - ) { - customChartGroupByPlain.validate() - } - - override fun visitCustomChartGroupByComplex( - customChartGroupByComplex: CustomChartGroupByComplex - ) { - customChartGroupByComplex.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - accept( - object : Visitor { - override fun visitCustomChartGroupByPlain( - customChartGroupByPlain: CustomChartGroupByPlain - ) = customChartGroupByPlain.validity() - - override fun visitCustomChartGroupByComplex( - customChartGroupByComplex: CustomChartGroupByComplex - ) = customChartGroupByComplex.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is GroupByDefinition && - customChartGroupByPlain == other.customChartGroupByPlain && - customChartGroupByComplex == other.customChartGroupByComplex - } - - override fun hashCode(): Int = - Objects.hash(customChartGroupByPlain, customChartGroupByComplex) - - override fun toString(): String = - when { - customChartGroupByPlain != null -> - "GroupByDefinition{customChartGroupByPlain=$customChartGroupByPlain}" - customChartGroupByComplex != null -> - "GroupByDefinition{customChartGroupByComplex=$customChartGroupByComplex}" - _json != null -> "GroupByDefinition{_unknown=$_json}" - else -> throw IllegalStateException("Invalid GroupByDefinition") - } - - companion object { - - @JvmStatic - fun ofCustomChartGroupByPlain( - customChartGroupByPlain: CustomChartGroupByPlain - ) = GroupByDefinition(customChartGroupByPlain = customChartGroupByPlain) - - @JvmStatic - fun ofCustomChartGroupByComplex( - customChartGroupByComplex: CustomChartGroupByComplex - ) = GroupByDefinition(customChartGroupByComplex = customChartGroupByComplex) - } - - /** - * An interface that defines how to map each variant of [GroupByDefinition] to a - * value of type [T]. - */ - interface Visitor { - - fun visitCustomChartGroupByPlain( - customChartGroupByPlain: CustomChartGroupByPlain - ): T - - fun visitCustomChartGroupByComplex( - customChartGroupByComplex: CustomChartGroupByComplex - ): T - - /** - * Maps an unknown variant of [GroupByDefinition] to a value of type [T]. - * - * An instance of [GroupByDefinition] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if - * the SDK is on an older version than the API, then the API may respond with - * new variants that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown GroupByDefinition: $json") - } - } - - internal class Deserializer : - BaseDeserializer(GroupByDefinition::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): GroupByDefinition { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { - GroupByDefinition( - customChartGroupByPlain = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - GroupByDefinition( - customChartGroupByComplex = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing from - // boolean). - 0 -> GroupByDefinition(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use - // the first completely valid match, or simply the first match if none - // are completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : - BaseSerializer(GroupByDefinition::class) { - - override fun serialize( - value: GroupByDefinition, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.customChartGroupByPlain != null -> - generator.writeObject(value.customChartGroupByPlain) - value.customChartGroupByComplex != null -> - generator.writeObject(value.customChartGroupByComplex) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid GroupByDefinition") - } - } - } - - class CustomChartGroupByPlain - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of() - ) : this(attribute, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 attribute(): Attribute = attribute.getRequired("attribute") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - @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 - * [CustomChartGroupByPlain]. - * - * The following fields are required: - * ```java - * .attribute() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartGroupByPlain]. */ - class Builder internal constructor() { - - private var attribute: JsonField? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartGroupByPlain: CustomChartGroupByPlain) = - apply { - attribute = customChartGroupByPlain.attribute - additionalProperties = - customChartGroupByPlain.additionalProperties.toMutableMap() - } - - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - 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 [CustomChartGroupByPlain]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .attribute() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartGroupByPlain = - CustomChartGroupByPlain( - checkRequired("attribute", attribute), - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartGroupByPlain = apply { - if (validated) { - return@apply - } - - attribute().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (attribute.asKnown().getOrNull()?.validity() ?: 0) - - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val NAME = of("name") - - @JvmField val RUN_TYPE = of("run_type") - - @JvmField val TAG = of("tag") - - @JvmField val PROJECT = of("project") - - @JvmField val STATUS = of("status") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - NAME, - RUN_TYPE, - TAG, - PROJECT, - STATUS, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - NAME, - RUN_TYPE, - TAG, - PROJECT, - STATUS, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - NAME -> Value.NAME - RUN_TYPE -> Value.RUN_TYPE - TAG -> Value.TAG - PROJECT -> Value.PROJECT - STATUS -> Value.STATUS - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - NAME -> Known.NAME - RUN_TYPE -> Known.RUN_TYPE - TAG -> Known.TAG - PROJECT -> Known.PROJECT - STATUS -> Known.STATUS - else -> - throw LangChainInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartGroupByPlain && - attribute == other.attribute && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartGroupByPlain{attribute=$attribute, additionalProperties=$additionalProperties}" - } - - class CustomChartGroupByComplex - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val path: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("path") - @ExcludeMissing - path: JsonField = JsonMissing.of(), - ) : this(attribute, path, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 attribute(): Attribute = attribute.getRequired("attribute") - - /** - * @throws LangChainInvalidDataException 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 path(): String = path.getRequired("path") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [path]. - * - * Unlike [path], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path - - @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 - * [CustomChartGroupByComplex]. - * - * The following fields are required: - * ```java - * .attribute() - * .path() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartGroupByComplex]. */ - class Builder internal constructor() { - - private var attribute: JsonField? = null - private var path: JsonField? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartGroupByComplex: CustomChartGroupByComplex) = - apply { - attribute = customChartGroupByComplex.attribute - path = customChartGroupByComplex.path - additionalProperties = - customChartGroupByComplex.additionalProperties.toMutableMap() - } - - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - fun path(path: String) = path(JsonField.of(path)) - - /** - * Sets [Builder.path] to an arbitrary JSON value. - * - * You should usually call [Builder.path] with a well-typed [String] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun path(path: JsonField) = apply { this.path = path } - - 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 [CustomChartGroupByComplex]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .attribute() - * .path() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartGroupByComplex = - CustomChartGroupByComplex( - checkRequired("attribute", attribute), - checkRequired("path", path), - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartGroupByComplex = apply { - if (validated) { - return@apply - } - - attribute().validate() - path() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (if (path.asKnown().isPresent) 1 else 0) - - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val METADATA = of("metadata") - - @JvmField val FEEDBACK_LABEL = of("feedback_label") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - METADATA, - FEEDBACK_LABEL, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - METADATA, - FEEDBACK_LABEL, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - METADATA -> Value.METADATA - FEEDBACK_LABEL -> Value.FEEDBACK_LABEL - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - METADATA -> Known.METADATA - FEEDBACK_LABEL -> Known.FEEDBACK_LABEL - else -> - throw LangChainInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartGroupByComplex && - attribute == other.attribute && - path == other.path && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, path, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartGroupByComplex{attribute=$attribute, path=$path, additionalProperties=$additionalProperties}" - } + "CommonFilters{filter=$filter, session=$session, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" } class Metadata @@ -5404,447 +15442,421 @@ private constructor( override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SingleCustomChartResponse && + id == other.id && + chartType == other.chartType && + data == other.data && + index == other.index && + series == other.series && + title == other.title && + commonFilters == other.commonFilters && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + chartType, + data, + index, + series, + title, + commonFilters, + description, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SingleCustomChartResponse{id=$id, chartType=$chartType, data=$data, index=$index, series=$series, title=$title, commonFilters=$commonFilters, description=$description, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class Text + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val chartType: JsonValue, + private val index: JsonField, + private val markdown: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("chart_type") @ExcludeMissing chartType: JsonValue = JsonMissing.of(), + @JsonProperty("index") @ExcludeMissing index: JsonField = JsonMissing.of(), + @JsonProperty("markdown") + @ExcludeMissing + markdown: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(id, chartType, index, markdown, metadata, mutableMapOf()) + /** - * Metrics you can chart. Feedback metrics are not available for organization-scoped - * charts. + * @throws LangChainInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - class Metric @JsonCreator private constructor(private val value: JsonField) : - Enum { + fun id(): String = id.getRequired("id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("text") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("chart_type") @ExcludeMissing fun _chartType(): JsonValue = chartType + + /** + * @throws LangChainInvalidDataException 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 index(): Long = index.getRequired("index") + + /** + * @throws LangChainInvalidDataException 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 markdown(): String = markdown.getRequired("markdown") + + /** + * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [index]. + * + * Unlike [index], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index") @ExcludeMissing fun _index(): JsonField = index + + /** + * Returns the raw JSON value of [markdown]. + * + * Unlike [markdown], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("markdown") @ExcludeMissing fun _markdown(): JsonField = markdown + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 this class instance's raw value. + * Returns a mutable builder for constructing an instance of [Text]. * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. + * The following fields are required: + * ```java + * .id() + * .index() + * .markdown() + * ``` */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Text]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var chartType: JsonValue = JsonValue.from("text") + private var index: JsonField? = null + private var markdown: JsonField? = null + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + id = text.id + chartType = text.chartType + index = text.index + markdown = text.markdown + metadata = text.metadata + additionalProperties = text.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("text") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun chartType(chartType: JsonValue) = apply { this.chartType = chartType } + + fun index(index: Long) = index(JsonField.of(index)) + + /** + * Sets [Builder.index] to an arbitrary JSON value. + * + * You should usually call [Builder.index] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun index(index: JsonField) = apply { this.index = index } + + fun markdown(markdown: String) = markdown(JsonField.of(markdown)) + + /** + * Sets [Builder.markdown] to an arbitrary JSON value. + * + * You should usually call [Builder.markdown] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun markdown(markdown: JsonField) = apply { this.markdown = markdown } + + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * 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) + } + + 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 + * .id() + * .index() + * .markdown() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Text = + Text( + checkRequired("id", id), + chartType, + checkRequired("index", index), + checkRequired("markdown", markdown), + metadata, + 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 LangChainInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Text = apply { + if (validated) { + return@apply + } + + id() + _chartType().let { + if (it != JsonValue.from("text")) { + throw LangChainInvalidDataException("'chartType' is invalid, received $it") + } + } + index() + markdown() + metadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LangChainInvalidDataException) { + 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 (id.asKnown().isPresent) 1 else 0) + + chartType.let { if (it == JsonValue.from("text")) 1 else 0 } + + (if (index.asKnown().isPresent) 1 else 0) + + (if (markdown.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) companion object { - @JvmField val RUN_COUNT = of("run_count") - - @JvmField val LATENCY_P50 = of("latency_p50") - - @JvmField val LATENCY_P99 = of("latency_p99") - - @JvmField val LATENCY_AVG = of("latency_avg") - - @JvmField val FIRST_TOKEN_P50 = of("first_token_p50") - - @JvmField val FIRST_TOKEN_P99 = of("first_token_p99") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val MEDIAN_TOKENS = of("median_tokens") - - @JvmField val COMPLETION_TOKENS_P50 = of("completion_tokens_p50") - - @JvmField val PROMPT_TOKENS_P50 = of("prompt_tokens_p50") - - @JvmField val TOKENS_P99 = of("tokens_p99") - - @JvmField val COMPLETION_TOKENS_P99 = of("completion_tokens_p99") - - @JvmField val PROMPT_TOKENS_P99 = of("prompt_tokens_p99") - - @JvmField val FEEDBACK = of("feedback") - - @JvmField val FEEDBACK_SCORE_AVG = of("feedback_score_avg") - - @JvmField val FEEDBACK_VALUES = of("feedback_values") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val ERROR_RATE = of("error_rate") - - @JvmField val STREAMING_RATE = of("streaming_rate") - - @JvmField val COST_P50 = of("cost_p50") - - @JvmField val COST_P99 = of("cost_p99") - - @JvmStatic fun of(value: String) = Metric(JsonField.of(value)) + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() } - /** An enum containing [Metric]'s known values. */ - enum class Known { - RUN_COUNT, - LATENCY_P50, - LATENCY_P99, - LATENCY_AVG, - FIRST_TOKEN_P50, - FIRST_TOKEN_P99, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - MEDIAN_TOKENS, - COMPLETION_TOKENS_P50, - PROMPT_TOKENS_P50, - TOKENS_P99, - COMPLETION_TOKENS_P99, - PROMPT_TOKENS_P99, - FEEDBACK, - FEEDBACK_SCORE_AVG, - FEEDBACK_VALUES, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - ERROR_RATE, - STREAMING_RATE, - COST_P50, - COST_P99, - } + /** A builder for [Metadata]. */ + class Builder internal constructor() { - /** - * An enum containing [Metric]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Metric] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - RUN_COUNT, - LATENCY_P50, - LATENCY_P99, - LATENCY_AVG, - FIRST_TOKEN_P50, - FIRST_TOKEN_P99, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - MEDIAN_TOKENS, - COMPLETION_TOKENS_P50, - PROMPT_TOKENS_P50, - TOKENS_P99, - COMPLETION_TOKENS_P99, - PROMPT_TOKENS_P99, - FEEDBACK, - FEEDBACK_SCORE_AVG, - FEEDBACK_VALUES, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - ERROR_RATE, - STREAMING_RATE, - COST_P50, - COST_P99, - /** - * An enum member indicating that [Metric] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - RUN_COUNT -> Value.RUN_COUNT - LATENCY_P50 -> Value.LATENCY_P50 - LATENCY_P99 -> Value.LATENCY_P99 - LATENCY_AVG -> Value.LATENCY_AVG - FIRST_TOKEN_P50 -> Value.FIRST_TOKEN_P50 - FIRST_TOKEN_P99 -> Value.FIRST_TOKEN_P99 - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - MEDIAN_TOKENS -> Value.MEDIAN_TOKENS - COMPLETION_TOKENS_P50 -> Value.COMPLETION_TOKENS_P50 - PROMPT_TOKENS_P50 -> Value.PROMPT_TOKENS_P50 - TOKENS_P99 -> Value.TOKENS_P99 - COMPLETION_TOKENS_P99 -> Value.COMPLETION_TOKENS_P99 - PROMPT_TOKENS_P99 -> Value.PROMPT_TOKENS_P99 - FEEDBACK -> Value.FEEDBACK - FEEDBACK_SCORE_AVG -> Value.FEEDBACK_SCORE_AVG - FEEDBACK_VALUES -> Value.FEEDBACK_VALUES - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - ERROR_RATE -> Value.ERROR_RATE - STREAMING_RATE -> Value.STREAMING_RATE - COST_P50 -> Value.COST_P50 - COST_P99 -> Value.COST_P99 - else -> Value._UNKNOWN + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - RUN_COUNT -> Known.RUN_COUNT - LATENCY_P50 -> Known.LATENCY_P50 - LATENCY_P99 -> Known.LATENCY_P99 - LATENCY_AVG -> Known.LATENCY_AVG - FIRST_TOKEN_P50 -> Known.FIRST_TOKEN_P50 - FIRST_TOKEN_P99 -> Known.FIRST_TOKEN_P99 - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - MEDIAN_TOKENS -> Known.MEDIAN_TOKENS - COMPLETION_TOKENS_P50 -> Known.COMPLETION_TOKENS_P50 - PROMPT_TOKENS_P50 -> Known.PROMPT_TOKENS_P50 - TOKENS_P99 -> Known.TOKENS_P99 - COMPLETION_TOKENS_P99 -> Known.COMPLETION_TOKENS_P99 - PROMPT_TOKENS_P99 -> Known.PROMPT_TOKENS_P99 - FEEDBACK -> Known.FEEDBACK - FEEDBACK_SCORE_AVG -> Known.FEEDBACK_SCORE_AVG - FEEDBACK_VALUES -> Known.FEEDBACK_VALUES - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - ERROR_RATE -> Known.ERROR_RATE - STREAMING_RATE -> Known.STREAMING_RATE - COST_P50 -> Known.COST_P50 - COST_P99 -> Known.COST_P99 - else -> throw LangChainInvalidDataException("Unknown Metric: $value") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): Metric = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Metric && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - @JsonDeserialize(using = MetricDefinition.Deserializer::class) - @JsonSerialize(using = MetricDefinition.Serializer::class) - class MetricDefinition - private constructor( - private val customChartMetricCount: CustomChartMetricCount? = null, - private val customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar? = - null, - private val customChartMetricScalar: CustomChartMetricScalar? = null, - private val customChartMetricPercentile: CustomChartMetricPercentile? = null, - private val customChartMetricRatioOutput: CustomChartMetricRatioOutput? = null, - private val _json: JsonValue? = null, - ) { - - fun customChartMetricCount(): Optional = - Optional.ofNullable(customChartMetricCount) - - fun customChartFeedbackScoreMetricScalar(): - Optional = - Optional.ofNullable(customChartFeedbackScoreMetricScalar) - - fun customChartMetricScalar(): Optional = - Optional.ofNullable(customChartMetricScalar) - - fun customChartMetricPercentile(): Optional = - Optional.ofNullable(customChartMetricPercentile) - - fun customChartMetricRatioOutput(): Optional = - Optional.ofNullable(customChartMetricRatioOutput) - - fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null - - fun isCustomChartFeedbackScoreMetricScalar(): Boolean = - customChartFeedbackScoreMetricScalar != null - - fun isCustomChartMetricScalar(): Boolean = customChartMetricScalar != null - - fun isCustomChartMetricPercentile(): Boolean = customChartMetricPercentile != null - - fun isCustomChartMetricRatioOutput(): Boolean = customChartMetricRatioOutput != null - - fun asCustomChartMetricCount(): CustomChartMetricCount = - customChartMetricCount.getOrThrow("customChartMetricCount") - - fun asCustomChartFeedbackScoreMetricScalar(): CustomChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar.getOrThrow( - "customChartFeedbackScoreMetricScalar" - ) - - fun asCustomChartMetricScalar(): CustomChartMetricScalar = - customChartMetricScalar.getOrThrow("customChartMetricScalar") - - fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = - customChartMetricPercentile.getOrThrow("customChartMetricPercentile") - - fun asCustomChartMetricRatioOutput(): CustomChartMetricRatioOutput = - customChartMetricRatioOutput.getOrThrow("customChartMetricRatioOutput") - - fun _json(): Optional = Optional.ofNullable(_json) - - /** - * Maps this instance's current variant to a value of type [T] using the given - * [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from the - * API, unless [visitor] overrides [Visitor.unknown]. To handle variants not known - * to this version of the SDK gracefully, consider overriding [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = metricDefinition.accept(new MetricDefinition.Visitor>() { - * @Override - * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { - * return Optional.of(customChartMetricCount.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not overridden in - * [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - customChartMetricCount != null -> - visitor.visitCustomChartMetricCount(customChartMetricCount) - customChartFeedbackScoreMetricScalar != null -> - visitor.visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - customChartMetricScalar != null -> - visitor.visitCustomChartMetricScalar(customChartMetricScalar) - customChartMetricPercentile != null -> - visitor.visitCustomChartMetricPercentile(customChartMetricPercentile) - customChartMetricRatioOutput != null -> - visitor.visitCustomChartMetricRatioOutput(customChartMetricRatioOutput) - else -> visitor.unknown(_json) - } - - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): MetricDefinition = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) { - customChartMetricCount.validate() - } - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) { - customChartFeedbackScoreMetricScalar.validate() - } - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) { - customChartMetricScalar.validate() - } - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) { - customChartMetricPercentile.validate() - } - - override fun visitCustomChartMetricRatioOutput( - customChartMetricRatioOutput: CustomChartMetricRatioOutput - ) { - customChartMetricRatioOutput.validate() - } + 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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + 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 LangChainInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + validated = true } @@ -5864,8557 +15876,23 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) = customChartMetricCount.validity() - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = customChartFeedbackScoreMetricScalar.validity() - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = customChartMetricScalar.validity() - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = customChartMetricPercentile.validity() - - override fun visitCustomChartMetricRatioOutput( - customChartMetricRatioOutput: CustomChartMetricRatioOutput - ) = customChartMetricRatioOutput.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is MetricDefinition && - customChartMetricCount == other.customChartMetricCount && - customChartFeedbackScoreMetricScalar == - other.customChartFeedbackScoreMetricScalar && - customChartMetricScalar == other.customChartMetricScalar && - customChartMetricPercentile == other.customChartMetricPercentile && - customChartMetricRatioOutput == other.customChartMetricRatioOutput + return other is Metadata && additionalProperties == other.additionalProperties } - override fun hashCode(): Int = - Objects.hash( - customChartMetricCount, - customChartFeedbackScoreMetricScalar, - customChartMetricScalar, - customChartMetricPercentile, - customChartMetricRatioOutput, - ) + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - override fun toString(): String = - when { - customChartMetricCount != null -> - "MetricDefinition{customChartMetricCount=$customChartMetricCount}" - customChartFeedbackScoreMetricScalar != null -> - "MetricDefinition{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" - customChartMetricScalar != null -> - "MetricDefinition{customChartMetricScalar=$customChartMetricScalar}" - customChartMetricPercentile != null -> - "MetricDefinition{customChartMetricPercentile=$customChartMetricPercentile}" - customChartMetricRatioOutput != null -> - "MetricDefinition{customChartMetricRatioOutput=$customChartMetricRatioOutput}" - _json != null -> "MetricDefinition{_unknown=$_json}" - else -> throw IllegalStateException("Invalid MetricDefinition") - } + override fun hashCode(): Int = hashCode - companion object { - - @JvmStatic - fun ofCustomChartMetricCount(customChartMetricCount: CustomChartMetricCount) = - MetricDefinition(customChartMetricCount = customChartMetricCount) - - @JvmStatic - fun ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: CustomChartFeedbackScoreMetricScalar - ) = - MetricDefinition( - customChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar - ) - - @JvmStatic - fun ofCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = MetricDefinition(customChartMetricScalar = customChartMetricScalar) - - @JvmStatic - fun ofCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = MetricDefinition(customChartMetricPercentile = customChartMetricPercentile) - - @JvmStatic - fun ofCustomChartMetricRatioOutput( - customChartMetricRatioOutput: CustomChartMetricRatioOutput - ) = - MetricDefinition( - customChartMetricRatioOutput = customChartMetricRatioOutput - ) - } - - /** - * An interface that defines how to map each variant of [MetricDefinition] to a - * value of type [T]. - */ - interface Visitor { - - fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ): T - - fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: CustomChartFeedbackScoreMetricScalar - ): T - - fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ): T - - fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ): T - - fun visitCustomChartMetricRatioOutput( - customChartMetricRatioOutput: CustomChartMetricRatioOutput - ): T - - /** - * Maps an unknown variant of [MetricDefinition] to a value of type [T]. - * - * An instance of [MetricDefinition] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if - * the SDK is on an older version than the API, then the API may respond with - * new variants that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown MetricDefinition: $json") - } - } - - internal class Deserializer : - BaseDeserializer(MetricDefinition::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): MetricDefinition { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { - MetricDefinition( - customChartMetricCount = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - MetricDefinition( - customChartFeedbackScoreMetricScalar = it, - _json = json, - ) - }, - tryDeserialize(node, jacksonTypeRef()) - ?.let { - MetricDefinition( - customChartMetricScalar = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - MetricDefinition( - customChartMetricPercentile = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - MetricDefinition( - customChartMetricRatioOutput = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing from - // boolean). - 0 -> MetricDefinition(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use - // the first completely valid match, or simply the first match if none - // are completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : - BaseSerializer(MetricDefinition::class) { - - override fun serialize( - value: MetricDefinition, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.customChartMetricCount != null -> - generator.writeObject(value.customChartMetricCount) - value.customChartFeedbackScoreMetricScalar != null -> - generator.writeObject(value.customChartFeedbackScoreMetricScalar) - value.customChartMetricScalar != null -> - generator.writeObject(value.customChartMetricScalar) - value.customChartMetricPercentile != null -> - generator.writeObject(value.customChartMetricPercentile) - value.customChartMetricRatioOutput != null -> - generator.writeObject(value.customChartMetricRatioOutput) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid MetricDefinition") - } - } - } - - class CustomChartMetricCount - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val filter: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - ) : this(filter, type, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * @throws LangChainInvalidDataException 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 [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - /** - * 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 - * [CustomChartMetricCount]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricCount]. */ - class Builder internal constructor() { - - private var filter: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartMetricCount: CustomChartMetricCount) = apply { - filter = customChartMetricCount.filter - type = customChartMetricCount.type - additionalProperties = - customChartMetricCount.additionalProperties.toMutableMap() - } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { this.filter = filter } - - 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 [CustomChartMetricCount]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): CustomChartMetricCount = - CustomChartMetricCount( - filter, - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartMetricCount = apply { - if (validated) { - return@apply - } - - filter() - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (filter.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val COUNT = of("count") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - COUNT - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - COUNT, - /** - * An enum member indicating that [Type] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - COUNT -> Value.COUNT - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - COUNT -> Known.COUNT - else -> throw LangChainInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricCount && - filter == other.filter && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(filter, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" - } - - class CustomChartFeedbackScoreMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonValue, - private val params: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") @ExcludeMissing field: JsonValue = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonValue = field - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartFeedbackScoreMetricScalar]. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonValue = JsonValue.from("feedback_score") - private var params: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = apply { - field = customChartFeedbackScoreMetricScalar.field - params = customChartFeedbackScoreMetricScalar.params - type = customChartFeedbackScoreMetricScalar.type - filter = customChartFeedbackScoreMetricScalar.filter - additionalProperties = - customChartFeedbackScoreMetricScalar.additionalProperties - .toMutableMap() - } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field defaults - * to the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun field(field: JsonValue) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed [Params] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { this.params = params } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { this.filter = filter } - - 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 [CustomChartFeedbackScoreMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartFeedbackScoreMetricScalar = - CustomChartFeedbackScoreMetricScalar( - field, - checkRequired("params", params), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartFeedbackScoreMetricScalar = apply { - if (validated) { - return@apply - } - - _field().let { - if (it != JsonValue.from("feedback_score")) { - throw LangChainInvalidDataException( - "'field' is invalid, received $it" - ) - } - } - params().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - field.let { if (it == JsonValue.from("feedback_score")) 1 else 0 } + - (params.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val feedbackKey: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("feedback_key") - @ExcludeMissing - feedbackKey: JsonField = JsonMissing.of() - ) : this(feedbackKey, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 feedbackKey(): String = feedbackKey.getRequired("feedback_key") - - /** - * Returns the raw JSON value of [feedbackKey]. - * - * Unlike [feedbackKey], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("feedback_key") - @ExcludeMissing - fun _feedbackKey(): JsonField = feedbackKey - - @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 [Params]. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var feedbackKey: JsonField? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - feedbackKey = params.feedbackKey - additionalProperties = params.additionalProperties.toMutableMap() - } - - fun feedbackKey(feedbackKey: String) = - feedbackKey(JsonField.of(feedbackKey)) - - /** - * Sets [Builder.feedbackKey] to an arbitrary JSON value. - * - * You should usually call [Builder.feedbackKey] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun feedbackKey(feedbackKey: JsonField) = apply { - this.feedbackKey = feedbackKey - } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params( - checkRequired("feedbackKey", feedbackKey), - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - feedbackKey() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (feedbackKey.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - feedbackKey == other.feedbackKey && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(feedbackKey, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> throw LangChainInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartFeedbackScoreMetricScalar && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricScalar]. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartMetricScalar: CustomChartMetricScalar) = - apply { - field = customChartMetricScalar.field - type = customChartMetricScalar.type - filter = customChartMetricScalar.filter - additionalProperties = - customChartMetricScalar.additionalProperties.toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { this.filter = filter } - - 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 [CustomChartMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricScalar = - CustomChartMetricScalar( - checkRequired("field", field), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartMetricScalar = apply { - if (validated) { - return@apply - } - - field().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Field] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> throw LangChainInvalidDataException("Unknown Field: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val SUM = of("sum") - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - SUM, - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - SUM, - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - SUM -> Value.SUM - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - SUM -> Known.SUM - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> throw LangChainInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricScalar && - field == other.field && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricPercentile - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val params: JsonField, - private val type: JsonValue, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricPercentile]. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricPercentile]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var params: JsonField? = null - private var type: JsonValue = JsonValue.from("percentile") - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricPercentile: CustomChartMetricPercentile - ) = apply { - field = customChartMetricPercentile.field - params = customChartMetricPercentile.params - type = customChartMetricPercentile.type - filter = customChartMetricPercentile.filter - additionalProperties = - customChartMetricPercentile.additionalProperties.toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed [Params] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { this.params = params } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field defaults - * to the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { this.filter = filter } - - 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 [CustomChartMetricPercentile]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricPercentile = - CustomChartMetricPercentile( - checkRequired("field", field), - checkRequired("params", params), - type, - filter, - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartMetricPercentile = apply { - if (validated) { - return@apply - } - - field().validate() - params().validate() - _type().let { - if (it != JsonValue.from("percentile")) { - throw LangChainInvalidDataException( - "'type' is invalid, received $it" - ) - } - } - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (params.asKnown().getOrNull()?.validity() ?: 0) + - type.let { if (it == JsonValue.from("percentile")) 1 else 0 } + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Field] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> throw LangChainInvalidDataException("Unknown Field: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val p: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("p") - @ExcludeMissing - p: JsonField = JsonMissing.of() - ) : this(p, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") - - /** - * Returns the raw JSON value of [p]. - * - * Unlike [p], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("p") @ExcludeMissing fun _p(): JsonField = p - - @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 [Params]. - * - * The following fields are required: - * ```java - * .p() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var p: JsonField? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - p = params.p - additionalProperties = params.additionalProperties.toMutableMap() - } - - fun p(p: Double) = p(JsonField.of(p)) - - /** - * Sets [Builder.p] to an arbitrary JSON value. - * - * You should usually call [Builder.p] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun p(p: JsonField) = apply { this.p = p } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .p() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params(checkRequired("p", p), 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - p() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (p.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - p == other.p && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(p, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{p=$p, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricPercentile && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricRatioOutput - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val denominator: JsonField, - private val numerator: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("denominator") - @ExcludeMissing - denominator: JsonField = JsonMissing.of(), - @JsonProperty("numerator") - @ExcludeMissing - numerator: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(denominator, numerator, type, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 denominator(): Denominator = denominator.getRequired("denominator") - - /** - * @throws LangChainInvalidDataException 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 numerator(): Numerator = numerator.getRequired("numerator") - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("ratio") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type - - /** - * Returns the raw JSON value of [denominator]. - * - * Unlike [denominator], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("denominator") - @ExcludeMissing - fun _denominator(): JsonField = denominator - - /** - * Returns the raw JSON value of [numerator]. - * - * Unlike [numerator], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("numerator") - @ExcludeMissing - fun _numerator(): JsonField = numerator - - @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 - * [CustomChartMetricRatioOutput]. - * - * The following fields are required: - * ```java - * .denominator() - * .numerator() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricRatioOutput]. */ - class Builder internal constructor() { - - private var denominator: JsonField? = null - private var numerator: JsonField? = null - private var type: JsonValue = JsonValue.from("ratio") - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricRatioOutput: CustomChartMetricRatioOutput - ) = apply { - denominator = customChartMetricRatioOutput.denominator - numerator = customChartMetricRatioOutput.numerator - type = customChartMetricRatioOutput.type - additionalProperties = - customChartMetricRatioOutput.additionalProperties.toMutableMap() - } - - fun denominator(denominator: Denominator) = - denominator(JsonField.of(denominator)) - - /** - * Sets [Builder.denominator] to an arbitrary JSON value. - * - * You should usually call [Builder.denominator] with a well-typed - * [Denominator] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun denominator(denominator: JsonField) = apply { - this.denominator = denominator - } - - /** - * Alias for calling [denominator] with - * `Denominator.ofCustomChartMetricCount(customChartMetricCount)`. - */ - fun denominator( - customChartMetricCount: Denominator.CustomChartMetricCount - ) = - denominator( - Denominator.ofCustomChartMetricCount(customChartMetricCount) - ) - - /** - * Alias for calling [denominator] with - * `Denominator.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. - */ - fun denominator( - customChartFeedbackScoreMetricScalar: - Denominator.CustomChartFeedbackScoreMetricScalar - ) = - denominator( - Denominator.ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - ) - - /** - * Alias for calling [denominator] with - * `Denominator.ofCustomChartMetricScalar(customChartMetricScalar)`. - */ - fun denominator( - customChartMetricScalar: Denominator.CustomChartMetricScalar - ) = - denominator( - Denominator.ofCustomChartMetricScalar(customChartMetricScalar) - ) - - /** - * Alias for calling [denominator] with - * `Denominator.ofCustomChartMetricPercentile(customChartMetricPercentile)`. - */ - fun denominator( - customChartMetricPercentile: Denominator.CustomChartMetricPercentile - ) = - denominator( - Denominator.ofCustomChartMetricPercentile( - customChartMetricPercentile - ) - ) - - fun numerator(numerator: Numerator) = numerator(JsonField.of(numerator)) - - /** - * Sets [Builder.numerator] to an arbitrary JSON value. - * - * You should usually call [Builder.numerator] with a well-typed [Numerator] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun numerator(numerator: JsonField) = apply { - this.numerator = numerator - } - - /** - * Alias for calling [numerator] with - * `Numerator.ofCustomChartMetricCount(customChartMetricCount)`. - */ - fun numerator(customChartMetricCount: Numerator.CustomChartMetricCount) = - numerator(Numerator.ofCustomChartMetricCount(customChartMetricCount)) - - /** - * Alias for calling [numerator] with - * `Numerator.ofCustomChartFeedbackScoreMetricScalar(customChartFeedbackScoreMetricScalar)`. - */ - fun numerator( - customChartFeedbackScoreMetricScalar: - Numerator.CustomChartFeedbackScoreMetricScalar - ) = - numerator( - Numerator.ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - ) - - /** - * Alias for calling [numerator] with - * `Numerator.ofCustomChartMetricScalar(customChartMetricScalar)`. - */ - fun numerator(customChartMetricScalar: Numerator.CustomChartMetricScalar) = - numerator(Numerator.ofCustomChartMetricScalar(customChartMetricScalar)) - - /** - * Alias for calling [numerator] with - * `Numerator.ofCustomChartMetricPercentile(customChartMetricPercentile)`. - */ - fun numerator( - customChartMetricPercentile: Numerator.CustomChartMetricPercentile - ) = - numerator( - Numerator.ofCustomChartMetricPercentile(customChartMetricPercentile) - ) - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field defaults - * to the following: - * ```java - * JsonValue.from("ratio") - * ``` - * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun type(type: JsonValue) = 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 [CustomChartMetricRatioOutput]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .denominator() - * .numerator() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricRatioOutput = - CustomChartMetricRatioOutput( - checkRequired("denominator", denominator), - checkRequired("numerator", numerator), - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): CustomChartMetricRatioOutput = apply { - if (validated) { - return@apply - } - - denominator().validate() - numerator().validate() - _type().let { - if (it != JsonValue.from("ratio")) { - throw LangChainInvalidDataException( - "'type' is invalid, received $it" - ) - } - } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (denominator.asKnown().getOrNull()?.validity() ?: 0) + - (numerator.asKnown().getOrNull()?.validity() ?: 0) + - type.let { if (it == JsonValue.from("ratio")) 1 else 0 } - - @JsonDeserialize(using = Denominator.Deserializer::class) - @JsonSerialize(using = Denominator.Serializer::class) - class Denominator - private constructor( - private val customChartMetricCount: CustomChartMetricCount? = null, - private val customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar? = - null, - private val customChartMetricScalar: CustomChartMetricScalar? = null, - private val customChartMetricPercentile: CustomChartMetricPercentile? = - null, - private val _json: JsonValue? = null, - ) { - - fun customChartMetricCount(): Optional = - Optional.ofNullable(customChartMetricCount) - - fun customChartFeedbackScoreMetricScalar(): - Optional = - Optional.ofNullable(customChartFeedbackScoreMetricScalar) - - fun customChartMetricScalar(): Optional = - Optional.ofNullable(customChartMetricScalar) - - fun customChartMetricPercentile(): Optional = - Optional.ofNullable(customChartMetricPercentile) - - fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null - - fun isCustomChartFeedbackScoreMetricScalar(): Boolean = - customChartFeedbackScoreMetricScalar != null - - fun isCustomChartMetricScalar(): Boolean = customChartMetricScalar != null - - fun isCustomChartMetricPercentile(): Boolean = - customChartMetricPercentile != null - - fun asCustomChartMetricCount(): CustomChartMetricCount = - customChartMetricCount.getOrThrow("customChartMetricCount") - - fun asCustomChartFeedbackScoreMetricScalar(): - CustomChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar.getOrThrow( - "customChartFeedbackScoreMetricScalar" - ) - - fun asCustomChartMetricScalar(): CustomChartMetricScalar = - customChartMetricScalar.getOrThrow("customChartMetricScalar") - - fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = - customChartMetricPercentile.getOrThrow("customChartMetricPercentile") - - fun _json(): Optional = Optional.ofNullable(_json) - - /** - * Maps this instance's current variant to a value of type [T] using the - * given [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from - * the API, unless [visitor] overrides [Visitor.unknown]. To handle variants - * not known to this version of the SDK gracefully, consider overriding - * [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = denominator.accept(new Denominator.Visitor>() { - * @Override - * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { - * return Optional.of(customChartMetricCount.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not - * overridden in [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - customChartMetricCount != null -> - visitor.visitCustomChartMetricCount(customChartMetricCount) - customChartFeedbackScoreMetricScalar != null -> - visitor.visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - customChartMetricScalar != null -> - visitor.visitCustomChartMetricScalar(customChartMetricScalar) - customChartMetricPercentile != null -> - visitor.visitCustomChartMetricPercentile( - customChartMetricPercentile - ) - else -> visitor.unknown(_json) - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Denominator = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) { - customChartMetricCount.validate() - } - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) { - customChartFeedbackScoreMetricScalar.validate() - } - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) { - customChartMetricScalar.validate() - } - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) { - customChartMetricPercentile.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) = customChartMetricCount.validity() - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = customChartFeedbackScoreMetricScalar.validity() - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = customChartMetricScalar.validity() - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = customChartMetricPercentile.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Denominator && - customChartMetricCount == other.customChartMetricCount && - customChartFeedbackScoreMetricScalar == - other.customChartFeedbackScoreMetricScalar && - customChartMetricScalar == other.customChartMetricScalar && - customChartMetricPercentile == other.customChartMetricPercentile - } - - override fun hashCode(): Int = - Objects.hash( - customChartMetricCount, - customChartFeedbackScoreMetricScalar, - customChartMetricScalar, - customChartMetricPercentile, - ) - - override fun toString(): String = - when { - customChartMetricCount != null -> - "Denominator{customChartMetricCount=$customChartMetricCount}" - customChartFeedbackScoreMetricScalar != null -> - "Denominator{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" - customChartMetricScalar != null -> - "Denominator{customChartMetricScalar=$customChartMetricScalar}" - customChartMetricPercentile != null -> - "Denominator{customChartMetricPercentile=$customChartMetricPercentile}" - _json != null -> "Denominator{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Denominator") - } - - companion object { - - @JvmStatic - fun ofCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) = Denominator(customChartMetricCount = customChartMetricCount) - - @JvmStatic - fun ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = - Denominator( - customChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar - ) - - @JvmStatic - fun ofCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = Denominator(customChartMetricScalar = customChartMetricScalar) - - @JvmStatic - fun ofCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = - Denominator( - customChartMetricPercentile = customChartMetricPercentile - ) - } - - /** - * An interface that defines how to map each variant of [Denominator] to a - * value of type [T]. - */ - interface Visitor { - - fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ): T - - fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ): T - - fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ): T - - fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ): T - - /** - * Maps an unknown variant of [Denominator] to a value of type [T]. - * - * An instance of [Denominator] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown Denominator: $json") - } - } - - internal class Deserializer : - BaseDeserializer(Denominator::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Denominator { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Denominator( - customChartMetricCount = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef< - CustomChartFeedbackScoreMetricScalar - >(), - ) - ?.let { - Denominator( - customChartFeedbackScoreMetricScalar = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Denominator( - customChartMetricScalar = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Denominator( - customChartMetricPercentile = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from boolean). - 0 -> Denominator(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : - BaseSerializer(Denominator::class) { - - override fun serialize( - value: Denominator, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.customChartMetricCount != null -> - generator.writeObject(value.customChartMetricCount) - value.customChartFeedbackScoreMetricScalar != null -> - generator.writeObject( - value.customChartFeedbackScoreMetricScalar - ) - value.customChartMetricScalar != null -> - generator.writeObject(value.customChartMetricScalar) - value.customChartMetricPercentile != null -> - generator.writeObject(value.customChartMetricPercentile) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Denominator") - } - } - } - - class CustomChartMetricCount - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val filter: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - ) : this(filter, type, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * @throws LangChainInvalidDataException 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 [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - /** - * 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 - * [CustomChartMetricCount]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricCount]. */ - class Builder internal constructor() { - - private var filter: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartMetricCount: CustomChartMetricCount) = - apply { - filter = customChartMetricCount.filter - type = customChartMetricCount.type - additionalProperties = - customChartMetricCount.additionalProperties - .toMutableMap() - } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricCount]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): CustomChartMetricCount = - CustomChartMetricCount( - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricCount = apply { - if (validated) { - return@apply - } - - filter() - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (filter.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val COUNT = of("count") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - COUNT - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - COUNT, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - COUNT -> Value.COUNT - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - COUNT -> Known.COUNT - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricCount && - filter == other.filter && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(filter, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" - } - - class CustomChartFeedbackScoreMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonValue, - private val params: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonValue = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if - * the server responded with an unexpected value). - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonValue = field - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartFeedbackScoreMetricScalar]. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonValue = JsonValue.from("feedback_score") - private var params: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = apply { - field = customChartFeedbackScoreMetricScalar.field - params = customChartFeedbackScoreMetricScalar.params - type = customChartFeedbackScoreMetricScalar.type - filter = customChartFeedbackScoreMetricScalar.filter - additionalProperties = - customChartFeedbackScoreMetricScalar.additionalProperties - .toMutableMap() - } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field - * defaults to the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun field(field: JsonValue) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed - * [Params] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { - this.params = params - } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 - * [CustomChartFeedbackScoreMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartFeedbackScoreMetricScalar = - CustomChartFeedbackScoreMetricScalar( - field, - checkRequired("params", params), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartFeedbackScoreMetricScalar = apply { - if (validated) { - return@apply - } - - _field().let { - if (it != JsonValue.from("feedback_score")) { - throw LangChainInvalidDataException( - "'field' is invalid, received $it" - ) - } - } - params().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - field.let { if (it == JsonValue.from("feedback_score")) 1 else 0 } + - (params.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val feedbackKey: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("feedback_key") - @ExcludeMissing - feedbackKey: JsonField = JsonMissing.of() - ) : this(feedbackKey, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 feedbackKey(): String = feedbackKey.getRequired("feedback_key") - - /** - * Returns the raw JSON value of [feedbackKey]. - * - * Unlike [feedbackKey], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("feedback_key") - @ExcludeMissing - fun _feedbackKey(): JsonField = feedbackKey - - @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 - * [Params]. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var feedbackKey: JsonField? = null - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - feedbackKey = params.feedbackKey - additionalProperties = - params.additionalProperties.toMutableMap() - } - - fun feedbackKey(feedbackKey: String) = - feedbackKey(JsonField.of(feedbackKey)) - - /** - * Sets [Builder.feedbackKey] to an arbitrary JSON value. - * - * You should usually call [Builder.feedbackKey] with a - * well-typed [String] value instead. This method is primarily - * for setting the field to an undocumented or not yet supported - * value. - */ - fun feedbackKey(feedbackKey: JsonField) = apply { - this.feedbackKey = feedbackKey - } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the - * returned instance. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params( - checkRequired("feedbackKey", feedbackKey), - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - feedbackKey() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (feedbackKey.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - feedbackKey == other.feedbackKey && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(feedbackKey, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartFeedbackScoreMetricScalar && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("field") - @ExcludeMissing - fun _field(): JsonField = field - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricScalar]. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricScalar: CustomChartMetricScalar - ) = apply { - field = customChartMetricScalar.field - type = customChartMetricScalar.type - filter = customChartMetricScalar.filter - additionalProperties = - customChartMetricScalar.additionalProperties.toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] - * value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricScalar = - CustomChartMetricScalar( - checkRequired("field", field), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricScalar = apply { - if (validated) { - return@apply - } - - field().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Field] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> - throw LangChainInvalidDataException( - "Unknown Field: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val SUM = of("sum") - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - SUM, - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - SUM, - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - SUM -> Value.SUM - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - SUM -> Known.SUM - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricScalar && - field == other.field && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricPercentile - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val params: JsonField, - private val type: JsonValue, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonValue = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if - * the server responded with an unexpected value). - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("field") - @ExcludeMissing - fun _field(): JsonField = field - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricPercentile]. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricPercentile]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var params: JsonField? = null - private var type: JsonValue = JsonValue.from("percentile") - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricPercentile: CustomChartMetricPercentile - ) = apply { - field = customChartMetricPercentile.field - params = customChartMetricPercentile.params - type = customChartMetricPercentile.type - filter = customChartMetricPercentile.filter - additionalProperties = - customChartMetricPercentile.additionalProperties - .toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] - * value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed - * [Params] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { - this.params = params - } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field - * defaults to the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricPercentile]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricPercentile = - CustomChartMetricPercentile( - checkRequired("field", field), - checkRequired("params", params), - type, - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricPercentile = apply { - if (validated) { - return@apply - } - - field().validate() - params().validate() - _type().let { - if (it != JsonValue.from("percentile")) { - throw LangChainInvalidDataException( - "'type' is invalid, received $it" - ) - } - } - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (params.asKnown().getOrNull()?.validity() ?: 0) + - type.let { if (it == JsonValue.from("percentile")) 1 else 0 } + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Field] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> - throw LangChainInvalidDataException( - "Unknown Field: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val p: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("p") - @ExcludeMissing - p: JsonField = JsonMissing.of() - ) : this(p, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") - - /** - * Returns the raw JSON value of [p]. - * - * Unlike [p], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("p") @ExcludeMissing fun _p(): JsonField = p - - @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 - * [Params]. - * - * The following fields are required: - * ```java - * .p() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var p: JsonField? = null - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - p = params.p - additionalProperties = - params.additionalProperties.toMutableMap() - } - - fun p(p: Double) = p(JsonField.of(p)) - - /** - * Sets [Builder.p] to an arbitrary JSON value. - * - * You should usually call [Builder.p] with a well-typed - * [Double] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun p(p: JsonField) = apply { this.p = p } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the - * returned instance. - * - * The following fields are required: - * ```java - * .p() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params( - checkRequired("p", p), - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - p() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (p.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - p == other.p && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(p, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{p=$p, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricPercentile && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - } - - @JsonDeserialize(using = Numerator.Deserializer::class) - @JsonSerialize(using = Numerator.Serializer::class) - class Numerator - private constructor( - private val customChartMetricCount: CustomChartMetricCount? = null, - private val customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar? = - null, - private val customChartMetricScalar: CustomChartMetricScalar? = null, - private val customChartMetricPercentile: CustomChartMetricPercentile? = - null, - private val _json: JsonValue? = null, - ) { - - fun customChartMetricCount(): Optional = - Optional.ofNullable(customChartMetricCount) - - fun customChartFeedbackScoreMetricScalar(): - Optional = - Optional.ofNullable(customChartFeedbackScoreMetricScalar) - - fun customChartMetricScalar(): Optional = - Optional.ofNullable(customChartMetricScalar) - - fun customChartMetricPercentile(): Optional = - Optional.ofNullable(customChartMetricPercentile) - - fun isCustomChartMetricCount(): Boolean = customChartMetricCount != null - - fun isCustomChartFeedbackScoreMetricScalar(): Boolean = - customChartFeedbackScoreMetricScalar != null - - fun isCustomChartMetricScalar(): Boolean = customChartMetricScalar != null - - fun isCustomChartMetricPercentile(): Boolean = - customChartMetricPercentile != null - - fun asCustomChartMetricCount(): CustomChartMetricCount = - customChartMetricCount.getOrThrow("customChartMetricCount") - - fun asCustomChartFeedbackScoreMetricScalar(): - CustomChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar.getOrThrow( - "customChartFeedbackScoreMetricScalar" - ) - - fun asCustomChartMetricScalar(): CustomChartMetricScalar = - customChartMetricScalar.getOrThrow("customChartMetricScalar") - - fun asCustomChartMetricPercentile(): CustomChartMetricPercentile = - customChartMetricPercentile.getOrThrow("customChartMetricPercentile") - - fun _json(): Optional = Optional.ofNullable(_json) - - /** - * Maps this instance's current variant to a value of type [T] using the - * given [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from - * the API, unless [visitor] overrides [Visitor.unknown]. To handle variants - * not known to this version of the SDK gracefully, consider overriding - * [Visitor.unknown]: - * ```java - * import com.langchain.smith.core.JsonValue; - * import java.util.Optional; - * - * Optional result = numerator.accept(new Numerator.Visitor>() { - * @Override - * public Optional visitCustomChartMetricCount(CustomChartMetricCount customChartMetricCount) { - * return Optional.of(customChartMetricCount.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws LangChainInvalidDataException if [Visitor.unknown] is not - * overridden in [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - customChartMetricCount != null -> - visitor.visitCustomChartMetricCount(customChartMetricCount) - customChartFeedbackScoreMetricScalar != null -> - visitor.visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar - ) - customChartMetricScalar != null -> - visitor.visitCustomChartMetricScalar(customChartMetricScalar) - customChartMetricPercentile != null -> - visitor.visitCustomChartMetricPercentile( - customChartMetricPercentile - ) - else -> visitor.unknown(_json) - } - - 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 LangChainInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Numerator = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) { - customChartMetricCount.validate() - } - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) { - customChartFeedbackScoreMetricScalar.validate() - } - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) { - customChartMetricScalar.validate() - } - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) { - customChartMetricPercentile.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - accept( - object : Visitor { - override fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) = customChartMetricCount.validity() - - override fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = customChartFeedbackScoreMetricScalar.validity() - - override fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = customChartMetricScalar.validity() - - override fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = customChartMetricPercentile.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Numerator && - customChartMetricCount == other.customChartMetricCount && - customChartFeedbackScoreMetricScalar == - other.customChartFeedbackScoreMetricScalar && - customChartMetricScalar == other.customChartMetricScalar && - customChartMetricPercentile == other.customChartMetricPercentile - } - - override fun hashCode(): Int = - Objects.hash( - customChartMetricCount, - customChartFeedbackScoreMetricScalar, - customChartMetricScalar, - customChartMetricPercentile, - ) - - override fun toString(): String = - when { - customChartMetricCount != null -> - "Numerator{customChartMetricCount=$customChartMetricCount}" - customChartFeedbackScoreMetricScalar != null -> - "Numerator{customChartFeedbackScoreMetricScalar=$customChartFeedbackScoreMetricScalar}" - customChartMetricScalar != null -> - "Numerator{customChartMetricScalar=$customChartMetricScalar}" - customChartMetricPercentile != null -> - "Numerator{customChartMetricPercentile=$customChartMetricPercentile}" - _json != null -> "Numerator{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Numerator") - } - - companion object { - - @JvmStatic - fun ofCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ) = Numerator(customChartMetricCount = customChartMetricCount) - - @JvmStatic - fun ofCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = - Numerator( - customChartFeedbackScoreMetricScalar = - customChartFeedbackScoreMetricScalar - ) - - @JvmStatic - fun ofCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ) = Numerator(customChartMetricScalar = customChartMetricScalar) - - @JvmStatic - fun ofCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ) = Numerator(customChartMetricPercentile = customChartMetricPercentile) - } - - /** - * An interface that defines how to map each variant of [Numerator] to a - * value of type [T]. - */ - interface Visitor { - - fun visitCustomChartMetricCount( - customChartMetricCount: CustomChartMetricCount - ): T - - fun visitCustomChartFeedbackScoreMetricScalar( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ): T - - fun visitCustomChartMetricScalar( - customChartMetricScalar: CustomChartMetricScalar - ): T - - fun visitCustomChartMetricPercentile( - customChartMetricPercentile: CustomChartMetricPercentile - ): T - - /** - * Maps an unknown variant of [Numerator] to a value of type [T]. - * - * An instance of [Numerator] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LangChainInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LangChainInvalidDataException("Unknown Numerator: $json") - } - } - - internal class Deserializer : - BaseDeserializer(Numerator::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Numerator { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Numerator( - customChartMetricCount = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef< - CustomChartFeedbackScoreMetricScalar - >(), - ) - ?.let { - Numerator( - customChartFeedbackScoreMetricScalar = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Numerator( - customChartMetricScalar = it, - _json = json, - ) - }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Numerator( - customChartMetricPercentile = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from boolean). - 0 -> Numerator(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Numerator::class) { - - override fun serialize( - value: Numerator, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.customChartMetricCount != null -> - generator.writeObject(value.customChartMetricCount) - value.customChartFeedbackScoreMetricScalar != null -> - generator.writeObject( - value.customChartFeedbackScoreMetricScalar - ) - value.customChartMetricScalar != null -> - generator.writeObject(value.customChartMetricScalar) - value.customChartMetricPercentile != null -> - generator.writeObject(value.customChartMetricPercentile) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Numerator") - } - } - } - - class CustomChartMetricCount - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val filter: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - ) : this(filter, type, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * @throws LangChainInvalidDataException 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 [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - /** - * 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 - * [CustomChartMetricCount]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricCount]. */ - class Builder internal constructor() { - - private var filter: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(customChartMetricCount: CustomChartMetricCount) = - apply { - filter = customChartMetricCount.filter - type = customChartMetricCount.type - additionalProperties = - customChartMetricCount.additionalProperties - .toMutableMap() - } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricCount]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): CustomChartMetricCount = - CustomChartMetricCount( - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricCount = apply { - if (validated) { - return@apply - } - - filter() - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (filter.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val COUNT = of("count") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - COUNT - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - COUNT, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - COUNT -> Value.COUNT - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - COUNT -> Known.COUNT - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricCount && - filter == other.filter && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(filter, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricCount{filter=$filter, type=$type, additionalProperties=$additionalProperties}" - } - - class CustomChartFeedbackScoreMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonValue, - private val params: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonValue = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if - * the server responded with an unexpected value). - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonValue = field - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartFeedbackScoreMetricScalar]. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartFeedbackScoreMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonValue = JsonValue.from("feedback_score") - private var params: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartFeedbackScoreMetricScalar: - CustomChartFeedbackScoreMetricScalar - ) = apply { - field = customChartFeedbackScoreMetricScalar.field - params = customChartFeedbackScoreMetricScalar.params - type = customChartFeedbackScoreMetricScalar.type - filter = customChartFeedbackScoreMetricScalar.filter - additionalProperties = - customChartFeedbackScoreMetricScalar.additionalProperties - .toMutableMap() - } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field - * defaults to the following: - * ```java - * JsonValue.from("feedback_score") - * ``` - * - * This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun field(field: JsonValue) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed - * [Params] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { - this.params = params - } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 - * [CustomChartFeedbackScoreMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .params() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartFeedbackScoreMetricScalar = - CustomChartFeedbackScoreMetricScalar( - field, - checkRequired("params", params), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartFeedbackScoreMetricScalar = apply { - if (validated) { - return@apply - } - - _field().let { - if (it != JsonValue.from("feedback_score")) { - throw LangChainInvalidDataException( - "'field' is invalid, received $it" - ) - } - } - params().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - field.let { if (it == JsonValue.from("feedback_score")) 1 else 0 } + - (params.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val feedbackKey: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("feedback_key") - @ExcludeMissing - feedbackKey: JsonField = JsonMissing.of() - ) : this(feedbackKey, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 feedbackKey(): String = feedbackKey.getRequired("feedback_key") - - /** - * Returns the raw JSON value of [feedbackKey]. - * - * Unlike [feedbackKey], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("feedback_key") - @ExcludeMissing - fun _feedbackKey(): JsonField = feedbackKey - - @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 - * [Params]. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var feedbackKey: JsonField? = null - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - feedbackKey = params.feedbackKey - additionalProperties = - params.additionalProperties.toMutableMap() - } - - fun feedbackKey(feedbackKey: String) = - feedbackKey(JsonField.of(feedbackKey)) - - /** - * Sets [Builder.feedbackKey] to an arbitrary JSON value. - * - * You should usually call [Builder.feedbackKey] with a - * well-typed [String] value instead. This method is primarily - * for setting the field to an undocumented or not yet supported - * value. - */ - fun feedbackKey(feedbackKey: JsonField) = apply { - this.feedbackKey = feedbackKey - } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the - * returned instance. - * - * The following fields are required: - * ```java - * .feedbackKey() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params( - checkRequired("feedbackKey", feedbackKey), - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - feedbackKey() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (feedbackKey.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - feedbackKey == other.feedbackKey && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(feedbackKey, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{feedbackKey=$feedbackKey, additionalProperties=$additionalProperties}" - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartFeedbackScoreMetricScalar && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartFeedbackScoreMetricScalar{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricScalar - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val type: JsonField, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("field") - @ExcludeMissing - fun _field(): JsonField = field - - /** - * 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 - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricScalar]. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricScalar]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var type: JsonField? = null - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricScalar: CustomChartMetricScalar - ) = apply { - field = customChartMetricScalar.field - type = customChartMetricScalar.type - filter = customChartMetricScalar.filter - additionalProperties = - customChartMetricScalar.additionalProperties.toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] - * value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - 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 filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricScalar]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .field() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricScalar = - CustomChartMetricScalar( - checkRequired("field", field), - checkRequired("type", type), - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricScalar = apply { - if (validated) { - return@apply - } - - field().validate() - type().validate() - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Field] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> - throw LangChainInvalidDataException( - "Unknown Field: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Type - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val SUM = of("sum") - - @JvmField val MAX = of("max") - - @JvmField val MIN = of("min") - - @JvmField val AVG = of("avg") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - SUM, - MAX, - MIN, - AVG, - } - - /** - * An enum containing [Type]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - SUM, - MAX, - MIN, - AVG, - /** - * An enum member indicating that [Type] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - SUM -> Value.SUM - MAX -> Value.MAX - MIN -> Value.MIN - AVG -> Value.AVG - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - SUM -> Known.SUM - MAX -> Known.MAX - MIN -> Known.MIN - AVG -> Known.AVG - else -> - throw LangChainInvalidDataException( - "Unknown Type: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricScalar && - field == other.field && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricScalar{field=$field, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - - class CustomChartMetricPercentile - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val field: JsonField, - private val params: JsonField, - private val type: JsonValue, - private val filter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("field") - @ExcludeMissing - field: JsonField = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - params: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonValue = JsonMissing.of(), - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - ) : this(field, params, type, filter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 field(): Field = field.getRequired("field") - - /** - * @throws LangChainInvalidDataException 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 params(): Params = params.getRequired("params") - - /** - * Expected to always return the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if - * the server responded with an unexpected value). - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type - - /** - * @throws LangChainInvalidDataException if the JSON field has an - * unexpected type (e.g. if the server responded with an unexpected - * value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("field") - @ExcludeMissing - fun _field(): JsonField = field - - /** - * Returns the raw JSON value of [params]. - * - * Unlike [params], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("params") - @ExcludeMissing - fun _params(): JsonField = params - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("filter") - @ExcludeMissing - fun _filter(): JsonField = filter - - @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 - * [CustomChartMetricPercentile]. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomChartMetricPercentile]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var params: JsonField? = null - private var type: JsonValue = JsonValue.from("percentile") - private var filter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - customChartMetricPercentile: CustomChartMetricPercentile - ) = apply { - field = customChartMetricPercentile.field - params = customChartMetricPercentile.params - type = customChartMetricPercentile.type - filter = customChartMetricPercentile.filter - additionalProperties = - customChartMetricPercentile.additionalProperties - .toMutableMap() - } - - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] - * value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - fun params(params: Params) = params(JsonField.of(params)) - - /** - * Sets [Builder.params] to an arbitrary JSON value. - * - * You should usually call [Builder.params] with a well-typed - * [Params] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun params(params: JsonField) = apply { - this.params = params - } - - /** - * Sets the field to an arbitrary JSON value. - * - * It is usually unnecessary to call this method because the field - * defaults to the following: - * ```java - * JsonValue.from("percentile") - * ``` - * - * This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** - * Alias for calling [Builder.filter] with `filter.orElse(null)`. - */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun filter(filter: JsonField) = apply { - this.filter = filter - } - - 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 [CustomChartMetricPercentile]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - * - * The following fields are required: - * ```java - * .field() - * .params() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CustomChartMetricPercentile = - CustomChartMetricPercentile( - checkRequired("field", field), - checkRequired("params", params), - type, - filter, - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): CustomChartMetricPercentile = apply { - if (validated) { - return@apply - } - - field().validate() - params().validate() - _type().let { - if (it != JsonValue.from("percentile")) { - throw LangChainInvalidDataException( - "'type' is invalid, received $it" - ) - } - } - filter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - (field.asKnown().getOrNull()?.validity() ?: 0) + - (params.asKnown().getOrNull()?.validity() ?: 0) + - type.let { if (it == JsonValue.from("percentile")) 1 else 0 } + - (if (filter.asKnown().isPresent) 1 else 0) - - class Field - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized - * from data that doesn't match any known member, and you want to - * know that value. For example, if the SDK is on an older version - * than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val LATENCY_SECONDS = of("latency_seconds") - - @JvmField val FIRST_TOKEN_SECONDS = of("first_token_seconds") - - @JvmField val TOTAL_TOKENS = of("total_tokens") - - @JvmField val PROMPT_TOKENS = of("prompt_tokens") - - @JvmField val COMPLETION_TOKENS = of("completion_tokens") - - @JvmField val TOTAL_COST = of("total_cost") - - @JvmField val PROMPT_COST = of("prompt_cost") - - @JvmField val COMPLETION_COST = of("completion_cost") - - @JvmField val FEEDBACK_SCORE = of("feedback_score") - - @JvmStatic fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - } - - /** - * An enum containing [Field]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Field] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known - * member. For example, if the SDK is on an older version than the - * API, then the API may respond with new members that the SDK is - * unaware of. - * - It was constructed with an arbitrary value using the [of] - * method. - */ - enum class Value { - LATENCY_SECONDS, - FIRST_TOKEN_SECONDS, - TOTAL_TOKENS, - PROMPT_TOKENS, - COMPLETION_TOKENS, - TOTAL_COST, - PROMPT_COST, - COMPLETION_COST, - FEEDBACK_SCORE, - /** - * An enum member indicating that [Field] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's - * value, or [Value._UNKNOWN] if the class was instantiated with an - * unknown value. - * - * Use the [known] method instead if you're certain the value is - * always known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LATENCY_SECONDS -> Value.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Value.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Value.TOTAL_TOKENS - PROMPT_TOKENS -> Value.PROMPT_TOKENS - COMPLETION_TOKENS -> Value.COMPLETION_TOKENS - TOTAL_COST -> Value.TOTAL_COST - PROMPT_COST -> Value.PROMPT_COST - COMPLETION_COST -> Value.COMPLETION_COST - FEEDBACK_SCORE -> Value.FEEDBACK_SCORE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's - * value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's - * value is a not a known member. - */ - fun known(): Known = - when (this) { - LATENCY_SECONDS -> Known.LATENCY_SECONDS - FIRST_TOKEN_SECONDS -> Known.FIRST_TOKEN_SECONDS - TOTAL_TOKENS -> Known.TOTAL_TOKENS - PROMPT_TOKENS -> Known.PROMPT_TOKENS - COMPLETION_TOKENS -> Known.COMPLETION_TOKENS - TOTAL_COST -> Known.TOTAL_COST - PROMPT_COST -> Known.PROMPT_COST - COMPLETION_COST -> Known.COMPLETION_COST - FEEDBACK_SCORE -> Known.FEEDBACK_SCORE - else -> - throw LangChainInvalidDataException( - "Unknown Field: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's - * value does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Field && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Params - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val p: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("p") - @ExcludeMissing - p: JsonField = JsonMissing.of() - ) : this(p, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException 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 p(): Double = p.getRequired("p") - - /** - * Returns the raw JSON value of [p]. - * - * Unlike [p], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("p") @ExcludeMissing fun _p(): JsonField = p - - @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 - * [Params]. - * - * The following fields are required: - * ```java - * .p() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Params]. */ - class Builder internal constructor() { - - private var p: JsonField? = null - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(params: Params) = apply { - p = params.p - additionalProperties = - params.additionalProperties.toMutableMap() - } - - fun p(p: Double) = p(JsonField.of(p)) - - /** - * Sets [Builder.p] to an arbitrary JSON value. - * - * You should usually call [Builder.p] with a well-typed - * [Double] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun p(p: JsonField) = apply { this.p = p } - - 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 [Params]. - * - * Further updates to this [Builder] will not mutate the - * returned instance. - * - * The following fields are required: - * ```java - * .p() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Params = - Params( - checkRequired("p", p), - 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 LangChainInvalidDataException if any value type in this - * object doesn't match its expected type. - */ - fun validate(): Params = apply { - if (validated) { - return@apply - } - - p() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (p.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - p == other.p && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(p, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Params{p=$p, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricPercentile && - field == other.field && - params == other.params && - type == other.type && - filter == other.filter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(field, params, type, filter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricPercentile{field=$field, params=$params, type=$type, filter=$filter, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CustomChartMetricRatioOutput && - denominator == other.denominator && - numerator == other.numerator && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(denominator, numerator, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CustomChartMetricRatioOutput{denominator=$denominator, numerator=$numerator, type=$type, additionalProperties=$additionalProperties}" - } - } - - /** LGP Metrics you can chart. */ - class ProjectMetric - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val MEMORY_USAGE = of("memory_usage") - - @JvmField val CPU_USAGE = of("cpu_usage") - - @JvmField val DISK_USAGE = of("disk_usage") - - @JvmField val RESTART_COUNT = of("restart_count") - - @JvmField val REPLICA_COUNT = of("replica_count") - - @JvmField val WORKER_COUNT = of("worker_count") - - @JvmField val LG_RUN_COUNT = of("lg_run_count") - - @JvmField val RESPONSES_PER_SECOND = of("responses_per_second") - - @JvmField val ERROR_RESPONSES_PER_SECOND = of("error_responses_per_second") - - @JvmField val P95_LATENCY = of("p95_latency") - - @JvmField val RUN_QUEUE_WAIT_TIME = of("run_queue_wait_time") - - @JvmStatic fun of(value: String) = ProjectMetric(JsonField.of(value)) - } - - /** An enum containing [ProjectMetric]'s known values. */ - enum class Known { - MEMORY_USAGE, - CPU_USAGE, - DISK_USAGE, - RESTART_COUNT, - REPLICA_COUNT, - WORKER_COUNT, - LG_RUN_COUNT, - RESPONSES_PER_SECOND, - ERROR_RESPONSES_PER_SECOND, - P95_LATENCY, - RUN_QUEUE_WAIT_TIME, - } - - /** - * An enum containing [ProjectMetric]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [ProjectMetric] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MEMORY_USAGE, - CPU_USAGE, - DISK_USAGE, - RESTART_COUNT, - REPLICA_COUNT, - WORKER_COUNT, - LG_RUN_COUNT, - RESPONSES_PER_SECOND, - ERROR_RESPONSES_PER_SECOND, - P95_LATENCY, - RUN_QUEUE_WAIT_TIME, - /** - * An enum member indicating that [ProjectMetric] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MEMORY_USAGE -> Value.MEMORY_USAGE - CPU_USAGE -> Value.CPU_USAGE - DISK_USAGE -> Value.DISK_USAGE - RESTART_COUNT -> Value.RESTART_COUNT - REPLICA_COUNT -> Value.REPLICA_COUNT - WORKER_COUNT -> Value.WORKER_COUNT - LG_RUN_COUNT -> Value.LG_RUN_COUNT - RESPONSES_PER_SECOND -> Value.RESPONSES_PER_SECOND - ERROR_RESPONSES_PER_SECOND -> Value.ERROR_RESPONSES_PER_SECOND - P95_LATENCY -> Value.P95_LATENCY - RUN_QUEUE_WAIT_TIME -> Value.RUN_QUEUE_WAIT_TIME - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LangChainInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - MEMORY_USAGE -> Known.MEMORY_USAGE - CPU_USAGE -> Known.CPU_USAGE - DISK_USAGE -> Known.DISK_USAGE - RESTART_COUNT -> Known.RESTART_COUNT - REPLICA_COUNT -> Known.REPLICA_COUNT - WORKER_COUNT -> Known.WORKER_COUNT - LG_RUN_COUNT -> Known.LG_RUN_COUNT - RESPONSES_PER_SECOND -> Known.RESPONSES_PER_SECOND - ERROR_RESPONSES_PER_SECOND -> Known.ERROR_RESPONSES_PER_SECOND - P95_LATENCY -> Known.P95_LATENCY - RUN_QUEUE_WAIT_TIME -> Known.RUN_QUEUE_WAIT_TIME - else -> throw LangChainInvalidDataException("Unknown ProjectMetric: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LangChainInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LangChainInvalidDataException("Value is not a String") - } - - 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 LangChainInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): ProjectMetric = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ProjectMetric && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -14422,498 +15900,24 @@ private constructor( return true } - return other is Series && + return other is Text && id == other.id && - name == other.name && - feedbackKey == other.feedbackKey && - filterDefinition == other.filterDefinition && - filters == other.filters && - groupBy == other.groupBy && - groupByDefinitions == other.groupByDefinitions && + chartType == other.chartType && + index == other.index && + markdown == other.markdown && metadata == other.metadata && - metric == other.metric && - metricDefinition == other.metricDefinition && - projectMetric == other.projectMetric && - workspaceId == other.workspaceId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash( - id, - name, - feedbackKey, - filterDefinition, - filters, - groupBy, - groupByDefinitions, - metadata, - metric, - metricDefinition, - projectMetric, - workspaceId, - additionalProperties, - ) + Objects.hash(id, chartType, index, markdown, metadata, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Series{id=$id, name=$name, feedbackKey=$feedbackKey, filterDefinition=$filterDefinition, filters=$filters, groupBy=$groupBy, groupByDefinitions=$groupByDefinitions, metadata=$metadata, metric=$metric, metricDefinition=$metricDefinition, projectMetric=$projectMetric, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" + "Text{id=$id, chartType=$chartType, index=$index, markdown=$markdown, metadata=$metadata, additionalProperties=$additionalProperties}" } - - class CommonFilters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val filter: JsonField, - private val session: JsonField>, - private val traceFilter: JsonField, - private val treeFilter: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("filter") - @ExcludeMissing - filter: JsonField = JsonMissing.of(), - @JsonProperty("session") - @ExcludeMissing - session: JsonField> = JsonMissing.of(), - @JsonProperty("trace_filter") - @ExcludeMissing - traceFilter: JsonField = JsonMissing.of(), - @JsonProperty("tree_filter") - @ExcludeMissing - treeFilter: JsonField = JsonMissing.of(), - ) : this(filter, session, traceFilter, treeFilter, mutableMapOf()) - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun filter(): Optional = filter.getOptional("filter") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun session(): Optional> = session.getOptional("session") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun traceFilter(): Optional = traceFilter.getOptional("trace_filter") - - /** - * @throws LangChainInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun treeFilter(): Optional = treeFilter.getOptional("tree_filter") - - /** - * Returns the raw JSON value of [filter]. - * - * Unlike [filter], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("filter") @ExcludeMissing fun _filter(): JsonField = filter - - /** - * Returns the raw JSON value of [session]. - * - * Unlike [session], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("session") - @ExcludeMissing - fun _session(): JsonField> = session - - /** - * Returns the raw JSON value of [traceFilter]. - * - * Unlike [traceFilter], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("trace_filter") - @ExcludeMissing - fun _traceFilter(): JsonField = traceFilter - - /** - * Returns the raw JSON value of [treeFilter]. - * - * Unlike [treeFilter], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("tree_filter") - @ExcludeMissing - fun _treeFilter(): JsonField = treeFilter - - @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 [CommonFilters]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CommonFilters]. */ - class Builder internal constructor() { - - private var filter: JsonField = JsonMissing.of() - private var session: JsonField>? = null - private var traceFilter: JsonField = JsonMissing.of() - private var treeFilter: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(commonFilters: CommonFilters) = apply { - filter = commonFilters.filter - session = commonFilters.session.map { it.toMutableList() } - traceFilter = commonFilters.traceFilter - treeFilter = commonFilters.treeFilter - additionalProperties = commonFilters.additionalProperties.toMutableMap() - } - - fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) - - /** Alias for calling [Builder.filter] with `filter.orElse(null)`. */ - fun filter(filter: Optional) = filter(filter.getOrNull()) - - /** - * Sets [Builder.filter] to an arbitrary JSON value. - * - * You should usually call [Builder.filter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun filter(filter: JsonField) = apply { this.filter = filter } - - fun session(session: List?) = session(JsonField.ofNullable(session)) - - /** Alias for calling [Builder.session] with `session.orElse(null)`. */ - fun session(session: Optional>) = session(session.getOrNull()) - - /** - * Sets [Builder.session] to an arbitrary JSON value. - * - * You should usually call [Builder.session] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun session(session: JsonField>) = apply { - this.session = session.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [Builder.session]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addSession(session: String) = apply { - this.session = - (this.session ?: JsonField.of(mutableListOf())).also { - checkKnown("session", it).add(session) - } - } - - fun traceFilter(traceFilter: String?) = - traceFilter(JsonField.ofNullable(traceFilter)) - - /** Alias for calling [Builder.traceFilter] with `traceFilter.orElse(null)`. */ - fun traceFilter(traceFilter: Optional) = - traceFilter(traceFilter.getOrNull()) - - /** - * Sets [Builder.traceFilter] to an arbitrary JSON value. - * - * You should usually call [Builder.traceFilter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun traceFilter(traceFilter: JsonField) = apply { - this.traceFilter = traceFilter - } - - fun treeFilter(treeFilter: String?) = treeFilter(JsonField.ofNullable(treeFilter)) - - /** Alias for calling [Builder.treeFilter] with `treeFilter.orElse(null)`. */ - fun treeFilter(treeFilter: Optional) = treeFilter(treeFilter.getOrNull()) - - /** - * Sets [Builder.treeFilter] to an arbitrary JSON value. - * - * You should usually call [Builder.treeFilter] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun treeFilter(treeFilter: JsonField) = apply { - this.treeFilter = treeFilter - } - - 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 [CommonFilters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): CommonFilters = - CommonFilters( - filter, - (session ?: JsonMissing.of()).map { it.toImmutable() }, - traceFilter, - treeFilter, - 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 LangChainInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): CommonFilters = apply { - if (validated) { - return@apply - } - - filter() - session() - traceFilter() - treeFilter() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 (filter.asKnown().isPresent) 1 else 0) + - (session.asKnown().getOrNull()?.size ?: 0) + - (if (traceFilter.asKnown().isPresent) 1 else 0) + - (if (treeFilter.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CommonFilters && - filter == other.filter && - session == other.session && - traceFilter == other.traceFilter && - treeFilter == other.treeFilter && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(filter, session, traceFilter, treeFilter, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CommonFilters{filter=$filter, session=$session, traceFilter=$traceFilter, treeFilter=$treeFilter, additionalProperties=$additionalProperties}" - } - - class Metadata - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Metadata]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() - } - - 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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - 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 LangChainInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LangChainInvalidDataException) { - 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 = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Metadata && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Chart && - id == other.id && - chartType == other.chartType && - data == other.data && - index == other.index && - series == other.series && - title == other.title && - commonFilters == other.commonFilters && - description == other.description && - metadata == other.metadata && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - id, - chartType, - data, - index, - series, - title, - commonFilters, - description, - metadata, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Chart{id=$id, chartType=$chartType, data=$data, index=$index, series=$series, title=$title, commonFilters=$commonFilters, description=$description, metadata=$metadata, additionalProperties=$additionalProperties}" } class Layout @@ -17000,8 +18004,6 @@ private constructor( fun id(): String = id.getRequired("id") /** - * Enum for custom chart types. - * * @throws LangChainInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected * value). @@ -17199,7 +18201,6 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } - /** Enum for custom chart types. */ fun chartType(chartType: ChartType) = chartType(JsonField.of(chartType)) /** @@ -17444,7 +18445,6 @@ private constructor( (if (description.asKnown().isPresent) 1 else 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) - /** Enum for custom chart types. */ class ChartType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/langsmith-java-core/src/test/kotlin/com/langchain/smith/models/sessions/CustomChartsSectionTest.kt b/langsmith-java-core/src/test/kotlin/com/langchain/smith/models/sessions/CustomChartsSectionTest.kt index 2f12632c..dec298ac 100644 --- a/langsmith-java-core/src/test/kotlin/com/langchain/smith/models/sessions/CustomChartsSectionTest.kt +++ b/langsmith-java-core/src/test/kotlin/com/langchain/smith/models/sessions/CustomChartsSectionTest.kt @@ -18,11 +18,13 @@ internal class CustomChartsSectionTest { CustomChartsSection.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .addChart( - CustomChartsSection.Chart.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .chartType(CustomChartsSection.Chart.ChartType.LINE) + .chartType( + CustomChartsSection.Chart.SingleCustomChartResponse.ChartType.LINE + ) .addData( - CustomChartsSection.Chart.Data.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Data.builder() .seriesId("series_id") .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .value(0.0) @@ -31,12 +33,13 @@ internal class CustomChartsSectionTest { ) .index(0L) .addSeries( - CustomChartsSection.Chart.Series.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .name("name") .feedbackKey("feedback_key") .filterDefinition( - CustomChartsSection.Chart.Series.FilterDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .FilterDefinition .CustomChartFilterByTracingProject .builder() .addProjectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -46,7 +49,9 @@ internal class CustomChartsSectionTest { .build() ) .filters( - CustomChartsSection.Chart.Series.Filters.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Filters + .builder() .filter("filter") .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .traceFilter("trace_filter") @@ -54,23 +59,36 @@ internal class CustomChartsSectionTest { .build() ) .groupBy( - CustomChartsSection.Chart.Series.GroupBy.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupBy + .builder() .attribute( - CustomChartsSection.Chart.Series.GroupBy.Attribute.NAME + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .Attribute + .NAME ) .maxGroups(0L) .path("path") .setBy( - CustomChartsSection.Chart.Series.GroupBy.SetBy.SECTION + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .SetBy + .SECTION ) .build() ) .addGroupByDefinition( - CustomChartsSection.Chart.Series.GroupByDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupByDefinition .CustomChartGroupByPlain .builder() .attribute( - CustomChartsSection.Chart.Series.GroupByDefinition + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupByDefinition .CustomChartGroupByPlain .Attribute .NAME @@ -78,18 +96,27 @@ internal class CustomChartsSectionTest { .build() ) .metadata( - CustomChartsSection.Chart.Series.Metadata.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metadata + .builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .metric(CustomChartsSection.Chart.Series.Metric.RUN_COUNT) + .metric( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metric + .RUN_COUNT + ) .metricDefinition( - CustomChartsSection.Chart.Series.MetricDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .MetricDefinition .CustomChartMetricCount .builder() .filter("filter") .type( - CustomChartsSection.Chart.Series.MetricDefinition + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .MetricDefinition .CustomChartMetricCount .Type .COUNT @@ -97,14 +124,17 @@ internal class CustomChartsSectionTest { .build() ) .projectMetric( - CustomChartsSection.Chart.Series.ProjectMetric.MEMORY_USAGE + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .ProjectMetric + .MEMORY_USAGE ) .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) .title("title") .commonFilters( - CustomChartsSection.Chart.CommonFilters.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.CommonFilters + .builder() .filter("filter") .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .traceFilter("trace_filter") @@ -113,7 +143,7 @@ internal class CustomChartsSectionTest { ) .description("description") .metadata( - CustomChartsSection.Chart.Metadata.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) @@ -305,104 +335,138 @@ internal class CustomChartsSectionTest { assertThat(customChartsSection.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(customChartsSection.charts()) .containsExactly( - CustomChartsSection.Chart.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .chartType(CustomChartsSection.Chart.ChartType.LINE) - .addData( - CustomChartsSection.Chart.Data.builder() - .seriesId("series_id") - .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .value(0.0) - .group("group") - .build() - ) - .index(0L) - .addSeries( - CustomChartsSection.Chart.Series.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .feedbackKey("feedback_key") - .filterDefinition( - CustomChartsSection.Chart.Series.FilterDefinition - .CustomChartFilterByTracingProject - .builder() - .addProjectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .runFilter("run_filter") - .traceFilter("trace_filter") - .treeFilter("tree_filter") - .build() - ) - .filters( - CustomChartsSection.Chart.Series.Filters.builder() - .filter("filter") - .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .traceFilter("trace_filter") - .treeFilter("tree_filter") - .build() - ) - .groupBy( - CustomChartsSection.Chart.Series.GroupBy.builder() - .attribute( - CustomChartsSection.Chart.Series.GroupBy.Attribute.NAME - ) - .maxGroups(0L) - .path("path") - .setBy(CustomChartsSection.Chart.Series.GroupBy.SetBy.SECTION) - .build() - ) - .addGroupByDefinition( - CustomChartsSection.Chart.Series.GroupByDefinition - .CustomChartGroupByPlain - .builder() - .attribute( - CustomChartsSection.Chart.Series.GroupByDefinition - .CustomChartGroupByPlain - .Attribute - .NAME - ) - .build() - ) - .metadata( - CustomChartsSection.Chart.Series.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .metric(CustomChartsSection.Chart.Series.Metric.RUN_COUNT) - .metricDefinition( - CustomChartsSection.Chart.Series.MetricDefinition - .CustomChartMetricCount - .builder() - .filter("filter") - .type( - CustomChartsSection.Chart.Series.MetricDefinition - .CustomChartMetricCount - .Type - .COUNT - ) - .build() - ) - .projectMetric( - CustomChartsSection.Chart.Series.ProjectMetric.MEMORY_USAGE - ) - .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) - .title("title") - .commonFilters( - CustomChartsSection.Chart.CommonFilters.builder() - .filter("filter") - .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .traceFilter("trace_filter") - .treeFilter("tree_filter") - .build() - ) - .description("description") - .metadata( - CustomChartsSection.Chart.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .build() + CustomChartsSection.Chart.ofSingleCustomChartResponse( + CustomChartsSection.Chart.SingleCustomChartResponse.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .chartType( + CustomChartsSection.Chart.SingleCustomChartResponse.ChartType.LINE + ) + .addData( + CustomChartsSection.Chart.SingleCustomChartResponse.Data.builder() + .seriesId("series_id") + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .value(0.0) + .group("group") + .build() + ) + .index(0L) + .addSeries( + CustomChartsSection.Chart.SingleCustomChartResponse.Series.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .feedbackKey("feedback_key") + .filterDefinition( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .FilterDefinition + .CustomChartFilterByTracingProject + .builder() + .addProjectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .runFilter("run_filter") + .traceFilter("trace_filter") + .treeFilter("tree_filter") + .build() + ) + .filters( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Filters + .builder() + .filter("filter") + .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .traceFilter("trace_filter") + .treeFilter("tree_filter") + .build() + ) + .groupBy( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupBy + .builder() + .attribute( + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .Attribute + .NAME + ) + .maxGroups(0L) + .path("path") + .setBy( + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .SetBy + .SECTION + ) + .build() + ) + .addGroupByDefinition( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupByDefinition + .CustomChartGroupByPlain + .builder() + .attribute( + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupByDefinition + .CustomChartGroupByPlain + .Attribute + .NAME + ) + .build() + ) + .metadata( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metadata + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .metric( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metric + .RUN_COUNT + ) + .metricDefinition( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .MetricDefinition + .CustomChartMetricCount + .builder() + .filter("filter") + .type( + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .MetricDefinition + .CustomChartMetricCount + .Type + .COUNT + ) + .build() + ) + .projectMetric( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .ProjectMetric + .MEMORY_USAGE + ) + .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .title("title") + .commonFilters( + CustomChartsSection.Chart.SingleCustomChartResponse.CommonFilters + .builder() + .filter("filter") + .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .traceFilter("trace_filter") + .treeFilter("tree_filter") + .build() + ) + .description("description") + .metadata( + CustomChartsSection.Chart.SingleCustomChartResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) ) assertThat(customChartsSection.title()).isEqualTo("title") assertThat(customChartsSection.description()).contains("description") @@ -582,11 +646,13 @@ internal class CustomChartsSectionTest { CustomChartsSection.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .addChart( - CustomChartsSection.Chart.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .chartType(CustomChartsSection.Chart.ChartType.LINE) + .chartType( + CustomChartsSection.Chart.SingleCustomChartResponse.ChartType.LINE + ) .addData( - CustomChartsSection.Chart.Data.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Data.builder() .seriesId("series_id") .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .value(0.0) @@ -595,12 +661,13 @@ internal class CustomChartsSectionTest { ) .index(0L) .addSeries( - CustomChartsSection.Chart.Series.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .name("name") .feedbackKey("feedback_key") .filterDefinition( - CustomChartsSection.Chart.Series.FilterDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .FilterDefinition .CustomChartFilterByTracingProject .builder() .addProjectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -610,7 +677,9 @@ internal class CustomChartsSectionTest { .build() ) .filters( - CustomChartsSection.Chart.Series.Filters.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Filters + .builder() .filter("filter") .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .traceFilter("trace_filter") @@ -618,23 +687,36 @@ internal class CustomChartsSectionTest { .build() ) .groupBy( - CustomChartsSection.Chart.Series.GroupBy.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupBy + .builder() .attribute( - CustomChartsSection.Chart.Series.GroupBy.Attribute.NAME + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .Attribute + .NAME ) .maxGroups(0L) .path("path") .setBy( - CustomChartsSection.Chart.Series.GroupBy.SetBy.SECTION + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupBy + .SetBy + .SECTION ) .build() ) .addGroupByDefinition( - CustomChartsSection.Chart.Series.GroupByDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .GroupByDefinition .CustomChartGroupByPlain .builder() .attribute( - CustomChartsSection.Chart.Series.GroupByDefinition + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .GroupByDefinition .CustomChartGroupByPlain .Attribute .NAME @@ -642,18 +724,27 @@ internal class CustomChartsSectionTest { .build() ) .metadata( - CustomChartsSection.Chart.Series.Metadata.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metadata + .builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .metric(CustomChartsSection.Chart.Series.Metric.RUN_COUNT) + .metric( + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .Metric + .RUN_COUNT + ) .metricDefinition( - CustomChartsSection.Chart.Series.MetricDefinition + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .MetricDefinition .CustomChartMetricCount .builder() .filter("filter") .type( - CustomChartsSection.Chart.Series.MetricDefinition + CustomChartsSection.Chart.SingleCustomChartResponse + .Series + .MetricDefinition .CustomChartMetricCount .Type .COUNT @@ -661,14 +752,17 @@ internal class CustomChartsSectionTest { .build() ) .projectMetric( - CustomChartsSection.Chart.Series.ProjectMetric.MEMORY_USAGE + CustomChartsSection.Chart.SingleCustomChartResponse.Series + .ProjectMetric + .MEMORY_USAGE ) .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) .title("title") .commonFilters( - CustomChartsSection.Chart.CommonFilters.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.CommonFilters + .builder() .filter("filter") .addSession("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .traceFilter("trace_filter") @@ -677,7 +771,7 @@ internal class CustomChartsSectionTest { ) .description("description") .metadata( - CustomChartsSection.Chart.Metadata.builder() + CustomChartsSection.Chart.SingleCustomChartResponse.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() )