diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index 4def13c..eddca26 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -1892,4 +1892,5862 @@ private constructor( fun build(): Metadata = Metadata(additionalProperties.toUnmodifiable()) } } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: JsonField, + private val options: JsonField, + private val origin: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun prompt(): Optional = Optional.ofNullable(prompt.getNullable("prompt")) + + fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + + fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + + @JsonProperty("prompt") @ExcludeMissing fun _prompt() = prompt + + @JsonProperty("options") @ExcludeMissing fun _options() = options + + @JsonProperty("origin") @ExcludeMissing fun _origin() = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): PromptData = apply { + if (!validated) { + prompt() + options().map { it.validate() } + origin().map { it.validate() } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: JsonField = JsonMissing.of() + private var options: JsonField = JsonMissing.of() + private var origin: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + fun prompt(prompt: Prompt) = prompt(JsonField.of(prompt)) + + @JsonProperty("prompt") + @ExcludeMissing + fun prompt(prompt: JsonField) = apply { this.prompt = prompt } + + fun options(options: Options) = options(JsonField.of(options)) + + @JsonProperty("options") + @ExcludeMissing + fun options(options: JsonField) = apply { this.options = options } + + fun origin(origin: Origin) = origin(JsonField.of(origin)) + + @JsonProperty("origin") + @ExcludeMissing + fun origin(origin: JsonField) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: JsonField, + private val params: JsonField, + private val position: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + + fun params(): Optional = Optional.ofNullable(params.getNullable("params")) + + fun position(): Optional = Optional.ofNullable(position.getNullable("position")) + + @JsonProperty("model") @ExcludeMissing fun _model() = model + + @JsonProperty("params") @ExcludeMissing fun _params() = params + + @JsonProperty("position") @ExcludeMissing fun _position() = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Options = apply { + if (!validated) { + model() + params() + position() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: JsonField = JsonMissing.of() + private var params: JsonField = JsonMissing.of() + private var position: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + fun model(model: String) = model(JsonField.of(model)) + + @JsonProperty("model") + @ExcludeMissing + fun model(model: JsonField) = apply { this.model = model } + + fun params(params: Params) = params(JsonField.of(params)) + + @JsonProperty("params") + @ExcludeMissing + fun params(params: JsonField) = apply { this.params = params } + + fun position(position: String) = position(JsonField.of(position)) + + @JsonProperty("position") + @ExcludeMissing + fun position(position: JsonField) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: JsonField, + private val projectId: JsonField, + private val promptVersion: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun promptId(): Optional = + Optional.ofNullable(promptId.getNullable("prompt_id")) + + fun projectId(): Optional = + Optional.ofNullable(projectId.getNullable("project_id")) + + fun promptVersion(): Optional = + Optional.ofNullable(promptVersion.getNullable("prompt_version")) + + @JsonProperty("prompt_id") @ExcludeMissing fun _promptId() = promptId + + @JsonProperty("project_id") @ExcludeMissing fun _projectId() = projectId + + @JsonProperty("prompt_version") @ExcludeMissing fun _promptVersion() = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Origin = apply { + if (!validated) { + promptId() + projectId() + promptVersion() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var promptVersion: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + fun promptId(promptId: String) = promptId(JsonField.of(promptId)) + + @JsonProperty("prompt_id") + @ExcludeMissing + fun promptId(promptId: JsonField) = apply { this.promptId = promptId } + + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + @JsonProperty("project_id") + @ExcludeMissing + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + + fun promptVersion(promptVersion: String) = + promptVersion(JsonField.of(promptVersion)) + + @JsonProperty("prompt_version") + @ExcludeMissing + fun promptVersion(promptVersion: JsonField) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent7s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent7s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent7s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent7s(): Boolean = + unnamedSchemaWithArrayParent7s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent7s(): + List = + unnamedSchemaWithArrayParent7s.getOrThrow( + "unnamedSchemaWithArrayParent7s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent7s != null -> + visitor.visitUnnamedSchemaWithArrayParent7s( + unnamedSchemaWithArrayParent7s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent7s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent7s == + other.unnamedSchemaWithArrayParent7s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent7s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent7s != null -> + "Content{unnamedSchemaWithArrayParent7s=$unnamedSchemaWithArrayParent7s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent7s( + unnamedSchemaWithArrayParent7s: + List + ) = + Content( + unnamedSchemaWithArrayParent7s = + unnamedSchemaWithArrayParent7s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent7s( + unnamedSchemaWithArrayParent7s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent7s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent7s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent7s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent7.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent7.Serializer::class) + class UnnamedSchemaWithArrayParent7 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent7 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent7: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent7 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent7{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent7{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent7{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent7" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent7(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent7(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent7: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent7::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent7 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent7( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent7( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent7(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent7::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent7, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent7" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index 6eb66e8..6282696 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -1792,4 +1792,5776 @@ constructor( } } } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent3s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent3s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent3s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent3s(): Boolean = + unnamedSchemaWithArrayParent3s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent3s(): + List = + unnamedSchemaWithArrayParent3s.getOrThrow( + "unnamedSchemaWithArrayParent3s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent3s != null -> + visitor.visitUnnamedSchemaWithArrayParent3s( + unnamedSchemaWithArrayParent3s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent3s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent3s == + other.unnamedSchemaWithArrayParent3s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent3s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent3s != null -> + "Content{unnamedSchemaWithArrayParent3s=$unnamedSchemaWithArrayParent3s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent3s( + unnamedSchemaWithArrayParent3s: + List + ) = + Content( + unnamedSchemaWithArrayParent3s = + unnamedSchemaWithArrayParent3s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent3s( + unnamedSchemaWithArrayParent3s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent3s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent3s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent3s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent3.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent3.Serializer::class) + class UnnamedSchemaWithArrayParent3 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent3 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent3: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent3 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent3{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent3{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent3{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent3" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent3(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent3(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent3: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent3::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent3 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent3( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent3( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent3(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent3::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent3, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent3" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index 0dbcfaa..993c3d9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -1792,4 +1792,5776 @@ constructor( } } } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent5s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent5s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent5s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent5s(): Boolean = + unnamedSchemaWithArrayParent5s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent5s(): + List = + unnamedSchemaWithArrayParent5s.getOrThrow( + "unnamedSchemaWithArrayParent5s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent5s != null -> + visitor.visitUnnamedSchemaWithArrayParent5s( + unnamedSchemaWithArrayParent5s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent5s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent5s == + other.unnamedSchemaWithArrayParent5s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent5s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent5s != null -> + "Content{unnamedSchemaWithArrayParent5s=$unnamedSchemaWithArrayParent5s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent5s( + unnamedSchemaWithArrayParent5s: + List + ) = + Content( + unnamedSchemaWithArrayParent5s = + unnamedSchemaWithArrayParent5s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent5s( + unnamedSchemaWithArrayParent5s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent5s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent5s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent5s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent5.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent5.Serializer::class) + class UnnamedSchemaWithArrayParent5 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent5 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent5: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent5 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent5{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent5{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent5{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent5" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent5(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent5(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent5: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent5::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent5 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent5( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent5( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent5(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent5::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent5, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent5" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index a0e9716..338eeaa 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -1863,4 +1863,5776 @@ constructor( } } } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent4s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent4s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent4s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent4s(): Boolean = + unnamedSchemaWithArrayParent4s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent4s(): + List = + unnamedSchemaWithArrayParent4s.getOrThrow( + "unnamedSchemaWithArrayParent4s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent4s != null -> + visitor.visitUnnamedSchemaWithArrayParent4s( + unnamedSchemaWithArrayParent4s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent4s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent4s == + other.unnamedSchemaWithArrayParent4s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent4s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent4s != null -> + "Content{unnamedSchemaWithArrayParent4s=$unnamedSchemaWithArrayParent4s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent4s( + unnamedSchemaWithArrayParent4s: + List + ) = + Content( + unnamedSchemaWithArrayParent4s = + unnamedSchemaWithArrayParent4s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent4s( + unnamedSchemaWithArrayParent4s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent4s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent4s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent4s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent4.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent4.Serializer::class) + class UnnamedSchemaWithArrayParent4 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent4 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent4: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent4 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent4{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent4{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent4{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent4" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent4(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent4(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent4: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent4::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent4 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent4( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent4( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent4(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent4::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent4, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent4" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index 31ac1cf..3b9cb7b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -2,19 +2,28 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.BaseDeserializer +import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.Enum import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.NoAutoDetect +import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.toUnmodifiable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import java.util.Objects import java.util.Optional @@ -489,4 +498,5862 @@ private constructor( fun build(): Metadata = Metadata(additionalProperties.toUnmodifiable()) } } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: JsonField, + private val options: JsonField, + private val origin: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun prompt(): Optional = Optional.ofNullable(prompt.getNullable("prompt")) + + fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + + fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + + @JsonProperty("prompt") @ExcludeMissing fun _prompt() = prompt + + @JsonProperty("options") @ExcludeMissing fun _options() = options + + @JsonProperty("origin") @ExcludeMissing fun _origin() = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): PromptData = apply { + if (!validated) { + prompt() + options().map { it.validate() } + origin().map { it.validate() } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: JsonField = JsonMissing.of() + private var options: JsonField = JsonMissing.of() + private var origin: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + fun prompt(prompt: Prompt) = prompt(JsonField.of(prompt)) + + @JsonProperty("prompt") + @ExcludeMissing + fun prompt(prompt: JsonField) = apply { this.prompt = prompt } + + fun options(options: Options) = options(JsonField.of(options)) + + @JsonProperty("options") + @ExcludeMissing + fun options(options: JsonField) = apply { this.options = options } + + fun origin(origin: Origin) = origin(JsonField.of(origin)) + + @JsonProperty("origin") + @ExcludeMissing + fun origin(origin: JsonField) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: JsonField, + private val params: JsonField, + private val position: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + + fun params(): Optional = Optional.ofNullable(params.getNullable("params")) + + fun position(): Optional = Optional.ofNullable(position.getNullable("position")) + + @JsonProperty("model") @ExcludeMissing fun _model() = model + + @JsonProperty("params") @ExcludeMissing fun _params() = params + + @JsonProperty("position") @ExcludeMissing fun _position() = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Options = apply { + if (!validated) { + model() + params() + position() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: JsonField = JsonMissing.of() + private var params: JsonField = JsonMissing.of() + private var position: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + fun model(model: String) = model(JsonField.of(model)) + + @JsonProperty("model") + @ExcludeMissing + fun model(model: JsonField) = apply { this.model = model } + + fun params(params: Params) = params(JsonField.of(params)) + + @JsonProperty("params") + @ExcludeMissing + fun params(params: JsonField) = apply { this.params = params } + + fun position(position: String) = position(JsonField.of(position)) + + @JsonProperty("position") + @ExcludeMissing + fun position(position: JsonField) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: JsonField, + private val projectId: JsonField, + private val promptVersion: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun promptId(): Optional = + Optional.ofNullable(promptId.getNullable("prompt_id")) + + fun projectId(): Optional = + Optional.ofNullable(projectId.getNullable("project_id")) + + fun promptVersion(): Optional = + Optional.ofNullable(promptVersion.getNullable("prompt_version")) + + @JsonProperty("prompt_id") @ExcludeMissing fun _promptId() = promptId + + @JsonProperty("project_id") @ExcludeMissing fun _projectId() = projectId + + @JsonProperty("prompt_version") @ExcludeMissing fun _promptVersion() = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Origin = apply { + if (!validated) { + promptId() + projectId() + promptVersion() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var promptVersion: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + fun promptId(promptId: String) = promptId(JsonField.of(promptId)) + + @JsonProperty("prompt_id") + @ExcludeMissing + fun promptId(promptId: JsonField) = apply { this.promptId = promptId } + + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + @JsonProperty("project_id") + @ExcludeMissing + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + + fun promptVersion(promptVersion: String) = + promptVersion(JsonField.of(promptVersion)) + + @JsonProperty("prompt_version") + @ExcludeMissing + fun promptVersion(promptVersion: JsonField) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent6s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent6s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent6s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent6s(): Boolean = + unnamedSchemaWithArrayParent6s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent6s(): + List = + unnamedSchemaWithArrayParent6s.getOrThrow( + "unnamedSchemaWithArrayParent6s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent6s != null -> + visitor.visitUnnamedSchemaWithArrayParent6s( + unnamedSchemaWithArrayParent6s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent6s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent6s == + other.unnamedSchemaWithArrayParent6s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent6s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent6s != null -> + "Content{unnamedSchemaWithArrayParent6s=$unnamedSchemaWithArrayParent6s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent6s( + unnamedSchemaWithArrayParent6s: + List + ) = + Content( + unnamedSchemaWithArrayParent6s = + unnamedSchemaWithArrayParent6s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent6s( + unnamedSchemaWithArrayParent6s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent6s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent6s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent6s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent6.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent6.Serializer::class) + class UnnamedSchemaWithArrayParent6 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent6 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent6: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent6 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent6{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent6{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent6{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent6" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent6(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent6(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent6: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent6::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent6 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent6( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent6( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent6(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent6::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent6, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent6" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index bf998c0..39ea06d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -2,15 +2,29 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.BaseDeserializer +import com.braintrustdata.api.core.BaseSerializer +import com.braintrustdata.api.core.Enum import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.NoAutoDetect +import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.toUnmodifiable +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.* import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional @@ -367,4 +381,5776 @@ constructor( additionalBodyProperties.toUnmodifiable(), ) } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent0s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent0s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent0s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent0s(): Boolean = + unnamedSchemaWithArrayParent0s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent0s(): + List = + unnamedSchemaWithArrayParent0s.getOrThrow( + "unnamedSchemaWithArrayParent0s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent0s != null -> + visitor.visitUnnamedSchemaWithArrayParent0s( + unnamedSchemaWithArrayParent0s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent0s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent0s == + other.unnamedSchemaWithArrayParent0s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent0s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent0s != null -> + "Content{unnamedSchemaWithArrayParent0s=$unnamedSchemaWithArrayParent0s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent0s( + unnamedSchemaWithArrayParent0s: + List + ) = + Content( + unnamedSchemaWithArrayParent0s = + unnamedSchemaWithArrayParent0s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent0s( + unnamedSchemaWithArrayParent0s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent0s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent0s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent0s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent0.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent0.Serializer::class) + class UnnamedSchemaWithArrayParent0 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent0 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent0: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent0 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent0{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent0{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent0{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent0" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent0(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent0(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent0: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent0::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent0 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent0( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent0( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent0(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent0::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent0, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent0" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt deleted file mode 100644 index c6f2dda..0000000 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ /dev/null @@ -1,5765 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.braintrustdata.api.models - -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.Enum -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.toUnmodifiable -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import java.util.Objects -import java.util.Optional - -/** The prompt, model, and its parameters */ -@JsonDeserialize(builder = PromptData.Builder::class) -@NoAutoDetect -class PromptData -private constructor( - private val prompt: JsonField, - private val options: JsonField, - private val origin: JsonField, - private val additionalProperties: Map, -) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun prompt(): Optional = Optional.ofNullable(prompt.getNullable("prompt")) - - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) - - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) - - @JsonProperty("prompt") @ExcludeMissing fun _prompt() = prompt - - @JsonProperty("options") @ExcludeMissing fun _options() = options - - @JsonProperty("origin") @ExcludeMissing fun _origin() = origin - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): PromptData = apply { - if (!validated) { - prompt() - options().map { it.validate() } - origin().map { it.validate() } - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PromptData && - this.prompt == other.prompt && - this.options == other.options && - this.origin == other.origin && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - prompt, - options, - origin, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var prompt: JsonField = JsonMissing.of() - private var options: JsonField = JsonMissing.of() - private var origin: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(promptData: PromptData) = apply { - this.prompt = promptData.prompt - this.options = promptData.options - this.origin = promptData.origin - additionalProperties(promptData.additionalProperties) - } - - fun prompt(prompt: Prompt) = prompt(JsonField.of(prompt)) - - @JsonProperty("prompt") - @ExcludeMissing - fun prompt(prompt: JsonField) = apply { this.prompt = prompt } - - fun options(options: Options) = options(JsonField.of(options)) - - @JsonProperty("options") - @ExcludeMissing - fun options(options: JsonField) = apply { this.options = options } - - fun origin(origin: Origin) = origin(JsonField.of(origin)) - - @JsonProperty("origin") - @ExcludeMissing - fun origin(origin: JsonField) = apply { this.origin = origin } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): PromptData = - PromptData( - prompt, - options, - origin, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(builder = Options.Builder::class) - @NoAutoDetect - class Options - private constructor( - private val model: JsonField, - private val params: JsonField, - private val position: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) - - fun params(): Optional = Optional.ofNullable(params.getNullable("params")) - - fun position(): Optional = Optional.ofNullable(position.getNullable("position")) - - @JsonProperty("model") @ExcludeMissing fun _model() = model - - @JsonProperty("params") @ExcludeMissing fun _params() = params - - @JsonProperty("position") @ExcludeMissing fun _position() = position - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Options = apply { - if (!validated) { - model() - params() - position() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Options && - this.model == other.model && - this.params == other.params && - this.position == other.position && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - model, - params, - position, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var model: JsonField = JsonMissing.of() - private var params: JsonField = JsonMissing.of() - private var position: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(options: Options) = apply { - this.model = options.model - this.params = options.params - this.position = options.position - additionalProperties(options.additionalProperties) - } - - fun model(model: String) = model(JsonField.of(model)) - - @JsonProperty("model") - @ExcludeMissing - fun model(model: JsonField) = apply { this.model = model } - - fun params(params: Params) = params(JsonField.of(params)) - - @JsonProperty("params") - @ExcludeMissing - fun params(params: JsonField) = apply { this.params = params } - - fun position(position: String) = position(JsonField.of(position)) - - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): Options = - Options( - model, - params, - position, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(using = Params.Deserializer::class) - @JsonSerialize(using = Params.Serializer::class) - class Params - private constructor( - private val openaiModelParams: OpenAIModelParams? = null, - private val anthropicModelParams: AnthropicModelParams? = null, - private val googleModelParams: GoogleModelParams? = null, - private val windowAiModelParams: WindowAiModelParams? = null, - private val jsCompletionParams: JsCompletionParams? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun openaiModelParams(): Optional = - Optional.ofNullable(openaiModelParams) - - fun anthropicModelParams(): Optional = - Optional.ofNullable(anthropicModelParams) - - fun googleModelParams(): Optional = - Optional.ofNullable(googleModelParams) - - fun windowAiModelParams(): Optional = - Optional.ofNullable(windowAiModelParams) - - fun jsCompletionParams(): Optional = - Optional.ofNullable(jsCompletionParams) - - fun isOpenAIModelParams(): Boolean = openaiModelParams != null - - fun isAnthropicModelParams(): Boolean = anthropicModelParams != null - - fun isGoogleModelParams(): Boolean = googleModelParams != null - - fun isWindowAiModelParams(): Boolean = windowAiModelParams != null - - fun isJsCompletionParams(): Boolean = jsCompletionParams != null - - fun asOpenAIModelParams(): OpenAIModelParams = - openaiModelParams.getOrThrow("openaiModelParams") - - fun asAnthropicModelParams(): AnthropicModelParams = - anthropicModelParams.getOrThrow("anthropicModelParams") - - fun asGoogleModelParams(): GoogleModelParams = - googleModelParams.getOrThrow("googleModelParams") - - fun asWindowAiModelParams(): WindowAiModelParams = - windowAiModelParams.getOrThrow("windowAiModelParams") - - fun asJsCompletionParams(): JsCompletionParams = - jsCompletionParams.getOrThrow("jsCompletionParams") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - openaiModelParams != null -> visitor.visitOpenAIModelParams(openaiModelParams) - anthropicModelParams != null -> - visitor.visitAnthropicModelParams(anthropicModelParams) - googleModelParams != null -> visitor.visitGoogleModelParams(googleModelParams) - windowAiModelParams != null -> - visitor.visitWindowAiModelParams(windowAiModelParams) - jsCompletionParams != null -> - visitor.visitJsCompletionParams(jsCompletionParams) - else -> visitor.unknown(_json) - } - } - - fun validate(): Params = apply { - if (!validated) { - if ( - openaiModelParams == null && - anthropicModelParams == null && - googleModelParams == null && - windowAiModelParams == null && - jsCompletionParams == null - ) { - throw BraintrustInvalidDataException("Unknown Params: $_json") - } - openaiModelParams?.validate() - anthropicModelParams?.validate() - googleModelParams?.validate() - windowAiModelParams?.validate() - jsCompletionParams?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Params && - this.openaiModelParams == other.openaiModelParams && - this.anthropicModelParams == other.anthropicModelParams && - this.googleModelParams == other.googleModelParams && - this.windowAiModelParams == other.windowAiModelParams && - this.jsCompletionParams == other.jsCompletionParams - } - - override fun hashCode(): Int { - return Objects.hash( - openaiModelParams, - anthropicModelParams, - googleModelParams, - windowAiModelParams, - jsCompletionParams, - ) - } - - override fun toString(): String { - return when { - openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" - anthropicModelParams != null -> - "Params{anthropicModelParams=$anthropicModelParams}" - googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" - windowAiModelParams != null -> - "Params{windowAiModelParams=$windowAiModelParams}" - jsCompletionParams != null -> "Params{jsCompletionParams=$jsCompletionParams}" - _json != null -> "Params{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Params") - } - } - - companion object { - - @JvmStatic - fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = - Params(openaiModelParams = openaiModelParams) - - @JvmStatic - fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = - Params(anthropicModelParams = anthropicModelParams) - - @JvmStatic - fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = - Params(googleModelParams = googleModelParams) - - @JvmStatic - fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = - Params(windowAiModelParams = windowAiModelParams) - - @JvmStatic - fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = - Params(jsCompletionParams = jsCompletionParams) - } - - interface Visitor { - - fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T - - fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T - - fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T - - fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T - - fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Params: $json") - } - } - - class Deserializer : BaseDeserializer(Params::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Params { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(openaiModelParams = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(anthropicModelParams = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(googleModelParams = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(windowAiModelParams = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(jsCompletionParams = it, _json = json) - } - - return Params(_json = json) - } - } - - class Serializer : BaseSerializer(Params::class) { - - override fun serialize( - value: Params, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.openaiModelParams != null -> - generator.writeObject(value.openaiModelParams) - value.anthropicModelParams != null -> - generator.writeObject(value.anthropicModelParams) - value.googleModelParams != null -> - generator.writeObject(value.googleModelParams) - value.windowAiModelParams != null -> - generator.writeObject(value.windowAiModelParams) - value.jsCompletionParams != null -> - generator.writeObject(value.jsCompletionParams) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Params") - } - } - } - - @JsonDeserialize(builder = OpenAIModelParams.Builder::class) - @NoAutoDetect - class OpenAIModelParams - private constructor( - private val useCache: JsonField, - private val temperature: JsonField, - private val topP: JsonField, - private val maxTokens: JsonField, - private val frequencyPenalty: JsonField, - private val presencePenalty: JsonField, - private val responseFormat: JsonField, - private val toolChoice: JsonField, - private val functionCall: JsonField, - private val n: JsonField, - private val stop: JsonField>, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) - - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) - - fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) - - fun maxTokens(): Optional = - Optional.ofNullable(maxTokens.getNullable("max_tokens")) - - fun frequencyPenalty(): Optional = - Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) - - fun presencePenalty(): Optional = - Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) - - fun responseFormat(): Optional = - Optional.ofNullable(responseFormat.getNullable("response_format")) - - fun toolChoice(): Optional = - Optional.ofNullable(toolChoice.getNullable("tool_choice")) - - fun functionCall(): Optional = - Optional.ofNullable(functionCall.getNullable("function_call")) - - fun n(): Optional = Optional.ofNullable(n.getNullable("n")) - - fun stop(): Optional> = Optional.ofNullable(stop.getNullable("stop")) - - @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache - - @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature - - @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP - - @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens - - @JsonProperty("frequency_penalty") - @ExcludeMissing - fun _frequencyPenalty() = frequencyPenalty - - @JsonProperty("presence_penalty") - @ExcludeMissing - fun _presencePenalty() = presencePenalty - - @JsonProperty("response_format") - @ExcludeMissing - fun _responseFormat() = responseFormat - - @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice - - @JsonProperty("function_call") @ExcludeMissing fun _functionCall() = functionCall - - @JsonProperty("n") @ExcludeMissing fun _n() = n - - @JsonProperty("stop") @ExcludeMissing fun _stop() = stop - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): OpenAIModelParams = apply { - if (!validated) { - useCache() - temperature() - topP() - maxTokens() - frequencyPenalty() - presencePenalty() - responseFormat().map { it.validate() } - toolChoice() - functionCall() - n() - stop() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is OpenAIModelParams && - this.useCache == other.useCache && - this.temperature == other.temperature && - this.topP == other.topP && - this.maxTokens == other.maxTokens && - this.frequencyPenalty == other.frequencyPenalty && - this.presencePenalty == other.presencePenalty && - this.responseFormat == other.responseFormat && - this.toolChoice == other.toolChoice && - this.functionCall == other.functionCall && - this.n == other.n && - this.stop == other.stop && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - useCache, - temperature, - topP, - maxTokens, - frequencyPenalty, - presencePenalty, - responseFormat, - toolChoice, - functionCall, - n, - stop, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var useCache: JsonField = JsonMissing.of() - private var temperature: JsonField = JsonMissing.of() - private var topP: JsonField = JsonMissing.of() - private var maxTokens: JsonField = JsonMissing.of() - private var frequencyPenalty: JsonField = JsonMissing.of() - private var presencePenalty: JsonField = JsonMissing.of() - private var responseFormat: JsonField = JsonMissing.of() - private var toolChoice: JsonField = JsonMissing.of() - private var functionCall: JsonField = JsonMissing.of() - private var n: JsonField = JsonMissing.of() - private var stop: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(openaiModelParams: OpenAIModelParams) = apply { - this.useCache = openaiModelParams.useCache - this.temperature = openaiModelParams.temperature - this.topP = openaiModelParams.topP - this.maxTokens = openaiModelParams.maxTokens - this.frequencyPenalty = openaiModelParams.frequencyPenalty - this.presencePenalty = openaiModelParams.presencePenalty - this.responseFormat = openaiModelParams.responseFormat - this.toolChoice = openaiModelParams.toolChoice - this.functionCall = openaiModelParams.functionCall - this.n = openaiModelParams.n - this.stop = openaiModelParams.stop - additionalProperties(openaiModelParams.additionalProperties) - } - - fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) - - @JsonProperty("use_cache") - @ExcludeMissing - fun useCache(useCache: JsonField) = apply { this.useCache = useCache } - - fun temperature(temperature: Double) = temperature(JsonField.of(temperature)) - - @JsonProperty("temperature") - @ExcludeMissing - fun temperature(temperature: JsonField) = apply { - this.temperature = temperature - } - - fun topP(topP: Double) = topP(JsonField.of(topP)) - - @JsonProperty("top_p") - @ExcludeMissing - fun topP(topP: JsonField) = apply { this.topP = topP } - - fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) - - @JsonProperty("max_tokens") - @ExcludeMissing - fun maxTokens(maxTokens: JsonField) = apply { - this.maxTokens = maxTokens - } - - fun frequencyPenalty(frequencyPenalty: Double) = - frequencyPenalty(JsonField.of(frequencyPenalty)) - - @JsonProperty("frequency_penalty") - @ExcludeMissing - fun frequencyPenalty(frequencyPenalty: JsonField) = apply { - this.frequencyPenalty = frequencyPenalty - } - - fun presencePenalty(presencePenalty: Double) = - presencePenalty(JsonField.of(presencePenalty)) - - @JsonProperty("presence_penalty") - @ExcludeMissing - fun presencePenalty(presencePenalty: JsonField) = apply { - this.presencePenalty = presencePenalty - } - - fun responseFormat(responseFormat: ResponseFormat) = - responseFormat(JsonField.of(responseFormat)) - - @JsonProperty("response_format") - @ExcludeMissing - fun responseFormat(responseFormat: JsonField) = apply { - this.responseFormat = responseFormat - } - - fun toolChoice(toolChoice: ToolChoice) = toolChoice(JsonField.of(toolChoice)) - - @JsonProperty("tool_choice") - @ExcludeMissing - fun toolChoice(toolChoice: JsonField) = apply { - this.toolChoice = toolChoice - } - - fun functionCall(functionCall: FunctionCall) = - functionCall(JsonField.of(functionCall)) - - @JsonProperty("function_call") - @ExcludeMissing - fun functionCall(functionCall: JsonField) = apply { - this.functionCall = functionCall - } - - fun n(n: Double) = n(JsonField.of(n)) - - @JsonProperty("n") - @ExcludeMissing - fun n(n: JsonField) = apply { this.n = n } - - fun stop(stop: List) = stop(JsonField.of(stop)) - - @JsonProperty("stop") - @ExcludeMissing - fun stop(stop: JsonField>) = apply { this.stop = stop } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): OpenAIModelParams = - OpenAIModelParams( - useCache, - temperature, - topP, - maxTokens, - frequencyPenalty, - presencePenalty, - responseFormat, - toolChoice, - functionCall, - n, - stop.map { it.toUnmodifiable() }, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(using = FunctionCall.Deserializer::class) - @JsonSerialize(using = FunctionCall.Serializer::class) - class FunctionCall - private constructor( - private val auto: Auto? = null, - private val none: None? = null, - private val function: Function? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun auto(): Optional = Optional.ofNullable(auto) - - fun none(): Optional = Optional.ofNullable(none) - - fun function(): Optional = Optional.ofNullable(function) - - fun isAuto(): Boolean = auto != null - - fun isNone(): Boolean = none != null - - fun isFunction(): Boolean = function != null - - fun asAuto(): Auto = auto.getOrThrow("auto") - - fun asNone(): None = none.getOrThrow("none") - - fun asFunction(): Function = function.getOrThrow("function") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - auto != null -> visitor.visitAuto(auto) - none != null -> visitor.visitNone(none) - function != null -> visitor.visitFunction(function) - else -> visitor.unknown(_json) - } - } - - fun validate(): FunctionCall = apply { - if (!validated) { - if (auto == null && none == null && function == null) { - throw BraintrustInvalidDataException("Unknown FunctionCall: $_json") - } - function?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is FunctionCall && - this.auto == other.auto && - this.none == other.none && - this.function == other.function - } - - override fun hashCode(): Int { - return Objects.hash( - auto, - none, - function, - ) - } - - override fun toString(): String { - return when { - auto != null -> "FunctionCall{auto=$auto}" - none != null -> "FunctionCall{none=$none}" - function != null -> "FunctionCall{function=$function}" - _json != null -> "FunctionCall{_unknown=$_json}" - else -> throw IllegalStateException("Invalid FunctionCall") - } - } - - companion object { - - @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) - - @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) - - @JvmStatic - fun ofFunction(function: Function) = FunctionCall(function = function) - } - - interface Visitor { - - fun visitAuto(auto: Auto): T - - fun visitNone(none: None): T - - fun visitFunction(function: Function): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown FunctionCall: $json") - } - } - - class Deserializer : BaseDeserializer(FunctionCall::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return FunctionCall(auto = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef())?.let { - return FunctionCall(none = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionCall(function = it, _json = json) - } - - return FunctionCall(_json = json) - } - } - - class Serializer : BaseSerializer(FunctionCall::class) { - - override fun serialize( - value: FunctionCall, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.auto != null -> generator.writeObject(value.auto) - value.none != null -> generator.writeObject(value.none) - value.function != null -> generator.writeObject(value.function) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid FunctionCall") - } - } - } - - class Auto - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Auto && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val AUTO = Auto(JsonField.of("auto")) - - @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) - } - - enum class Known { - AUTO, - } - - enum class Value { - AUTO, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - AUTO -> Value.AUTO - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - AUTO -> Known.AUTO - else -> throw BraintrustInvalidDataException("Unknown Auto: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - class None - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is None && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val NONE = None(JsonField.of("none")) - - @JvmStatic fun of(value: String) = None(JsonField.of(value)) - } - - enum class Known { - NONE, - } - - enum class Value { - NONE, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - NONE -> Value.NONE - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - NONE -> Known.NONE - else -> throw BraintrustInvalidDataException("Unknown None: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - @JsonDeserialize(builder = Function.Builder::class) - @NoAutoDetect - class Function - private constructor( - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun name(): String = name.getRequired("name") - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Function = apply { - if (!validated) { - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Function && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(name, additionalProperties) - } - return hashCode - } - - override fun toString() = - "Function{name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(function: Function) = apply { - this.name = function.name - additionalProperties(function.additionalProperties) - } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Function = - Function(name, additionalProperties.toUnmodifiable()) - } - } - } - - @JsonDeserialize(builder = ResponseFormat.Builder::class) - @NoAutoDetect - class ResponseFormat - private constructor( - private val type: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun type(): Type = type.getRequired("type") - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): ResponseFormat = apply { - if (!validated) { - type() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ResponseFormat && - this.type == other.type && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(type, additionalProperties) - } - return hashCode - } - - override fun toString() = - "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(responseFormat: ResponseFormat) = apply { - this.type = responseFormat.type - additionalProperties(responseFormat.additionalProperties) - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): ResponseFormat = - ResponseFormat(type, additionalProperties.toUnmodifiable()) - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - JSON_OBJECT, - } - - enum class Value { - JSON_OBJECT, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - JSON_OBJECT -> Value.JSON_OBJECT - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - JSON_OBJECT -> Known.JSON_OBJECT - else -> throw BraintrustInvalidDataException("Unknown Type: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(using = ToolChoice.Deserializer::class) - @JsonSerialize(using = ToolChoice.Serializer::class) - class ToolChoice - private constructor( - private val auto: Auto? = null, - private val none: None? = null, - private val function: Function? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun auto(): Optional = Optional.ofNullable(auto) - - fun none(): Optional = Optional.ofNullable(none) - - fun function(): Optional = Optional.ofNullable(function) - - fun isAuto(): Boolean = auto != null - - fun isNone(): Boolean = none != null - - fun isFunction(): Boolean = function != null - - fun asAuto(): Auto = auto.getOrThrow("auto") - - fun asNone(): None = none.getOrThrow("none") - - fun asFunction(): Function = function.getOrThrow("function") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - auto != null -> visitor.visitAuto(auto) - none != null -> visitor.visitNone(none) - function != null -> visitor.visitFunction(function) - else -> visitor.unknown(_json) - } - } - - fun validate(): ToolChoice = apply { - if (!validated) { - if (auto == null && none == null && function == null) { - throw BraintrustInvalidDataException("Unknown ToolChoice: $_json") - } - function?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ToolChoice && - this.auto == other.auto && - this.none == other.none && - this.function == other.function - } - - override fun hashCode(): Int { - return Objects.hash( - auto, - none, - function, - ) - } - - override fun toString(): String { - return when { - auto != null -> "ToolChoice{auto=$auto}" - none != null -> "ToolChoice{none=$none}" - function != null -> "ToolChoice{function=$function}" - _json != null -> "ToolChoice{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ToolChoice") - } - } - - companion object { - - @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) - - @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) - - @JvmStatic - fun ofFunction(function: Function) = ToolChoice(function = function) - } - - interface Visitor { - - fun visitAuto(auto: Auto): T - - fun visitNone(none: None): T - - fun visitFunction(function: Function): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown ToolChoice: $json") - } - } - - class Deserializer : BaseDeserializer(ToolChoice::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return ToolChoice(auto = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef())?.let { - return ToolChoice(none = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ToolChoice(function = it, _json = json) - } - - return ToolChoice(_json = json) - } - } - - class Serializer : BaseSerializer(ToolChoice::class) { - - override fun serialize( - value: ToolChoice, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.auto != null -> generator.writeObject(value.auto) - value.none != null -> generator.writeObject(value.none) - value.function != null -> generator.writeObject(value.function) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ToolChoice") - } - } - } - - class Auto - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Auto && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val AUTO = Auto(JsonField.of("auto")) - - @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) - } - - enum class Known { - AUTO, - } - - enum class Value { - AUTO, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - AUTO -> Value.AUTO - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - AUTO -> Known.AUTO - else -> throw BraintrustInvalidDataException("Unknown Auto: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - class None - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is None && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val NONE = None(JsonField.of("none")) - - @JvmStatic fun of(value: String) = None(JsonField.of(value)) - } - - enum class Known { - NONE, - } - - enum class Value { - NONE, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - NONE -> Value.NONE - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - NONE -> Known.NONE - else -> throw BraintrustInvalidDataException("Unknown None: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - @JsonDeserialize(builder = Function.Builder::class) - @NoAutoDetect - class Function - private constructor( - private val type: JsonField, - private val function: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun type(): Type = type.getRequired("type") - - fun function(): Function = function.getRequired("function") - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonProperty("function") @ExcludeMissing fun _function() = function - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Function = apply { - if (!validated) { - type() - function().validate() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Function && - this.type == other.type && - this.function == other.function && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - type, - function, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var type: JsonField = JsonMissing.of() - private var function: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(function: Function) = apply { - this.type = function.type - this.function = function.function - additionalProperties(function.additionalProperties) - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun function(function: Function) = function(JsonField.of(function)) - - @JsonProperty("function") - @ExcludeMissing - fun function(function: JsonField) = apply { - this.function = function - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Function = - Function( - type, - function, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(builder = Function.Builder::class) - @NoAutoDetect - class Function - private constructor( - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun name(): String = name.getRequired("name") - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - fun validate(): Function = apply { - if (!validated) { - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Function && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(name, additionalProperties) - } - return hashCode - } - - override fun toString() = - "Function{name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(function: Function) = apply { - this.name = function.name - additionalProperties(function.additionalProperties) - } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Function = - Function(name, additionalProperties.toUnmodifiable()) - } - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val FUNCTION = Type(JsonField.of("function")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - FUNCTION, - } - - enum class Value { - FUNCTION, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - FUNCTION -> Value.FUNCTION - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - FUNCTION -> Known.FUNCTION - else -> - throw BraintrustInvalidDataException("Unknown Type: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - } - } - - @JsonDeserialize(builder = AnthropicModelParams.Builder::class) - @NoAutoDetect - class AnthropicModelParams - private constructor( - private val useCache: JsonField, - private val maxTokens: JsonField, - private val temperature: JsonField, - private val topP: JsonField, - private val topK: JsonField, - private val stopSequences: JsonField>, - private val maxTokensToSample: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) - - fun maxTokens(): Double = maxTokens.getRequired("max_tokens") - - fun temperature(): Double = temperature.getRequired("temperature") - - fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) - - fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) - - fun stopSequences(): Optional> = - Optional.ofNullable(stopSequences.getNullable("stop_sequences")) - - /** This is a legacy parameter that should not be used. */ - fun maxTokensToSample(): Optional = - Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) - - @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache - - @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens - - @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature - - @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP - - @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK - - @JsonProperty("stop_sequences") @ExcludeMissing fun _stopSequences() = stopSequences - - /** This is a legacy parameter that should not be used. */ - @JsonProperty("max_tokens_to_sample") - @ExcludeMissing - fun _maxTokensToSample() = maxTokensToSample - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): AnthropicModelParams = apply { - if (!validated) { - useCache() - maxTokens() - temperature() - topP() - topK() - stopSequences() - maxTokensToSample() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is AnthropicModelParams && - this.useCache == other.useCache && - this.maxTokens == other.maxTokens && - this.temperature == other.temperature && - this.topP == other.topP && - this.topK == other.topK && - this.stopSequences == other.stopSequences && - this.maxTokensToSample == other.maxTokensToSample && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - useCache, - maxTokens, - temperature, - topP, - topK, - stopSequences, - maxTokensToSample, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var useCache: JsonField = JsonMissing.of() - private var maxTokens: JsonField = JsonMissing.of() - private var temperature: JsonField = JsonMissing.of() - private var topP: JsonField = JsonMissing.of() - private var topK: JsonField = JsonMissing.of() - private var stopSequences: JsonField> = JsonMissing.of() - private var maxTokensToSample: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(anthropicModelParams: AnthropicModelParams) = apply { - this.useCache = anthropicModelParams.useCache - this.maxTokens = anthropicModelParams.maxTokens - this.temperature = anthropicModelParams.temperature - this.topP = anthropicModelParams.topP - this.topK = anthropicModelParams.topK - this.stopSequences = anthropicModelParams.stopSequences - this.maxTokensToSample = anthropicModelParams.maxTokensToSample - additionalProperties(anthropicModelParams.additionalProperties) - } - - fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) - - @JsonProperty("use_cache") - @ExcludeMissing - fun useCache(useCache: JsonField) = apply { this.useCache = useCache } - - fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) - - @JsonProperty("max_tokens") - @ExcludeMissing - fun maxTokens(maxTokens: JsonField) = apply { - this.maxTokens = maxTokens - } - - fun temperature(temperature: Double) = temperature(JsonField.of(temperature)) - - @JsonProperty("temperature") - @ExcludeMissing - fun temperature(temperature: JsonField) = apply { - this.temperature = temperature - } - - fun topP(topP: Double) = topP(JsonField.of(topP)) - - @JsonProperty("top_p") - @ExcludeMissing - fun topP(topP: JsonField) = apply { this.topP = topP } - - fun topK(topK: Double) = topK(JsonField.of(topK)) - - @JsonProperty("top_k") - @ExcludeMissing - fun topK(topK: JsonField) = apply { this.topK = topK } - - fun stopSequences(stopSequences: List) = - stopSequences(JsonField.of(stopSequences)) - - @JsonProperty("stop_sequences") - @ExcludeMissing - fun stopSequences(stopSequences: JsonField>) = apply { - this.stopSequences = stopSequences - } - - /** This is a legacy parameter that should not be used. */ - fun maxTokensToSample(maxTokensToSample: Double) = - maxTokensToSample(JsonField.of(maxTokensToSample)) - - /** This is a legacy parameter that should not be used. */ - @JsonProperty("max_tokens_to_sample") - @ExcludeMissing - fun maxTokensToSample(maxTokensToSample: JsonField) = apply { - this.maxTokensToSample = maxTokensToSample - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): AnthropicModelParams = - AnthropicModelParams( - useCache, - maxTokens, - temperature, - topP, - topK, - stopSequences.map { it.toUnmodifiable() }, - maxTokensToSample, - additionalProperties.toUnmodifiable(), - ) - } - } - - @JsonDeserialize(builder = GoogleModelParams.Builder::class) - @NoAutoDetect - class GoogleModelParams - private constructor( - private val useCache: JsonField, - private val temperature: JsonField, - private val maxOutputTokens: JsonField, - private val topP: JsonField, - private val topK: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) - - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) - - fun maxOutputTokens(): Optional = - Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) - - fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) - - fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) - - @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache - - @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature - - @JsonProperty("maxOutputTokens") - @ExcludeMissing - fun _maxOutputTokens() = maxOutputTokens - - @JsonProperty("topP") @ExcludeMissing fun _topP() = topP - - @JsonProperty("topK") @ExcludeMissing fun _topK() = topK - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): GoogleModelParams = apply { - if (!validated) { - useCache() - temperature() - maxOutputTokens() - topP() - topK() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is GoogleModelParams && - this.useCache == other.useCache && - this.temperature == other.temperature && - this.maxOutputTokens == other.maxOutputTokens && - this.topP == other.topP && - this.topK == other.topK && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - useCache, - temperature, - maxOutputTokens, - topP, - topK, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var useCache: JsonField = JsonMissing.of() - private var temperature: JsonField = JsonMissing.of() - private var maxOutputTokens: JsonField = JsonMissing.of() - private var topP: JsonField = JsonMissing.of() - private var topK: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(googleModelParams: GoogleModelParams) = apply { - this.useCache = googleModelParams.useCache - this.temperature = googleModelParams.temperature - this.maxOutputTokens = googleModelParams.maxOutputTokens - this.topP = googleModelParams.topP - this.topK = googleModelParams.topK - additionalProperties(googleModelParams.additionalProperties) - } - - fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) - - @JsonProperty("use_cache") - @ExcludeMissing - fun useCache(useCache: JsonField) = apply { this.useCache = useCache } - - fun temperature(temperature: Double) = temperature(JsonField.of(temperature)) - - @JsonProperty("temperature") - @ExcludeMissing - fun temperature(temperature: JsonField) = apply { - this.temperature = temperature - } - - fun maxOutputTokens(maxOutputTokens: Double) = - maxOutputTokens(JsonField.of(maxOutputTokens)) - - @JsonProperty("maxOutputTokens") - @ExcludeMissing - fun maxOutputTokens(maxOutputTokens: JsonField) = apply { - this.maxOutputTokens = maxOutputTokens - } - - fun topP(topP: Double) = topP(JsonField.of(topP)) - - @JsonProperty("topP") - @ExcludeMissing - fun topP(topP: JsonField) = apply { this.topP = topP } - - fun topK(topK: Double) = topK(JsonField.of(topK)) - - @JsonProperty("topK") - @ExcludeMissing - fun topK(topK: JsonField) = apply { this.topK = topK } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): GoogleModelParams = - GoogleModelParams( - useCache, - temperature, - maxOutputTokens, - topP, - topK, - additionalProperties.toUnmodifiable(), - ) - } - } - - @JsonDeserialize(builder = WindowAiModelParams.Builder::class) - @NoAutoDetect - class WindowAiModelParams - private constructor( - private val useCache: JsonField, - private val temperature: JsonField, - private val topK: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) - - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) - - fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) - - @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache - - @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature - - @JsonProperty("topK") @ExcludeMissing fun _topK() = topK - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): WindowAiModelParams = apply { - if (!validated) { - useCache() - temperature() - topK() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is WindowAiModelParams && - this.useCache == other.useCache && - this.temperature == other.temperature && - this.topK == other.topK && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - useCache, - temperature, - topK, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var useCache: JsonField = JsonMissing.of() - private var temperature: JsonField = JsonMissing.of() - private var topK: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(windowAiModelParams: WindowAiModelParams) = apply { - this.useCache = windowAiModelParams.useCache - this.temperature = windowAiModelParams.temperature - this.topK = windowAiModelParams.topK - additionalProperties(windowAiModelParams.additionalProperties) - } - - fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) - - @JsonProperty("use_cache") - @ExcludeMissing - fun useCache(useCache: JsonField) = apply { this.useCache = useCache } - - fun temperature(temperature: Double) = temperature(JsonField.of(temperature)) - - @JsonProperty("temperature") - @ExcludeMissing - fun temperature(temperature: JsonField) = apply { - this.temperature = temperature - } - - fun topK(topK: Double) = topK(JsonField.of(topK)) - - @JsonProperty("topK") - @ExcludeMissing - fun topK(topK: JsonField) = apply { this.topK = topK } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): WindowAiModelParams = - WindowAiModelParams( - useCache, - temperature, - topK, - additionalProperties.toUnmodifiable(), - ) - } - } - - @JsonDeserialize(builder = JsCompletionParams.Builder::class) - @NoAutoDetect - class JsCompletionParams - private constructor( - private val useCache: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) - - @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): JsCompletionParams = apply { - if (!validated) { - useCache() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is JsCompletionParams && - this.useCache == other.useCache && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(useCache, additionalProperties) - } - return hashCode - } - - override fun toString() = - "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var useCache: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(jsCompletionParams: JsCompletionParams) = apply { - this.useCache = jsCompletionParams.useCache - additionalProperties(jsCompletionParams.additionalProperties) - } - - fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) - - @JsonProperty("use_cache") - @ExcludeMissing - fun useCache(useCache: JsonField) = apply { this.useCache = useCache } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): JsCompletionParams = - JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) - } - } - } - } - - @JsonDeserialize(builder = Origin.Builder::class) - @NoAutoDetect - class Origin - private constructor( - private val promptId: JsonField, - private val projectId: JsonField, - private val promptVersion: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun promptId(): Optional = Optional.ofNullable(promptId.getNullable("prompt_id")) - - fun projectId(): Optional = Optional.ofNullable(projectId.getNullable("project_id")) - - fun promptVersion(): Optional = - Optional.ofNullable(promptVersion.getNullable("prompt_version")) - - @JsonProperty("prompt_id") @ExcludeMissing fun _promptId() = promptId - - @JsonProperty("project_id") @ExcludeMissing fun _projectId() = projectId - - @JsonProperty("prompt_version") @ExcludeMissing fun _promptVersion() = promptVersion - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Origin = apply { - if (!validated) { - promptId() - projectId() - promptVersion() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Origin && - this.promptId == other.promptId && - this.projectId == other.projectId && - this.promptVersion == other.promptVersion && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - promptId, - projectId, - promptVersion, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var promptId: JsonField = JsonMissing.of() - private var projectId: JsonField = JsonMissing.of() - private var promptVersion: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(origin: Origin) = apply { - this.promptId = origin.promptId - this.projectId = origin.projectId - this.promptVersion = origin.promptVersion - additionalProperties(origin.additionalProperties) - } - - fun promptId(promptId: String) = promptId(JsonField.of(promptId)) - - @JsonProperty("prompt_id") - @ExcludeMissing - fun promptId(promptId: JsonField) = apply { this.promptId = promptId } - - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - @JsonProperty("project_id") - @ExcludeMissing - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - fun promptVersion(promptVersion: String) = promptVersion(JsonField.of(promptVersion)) - - @JsonProperty("prompt_version") - @ExcludeMissing - fun promptVersion(promptVersion: JsonField) = apply { - this.promptVersion = promptVersion - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): Origin = - Origin( - promptId, - projectId, - promptVersion, - additionalProperties.toUnmodifiable(), - ) - } - } - - @JsonDeserialize(using = Prompt.Deserializer::class) - @JsonSerialize(using = Prompt.Serializer::class) - class Prompt - private constructor( - private val completion: Completion? = null, - private val chat: Chat? = null, - private val nullableVariant: NullableVariant? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun completion(): Optional = Optional.ofNullable(completion) - - fun chat(): Optional = Optional.ofNullable(chat) - - fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) - - fun isCompletion(): Boolean = completion != null - - fun isChat(): Boolean = chat != null - - fun isNullableVariant(): Boolean = nullableVariant != null - - fun asCompletion(): Completion = completion.getOrThrow("completion") - - fun asChat(): Chat = chat.getOrThrow("chat") - - fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - completion != null -> visitor.visitCompletion(completion) - chat != null -> visitor.visitChat(chat) - nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) - else -> visitor.unknown(_json) - } - } - - fun validate(): Prompt = apply { - if (!validated) { - if (completion == null && chat == null && nullableVariant == null) { - throw BraintrustInvalidDataException("Unknown Prompt: $_json") - } - completion?.validate() - chat?.validate() - nullableVariant?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Prompt && - this.completion == other.completion && - this.chat == other.chat && - this.nullableVariant == other.nullableVariant - } - - override fun hashCode(): Int { - return Objects.hash( - completion, - chat, - nullableVariant, - ) - } - - override fun toString(): String { - return when { - completion != null -> "Prompt{completion=$completion}" - chat != null -> "Prompt{chat=$chat}" - nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" - _json != null -> "Prompt{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Prompt") - } - } - - companion object { - - @JvmStatic fun ofCompletion(completion: Completion) = Prompt(completion = completion) - - @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) - - @JvmStatic - fun ofNullableVariant(nullableVariant: NullableVariant) = - Prompt(nullableVariant = nullableVariant) - } - - interface Visitor { - - fun visitCompletion(completion: Completion): T - - fun visitChat(chat: Chat): T - - fun visitNullableVariant(nullableVariant: NullableVariant): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Prompt: $json") - } - } - - class Deserializer : BaseDeserializer(Prompt::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Prompt { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Prompt(completion = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Prompt(chat = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Prompt(nullableVariant = it, _json = json) - } - - return Prompt(_json = json) - } - } - - class Serializer : BaseSerializer(Prompt::class) { - - override fun serialize( - value: Prompt, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.completion != null -> generator.writeObject(value.completion) - value.chat != null -> generator.writeObject(value.chat) - value.nullableVariant != null -> generator.writeObject(value.nullableVariant) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Prompt") - } - } - } - - @JsonDeserialize(builder = Completion.Builder::class) - @NoAutoDetect - class Completion - private constructor( - private val type: JsonField, - private val content: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun type(): Type = type.getRequired("type") - - fun content(): String = content.getRequired("content") - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Completion = apply { - if (!validated) { - type() - content() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Completion && - this.type == other.type && - this.content == other.content && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - type, - content, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var type: JsonField = JsonMissing.of() - private var content: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(completion: Completion) = apply { - this.type = completion.type - this.content = completion.content - additionalProperties(completion.additionalProperties) - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): Completion = - Completion( - type, - content, - additionalProperties.toUnmodifiable(), - ) - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val COMPLETION = Type(JsonField.of("completion")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - COMPLETION, - } - - enum class Value { - COMPLETION, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - COMPLETION -> Value.COMPLETION - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - COMPLETION -> Known.COMPLETION - else -> throw BraintrustInvalidDataException("Unknown Type: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = Chat.Builder::class) - @NoAutoDetect - class Chat - private constructor( - private val type: JsonField, - private val messages: JsonField>, - private val tools: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun type(): Type = type.getRequired("type") - - fun messages(): List = messages.getRequired("messages") - - fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonProperty("messages") @ExcludeMissing fun _messages() = messages - - @JsonProperty("tools") @ExcludeMissing fun _tools() = tools - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Chat = apply { - if (!validated) { - type() - messages() - tools() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Chat && - this.type == other.type && - this.messages == other.messages && - this.tools == other.tools && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - type, - messages, - tools, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var type: JsonField = JsonMissing.of() - private var messages: JsonField> = JsonMissing.of() - private var tools: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(chat: Chat) = apply { - this.type = chat.type - this.messages = chat.messages - this.tools = chat.tools - additionalProperties(chat.additionalProperties) - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun messages(messages: List) = messages(JsonField.of(messages)) - - @JsonProperty("messages") - @ExcludeMissing - fun messages(messages: JsonField>) = apply { - this.messages = messages - } - - fun tools(tools: String) = tools(JsonField.of(tools)) - - @JsonProperty("tools") - @ExcludeMissing - fun tools(tools: JsonField) = apply { this.tools = tools } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): Chat = - Chat( - type, - messages.map { it.toUnmodifiable() }, - tools, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(using = Message.Deserializer::class) - @JsonSerialize(using = Message.Serializer::class) - class Message - private constructor( - private val system: System? = null, - private val user: User? = null, - private val assistant: Assistant? = null, - private val tool: Tool? = null, - private val function: Function? = null, - private val fallback: Fallback? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun system(): Optional = Optional.ofNullable(system) - - fun user(): Optional = Optional.ofNullable(user) - - fun assistant(): Optional = Optional.ofNullable(assistant) - - fun tool(): Optional = Optional.ofNullable(tool) - - fun function(): Optional = Optional.ofNullable(function) - - fun fallback(): Optional = Optional.ofNullable(fallback) - - fun isSystem(): Boolean = system != null - - fun isUser(): Boolean = user != null - - fun isAssistant(): Boolean = assistant != null - - fun isTool(): Boolean = tool != null - - fun isFunction(): Boolean = function != null - - fun isFallback(): Boolean = fallback != null - - fun asSystem(): System = system.getOrThrow("system") - - fun asUser(): User = user.getOrThrow("user") - - fun asAssistant(): Assistant = assistant.getOrThrow("assistant") - - fun asTool(): Tool = tool.getOrThrow("tool") - - fun asFunction(): Function = function.getOrThrow("function") - - fun asFallback(): Fallback = fallback.getOrThrow("fallback") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - system != null -> visitor.visitSystem(system) - user != null -> visitor.visitUser(user) - assistant != null -> visitor.visitAssistant(assistant) - tool != null -> visitor.visitTool(tool) - function != null -> visitor.visitFunction(function) - fallback != null -> visitor.visitFallback(fallback) - else -> visitor.unknown(_json) - } - } - - fun validate(): Message = apply { - if (!validated) { - if ( - system == null && - user == null && - assistant == null && - tool == null && - function == null && - fallback == null - ) { - throw BraintrustInvalidDataException("Unknown Message: $_json") - } - system?.validate() - user?.validate() - assistant?.validate() - tool?.validate() - function?.validate() - fallback?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Message && - this.system == other.system && - this.user == other.user && - this.assistant == other.assistant && - this.tool == other.tool && - this.function == other.function && - this.fallback == other.fallback - } - - override fun hashCode(): Int { - return Objects.hash( - system, - user, - assistant, - tool, - function, - fallback, - ) - } - - override fun toString(): String { - return when { - system != null -> "Message{system=$system}" - user != null -> "Message{user=$user}" - assistant != null -> "Message{assistant=$assistant}" - tool != null -> "Message{tool=$tool}" - function != null -> "Message{function=$function}" - fallback != null -> "Message{fallback=$fallback}" - _json != null -> "Message{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Message") - } - } - - companion object { - - @JvmStatic fun ofSystem(system: System) = Message(system = system) - - @JvmStatic fun ofUser(user: User) = Message(user = user) - - @JvmStatic - fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) - - @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) - - @JvmStatic fun ofFunction(function: Function) = Message(function = function) - - @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) - } - - interface Visitor { - - fun visitSystem(system: System): T - - fun visitUser(user: User): T - - fun visitAssistant(assistant: Assistant): T - - fun visitTool(tool: Tool): T - - fun visitFunction(function: Function): T - - fun visitFallback(fallback: Fallback): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Message: $json") - } - } - - class Deserializer : BaseDeserializer(Message::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Message { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(system = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(user = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(assistant = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(tool = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(function = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(fallback = it, _json = json) - } - - return Message(_json = json) - } - } - - class Serializer : BaseSerializer(Message::class) { - - override fun serialize( - value: Message, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.system != null -> generator.writeObject(value.system) - value.user != null -> generator.writeObject(value.user) - value.assistant != null -> generator.writeObject(value.assistant) - value.tool != null -> generator.writeObject(value.tool) - value.function != null -> generator.writeObject(value.function) - value.fallback != null -> generator.writeObject(value.fallback) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Message") - } - } - } - - @JsonDeserialize(builder = System.Builder::class) - @NoAutoDetect - class System - private constructor( - private val content: JsonField, - private val role: JsonField, - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - fun role(): Role = role.getRequired("role") - - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): System = apply { - if (!validated) { - content() - role() - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is System && - this.content == other.content && - this.role == other.role && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - content, - role, - name, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var content: JsonField = JsonMissing.of() - private var role: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(system: System) = apply { - this.content = system.content - this.role = system.role - this.name = system.name - additionalProperties(system.additionalProperties) - } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): System = - System( - content, - role, - name, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val SYSTEM = Role(JsonField.of("system")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - SYSTEM, - } - - enum class Value { - SYSTEM, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - SYSTEM -> Value.SYSTEM - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - SYSTEM -> Known.SYSTEM - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = User.Builder::class) - @NoAutoDetect - class User - private constructor( - private val content: JsonField, - private val role: JsonField, - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - fun role(): Role = role.getRequired("role") - - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): User = apply { - if (!validated) { - content() - role() - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is User && - this.content == other.content && - this.role == other.role && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - content, - role, - name, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var content: JsonField = JsonMissing.of() - private var role: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(user: User) = apply { - this.content = user.content - this.role = user.role - this.name = user.name - additionalProperties(user.additionalProperties) - } - - fun content(content: Content) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): User = - User( - content, - role, - name, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val USER = Role(JsonField.of("user")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - USER, - } - - enum class Value { - USER, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - USER -> Value.USER - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - USER -> Known.USER - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - @JsonDeserialize(using = Content.Deserializer::class) - @JsonSerialize(using = Content.Serializer::class) - class Content - private constructor( - private val string: String? = null, - private val unnamedSchemaWithArrayParent0s: - List? = - null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun string(): Optional = Optional.ofNullable(string) - - fun unnamedSchemaWithArrayParent0s(): - Optional> = - Optional.ofNullable(unnamedSchemaWithArrayParent0s) - - fun isString(): Boolean = string != null - - fun isUnnamedSchemaWithArrayParent0s(): Boolean = - unnamedSchemaWithArrayParent0s != null - - fun asString(): String = string.getOrThrow("string") - - fun asUnnamedSchemaWithArrayParent0s(): - List = - unnamedSchemaWithArrayParent0s.getOrThrow( - "unnamedSchemaWithArrayParent0s" - ) - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - string != null -> visitor.visitString(string) - unnamedSchemaWithArrayParent0s != null -> - visitor.visitUnnamedSchemaWithArrayParent0s( - unnamedSchemaWithArrayParent0s - ) - else -> visitor.unknown(_json) - } - } - - fun validate(): Content = apply { - if (!validated) { - if (string == null && unnamedSchemaWithArrayParent0s == null) { - throw BraintrustInvalidDataException("Unknown Content: $_json") - } - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Content && - this.string == other.string && - this.unnamedSchemaWithArrayParent0s == - other.unnamedSchemaWithArrayParent0s - } - - override fun hashCode(): Int { - return Objects.hash(string, unnamedSchemaWithArrayParent0s) - } - - override fun toString(): String { - return when { - string != null -> "Content{string=$string}" - unnamedSchemaWithArrayParent0s != null -> - "Content{unnamedSchemaWithArrayParent0s=$unnamedSchemaWithArrayParent0s}" - _json != null -> "Content{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Content") - } - } - - companion object { - - @JvmStatic fun ofString(string: String) = Content(string = string) - - @JvmStatic - fun ofUnnamedSchemaWithArrayParent0s( - unnamedSchemaWithArrayParent0s: List - ) = - Content( - unnamedSchemaWithArrayParent0s = unnamedSchemaWithArrayParent0s - ) - } - - interface Visitor { - - fun visitString(string: String): T - - fun visitUnnamedSchemaWithArrayParent0s( - unnamedSchemaWithArrayParent0s: List - ): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Content: $json") - } - } - - class Deserializer : BaseDeserializer(Content::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Content { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return Content(string = it, _json = json) - } - tryDeserialize( - node, - jacksonTypeRef>() - ) - ?.let { - return Content( - unnamedSchemaWithArrayParent0s = it, - _json = json - ) - } - - return Content(_json = json) - } - } - - class Serializer : BaseSerializer(Content::class) { - - override fun serialize( - value: Content, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.unnamedSchemaWithArrayParent0s != null -> - generator.writeObject(value.unnamedSchemaWithArrayParent0s) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Content") - } - } - } - - @JsonDeserialize(using = UnnamedSchemaWithArrayParent0.Deserializer::class) - @JsonSerialize(using = UnnamedSchemaWithArrayParent0.Serializer::class) - class UnnamedSchemaWithArrayParent0 - private constructor( - private val text: Text? = null, - private val imageUrl: ImageUrl? = null, - private val _json: JsonValue? = null, - ) { - - private var validated: Boolean = false - - fun text(): Optional = Optional.ofNullable(text) - - fun imageUrl(): Optional = Optional.ofNullable(imageUrl) - - fun isText(): Boolean = text != null - - fun isImageUrl(): Boolean = imageUrl != null - - fun asText(): Text = text.getOrThrow("text") - - fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { - text != null -> visitor.visitText(text) - imageUrl != null -> visitor.visitImageUrl(imageUrl) - else -> visitor.unknown(_json) - } - } - - fun validate(): UnnamedSchemaWithArrayParent0 = apply { - if (!validated) { - if (text == null && imageUrl == null) { - throw BraintrustInvalidDataException( - "Unknown UnnamedSchemaWithArrayParent0: $_json" - ) - } - text?.validate() - imageUrl?.validate() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is UnnamedSchemaWithArrayParent0 && - this.text == other.text && - this.imageUrl == other.imageUrl - } - - override fun hashCode(): Int { - return Objects.hash(text, imageUrl) - } - - override fun toString(): String { - return when { - text != null -> "UnnamedSchemaWithArrayParent0{text=$text}" - imageUrl != null -> - "UnnamedSchemaWithArrayParent0{imageUrl=$imageUrl}" - _json != null -> - "UnnamedSchemaWithArrayParent0{_unknown=$_json}" - else -> - throw IllegalStateException( - "Invalid UnnamedSchemaWithArrayParent0" - ) - } - } - - companion object { - - @JvmStatic - fun ofText(text: Text) = UnnamedSchemaWithArrayParent0(text = text) - - @JvmStatic - fun ofImageUrl(imageUrl: ImageUrl) = - UnnamedSchemaWithArrayParent0(imageUrl = imageUrl) - } - - interface Visitor { - - fun visitText(text: Text): T - - fun visitImageUrl(imageUrl: ImageUrl): T - - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException( - "Unknown UnnamedSchemaWithArrayParent0: $json" - ) - } - } - - class Deserializer : - BaseDeserializer( - UnnamedSchemaWithArrayParent0::class - ) { - - override fun ObjectCodec.deserialize( - node: JsonNode - ): UnnamedSchemaWithArrayParent0 { - val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return UnnamedSchemaWithArrayParent0( - text = it, - _json = json - ) - } - tryDeserialize(node, jacksonTypeRef()) { - it.validate() - } - ?.let { - return UnnamedSchemaWithArrayParent0( - imageUrl = it, - _json = json - ) - } - - return UnnamedSchemaWithArrayParent0(_json = json) - } - } - - class Serializer : - BaseSerializer( - UnnamedSchemaWithArrayParent0::class - ) { - - override fun serialize( - value: UnnamedSchemaWithArrayParent0, - generator: JsonGenerator, - provider: SerializerProvider - ) { - when { - value.text != null -> generator.writeObject(value.text) - value.imageUrl != null -> - generator.writeObject(value.imageUrl) - value._json != null -> generator.writeObject(value._json) - else -> - throw IllegalStateException( - "Invalid UnnamedSchemaWithArrayParent0" - ) - } - } - } - - @JsonDeserialize(builder = Text.Builder::class) - @NoAutoDetect - class Text - private constructor( - private val text: JsonField, - private val type: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun text(): Optional = - Optional.ofNullable(text.getNullable("text")) - - fun type(): Type = type.getRequired("type") - - @JsonProperty("text") @ExcludeMissing fun _text() = text - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - fun validate(): Text = apply { - if (!validated) { - text() - type() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Text && - this.text == other.text && - this.type == other.type && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - text, - type, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var text: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(text: Text) = apply { - this.text = text.text - this.type = text.type - additionalProperties(text.additionalProperties) - } - - fun text(text: String) = text(JsonField.of(text)) - - @JsonProperty("text") - @ExcludeMissing - fun text(text: JsonField) = apply { this.text = text } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = - apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): Text = - Text( - text, - type, - additionalProperties.toUnmodifiable(), - ) - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val TEXT = Type(JsonField.of("text")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - TEXT, - } - - enum class Value { - TEXT, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - TEXT -> Value.TEXT - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - TEXT -> Known.TEXT - else -> - throw BraintrustInvalidDataException( - "Unknown Type: $value" - ) - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = ImageUrl.Builder::class) - @NoAutoDetect - class ImageUrl - private constructor( - private val imageUrl: JsonField, - private val type: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") - - fun type(): Type = type.getRequired("type") - - @JsonProperty("image_url") - @ExcludeMissing - fun _imageUrl() = imageUrl - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - fun validate(): ImageUrl = apply { - if (!validated) { - imageUrl().validate() - type() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ImageUrl && - this.imageUrl == other.imageUrl && - this.type == other.type && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - imageUrl, - type, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var imageUrl: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(imageUrl: ImageUrl) = apply { - this.imageUrl = imageUrl.imageUrl - this.type = imageUrl.type - additionalProperties(imageUrl.additionalProperties) - } - - fun imageUrl(imageUrl: ImageUrl) = - imageUrl(JsonField.of(imageUrl)) - - @JsonProperty("image_url") - @ExcludeMissing - fun imageUrl(imageUrl: JsonField) = apply { - this.imageUrl = imageUrl - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = - apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): ImageUrl = - ImageUrl( - imageUrl, - type, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(builder = ImageUrl.Builder::class) - @NoAutoDetect - class ImageUrl - private constructor( - private val url: JsonField, - private val detail: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun url(): String = url.getRequired("url") - - fun detail(): Optional = - Optional.ofNullable(detail.getNullable("detail")) - - @JsonProperty("url") @ExcludeMissing fun _url() = url - - @JsonProperty("detail") @ExcludeMissing fun _detail() = detail - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - fun validate(): ImageUrl = apply { - if (!validated) { - url() - detail() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ImageUrl && - this.url == other.url && - this.detail == other.detail && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - url, - detail, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var url: JsonField = JsonMissing.of() - private var detail: JsonField = JsonMissing.of() - private var additionalProperties: - MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(imageUrl: ImageUrl) = apply { - this.url = imageUrl.url - this.detail = imageUrl.detail - additionalProperties(imageUrl.additionalProperties) - } - - fun url(url: String) = url(JsonField.of(url)) - - @JsonProperty("url") - @ExcludeMissing - fun url(url: JsonField) = apply { this.url = url } - - fun detail(detail: Detail) = detail(JsonField.of(detail)) - - @JsonProperty("detail") - @ExcludeMissing - fun detail(detail: JsonField) = apply { - this.detail = detail - } - - fun additionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = - apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): ImageUrl = - ImageUrl( - url, - detail, - additionalProperties.toUnmodifiable(), - ) - } - - class Detail - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Detail && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val AUTO = Detail(JsonField.of("auto")) - - @JvmField val LOW = Detail(JsonField.of("low")) - - @JvmField val HIGH = Detail(JsonField.of("high")) - - @JvmStatic - fun of(value: String) = Detail(JsonField.of(value)) - } - - enum class Known { - AUTO, - LOW, - HIGH, - } - - enum class Value { - AUTO, - LOW, - HIGH, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - AUTO -> Value.AUTO - LOW -> Value.LOW - HIGH -> Value.HIGH - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - AUTO -> Known.AUTO - LOW -> Known.LOW - HIGH -> Known.HIGH - else -> - throw BraintrustInvalidDataException( - "Unknown Detail: $value" - ) - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val IMAGE_URL = Type(JsonField.of("image_url")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - IMAGE_URL, - } - - enum class Value { - IMAGE_URL, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - IMAGE_URL -> Value.IMAGE_URL - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - IMAGE_URL -> Known.IMAGE_URL - else -> - throw BraintrustInvalidDataException( - "Unknown Type: $value" - ) - } - - fun asString(): String = _value().asStringOrThrow() - } - } - } - } - } - - @JsonDeserialize(builder = Assistant.Builder::class) - @NoAutoDetect - class Assistant - private constructor( - private val role: JsonField, - private val content: JsonField, - private val functionCall: JsonField, - private val name: JsonField, - private val toolCalls: JsonField>, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun role(): Role = role.getRequired("role") - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - fun functionCall(): Optional = - Optional.ofNullable(functionCall.getNullable("function_call")) - - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - fun toolCalls(): Optional> = - Optional.ofNullable(toolCalls.getNullable("tool_calls")) - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonProperty("function_call") - @ExcludeMissing - fun _functionCall() = functionCall - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Assistant = apply { - if (!validated) { - role() - content() - functionCall().map { it.validate() } - name() - toolCalls().map { it.forEach { it.validate() } } - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Assistant && - this.role == other.role && - this.content == other.content && - this.functionCall == other.functionCall && - this.name == other.name && - this.toolCalls == other.toolCalls && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - role, - content, - functionCall, - name, - toolCalls, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var role: JsonField = JsonMissing.of() - private var content: JsonField = JsonMissing.of() - private var functionCall: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var toolCalls: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(assistant: Assistant) = apply { - this.role = assistant.role - this.content = assistant.content - this.functionCall = assistant.functionCall - this.name = assistant.name - this.toolCalls = assistant.toolCalls - additionalProperties(assistant.additionalProperties) - } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun functionCall(functionCall: FunctionCall) = - functionCall(JsonField.of(functionCall)) - - @JsonProperty("function_call") - @ExcludeMissing - fun functionCall(functionCall: JsonField) = apply { - this.functionCall = functionCall - } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun toolCalls(toolCalls: List) = - toolCalls(JsonField.of(toolCalls)) - - @JsonProperty("tool_calls") - @ExcludeMissing - fun toolCalls(toolCalls: JsonField>) = apply { - this.toolCalls = toolCalls - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Assistant = - Assistant( - role, - content, - functionCall, - name, - toolCalls.map { it.toUnmodifiable() }, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val ASSISTANT = Role(JsonField.of("assistant")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - ASSISTANT, - } - - enum class Value { - ASSISTANT, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - ASSISTANT -> Value.ASSISTANT - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - ASSISTANT -> Known.ASSISTANT - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - - @JsonDeserialize(builder = FunctionCall.Builder::class) - @NoAutoDetect - class FunctionCall - private constructor( - private val arguments: JsonField, - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun arguments(): String = arguments.getRequired("arguments") - - fun name(): String = name.getRequired("name") - - @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): FunctionCall = apply { - if (!validated) { - arguments() - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is FunctionCall && - this.arguments == other.arguments && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - arguments, - name, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var arguments: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(functionCall: FunctionCall) = apply { - this.arguments = functionCall.arguments - this.name = functionCall.name - additionalProperties(functionCall.additionalProperties) - } - - fun arguments(arguments: String) = arguments(JsonField.of(arguments)) - - @JsonProperty("arguments") - @ExcludeMissing - fun arguments(arguments: JsonField) = apply { - this.arguments = arguments - } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): FunctionCall = - FunctionCall( - arguments, - name, - additionalProperties.toUnmodifiable(), - ) - } - } - - @JsonDeserialize(builder = ToolCall.Builder::class) - @NoAutoDetect - class ToolCall - private constructor( - private val id: JsonField, - private val function: JsonField, - private val type: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun id(): String = id.getRequired("id") - - fun function(): Function = function.getRequired("function") - - fun type(): Type = type.getRequired("type") - - @JsonProperty("id") @ExcludeMissing fun _id() = id - - @JsonProperty("function") @ExcludeMissing fun _function() = function - - @JsonProperty("type") @ExcludeMissing fun _type() = type - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): ToolCall = apply { - if (!validated) { - id() - function().validate() - type() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ToolCall && - this.id == other.id && - this.function == other.function && - this.type == other.type && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - id, - function, - type, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var id: JsonField = JsonMissing.of() - private var function: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(toolCall: ToolCall) = apply { - this.id = toolCall.id - this.function = toolCall.function - this.type = toolCall.type - additionalProperties(toolCall.additionalProperties) - } - - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - - fun function(function: Function) = function(JsonField.of(function)) - - @JsonProperty("function") - @ExcludeMissing - fun function(function: JsonField) = apply { - this.function = function - } - - fun type(type: Type) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): ToolCall = - ToolCall( - id, - function, - type, - additionalProperties.toUnmodifiable(), - ) - } - - @JsonDeserialize(builder = Function.Builder::class) - @NoAutoDetect - class Function - private constructor( - private val arguments: JsonField, - private val name: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun arguments(): String = arguments.getRequired("arguments") - - fun name(): String = name.getRequired("name") - - @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - fun validate(): Function = apply { - if (!validated) { - arguments() - name() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Function && - this.arguments == other.arguments && - this.name == other.name && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - arguments, - name, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var arguments: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(function: Function) = apply { - this.arguments = function.arguments - this.name = function.name - additionalProperties(function.additionalProperties) - } - - fun arguments(arguments: String) = - arguments(JsonField.of(arguments)) - - @JsonProperty("arguments") - @ExcludeMissing - fun arguments(arguments: JsonField) = apply { - this.arguments = arguments - } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties( - additionalProperties: Map - ) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Function = - Function( - arguments, - name, - additionalProperties.toUnmodifiable(), - ) - } - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val FUNCTION = Type(JsonField.of("function")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - FUNCTION, - } - - enum class Value { - FUNCTION, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - FUNCTION -> Value.FUNCTION - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - FUNCTION -> Known.FUNCTION - else -> - throw BraintrustInvalidDataException("Unknown Type: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - } - - @JsonDeserialize(builder = Tool.Builder::class) - @NoAutoDetect - class Tool - private constructor( - private val content: JsonField, - private val role: JsonField, - private val toolCallId: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - fun role(): Role = role.getRequired("role") - - fun toolCallId(): Optional = - Optional.ofNullable(toolCallId.getNullable("tool_call_id")) - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Tool = apply { - if (!validated) { - content() - role() - toolCallId() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Tool && - this.content == other.content && - this.role == other.role && - this.toolCallId == other.toolCallId && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - content, - role, - toolCallId, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var content: JsonField = JsonMissing.of() - private var role: JsonField = JsonMissing.of() - private var toolCallId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(tool: Tool) = apply { - this.content = tool.content - this.role = tool.role - this.toolCallId = tool.toolCallId - additionalProperties(tool.additionalProperties) - } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun toolCallId(toolCallId: String) = toolCallId(JsonField.of(toolCallId)) - - @JsonProperty("tool_call_id") - @ExcludeMissing - fun toolCallId(toolCallId: JsonField) = apply { - this.toolCallId = toolCallId - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Tool = - Tool( - content, - role, - toolCallId, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val TOOL = Role(JsonField.of("tool")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - TOOL, - } - - enum class Value { - TOOL, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - TOOL -> Value.TOOL - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - TOOL -> Known.TOOL - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = Function.Builder::class) - @NoAutoDetect - class Function - private constructor( - private val content: JsonField, - private val name: JsonField, - private val role: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - fun name(): String = name.getRequired("name") - - fun role(): Role = role.getRequired("role") - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonProperty("name") @ExcludeMissing fun _name() = name - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Function = apply { - if (!validated) { - content() - name() - role() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Function && - this.content == other.content && - this.name == other.name && - this.role == other.role && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - content, - name, - role, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var content: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var role: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(function: Function) = apply { - this.content = function.content - this.name = function.name - this.role = function.role - additionalProperties(function.additionalProperties) - } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Function = - Function( - content, - name, - role, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val FUNCTION = Role(JsonField.of("function")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - FUNCTION, - } - - enum class Value { - FUNCTION, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - FUNCTION -> Value.FUNCTION - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - FUNCTION -> Known.FUNCTION - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = Fallback.Builder::class) - @NoAutoDetect - class Fallback - private constructor( - private val role: JsonField, - private val content: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun role(): Role = role.getRequired("role") - - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) - - @JsonProperty("role") @ExcludeMissing fun _role() = role - - @JsonProperty("content") @ExcludeMissing fun _content() = content - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): Fallback = apply { - if (!validated) { - role() - content() - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Fallback && - this.role == other.role && - this.content == other.content && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - role, - content, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var role: JsonField = JsonMissing.of() - private var content: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(fallback: Fallback) = apply { - this.role = fallback.role - this.content = fallback.content - additionalProperties(fallback.additionalProperties) - } - - fun role(role: Role) = role(JsonField.of(role)) - - @JsonProperty("role") - @ExcludeMissing - fun role(role: JsonField) = apply { this.role = role } - - fun content(content: String) = content(JsonField.of(content)) - - @JsonProperty("content") - @ExcludeMissing - fun content(content: JsonField) = apply { this.content = content } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun build(): Fallback = - Fallback( - role, - content, - additionalProperties.toUnmodifiable(), - ) - } - - class Role - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Role && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val MODEL = Role(JsonField.of("model")) - - @JvmStatic fun of(value: String) = Role(JsonField.of(value)) - } - - enum class Known { - MODEL, - } - - enum class Value { - MODEL, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - MODEL -> Value.MODEL - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - MODEL -> Known.MODEL - else -> throw BraintrustInvalidDataException("Unknown Role: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - } - - class Type - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && this.value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - - companion object { - - @JvmField val CHAT = Type(JsonField.of("chat")) - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - enum class Known { - CHAT, - } - - enum class Value { - CHAT, - _UNKNOWN, - } - - fun value(): Value = - when (this) { - CHAT -> Value.CHAT - else -> Value._UNKNOWN - } - - fun known(): Known = - when (this) { - CHAT -> Known.CHAT - else -> throw BraintrustInvalidDataException("Unknown Type: $value") - } - - fun asString(): String = _value().asStringOrThrow() - } - } - - @JsonDeserialize(builder = NullableVariant.Builder::class) - @NoAutoDetect - class NullableVariant - private constructor( - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate(): NullableVariant = apply { - if (!validated) { - validated = true - } - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is NullableVariant && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(additionalProperties) - } - return hashCode - } - - override fun toString() = "NullableVariant{additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(nullableVariant: NullableVariant) = apply { - additionalProperties(nullableVariant.additionalProperties) - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): NullableVariant = - NullableVariant(additionalProperties.toUnmodifiable()) - } - } - } -} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index 65e9e68..be51d91 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -2,15 +2,29 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.BaseDeserializer +import com.braintrustdata.api.core.BaseSerializer +import com.braintrustdata.api.core.Enum import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.NoAutoDetect +import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.toUnmodifiable +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.* import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional @@ -367,4 +381,5776 @@ constructor( additionalBodyProperties.toUnmodifiable(), ) } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent2s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent2s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent2s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent2s(): Boolean = + unnamedSchemaWithArrayParent2s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent2s(): + List = + unnamedSchemaWithArrayParent2s.getOrThrow( + "unnamedSchemaWithArrayParent2s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent2s != null -> + visitor.visitUnnamedSchemaWithArrayParent2s( + unnamedSchemaWithArrayParent2s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent2s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent2s == + other.unnamedSchemaWithArrayParent2s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent2s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent2s != null -> + "Content{unnamedSchemaWithArrayParent2s=$unnamedSchemaWithArrayParent2s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent2s( + unnamedSchemaWithArrayParent2s: + List + ) = + Content( + unnamedSchemaWithArrayParent2s = + unnamedSchemaWithArrayParent2s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent2s( + unnamedSchemaWithArrayParent2s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent2s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent2s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent2s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent2.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent2.Serializer::class) + class UnnamedSchemaWithArrayParent2 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent2 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent2: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent2 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent2{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent2{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent2{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent2" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent2(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent2(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent2: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent2::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent2 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent2( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent2( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent2(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent2::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent2, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent2" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index 8f99c8f..38346e1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -2,15 +2,29 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.BaseDeserializer +import com.braintrustdata.api.core.BaseSerializer +import com.braintrustdata.api.core.Enum import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.NoAutoDetect +import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.toUnmodifiable +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.* import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional @@ -336,4 +350,5776 @@ constructor( additionalBodyProperties.toUnmodifiable(), ) } + + /** The prompt, model, and its parameters */ + @JsonDeserialize(builder = PromptData.Builder::class) + @NoAutoDetect + class PromptData + private constructor( + private val prompt: Prompt?, + private val options: Options?, + private val origin: Origin?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt") fun prompt(): Prompt? = prompt + + @JsonProperty("options") fun options(): Options? = options + + @JsonProperty("origin") fun origin(): Origin? = origin + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PromptData && + this.prompt == other.prompt && + this.options == other.options && + this.origin == other.origin && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + prompt, + options, + origin, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "PromptData{prompt=$prompt, options=$options, origin=$origin, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var prompt: Prompt? = null + private var options: Options? = null + private var origin: Origin? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptData: PromptData) = apply { + this.prompt = promptData.prompt + this.options = promptData.options + this.origin = promptData.origin + additionalProperties(promptData.additionalProperties) + } + + @JsonProperty("prompt") fun prompt(prompt: Prompt) = apply { this.prompt = prompt } + + @JsonProperty("options") + fun options(options: Options) = apply { this.options = options } + + @JsonProperty("origin") fun origin(origin: Origin) = apply { this.origin = origin } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): PromptData = + PromptData( + prompt, + options, + origin, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Options.Builder::class) + @NoAutoDetect + class Options + private constructor( + private val model: String?, + private val params: Params?, + private val position: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("model") fun model(): String? = model + + @JsonProperty("params") fun params(): Params? = params + + @JsonProperty("position") fun position(): String? = position + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Options && + this.model == other.model && + this.params == other.params && + this.position == other.position && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + model, + params, + position, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Options{model=$model, params=$params, position=$position, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: String? = null + private var params: Params? = null + private var position: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(options: Options) = apply { + this.model = options.model + this.params = options.params + this.position = options.position + additionalProperties(options.additionalProperties) + } + + @JsonProperty("model") fun model(model: String) = apply { this.model = model } + + @JsonProperty("params") fun params(params: Params) = apply { this.params = params } + + @JsonProperty("position") + fun position(position: String) = apply { this.position = position } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Options = + Options( + model, + params, + position, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Params.Deserializer::class) + @JsonSerialize(using = Params.Serializer::class) + class Params + private constructor( + private val openaiModelParams: OpenAIModelParams? = null, + private val anthropicModelParams: AnthropicModelParams? = null, + private val googleModelParams: GoogleModelParams? = null, + private val windowAiModelParams: WindowAiModelParams? = null, + private val jsCompletionParams: JsCompletionParams? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun openaiModelParams(): Optional = + Optional.ofNullable(openaiModelParams) + + fun anthropicModelParams(): Optional = + Optional.ofNullable(anthropicModelParams) + + fun googleModelParams(): Optional = + Optional.ofNullable(googleModelParams) + + fun windowAiModelParams(): Optional = + Optional.ofNullable(windowAiModelParams) + + fun jsCompletionParams(): Optional = + Optional.ofNullable(jsCompletionParams) + + fun isOpenAIModelParams(): Boolean = openaiModelParams != null + + fun isAnthropicModelParams(): Boolean = anthropicModelParams != null + + fun isGoogleModelParams(): Boolean = googleModelParams != null + + fun isWindowAiModelParams(): Boolean = windowAiModelParams != null + + fun isJsCompletionParams(): Boolean = jsCompletionParams != null + + fun asOpenAIModelParams(): OpenAIModelParams = + openaiModelParams.getOrThrow("openaiModelParams") + + fun asAnthropicModelParams(): AnthropicModelParams = + anthropicModelParams.getOrThrow("anthropicModelParams") + + fun asGoogleModelParams(): GoogleModelParams = + googleModelParams.getOrThrow("googleModelParams") + + fun asWindowAiModelParams(): WindowAiModelParams = + windowAiModelParams.getOrThrow("windowAiModelParams") + + fun asJsCompletionParams(): JsCompletionParams = + jsCompletionParams.getOrThrow("jsCompletionParams") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + openaiModelParams != null -> + visitor.visitOpenAIModelParams(openaiModelParams) + anthropicModelParams != null -> + visitor.visitAnthropicModelParams(anthropicModelParams) + googleModelParams != null -> + visitor.visitGoogleModelParams(googleModelParams) + windowAiModelParams != null -> + visitor.visitWindowAiModelParams(windowAiModelParams) + jsCompletionParams != null -> + visitor.visitJsCompletionParams(jsCompletionParams) + else -> visitor.unknown(_json) + } + } + + fun validate(): Params = apply { + if (!validated) { + if ( + openaiModelParams == null && + anthropicModelParams == null && + googleModelParams == null && + windowAiModelParams == null && + jsCompletionParams == null + ) { + throw BraintrustInvalidDataException("Unknown Params: $_json") + } + openaiModelParams?.validate() + anthropicModelParams?.validate() + googleModelParams?.validate() + windowAiModelParams?.validate() + jsCompletionParams?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Params && + this.openaiModelParams == other.openaiModelParams && + this.anthropicModelParams == other.anthropicModelParams && + this.googleModelParams == other.googleModelParams && + this.windowAiModelParams == other.windowAiModelParams && + this.jsCompletionParams == other.jsCompletionParams + } + + override fun hashCode(): Int { + return Objects.hash( + openaiModelParams, + anthropicModelParams, + googleModelParams, + windowAiModelParams, + jsCompletionParams, + ) + } + + override fun toString(): String { + return when { + openaiModelParams != null -> "Params{openaiModelParams=$openaiModelParams}" + anthropicModelParams != null -> + "Params{anthropicModelParams=$anthropicModelParams}" + googleModelParams != null -> "Params{googleModelParams=$googleModelParams}" + windowAiModelParams != null -> + "Params{windowAiModelParams=$windowAiModelParams}" + jsCompletionParams != null -> + "Params{jsCompletionParams=$jsCompletionParams}" + _json != null -> "Params{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Params") + } + } + + companion object { + + @JvmStatic + fun ofOpenAIModelParams(openaiModelParams: OpenAIModelParams) = + Params(openaiModelParams = openaiModelParams) + + @JvmStatic + fun ofAnthropicModelParams(anthropicModelParams: AnthropicModelParams) = + Params(anthropicModelParams = anthropicModelParams) + + @JvmStatic + fun ofGoogleModelParams(googleModelParams: GoogleModelParams) = + Params(googleModelParams = googleModelParams) + + @JvmStatic + fun ofWindowAiModelParams(windowAiModelParams: WindowAiModelParams) = + Params(windowAiModelParams = windowAiModelParams) + + @JvmStatic + fun ofJsCompletionParams(jsCompletionParams: JsCompletionParams) = + Params(jsCompletionParams = jsCompletionParams) + } + + interface Visitor { + + fun visitOpenAIModelParams(openaiModelParams: OpenAIModelParams): T + + fun visitAnthropicModelParams(anthropicModelParams: AnthropicModelParams): T + + fun visitGoogleModelParams(googleModelParams: GoogleModelParams): T + + fun visitWindowAiModelParams(windowAiModelParams: WindowAiModelParams): T + + fun visitJsCompletionParams(jsCompletionParams: JsCompletionParams): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Params: $json") + } + } + + class Deserializer : BaseDeserializer(Params::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Params { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(openaiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(anthropicModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(googleModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return Params(windowAiModelParams = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Params(jsCompletionParams = it, _json = json) + } + + return Params(_json = json) + } + } + + class Serializer : BaseSerializer(Params::class) { + + override fun serialize( + value: Params, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.openaiModelParams != null -> + generator.writeObject(value.openaiModelParams) + value.anthropicModelParams != null -> + generator.writeObject(value.anthropicModelParams) + value.googleModelParams != null -> + generator.writeObject(value.googleModelParams) + value.windowAiModelParams != null -> + generator.writeObject(value.windowAiModelParams) + value.jsCompletionParams != null -> + generator.writeObject(value.jsCompletionParams) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Params") + } + } + } + + @JsonDeserialize(builder = OpenAIModelParams.Builder::class) + @NoAutoDetect + class OpenAIModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val maxTokens: JsonField, + private val frequencyPenalty: JsonField, + private val presencePenalty: JsonField, + private val responseFormat: JsonField, + private val toolChoice: JsonField, + private val functionCall: JsonField, + private val n: JsonField, + private val stop: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun maxTokens(): Optional = + Optional.ofNullable(maxTokens.getNullable("max_tokens")) + + fun frequencyPenalty(): Optional = + Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + + fun presencePenalty(): Optional = + Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + fun toolChoice(): Optional = + Optional.ofNullable(toolChoice.getNullable("tool_choice")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + + fun stop(): Optional> = + Optional.ofNullable(stop.getNullable("stop")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun _frequencyPenalty() = frequencyPenalty + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun _presencePenalty() = presencePenalty + + @JsonProperty("response_format") + @ExcludeMissing + fun _responseFormat() = responseFormat + + @JsonProperty("tool_choice") @ExcludeMissing fun _toolChoice() = toolChoice + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("n") @ExcludeMissing fun _n() = n + + @JsonProperty("stop") @ExcludeMissing fun _stop() = stop + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): OpenAIModelParams = apply { + if (!validated) { + useCache() + temperature() + topP() + maxTokens() + frequencyPenalty() + presencePenalty() + responseFormat().map { it.validate() } + toolChoice() + functionCall() + n() + stop() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OpenAIModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topP == other.topP && + this.maxTokens == other.maxTokens && + this.frequencyPenalty == other.frequencyPenalty && + this.presencePenalty == other.presencePenalty && + this.responseFormat == other.responseFormat && + this.toolChoice == other.toolChoice && + this.functionCall == other.functionCall && + this.n == other.n && + this.stop == other.stop && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "OpenAIModelParams{useCache=$useCache, temperature=$temperature, topP=$topP, maxTokens=$maxTokens, frequencyPenalty=$frequencyPenalty, presencePenalty=$presencePenalty, responseFormat=$responseFormat, toolChoice=$toolChoice, functionCall=$functionCall, n=$n, stop=$stop, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var frequencyPenalty: JsonField = JsonMissing.of() + private var presencePenalty: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var toolChoice: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var n: JsonField = JsonMissing.of() + private var stop: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(openaiModelParams: OpenAIModelParams) = apply { + this.useCache = openaiModelParams.useCache + this.temperature = openaiModelParams.temperature + this.topP = openaiModelParams.topP + this.maxTokens = openaiModelParams.maxTokens + this.frequencyPenalty = openaiModelParams.frequencyPenalty + this.presencePenalty = openaiModelParams.presencePenalty + this.responseFormat = openaiModelParams.responseFormat + this.toolChoice = openaiModelParams.toolChoice + this.functionCall = openaiModelParams.functionCall + this.n = openaiModelParams.n + this.stop = openaiModelParams.stop + additionalProperties(openaiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun frequencyPenalty(frequencyPenalty: Double) = + frequencyPenalty(JsonField.of(frequencyPenalty)) + + @JsonProperty("frequency_penalty") + @ExcludeMissing + fun frequencyPenalty(frequencyPenalty: JsonField) = apply { + this.frequencyPenalty = frequencyPenalty + } + + fun presencePenalty(presencePenalty: Double) = + presencePenalty(JsonField.of(presencePenalty)) + + @JsonProperty("presence_penalty") + @ExcludeMissing + fun presencePenalty(presencePenalty: JsonField) = apply { + this.presencePenalty = presencePenalty + } + + fun responseFormat(responseFormat: ResponseFormat) = + responseFormat(JsonField.of(responseFormat)) + + @JsonProperty("response_format") + @ExcludeMissing + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + fun toolChoice(toolChoice: ToolChoice) = + toolChoice(JsonField.of(toolChoice)) + + @JsonProperty("tool_choice") + @ExcludeMissing + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun n(n: Double) = n(JsonField.of(n)) + + @JsonProperty("n") + @ExcludeMissing + fun n(n: JsonField) = apply { this.n = n } + + fun stop(stop: List) = stop(JsonField.of(stop)) + + @JsonProperty("stop") + @ExcludeMissing + fun stop(stop: JsonField>) = apply { this.stop = stop } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): OpenAIModelParams = + OpenAIModelParams( + useCache, + temperature, + topP, + maxTokens, + frequencyPenalty, + presencePenalty, + responseFormat, + toolChoice, + functionCall, + n, + stop.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = FunctionCall.Deserializer::class) + @JsonSerialize(using = FunctionCall.Serializer::class) + class FunctionCall + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): FunctionCall = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown FunctionCall: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "FunctionCall{auto=$auto}" + none != null -> "FunctionCall{none=$none}" + function != null -> "FunctionCall{function=$function}" + _json != null -> "FunctionCall{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = FunctionCall(auto = auto) + + @JvmStatic fun ofNone(none: None) = FunctionCall(none = none) + + @JvmStatic + fun ofFunction(function: Function) = FunctionCall(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown FunctionCall: $json") + } + } + + class Deserializer : BaseDeserializer(FunctionCall::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return FunctionCall(function = it, _json = json) + } + + return FunctionCall(_json = json) + } + } + + class Serializer : BaseSerializer(FunctionCall::class) { + + override fun serialize( + value: FunctionCall, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FunctionCall") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + } + + @JsonDeserialize(builder = ResponseFormat.Builder::class) + @NoAutoDetect + class ResponseFormat + private constructor( + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): ResponseFormat = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseFormat && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(type, additionalProperties) + } + return hashCode + } + + override fun toString() = + "ResponseFormat{type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(responseFormat: ResponseFormat) = apply { + this.type = responseFormat.type + additionalProperties(responseFormat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ResponseFormat = + ResponseFormat(type, additionalProperties.toUnmodifiable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val JSON_OBJECT = Type(JsonField.of("json_object")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + JSON_OBJECT, + } + + enum class Value { + JSON_OBJECT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + JSON_OBJECT -> Value.JSON_OBJECT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + JSON_OBJECT -> Known.JSON_OBJECT + else -> + throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(using = ToolChoice.Deserializer::class) + @JsonSerialize(using = ToolChoice.Serializer::class) + class ToolChoice + private constructor( + private val auto: Auto? = null, + private val none: None? = null, + private val function: Function? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun auto(): Optional = Optional.ofNullable(auto) + + fun none(): Optional = Optional.ofNullable(none) + + fun function(): Optional = Optional.ofNullable(function) + + fun isAuto(): Boolean = auto != null + + fun isNone(): Boolean = none != null + + fun isFunction(): Boolean = function != null + + fun asAuto(): Auto = auto.getOrThrow("auto") + + fun asNone(): None = none.getOrThrow("none") + + fun asFunction(): Function = function.getOrThrow("function") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + auto != null -> visitor.visitAuto(auto) + none != null -> visitor.visitNone(none) + function != null -> visitor.visitFunction(function) + else -> visitor.unknown(_json) + } + } + + fun validate(): ToolChoice = apply { + if (!validated) { + if (auto == null && none == null && function == null) { + throw BraintrustInvalidDataException( + "Unknown ToolChoice: $_json" + ) + } + function?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + this.auto == other.auto && + this.none == other.none && + this.function == other.function + } + + override fun hashCode(): Int { + return Objects.hash( + auto, + none, + function, + ) + } + + override fun toString(): String { + return when { + auto != null -> "ToolChoice{auto=$auto}" + none != null -> "ToolChoice{none=$none}" + function != null -> "ToolChoice{function=$function}" + _json != null -> "ToolChoice{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + + companion object { + + @JvmStatic fun ofAuto(auto: Auto) = ToolChoice(auto = auto) + + @JvmStatic fun ofNone(none: None) = ToolChoice(none = none) + + @JvmStatic + fun ofFunction(function: Function) = ToolChoice(function = function) + } + + interface Visitor { + + fun visitAuto(auto: Auto): T + + fun visitNone(none: None): T + + fun visitFunction(function: Function): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown ToolChoice: $json") + } + } + + class Deserializer : BaseDeserializer(ToolChoice::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(auto = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ToolChoice(none = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return ToolChoice(function = it, _json = json) + } + + return ToolChoice(_json = json) + } + } + + class Serializer : BaseSerializer(ToolChoice::class) { + + override fun serialize( + value: ToolChoice, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.auto != null -> generator.writeObject(value.auto) + value.none != null -> generator.writeObject(value.none) + value.function != null -> generator.writeObject(value.function) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ToolChoice") + } + } + } + + class Auto + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auto && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Auto(JsonField.of("auto")) + + @JvmStatic fun of(value: String) = Auto(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> + throw BraintrustInvalidDataException("Unknown Auto: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + class None + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is None && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val NONE = None(JsonField.of("none")) + + @JvmStatic fun of(value: String) = None(JsonField.of(value)) + } + + enum class Known { + NONE, + } + + enum class Value { + NONE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + else -> + throw BraintrustInvalidDataException("Unknown None: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val type: JsonField, + private val function: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun function(): Function = function.getRequired("function") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + type() + function().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.type == other.type && + this.function == other.function && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + function, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{type=$type, function=$function, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.type = function.type + this.function = function.function + additionalProperties(function.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + type, + function, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun name(): String = name.getRequired("name") + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(name, additionalProperties) + } + return hashCode + } + + override fun toString() = + "Function{name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function(name, additionalProperties.toUnmodifiable()) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + + @JsonDeserialize(builder = AnthropicModelParams.Builder::class) + @NoAutoDetect + class AnthropicModelParams + private constructor( + private val useCache: JsonField, + private val maxTokens: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val stopSequences: JsonField>, + private val maxTokensToSample: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun maxTokens(): Double = maxTokens.getRequired("max_tokens") + + fun temperature(): Double = temperature.getRequired("temperature") + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + + fun stopSequences(): Optional> = + Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(): Optional = + Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("max_tokens") @ExcludeMissing fun _maxTokens() = maxTokens + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + @JsonProperty("top_k") @ExcludeMissing fun _topK() = topK + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun _stopSequences() = stopSequences + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun _maxTokensToSample() = maxTokensToSample + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): AnthropicModelParams = apply { + if (!validated) { + useCache() + maxTokens() + temperature() + topP() + topK() + stopSequences() + maxTokensToSample() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AnthropicModelParams && + this.useCache == other.useCache && + this.maxTokens == other.maxTokens && + this.temperature == other.temperature && + this.topP == other.topP && + this.topK == other.topK && + this.stopSequences == other.stopSequences && + this.maxTokensToSample == other.maxTokensToSample && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences, + maxTokensToSample, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "AnthropicModelParams{useCache=$useCache, maxTokens=$maxTokens, temperature=$temperature, topP=$topP, topK=$topK, stopSequences=$stopSequences, maxTokensToSample=$maxTokensToSample, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var maxTokens: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var stopSequences: JsonField> = JsonMissing.of() + private var maxTokensToSample: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(anthropicModelParams: AnthropicModelParams) = apply { + this.useCache = anthropicModelParams.useCache + this.maxTokens = anthropicModelParams.maxTokens + this.temperature = anthropicModelParams.temperature + this.topP = anthropicModelParams.topP + this.topK = anthropicModelParams.topK + this.stopSequences = anthropicModelParams.stopSequences + this.maxTokensToSample = anthropicModelParams.maxTokensToSample + additionalProperties(anthropicModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun maxTokens(maxTokens: Double) = maxTokens(JsonField.of(maxTokens)) + + @JsonProperty("max_tokens") + @ExcludeMissing + fun maxTokens(maxTokens: JsonField) = apply { + this.maxTokens = maxTokens + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("top_p") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("top_k") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun stopSequences(stopSequences: List) = + stopSequences(JsonField.of(stopSequences)) + + @JsonProperty("stop_sequences") + @ExcludeMissing + fun stopSequences(stopSequences: JsonField>) = apply { + this.stopSequences = stopSequences + } + + /** This is a legacy parameter that should not be used. */ + fun maxTokensToSample(maxTokensToSample: Double) = + maxTokensToSample(JsonField.of(maxTokensToSample)) + + /** This is a legacy parameter that should not be used. */ + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + fun maxTokensToSample(maxTokensToSample: JsonField) = apply { + this.maxTokensToSample = maxTokensToSample + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): AnthropicModelParams = + AnthropicModelParams( + useCache, + maxTokens, + temperature, + topP, + topK, + stopSequences.map { it.toUnmodifiable() }, + maxTokensToSample, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = GoogleModelParams.Builder::class) + @NoAutoDetect + class GoogleModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val maxOutputTokens: JsonField, + private val topP: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun maxOutputTokens(): Optional = + Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + + fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun _maxOutputTokens() = maxOutputTokens + + @JsonProperty("topP") @ExcludeMissing fun _topP() = topP + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): GoogleModelParams = apply { + if (!validated) { + useCache() + temperature() + maxOutputTokens() + topP() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GoogleModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.maxOutputTokens == other.maxOutputTokens && + this.topP == other.topP && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "GoogleModelParams{useCache=$useCache, temperature=$temperature, maxOutputTokens=$maxOutputTokens, topP=$topP, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var maxOutputTokens: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(googleModelParams: GoogleModelParams) = apply { + this.useCache = googleModelParams.useCache + this.temperature = googleModelParams.temperature + this.maxOutputTokens = googleModelParams.maxOutputTokens + this.topP = googleModelParams.topP + this.topK = googleModelParams.topK + additionalProperties(googleModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun maxOutputTokens(maxOutputTokens: Double) = + maxOutputTokens(JsonField.of(maxOutputTokens)) + + @JsonProperty("maxOutputTokens") + @ExcludeMissing + fun maxOutputTokens(maxOutputTokens: JsonField) = apply { + this.maxOutputTokens = maxOutputTokens + } + + fun topP(topP: Double) = topP(JsonField.of(topP)) + + @JsonProperty("topP") + @ExcludeMissing + fun topP(topP: JsonField) = apply { this.topP = topP } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): GoogleModelParams = + GoogleModelParams( + useCache, + temperature, + maxOutputTokens, + topP, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = WindowAiModelParams.Builder::class) + @NoAutoDetect + class WindowAiModelParams + private constructor( + private val useCache: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + @JsonProperty("topK") @ExcludeMissing fun _topK() = topK + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): WindowAiModelParams = apply { + if (!validated) { + useCache() + temperature() + topK() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WindowAiModelParams && + this.useCache == other.useCache && + this.temperature == other.temperature && + this.topK == other.topK && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + useCache, + temperature, + topK, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "WindowAiModelParams{useCache=$useCache, temperature=$temperature, topK=$topK, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(windowAiModelParams: WindowAiModelParams) = apply { + this.useCache = windowAiModelParams.useCache + this.temperature = windowAiModelParams.temperature + this.topK = windowAiModelParams.topK + additionalProperties(windowAiModelParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun temperature(temperature: Double) = + temperature(JsonField.of(temperature)) + + @JsonProperty("temperature") + @ExcludeMissing + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + fun topK(topK: Double) = topK(JsonField.of(topK)) + + @JsonProperty("topK") + @ExcludeMissing + fun topK(topK: JsonField) = apply { this.topK = topK } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): WindowAiModelParams = + WindowAiModelParams( + useCache, + temperature, + topK, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = JsCompletionParams.Builder::class) + @NoAutoDetect + class JsCompletionParams + private constructor( + private val useCache: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun useCache(): Optional = + Optional.ofNullable(useCache.getNullable("use_cache")) + + @JsonProperty("use_cache") @ExcludeMissing fun _useCache() = useCache + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): JsCompletionParams = apply { + if (!validated) { + useCache() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JsCompletionParams && + this.useCache == other.useCache && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(useCache, additionalProperties) + } + return hashCode + } + + override fun toString() = + "JsCompletionParams{useCache=$useCache, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var useCache: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(jsCompletionParams: JsCompletionParams) = apply { + this.useCache = jsCompletionParams.useCache + additionalProperties(jsCompletionParams.additionalProperties) + } + + fun useCache(useCache: Boolean) = useCache(JsonField.of(useCache)) + + @JsonProperty("use_cache") + @ExcludeMissing + fun useCache(useCache: JsonField) = apply { + this.useCache = useCache + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): JsCompletionParams = + JsCompletionParams(useCache, additionalProperties.toUnmodifiable()) + } + } + } + } + + @JsonDeserialize(builder = Origin.Builder::class) + @NoAutoDetect + class Origin + private constructor( + private val promptId: String?, + private val projectId: String?, + private val promptVersion: String?, + private val additionalProperties: Map, + ) { + + private var hashCode: Int = 0 + + @JsonProperty("prompt_id") fun promptId(): String? = promptId + + @JsonProperty("project_id") fun projectId(): String? = projectId + + @JsonProperty("prompt_version") fun promptVersion(): String? = promptVersion + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Origin && + this.promptId == other.promptId && + this.projectId == other.projectId && + this.promptVersion == other.promptVersion && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + promptId, + projectId, + promptVersion, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Origin{promptId=$promptId, projectId=$projectId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var promptId: String? = null + private var projectId: String? = null + private var promptVersion: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(origin: Origin) = apply { + this.promptId = origin.promptId + this.projectId = origin.projectId + this.promptVersion = origin.promptVersion + additionalProperties(origin.additionalProperties) + } + + @JsonProperty("prompt_id") + fun promptId(promptId: String) = apply { this.promptId = promptId } + + @JsonProperty("project_id") + fun projectId(projectId: String) = apply { this.projectId = projectId } + + @JsonProperty("prompt_version") + fun promptVersion(promptVersion: String) = apply { + this.promptVersion = promptVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Origin = + Origin( + promptId, + projectId, + promptVersion, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(using = Prompt.Deserializer::class) + @JsonSerialize(using = Prompt.Serializer::class) + class Prompt + private constructor( + private val completion: Completion? = null, + private val chat: Chat? = null, + private val nullableVariant: NullableVariant? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun completion(): Optional = Optional.ofNullable(completion) + + fun chat(): Optional = Optional.ofNullable(chat) + + fun nullableVariant(): Optional = Optional.ofNullable(nullableVariant) + + fun isCompletion(): Boolean = completion != null + + fun isChat(): Boolean = chat != null + + fun isNullableVariant(): Boolean = nullableVariant != null + + fun asCompletion(): Completion = completion.getOrThrow("completion") + + fun asChat(): Chat = chat.getOrThrow("chat") + + fun asNullableVariant(): NullableVariant = nullableVariant.getOrThrow("nullableVariant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + completion != null -> visitor.visitCompletion(completion) + chat != null -> visitor.visitChat(chat) + nullableVariant != null -> visitor.visitNullableVariant(nullableVariant) + else -> visitor.unknown(_json) + } + } + + fun validate(): Prompt = apply { + if (!validated) { + if (completion == null && chat == null && nullableVariant == null) { + throw BraintrustInvalidDataException("Unknown Prompt: $_json") + } + completion?.validate() + chat?.validate() + nullableVariant?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Prompt && + this.completion == other.completion && + this.chat == other.chat && + this.nullableVariant == other.nullableVariant + } + + override fun hashCode(): Int { + return Objects.hash( + completion, + chat, + nullableVariant, + ) + } + + override fun toString(): String { + return when { + completion != null -> "Prompt{completion=$completion}" + chat != null -> "Prompt{chat=$chat}" + nullableVariant != null -> "Prompt{nullableVariant=$nullableVariant}" + _json != null -> "Prompt{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Prompt") + } + } + + companion object { + + @JvmStatic + fun ofCompletion(completion: Completion) = Prompt(completion = completion) + + @JvmStatic fun ofChat(chat: Chat) = Prompt(chat = chat) + + @JvmStatic + fun ofNullableVariant(nullableVariant: NullableVariant) = + Prompt(nullableVariant = nullableVariant) + } + + interface Visitor { + + fun visitCompletion(completion: Completion): T + + fun visitChat(chat: Chat): T + + fun visitNullableVariant(nullableVariant: NullableVariant): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Prompt: $json") + } + } + + class Deserializer : BaseDeserializer(Prompt::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Prompt { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(completion = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(chat = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Prompt(nullableVariant = it, _json = json) + } + + return Prompt(_json = json) + } + } + + class Serializer : BaseSerializer(Prompt::class) { + + override fun serialize( + value: Prompt, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.completion != null -> generator.writeObject(value.completion) + value.chat != null -> generator.writeObject(value.chat) + value.nullableVariant != null -> + generator.writeObject(value.nullableVariant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Prompt") + } + } + } + + @JsonDeserialize(builder = Completion.Builder::class) + @NoAutoDetect + class Completion + private constructor( + private val type: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun content(): String = content.getRequired("content") + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Completion = apply { + if (!validated) { + type() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Completion && + this.type == other.type && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Completion{type=$type, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(completion: Completion) = apply { + this.type = completion.type + this.content = completion.content + additionalProperties(completion.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Completion = + Completion( + type, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val COMPLETION = Type(JsonField.of("completion")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + COMPLETION, + } + + enum class Value { + COMPLETION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + COMPLETION -> Value.COMPLETION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + COMPLETION -> Known.COMPLETION + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Chat.Builder::class) + @NoAutoDetect + class Chat + private constructor( + private val type: JsonField, + private val messages: JsonField>, + private val tools: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun type(): Type = type.getRequired("type") + + fun messages(): List = messages.getRequired("messages") + + fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("messages") @ExcludeMissing fun _messages() = messages + + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Chat = apply { + if (!validated) { + type() + messages() + tools() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Chat && + this.type == other.type && + this.messages == other.messages && + this.tools == other.tools && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + type, + messages, + tools, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Chat{type=$type, messages=$messages, tools=$tools, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var messages: JsonField> = JsonMissing.of() + private var tools: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chat: Chat) = apply { + this.type = chat.type + this.messages = chat.messages + this.tools = chat.tools + additionalProperties(chat.additionalProperties) + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun messages(messages: List) = messages(JsonField.of(messages)) + + @JsonProperty("messages") + @ExcludeMissing + fun messages(messages: JsonField>) = apply { + this.messages = messages + } + + fun tools(tools: String) = tools(JsonField.of(tools)) + + @JsonProperty("tools") + @ExcludeMissing + fun tools(tools: JsonField) = apply { this.tools = tools } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Chat = + Chat( + type, + messages.map { it.toUnmodifiable() }, + tools, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(using = Message.Deserializer::class) + @JsonSerialize(using = Message.Serializer::class) + class Message + private constructor( + private val system: System? = null, + private val user: User? = null, + private val assistant: Assistant? = null, + private val tool: Tool? = null, + private val function: Function? = null, + private val fallback: Fallback? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun system(): Optional = Optional.ofNullable(system) + + fun user(): Optional = Optional.ofNullable(user) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun tool(): Optional = Optional.ofNullable(tool) + + fun function(): Optional = Optional.ofNullable(function) + + fun fallback(): Optional = Optional.ofNullable(fallback) + + fun isSystem(): Boolean = system != null + + fun isUser(): Boolean = user != null + + fun isAssistant(): Boolean = assistant != null + + fun isTool(): Boolean = tool != null + + fun isFunction(): Boolean = function != null + + fun isFallback(): Boolean = fallback != null + + fun asSystem(): System = system.getOrThrow("system") + + fun asUser(): User = user.getOrThrow("user") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun asTool(): Tool = tool.getOrThrow("tool") + + fun asFunction(): Function = function.getOrThrow("function") + + fun asFallback(): Fallback = fallback.getOrThrow("fallback") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + system != null -> visitor.visitSystem(system) + user != null -> visitor.visitUser(user) + assistant != null -> visitor.visitAssistant(assistant) + tool != null -> visitor.visitTool(tool) + function != null -> visitor.visitFunction(function) + fallback != null -> visitor.visitFallback(fallback) + else -> visitor.unknown(_json) + } + } + + fun validate(): Message = apply { + if (!validated) { + if ( + system == null && + user == null && + assistant == null && + tool == null && + function == null && + fallback == null + ) { + throw BraintrustInvalidDataException("Unknown Message: $_json") + } + system?.validate() + user?.validate() + assistant?.validate() + tool?.validate() + function?.validate() + fallback?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Message && + this.system == other.system && + this.user == other.user && + this.assistant == other.assistant && + this.tool == other.tool && + this.function == other.function && + this.fallback == other.fallback + } + + override fun hashCode(): Int { + return Objects.hash( + system, + user, + assistant, + tool, + function, + fallback, + ) + } + + override fun toString(): String { + return when { + system != null -> "Message{system=$system}" + user != null -> "Message{user=$user}" + assistant != null -> "Message{assistant=$assistant}" + tool != null -> "Message{tool=$tool}" + function != null -> "Message{function=$function}" + fallback != null -> "Message{fallback=$fallback}" + _json != null -> "Message{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Message") + } + } + + companion object { + + @JvmStatic fun ofSystem(system: System) = Message(system = system) + + @JvmStatic fun ofUser(user: User) = Message(user = user) + + @JvmStatic + fun ofAssistant(assistant: Assistant) = Message(assistant = assistant) + + @JvmStatic fun ofTool(tool: Tool) = Message(tool = tool) + + @JvmStatic fun ofFunction(function: Function) = Message(function = function) + + @JvmStatic fun ofFallback(fallback: Fallback) = Message(fallback = fallback) + } + + interface Visitor { + + fun visitSystem(system: System): T + + fun visitUser(user: User): T + + fun visitAssistant(assistant: Assistant): T + + fun visitTool(tool: Tool): T + + fun visitFunction(function: Function): T + + fun visitFallback(fallback: Fallback): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Message: $json") + } + } + + class Deserializer : BaseDeserializer(Message::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Message { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(system = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(user = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(assistant = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(tool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(function = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Message(fallback = it, _json = json) + } + + return Message(_json = json) + } + } + + class Serializer : BaseSerializer(Message::class) { + + override fun serialize( + value: Message, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.system != null -> generator.writeObject(value.system) + value.user != null -> generator.writeObject(value.user) + value.assistant != null -> generator.writeObject(value.assistant) + value.tool != null -> generator.writeObject(value.tool) + value.function != null -> generator.writeObject(value.function) + value.fallback != null -> generator.writeObject(value.fallback) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Message") + } + } + } + + @JsonDeserialize(builder = System.Builder::class) + @NoAutoDetect + class System + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): System = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is System && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "System{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(system: System) = apply { + this.content = system.content + this.role = system.role + this.name = system.name + additionalProperties(system.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): System = + System( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val SYSTEM = Role(JsonField.of("system")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + SYSTEM, + } + + enum class Value { + SYSTEM, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + SYSTEM -> Value.SYSTEM + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + SYSTEM -> Known.SYSTEM + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = User.Builder::class) + @NoAutoDetect + class User + private constructor( + private val content: JsonField, + private val role: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): User = apply { + if (!validated) { + content() + role() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + this.content == other.content && + this.role == other.role && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "User{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + this.content = user.content + this.role = user.role + this.name = user.name + additionalProperties(user.additionalProperties) + } + + fun content(content: Content) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): User = + User( + content, + role, + name, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val USER = Role(JsonField.of("user")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + } + + enum class Value { + USER, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val string: String? = null, + private val unnamedSchemaWithArrayParent1s: + List? = + null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun string(): Optional = Optional.ofNullable(string) + + fun unnamedSchemaWithArrayParent1s(): + Optional> = + Optional.ofNullable(unnamedSchemaWithArrayParent1s) + + fun isString(): Boolean = string != null + + fun isUnnamedSchemaWithArrayParent1s(): Boolean = + unnamedSchemaWithArrayParent1s != null + + fun asString(): String = string.getOrThrow("string") + + fun asUnnamedSchemaWithArrayParent1s(): + List = + unnamedSchemaWithArrayParent1s.getOrThrow( + "unnamedSchemaWithArrayParent1s" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + string != null -> visitor.visitString(string) + unnamedSchemaWithArrayParent1s != null -> + visitor.visitUnnamedSchemaWithArrayParent1s( + unnamedSchemaWithArrayParent1s + ) + else -> visitor.unknown(_json) + } + } + + fun validate(): Content = apply { + if (!validated) { + if (string == null && unnamedSchemaWithArrayParent1s == null) { + throw BraintrustInvalidDataException( + "Unknown Content: $_json" + ) + } + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + this.string == other.string && + this.unnamedSchemaWithArrayParent1s == + other.unnamedSchemaWithArrayParent1s + } + + override fun hashCode(): Int { + return Objects.hash(string, unnamedSchemaWithArrayParent1s) + } + + override fun toString(): String { + return when { + string != null -> "Content{string=$string}" + unnamedSchemaWithArrayParent1s != null -> + "Content{unnamedSchemaWithArrayParent1s=$unnamedSchemaWithArrayParent1s}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + } + + companion object { + + @JvmStatic fun ofString(string: String) = Content(string = string) + + @JvmStatic + fun ofUnnamedSchemaWithArrayParent1s( + unnamedSchemaWithArrayParent1s: + List + ) = + Content( + unnamedSchemaWithArrayParent1s = + unnamedSchemaWithArrayParent1s + ) + } + + interface Visitor { + + fun visitString(string: String): T + + fun visitUnnamedSchemaWithArrayParent1s( + unnamedSchemaWithArrayParent1s: + List + ): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(string = it, _json = json) + } + tryDeserialize( + node, + jacksonTypeRef>() + ) + ?.let { + return Content( + unnamedSchemaWithArrayParent1s = it, + _json = json + ) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.unnamedSchemaWithArrayParent1s != null -> + generator.writeObject( + value.unnamedSchemaWithArrayParent1s + ) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + @JsonDeserialize( + using = UnnamedSchemaWithArrayParent1.Deserializer::class + ) + @JsonSerialize(using = UnnamedSchemaWithArrayParent1.Serializer::class) + class UnnamedSchemaWithArrayParent1 + private constructor( + private val text: Text? = null, + private val imageUrl: ImageUrl? = null, + private val _json: JsonValue? = null, + ) { + + private var validated: Boolean = false + + fun text(): Optional = Optional.ofNullable(text) + + fun imageUrl(): Optional = Optional.ofNullable(imageUrl) + + fun isText(): Boolean = text != null + + fun isImageUrl(): Boolean = imageUrl != null + + fun asText(): Text = text.getOrThrow("text") + + fun asImageUrl(): ImageUrl = imageUrl.getOrThrow("imageUrl") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + text != null -> visitor.visitText(text) + imageUrl != null -> visitor.visitImageUrl(imageUrl) + else -> visitor.unknown(_json) + } + } + + fun validate(): UnnamedSchemaWithArrayParent1 = apply { + if (!validated) { + if (text == null && imageUrl == null) { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent1: $_json" + ) + } + text?.validate() + imageUrl?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnnamedSchemaWithArrayParent1 && + this.text == other.text && + this.imageUrl == other.imageUrl + } + + override fun hashCode(): Int { + return Objects.hash(text, imageUrl) + } + + override fun toString(): String { + return when { + text != null -> "UnnamedSchemaWithArrayParent1{text=$text}" + imageUrl != null -> + "UnnamedSchemaWithArrayParent1{imageUrl=$imageUrl}" + _json != null -> + "UnnamedSchemaWithArrayParent1{_unknown=$_json}" + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent1" + ) + } + } + + companion object { + + @JvmStatic + fun ofText(text: Text) = + UnnamedSchemaWithArrayParent1(text = text) + + @JvmStatic + fun ofImageUrl(imageUrl: ImageUrl) = + UnnamedSchemaWithArrayParent1(imageUrl = imageUrl) + } + + interface Visitor { + + fun visitText(text: Text): T + + fun visitImageUrl(imageUrl: ImageUrl): T + + fun unknown(json: JsonValue?): T { + throw BraintrustInvalidDataException( + "Unknown UnnamedSchemaWithArrayParent1: $json" + ) + } + } + + class Deserializer : + BaseDeserializer( + UnnamedSchemaWithArrayParent1::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): UnnamedSchemaWithArrayParent1 { + val json = JsonValue.fromJsonNode(node) + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent1( + text = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return UnnamedSchemaWithArrayParent1( + imageUrl = it, + _json = json + ) + } + + return UnnamedSchemaWithArrayParent1(_json = json) + } + } + + class Serializer : + BaseSerializer( + UnnamedSchemaWithArrayParent1::class + ) { + + override fun serialize( + value: UnnamedSchemaWithArrayParent1, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.imageUrl != null -> + generator.writeObject(value.imageUrl) + value._json != null -> + generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid UnnamedSchemaWithArrayParent1" + ) + } + } + } + + @JsonDeserialize(builder = Text.Builder::class) + @NoAutoDetect + class Text + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun text(): Optional = + Optional.ofNullable(text.getNullable("text")) + + fun type(): Type = type.getRequired("type") + + @JsonProperty("text") @ExcludeMissing fun _text() = text + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Text = apply { + if (!validated) { + text() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Text && + this.text == other.text && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + text, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Text{text=$text, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var text: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + this.text = text.text + this.type = text.type + additionalProperties(text.additionalProperties) + } + + fun text(text: String) = text(JsonField.of(text)) + + @JsonProperty("text") + @ExcludeMissing + fun text(text: JsonField) = apply { + this.text = text + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Text = + Text( + text, + type, + additionalProperties.toUnmodifiable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TEXT = Type(JsonField.of("text")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + TEXT, + } + + enum class Value { + TEXT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TEXT -> Value.TEXT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun imageUrl(): ImageUrl = imageUrl.getRequired("image_url") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("image_url") + @ExcludeMissing + fun _imageUrl() = imageUrl + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + imageUrl().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.imageUrl == other.imageUrl && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + imageUrl, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var imageUrl: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.imageUrl = imageUrl.imageUrl + this.type = imageUrl.type + additionalProperties(imageUrl.additionalProperties) + } + + fun imageUrl(imageUrl: ImageUrl) = + imageUrl(JsonField.of(imageUrl)) + + @JsonProperty("image_url") + @ExcludeMissing + fun imageUrl(imageUrl: JsonField) = apply { + this.imageUrl = imageUrl + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): ImageUrl = + ImageUrl( + imageUrl, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = ImageUrl.Builder::class) + @NoAutoDetect + class ImageUrl + private constructor( + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun url(): String = url.getRequired("url") + + fun detail(): Optional = + Optional.ofNullable(detail.getNullable("detail")) + + @JsonProperty("url") @ExcludeMissing fun _url() = url + + @JsonProperty("detail") + @ExcludeMissing + fun _detail() = detail + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ImageUrl = apply { + if (!validated) { + url() + detail() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageUrl && + this.url == other.url && + this.detail == other.detail && + this.additionalProperties == + other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + url, + detail, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ImageUrl{url=$url, detail=$detail, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var url: JsonField = JsonMissing.of() + private var detail: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(imageUrl: ImageUrl) = apply { + this.url = imageUrl.url + this.detail = imageUrl.detail + additionalProperties(imageUrl.additionalProperties) + } + + fun url(url: String) = url(JsonField.of(url)) + + @JsonProperty("url") + @ExcludeMissing + fun url(url: JsonField) = apply { + this.url = url + } + + fun detail(detail: Detail) = + detail(JsonField.of(detail)) + + @JsonProperty("detail") + @ExcludeMissing + fun detail(detail: JsonField) = apply { + this.detail = detail + } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll( + additionalProperties + ) + } + + @JsonAnySetter + fun putAdditionalProperty( + key: String, + value: JsonValue + ) = apply { this.additionalProperties.put(key, value) } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll( + additionalProperties + ) + } + + fun build(): ImageUrl = + ImageUrl( + url, + detail, + additionalProperties.toUnmodifiable(), + ) + } + + class Detail + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Detail && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val AUTO = Detail(JsonField.of("auto")) + + @JvmField val LOW = Detail(JsonField.of("low")) + + @JvmField val HIGH = Detail(JsonField.of("high")) + + @JvmStatic + fun of(value: String) = Detail(JsonField.of(value)) + } + + enum class Known { + AUTO, + LOW, + HIGH, + } + + enum class Value { + AUTO, + LOW, + HIGH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LOW -> Value.LOW + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LOW -> Known.LOW + HIGH -> Known.HIGH + else -> + throw BraintrustInvalidDataException( + "Unknown Detail: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField + val IMAGE_URL = Type(JsonField.of("image_url")) + + @JvmStatic + fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + IMAGE_URL, + } + + enum class Value { + IMAGE_URL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IMAGE_URL -> Value.IMAGE_URL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IMAGE_URL -> Known.IMAGE_URL + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + } + } + + @JsonDeserialize(builder = Assistant.Builder::class) + @NoAutoDetect + class Assistant + private constructor( + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun functionCall(): Optional = + Optional.ofNullable(functionCall.getNullable("function_call")) + + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + fun toolCalls(): Optional> = + Optional.ofNullable(toolCalls.getNullable("tool_calls")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("function_call") + @ExcludeMissing + fun _functionCall() = functionCall + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("tool_calls") @ExcludeMissing fun _toolCalls() = toolCalls + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Assistant = apply { + if (!validated) { + role() + content() + functionCall().map { it.validate() } + name() + toolCalls().map { it.forEach { it.validate() } } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Assistant && + this.role == other.role && + this.content == other.content && + this.functionCall == other.functionCall && + this.name == other.name && + this.toolCalls == other.toolCalls && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var functionCall: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var toolCalls: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + this.role = assistant.role + this.content = assistant.content + this.functionCall = assistant.functionCall + this.name = assistant.name + this.toolCalls = assistant.toolCalls + additionalProperties(assistant.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun functionCall(functionCall: FunctionCall) = + functionCall(JsonField.of(functionCall)) + + @JsonProperty("function_call") + @ExcludeMissing + fun functionCall(functionCall: JsonField) = apply { + this.functionCall = functionCall + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun toolCalls(toolCalls: List) = + toolCalls(JsonField.of(toolCalls)) + + @JsonProperty("tool_calls") + @ExcludeMissing + fun toolCalls(toolCalls: JsonField>) = apply { + this.toolCalls = toolCalls + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Assistant = + Assistant( + role, + content, + functionCall, + name, + toolCalls.map { it.toUnmodifiable() }, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val ASSISTANT = Role(JsonField.of("assistant")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + + @JsonDeserialize(builder = FunctionCall.Builder::class) + @NoAutoDetect + class FunctionCall + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") @ExcludeMissing fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): FunctionCall = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FunctionCall && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "FunctionCall{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(functionCall: FunctionCall) = apply { + this.arguments = functionCall.arguments + this.name = functionCall.name + additionalProperties(functionCall.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): FunctionCall = + FunctionCall( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + @JsonDeserialize(builder = ToolCall.Builder::class) + @NoAutoDetect + class ToolCall + private constructor( + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun id(): String = id.getRequired("id") + + fun function(): Function = function.getRequired("function") + + fun type(): Type = type.getRequired("type") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): ToolCall = apply { + if (!validated) { + id() + function().validate() + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolCall && + this.id == other.id && + this.function == other.function && + this.type == other.type && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + id, + function, + type, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "ToolCall{id=$id, function=$function, type=$type, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + this.id = toolCall.id + this.function = toolCall.function + this.type = toolCall.type + additionalProperties(toolCall.additionalProperties) + } + + fun id(id: String) = id(JsonField.of(id)) + + @JsonProperty("id") + @ExcludeMissing + fun id(id: JsonField) = apply { this.id = id } + + fun function(function: Function) = function(JsonField.of(function)) + + @JsonProperty("function") + @ExcludeMissing + fun function(function: JsonField) = apply { + this.function = function + } + + fun type(type: Type) = type(JsonField.of(type)) + + @JsonProperty("type") + @ExcludeMissing + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): ToolCall = + ToolCall( + id, + function, + type, + additionalProperties.toUnmodifiable(), + ) + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun arguments(): String = arguments.getRequired("arguments") + + fun name(): String = name.getRequired("name") + + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments() = arguments + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties + + fun validate(): Function = apply { + if (!validated) { + arguments() + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.arguments == other.arguments && + this.name == other.name && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + arguments, + name, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{arguments=$arguments, name=$name, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var arguments: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: + MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.arguments = function.arguments + this.name = function.name + additionalProperties(function.additionalProperties) + } + + fun arguments(arguments: String) = + arguments(JsonField.of(arguments)) + + @JsonProperty("arguments") + @ExcludeMissing + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = + apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): Function = + Function( + arguments, + name, + additionalProperties.toUnmodifiable(), + ) + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Type(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException( + "Unknown Type: $value" + ) + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + @JsonDeserialize(builder = Tool.Builder::class) + @NoAutoDetect + class Tool + private constructor( + private val content: JsonField, + private val role: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun role(): Role = role.getRequired("role") + + fun toolCallId(): Optional = + Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("tool_call_id") @ExcludeMissing fun _toolCallId() = toolCallId + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Tool = apply { + if (!validated) { + content() + role() + toolCallId() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + this.content == other.content && + this.role == other.role && + this.toolCallId == other.toolCallId && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + role, + toolCallId, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Tool{content=$content, role=$role, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var toolCallId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tool: Tool) = apply { + this.content = tool.content + this.role = tool.role + this.toolCallId = tool.toolCallId + additionalProperties(tool.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun toolCallId(toolCallId: String) = + toolCallId(JsonField.of(toolCallId)) + + @JsonProperty("tool_call_id") + @ExcludeMissing + fun toolCallId(toolCallId: JsonField) = apply { + this.toolCallId = toolCallId + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Tool = + Tool( + content, + role, + toolCallId, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val TOOL = Role(JsonField.of("tool")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + TOOL, + } + + enum class Value { + TOOL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + TOOL -> Value.TOOL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + TOOL -> Known.TOOL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Function.Builder::class) + @NoAutoDetect + class Function + private constructor( + private val content: JsonField, + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + fun name(): String = name.getRequired("name") + + fun role(): Role = role.getRequired("role") + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Function = apply { + if (!validated) { + content() + name() + role() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Function && + this.content == other.content && + this.name == other.name && + this.role == other.role && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + content, + name, + role, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Function{content=$content, name=$name, role=$role, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(function: Function) = apply { + this.content = function.content + this.name = function.name + this.role = function.role + additionalProperties(function.additionalProperties) + } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun name(name: String) = name(JsonField.of(name)) + + @JsonProperty("name") + @ExcludeMissing + fun name(name: JsonField) = apply { this.name = name } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Function = + Function( + content, + name, + role, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val FUNCTION = Role(JsonField.of("function")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + } + + enum class Value { + FUNCTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = Fallback.Builder::class) + @NoAutoDetect + class Fallback + private constructor( + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + fun role(): Role = role.getRequired("role") + + fun content(): Optional = + Optional.ofNullable(content.getNullable("content")) + + @JsonProperty("role") @ExcludeMissing fun _role() = role + + @JsonProperty("content") @ExcludeMissing fun _content() = content + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Fallback = apply { + if (!validated) { + role() + content() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Fallback && + this.role == other.role && + this.content == other.content && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = + Objects.hash( + role, + content, + additionalProperties, + ) + } + return hashCode + } + + override fun toString() = + "Fallback{role=$role, content=$content, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: JsonField = JsonMissing.of() + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fallback: Fallback) = apply { + this.role = fallback.role + this.content = fallback.content + additionalProperties(fallback.additionalProperties) + } + + fun role(role: Role) = role(JsonField.of(role)) + + @JsonProperty("role") + @ExcludeMissing + fun role(role: JsonField) = apply { this.role = role } + + fun content(content: String) = content(JsonField.of(content)) + + @JsonProperty("content") + @ExcludeMissing + fun content(content: JsonField) = apply { + this.content = content + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun build(): Fallback = + Fallback( + role, + content, + additionalProperties.toUnmodifiable(), + ) + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val MODEL = Role(JsonField.of("model")) + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + MODEL, + } + + enum class Value { + MODEL, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + MODEL -> Value.MODEL + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + MODEL -> Known.MODEL + else -> + throw BraintrustInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && this.value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + @JvmField val CHAT = Type(JsonField.of("chat")) + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + CHAT, + } + + enum class Value { + CHAT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + CHAT -> Value.CHAT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + CHAT -> Known.CHAT + else -> throw BraintrustInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + } + + @JsonDeserialize(builder = NullableVariant.Builder::class) + @NoAutoDetect + class NullableVariant + private constructor( + private val additionalProperties: Map, + ) { + + private var validated: Boolean = false + + private var hashCode: Int = 0 + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): NullableVariant = apply { + if (!validated) { + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NullableVariant && + this.additionalProperties == other.additionalProperties + } + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = Objects.hash(additionalProperties) + } + return hashCode + } + + override fun toString() = + "NullableVariant{additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nullableVariant: NullableVariant) = apply { + additionalProperties(nullableVariant.additionalProperties) + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): NullableVariant = + NullableVariant(additionalProperties.toUnmodifiable()) + } + } + } + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt index 4c04458..6672164 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt @@ -23,18 +23,22 @@ class FunctionCreateParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionCreateParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionCreateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -44,11 +48,13 @@ class FunctionCreateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -58,9 +64,12 @@ class FunctionCreateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -75,17 +84,20 @@ class FunctionCreateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionCreateParams.PromptData.Prompt.ofCompletion( + FunctionCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -111,71 +123,86 @@ class FunctionCreateParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionCreateParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionCreateParams.PromptData.Prompt.ofCompletion( + FunctionCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -199,18 +226,22 @@ class FunctionCreateParamsTest { assertThat(body.description()).isEqualTo("description") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + FunctionCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionCreateParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionCreateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -220,11 +251,13 @@ class FunctionCreateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -234,9 +267,12 @@ class FunctionCreateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -251,17 +287,20 @@ class FunctionCreateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionCreateParams.PromptData.Prompt.ofCompletion( + FunctionCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt index 4fcda46..92d010d 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt @@ -23,18 +23,23 @@ class FunctionReplaceParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionReplaceParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -44,11 +49,13 @@ class FunctionReplaceParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -58,9 +65,12 @@ class FunctionReplaceParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -75,17 +85,20 @@ class FunctionReplaceParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionReplaceParams.PromptData.Prompt.ofCompletion( + FunctionReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -111,71 +124,86 @@ class FunctionReplaceParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionReplaceParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionReplaceParams.PromptData.Prompt.ofCompletion( + FunctionReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -199,18 +227,23 @@ class FunctionReplaceParamsTest { assertThat(body.description()).isEqualTo("description") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + FunctionReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionReplaceParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -220,11 +253,13 @@ class FunctionReplaceParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -234,9 +269,12 @@ class FunctionReplaceParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -251,17 +289,20 @@ class FunctionReplaceParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionReplaceParams.PromptData.Prompt.ofCompletion( + FunctionReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt index 1e94d2d..860deb9 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt @@ -30,19 +30,21 @@ class FunctionTest { .description("description") .metadata(Function.Metadata.builder().build()) .promptData( - PromptData.builder() + Function.PromptData.builder() .options( - PromptData.Options.builder() + Function.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + Function.PromptData.Options.Params.ofOpenAIModelParams( + Function.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params.OpenAIModelParams .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -52,11 +54,12 @@ class FunctionTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params.OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -66,10 +69,11 @@ class FunctionTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params.OpenAIModelParams .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -84,17 +88,17 @@ class FunctionTest { .build() ) .origin( - PromptData.Origin.builder() + Function.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + Function.PromptData.Prompt.ofCompletion( + Function.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type(Function.PromptData.Prompt.Completion.Type.COMPLETION) .build() ) ) @@ -123,18 +127,20 @@ class FunctionTest { assertThat(function.metadata()).contains(Function.Metadata.builder().build()) assertThat(function.promptData()) .contains( - PromptData.builder() + Function.PromptData.builder() .options( - PromptData.Options.builder() + Function.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + Function.PromptData.Options.Params.ofOpenAIModelParams( + Function.PromptData.Options.Params.OpenAIModelParams.builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + Function.PromptData.Options.Params.OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -144,11 +150,12 @@ class FunctionTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params.OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -158,9 +165,11 @@ class FunctionTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + Function.PromptData.Options.Params.OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Function.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -175,17 +184,17 @@ class FunctionTest { .build() ) .origin( - PromptData.Origin.builder() + Function.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + Function.PromptData.Prompt.ofCompletion( + Function.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type(Function.PromptData.Prompt.Completion.Type.COMPLETION) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt index 8468f01..79b01a8 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt @@ -22,18 +22,22 @@ class FunctionUpdateParamsTest { ) .name("name") .promptData( - PromptData.builder() + FunctionUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionUpdateParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionUpdateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -43,11 +47,13 @@ class FunctionUpdateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -57,9 +63,12 @@ class FunctionUpdateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -74,17 +83,20 @@ class FunctionUpdateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionUpdateParams.PromptData.Prompt.ofCompletion( + FunctionUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -109,71 +121,86 @@ class FunctionUpdateParamsTest { ) .name("name") .promptData( - PromptData.builder() + FunctionUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionUpdateParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionUpdateParams.PromptData.Prompt.ofCompletion( + FunctionUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -195,18 +222,22 @@ class FunctionUpdateParamsTest { assertThat(body.name()).isEqualTo("name") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + FunctionUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + FunctionUpdateParams.PromptData.Options.Params.ofOpenAIModelParams( + FunctionUpdateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -216,11 +247,13 @@ class FunctionUpdateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -230,9 +263,12 @@ class FunctionUpdateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -247,17 +283,20 @@ class FunctionUpdateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + FunctionUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionUpdateParams.PromptData.Prompt.ofCompletion( + FunctionUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt index 2d254a4..c4e100b 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt @@ -16,18 +16,22 @@ class PromptCreateParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptCreateParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptCreateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -37,11 +41,13 @@ class PromptCreateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -51,9 +57,12 @@ class PromptCreateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -68,17 +77,19 @@ class PromptCreateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptCreateParams.PromptData.Prompt.ofCompletion( + PromptCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptCreateParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) @@ -97,71 +108,86 @@ class PromptCreateParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptCreateParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptCreateParams.PromptData.Prompt.ofCompletion( + PromptCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -177,18 +203,22 @@ class PromptCreateParamsTest { assertThat(body.description()).isEqualTo("description") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + PromptCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptCreateParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptCreateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -198,11 +228,13 @@ class PromptCreateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -212,9 +244,12 @@ class PromptCreateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -229,17 +264,19 @@ class PromptCreateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptCreateParams.PromptData.Prompt.ofCompletion( + PromptCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptCreateParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt deleted file mode 100644 index 7e008d7..0000000 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt +++ /dev/null @@ -1,143 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.braintrustdata.api.models - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -class PromptDataTest { - - @Test - fun createPromptData() { - val promptData = - PromptData.builder() - .options( - PromptData.Options.builder() - .model("model") - .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams.ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) - ) - .position("position") - .build() - ) - .origin( - PromptData.Origin.builder() - .projectId("project_id") - .promptId("prompt_id") - .promptVersion("prompt_version") - .build() - ) - .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() - .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) - .build() - ) - ) - .build() - assertThat(promptData).isNotNull - assertThat(promptData.options()) - .contains( - PromptData.Options.builder() - .model("model") - .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall.ofAuto( - PromptData.Options.Params.OpenAIModelParams.FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams.ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice.ofAuto( - PromptData.Options.Params.OpenAIModelParams.ToolChoice.Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) - ) - .position("position") - .build() - ) - assertThat(promptData.origin()) - .contains( - PromptData.Origin.builder() - .projectId("project_id") - .promptId("prompt_id") - .promptVersion("prompt_version") - .build() - ) - assertThat(promptData.prompt()) - .contains( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() - .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) - .build() - ) - ) - } -} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt index cb2c399..0f30c19 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt @@ -16,18 +16,22 @@ class PromptReplaceParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptReplaceParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptReplaceParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -37,11 +41,13 @@ class PromptReplaceParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -51,9 +57,12 @@ class PromptReplaceParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -68,17 +77,19 @@ class PromptReplaceParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptReplaceParams.PromptData.Prompt.ofCompletion( + PromptReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptReplaceParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) @@ -97,71 +108,86 @@ class PromptReplaceParamsTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptReplaceParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptReplaceParams.PromptData.Prompt.ofCompletion( + PromptReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -177,18 +203,22 @@ class PromptReplaceParamsTest { assertThat(body.description()).isEqualTo("description") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + PromptReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptReplaceParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptReplaceParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -198,11 +228,13 @@ class PromptReplaceParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -212,9 +244,12 @@ class PromptReplaceParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -229,17 +264,19 @@ class PromptReplaceParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptReplaceParams.PromptData.Prompt.ofCompletion( + PromptReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptReplaceParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt index 963e093..b546d77 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt @@ -23,19 +23,20 @@ class PromptTest { .description("description") .metadata(Prompt.Metadata.builder().build()) .promptData( - PromptData.builder() + Prompt.PromptData.builder() .options( - PromptData.Options.builder() + Prompt.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + Prompt.PromptData.Options.Params.ofOpenAIModelParams( + Prompt.PromptData.Options.Params.OpenAIModelParams.builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params.OpenAIModelParams .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -45,11 +46,12 @@ class PromptTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params.OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -59,10 +61,11 @@ class PromptTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params.OpenAIModelParams .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -77,17 +80,17 @@ class PromptTest { .build() ) .origin( - PromptData.Origin.builder() + Prompt.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + Prompt.PromptData.Prompt.ofCompletion( + Prompt.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type(Prompt.PromptData.Prompt.Completion.Type.COMPLETION) .build() ) ) @@ -108,18 +111,20 @@ class PromptTest { assertThat(prompt.metadata()).contains(Prompt.Metadata.builder().build()) assertThat(prompt.promptData()) .contains( - PromptData.builder() + Prompt.PromptData.builder() .options( - PromptData.Options.builder() + Prompt.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + Prompt.PromptData.Options.Params.ofOpenAIModelParams( + Prompt.PromptData.Options.Params.OpenAIModelParams.builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + Prompt.PromptData.Options.Params.OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -129,11 +134,12 @@ class PromptTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params.OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -143,9 +149,11 @@ class PromptTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + Prompt.PromptData.Options.Params.OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + Prompt.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -160,17 +168,17 @@ class PromptTest { .build() ) .origin( - PromptData.Origin.builder() + Prompt.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + Prompt.PromptData.Prompt.ofCompletion( + Prompt.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type(Prompt.PromptData.Prompt.Completion.Type.COMPLETION) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt index 915559f..fbbda4a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt @@ -15,18 +15,22 @@ class PromptUpdateParamsTest { .description("description") .name("name") .promptData( - PromptData.builder() + PromptUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptUpdateParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptUpdateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -36,11 +40,13 @@ class PromptUpdateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -50,9 +56,12 @@ class PromptUpdateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -67,17 +76,19 @@ class PromptUpdateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptUpdateParams.PromptData.Prompt.ofCompletion( + PromptUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptUpdateParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) @@ -95,71 +106,86 @@ class PromptUpdateParamsTest { .description("description") .name("name") .promptData( - PromptData.builder() + PromptUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptUpdateParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptUpdateParams.PromptData.Prompt.ofCompletion( + PromptUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -173,18 +199,22 @@ class PromptUpdateParamsTest { assertThat(body.name()).isEqualTo("name") assertThat(body.promptData()) .isEqualTo( - PromptData.builder() + PromptUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() + PromptUpdateParams.PromptData.Options.Params.ofOpenAIModelParams( + PromptUpdateParams.PromptData.Options.Params.OpenAIModelParams + .builder() .frequencyPenalty(42.23) .functionCall( - PromptData.Options.Params.OpenAIModelParams.FunctionCall + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .FunctionCall .Auto .AUTO @@ -194,11 +224,13 @@ class PromptUpdateParamsTest { .n(42.23) .presencePenalty(42.23) .responseFormat( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .builder() .type( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ResponseFormat .Type .JSON_OBJECT @@ -208,9 +240,12 @@ class PromptUpdateParamsTest { .stop(listOf("string")) .temperature(42.23) .toolChoice( - PromptData.Options.Params.OpenAIModelParams.ToolChoice + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice .ofAuto( - PromptData.Options.Params.OpenAIModelParams + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams .ToolChoice .Auto .AUTO @@ -225,17 +260,19 @@ class PromptUpdateParamsTest { .build() ) .origin( - PromptData.Origin.builder() + PromptUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptUpdateParams.PromptData.Prompt.ofCompletion( + PromptUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptUpdateParams.PromptData.Prompt.Completion.Type.COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt index 70e2b88..51ac54d 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt @@ -35,74 +35,92 @@ class FunctionServiceTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionCreateParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionCreateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionCreateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionCreateParams.PromptData.Prompt.ofCompletion( + FunctionCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -155,74 +173,92 @@ class FunctionServiceTest { ) .name("name") .promptData( - PromptData.builder() + FunctionUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionUpdateParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionUpdateParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionUpdateParams.PromptData.Prompt.ofCompletion( + FunctionUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -289,74 +325,92 @@ class FunctionServiceTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + FunctionReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + FunctionReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + FunctionReplaceParams.PromptData.Options.Params + .ofOpenAIModelParams( + FunctionReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + FunctionReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + FunctionReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + FunctionReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + FunctionReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + FunctionReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + FunctionReplaceParams.PromptData.Prompt.ofCompletion( + FunctionReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + FunctionReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt index 5e841d8..e8ecd0c 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt @@ -28,74 +28,89 @@ class PromptServiceTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptCreateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptCreateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptCreateParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptCreateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptCreateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptCreateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptCreateParams.PromptData.Prompt.ofCompletion( + PromptCreateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptCreateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -141,74 +156,89 @@ class PromptServiceTest { .description("description") .name("name") .promptData( - PromptData.builder() + PromptUpdateParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptUpdateParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptUpdateParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptUpdateParams.PromptData.Options.Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptUpdateParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptUpdateParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptUpdateParams.PromptData.Prompt.ofCompletion( + PromptUpdateParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptUpdateParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) ) @@ -268,74 +298,92 @@ class PromptServiceTest { .slug("slug") .description("description") .promptData( - PromptData.builder() + PromptReplaceParams.PromptData.builder() .options( - PromptData.Options.builder() + PromptReplaceParams.PromptData.Options.builder() .model("model") .params( - PromptData.Options.Params.ofOpenAIModelParams( - PromptData.Options.Params.OpenAIModelParams.builder() - .frequencyPenalty(42.23) - .functionCall( - PromptData.Options.Params.OpenAIModelParams - .FunctionCall - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .FunctionCall - .Auto - .AUTO - ) - ) - .maxTokens(42.23) - .n(42.23) - .presencePenalty(42.23) - .responseFormat( - PromptData.Options.Params.OpenAIModelParams - .ResponseFormat - .builder() - .type( - PromptData.Options.Params - .OpenAIModelParams - .ResponseFormat - .Type - .JSON_OBJECT - ) - .build() - ) - .stop(listOf("string")) - .temperature(42.23) - .toolChoice( - PromptData.Options.Params.OpenAIModelParams - .ToolChoice - .ofAuto( - PromptData.Options.Params - .OpenAIModelParams - .ToolChoice - .Auto - .AUTO - ) - ) - .topP(42.23) - .useCache(true) - .build() - ) + PromptReplaceParams.PromptData.Options.Params + .ofOpenAIModelParams( + PromptReplaceParams.PromptData.Options.Params + .OpenAIModelParams + .builder() + .frequencyPenalty(42.23) + .functionCall( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .FunctionCall + .ofAuto( + PromptReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .FunctionCall + .Auto + .AUTO + ) + ) + .maxTokens(42.23) + .n(42.23) + .presencePenalty(42.23) + .responseFormat( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ResponseFormat + .builder() + .type( + PromptReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .ResponseFormat + .Type + .JSON_OBJECT + ) + .build() + ) + .stop(listOf("string")) + .temperature(42.23) + .toolChoice( + PromptReplaceParams.PromptData.Options + .Params + .OpenAIModelParams + .ToolChoice + .ofAuto( + PromptReplaceParams.PromptData + .Options + .Params + .OpenAIModelParams + .ToolChoice + .Auto + .AUTO + ) + ) + .topP(42.23) + .useCache(true) + .build() + ) ) .position("position") .build() ) .origin( - PromptData.Origin.builder() + PromptReplaceParams.PromptData.Origin.builder() .projectId("project_id") .promptId("prompt_id") .promptVersion("prompt_version") .build() ) .prompt( - PromptData.Prompt.ofCompletion( - PromptData.Prompt.Completion.builder() + PromptReplaceParams.PromptData.Prompt.ofCompletion( + PromptReplaceParams.PromptData.Prompt.Completion.builder() .content("content") - .type(PromptData.Prompt.Completion.Type.COMPLETION) + .type( + PromptReplaceParams.PromptData.Prompt.Completion.Type + .COMPLETION + ) .build() ) )