Skip to content

Commit 220503e

Browse files
feat(client): allow setting additional multipart body props
1 parent e89596d commit 220503e

File tree

7 files changed

+463
-38
lines changed

7 files changed

+463
-38
lines changed

openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateParams.kt

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ private constructor(
209209
fun _timestampGranularities(): MultipartField<List<TimestampGranularity>> =
210210
body._timestampGranularities()
211211

212+
fun _additionalBodyProperties(): Map<String, JsonValue> = body._additionalProperties()
213+
212214
fun _additionalHeaders(): Headers = additionalHeaders
213215

214216
fun _additionalQueryParams(): QueryParams = additionalQueryParams
@@ -466,6 +468,25 @@ private constructor(
466468
body.addTimestampGranularity(timestampGranularity)
467469
}
468470

471+
fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
472+
body.additionalProperties(additionalBodyProperties)
473+
}
474+
475+
fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
476+
body.putAdditionalProperty(key, value)
477+
}
478+
479+
fun putAllAdditionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) =
480+
apply {
481+
body.putAllAdditionalProperties(additionalBodyProperties)
482+
}
483+
484+
fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
485+
486+
fun removeAllAdditionalBodyProperties(keys: Set<String>) = apply {
487+
body.removeAllAdditionalProperties(keys)
488+
}
489+
469490
fun additionalHeaders(additionalHeaders: Headers) = apply {
470491
this.additionalHeaders.clear()
471492
putAllAdditionalHeaders(additionalHeaders)
@@ -586,7 +607,7 @@ private constructor(
586607
}
587608

588609
fun _body(): Map<String, MultipartField<*>> =
589-
mapOf(
610+
(mapOf(
590611
"file" to _file(),
591612
"model" to _model(),
592613
"chunking_strategy" to _chunkingStrategy(),
@@ -596,7 +617,7 @@ private constructor(
596617
"response_format" to _responseFormat(),
597618
"temperature" to _temperature(),
598619
"timestamp_granularities" to _timestampGranularities(),
599-
)
620+
) + _additionalBodyProperties().mapValues { MultipartField.of(it) })
600621
.toImmutable()
601622

602623
override fun _headers(): Headers = additionalHeaders
@@ -614,6 +635,7 @@ private constructor(
614635
private val responseFormat: MultipartField<AudioResponseFormat>,
615636
private val temperature: MultipartField<Double>,
616637
private val timestampGranularities: MultipartField<List<TimestampGranularity>>,
638+
private val additionalProperties: MutableMap<String, JsonValue>,
617639
) {
618640

619641
/**
@@ -792,6 +814,16 @@ private constructor(
792814
fun _timestampGranularities(): MultipartField<List<TimestampGranularity>> =
793815
timestampGranularities
794816

817+
@JsonAnySetter
818+
private fun putAdditionalProperty(key: String, value: JsonValue) {
819+
additionalProperties.put(key, value)
820+
}
821+
822+
@JsonAnyGetter
823+
@ExcludeMissing
824+
fun _additionalProperties(): Map<String, JsonValue> =
825+
Collections.unmodifiableMap(additionalProperties)
826+
795827
fun toBuilder() = Builder().from(this)
796828

797829
companion object {
@@ -822,6 +854,7 @@ private constructor(
822854
private var temperature: MultipartField<Double> = MultipartField.of(null)
823855
private var timestampGranularities: MultipartField<MutableList<TimestampGranularity>>? =
824856
null
857+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
825858

826859
@JvmSynthetic
827860
internal fun from(body: Body) = apply {
@@ -834,6 +867,7 @@ private constructor(
834867
responseFormat = body.responseFormat
835868
temperature = body.temperature
836869
timestampGranularities = body.timestampGranularities.map { it.toMutableList() }
870+
additionalProperties = body.additionalProperties.toMutableMap()
837871
}
838872

839873
/**
@@ -1065,6 +1099,25 @@ private constructor(
10651099
}
10661100
}
10671101

1102+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
1103+
this.additionalProperties.clear()
1104+
putAllAdditionalProperties(additionalProperties)
1105+
}
1106+
1107+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
1108+
additionalProperties.put(key, value)
1109+
}
1110+
1111+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
1112+
this.additionalProperties.putAll(additionalProperties)
1113+
}
1114+
1115+
fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
1116+
1117+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
1118+
keys.forEach(::removeAdditionalProperty)
1119+
}
1120+
10681121
/**
10691122
* Returns an immutable instance of [Body].
10701123
*
@@ -1089,6 +1142,7 @@ private constructor(
10891142
responseFormat,
10901143
temperature,
10911144
(timestampGranularities ?: MultipartField.of(null)).map { it.toImmutable() },
1145+
additionalProperties.toMutableMap(),
10921146
)
10931147
}
10941148

@@ -1124,17 +1178,17 @@ private constructor(
11241178
return true
11251179
}
11261180

1127-
return /* spotless:off */ other is Body && file == other.file && model == other.model && chunkingStrategy == other.chunkingStrategy && include == other.include && language == other.language && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature && timestampGranularities == other.timestampGranularities /* spotless:on */
1181+
return /* spotless:off */ other is Body && file == other.file && model == other.model && chunkingStrategy == other.chunkingStrategy && include == other.include && language == other.language && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature && timestampGranularities == other.timestampGranularities && additionalProperties == other.additionalProperties /* spotless:on */
11281182
}
11291183

11301184
/* spotless:off */
1131-
private val hashCode: Int by lazy { Objects.hash(file, model, chunkingStrategy, include, language, prompt, responseFormat, temperature, timestampGranularities) }
1185+
private val hashCode: Int by lazy { Objects.hash(file, model, chunkingStrategy, include, language, prompt, responseFormat, temperature, timestampGranularities, additionalProperties) }
11321186
/* spotless:on */
11331187

11341188
override fun hashCode(): Int = hashCode
11351189

11361190
override fun toString() =
1137-
"Body{file=$file, model=$model, chunkingStrategy=$chunkingStrategy, include=$include, language=$language, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature, timestampGranularities=$timestampGranularities}"
1191+
"Body{file=$file, model=$model, chunkingStrategy=$chunkingStrategy, include=$include, language=$language, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature, timestampGranularities=$timestampGranularities, additionalProperties=$additionalProperties}"
11381192
}
11391193

11401194
/**

openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateParams.kt

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
package com.openai.models.audio.translations
44

5+
import com.fasterxml.jackson.annotation.JsonAnyGetter
6+
import com.fasterxml.jackson.annotation.JsonAnySetter
57
import com.fasterxml.jackson.annotation.JsonCreator
68
import com.fasterxml.jackson.annotation.JsonProperty
79
import com.openai.core.Enum
810
import com.openai.core.ExcludeMissing
911
import com.openai.core.JsonField
12+
import com.openai.core.JsonValue
1013
import com.openai.core.MultipartField
1114
import com.openai.core.Params
1215
import com.openai.core.checkRequired
@@ -17,6 +20,7 @@ import com.openai.errors.OpenAIInvalidDataException
1720
import com.openai.models.audio.AudioModel
1821
import java.io.InputStream
1922
import java.nio.file.Path
23+
import java.util.Collections
2024
import java.util.Objects
2125
import java.util.Optional
2226
import kotlin.io.path.inputStream
@@ -115,6 +119,8 @@ private constructor(
115119
*/
116120
fun _temperature(): MultipartField<Double> = body._temperature()
117121

122+
fun _additionalBodyProperties(): Map<String, JsonValue> = body._additionalProperties()
123+
118124
fun _additionalHeaders(): Headers = additionalHeaders
119125

120126
fun _additionalQueryParams(): QueryParams = additionalQueryParams
@@ -267,6 +273,25 @@ private constructor(
267273
body.temperature(temperature)
268274
}
269275

276+
fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
277+
body.additionalProperties(additionalBodyProperties)
278+
}
279+
280+
fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
281+
body.putAdditionalProperty(key, value)
282+
}
283+
284+
fun putAllAdditionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) =
285+
apply {
286+
body.putAllAdditionalProperties(additionalBodyProperties)
287+
}
288+
289+
fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
290+
291+
fun removeAllAdditionalBodyProperties(keys: Set<String>) = apply {
292+
body.removeAllAdditionalProperties(keys)
293+
}
294+
270295
fun additionalHeaders(additionalHeaders: Headers) = apply {
271296
this.additionalHeaders.clear()
272297
putAllAdditionalHeaders(additionalHeaders)
@@ -387,13 +412,13 @@ private constructor(
387412
}
388413

389414
fun _body(): Map<String, MultipartField<*>> =
390-
mapOf(
415+
(mapOf(
391416
"file" to _file(),
392417
"model" to _model(),
393418
"prompt" to _prompt(),
394419
"response_format" to _responseFormat(),
395420
"temperature" to _temperature(),
396-
)
421+
) + _additionalBodyProperties().mapValues { MultipartField.of(it) })
397422
.toImmutable()
398423

399424
override fun _headers(): Headers = additionalHeaders
@@ -407,6 +432,7 @@ private constructor(
407432
private val prompt: MultipartField<String>,
408433
private val responseFormat: MultipartField<ResponseFormat>,
409434
private val temperature: MultipartField<Double>,
435+
private val additionalProperties: MutableMap<String, JsonValue>,
410436
) {
411437

412438
/**
@@ -500,6 +526,16 @@ private constructor(
500526
@ExcludeMissing
501527
fun _temperature(): MultipartField<Double> = temperature
502528

529+
@JsonAnySetter
530+
private fun putAdditionalProperty(key: String, value: JsonValue) {
531+
additionalProperties.put(key, value)
532+
}
533+
534+
@JsonAnyGetter
535+
@ExcludeMissing
536+
fun _additionalProperties(): Map<String, JsonValue> =
537+
Collections.unmodifiableMap(additionalProperties)
538+
503539
fun toBuilder() = Builder().from(this)
504540

505541
companion object {
@@ -524,6 +560,7 @@ private constructor(
524560
private var prompt: MultipartField<String> = MultipartField.of(null)
525561
private var responseFormat: MultipartField<ResponseFormat> = MultipartField.of(null)
526562
private var temperature: MultipartField<Double> = MultipartField.of(null)
563+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
527564

528565
@JvmSynthetic
529566
internal fun from(body: Body) = apply {
@@ -532,6 +569,7 @@ private constructor(
532569
prompt = body.prompt
533570
responseFormat = body.responseFormat
534571
temperature = body.temperature
572+
additionalProperties = body.additionalProperties.toMutableMap()
535573
}
536574

537575
/**
@@ -645,6 +683,25 @@ private constructor(
645683
this.temperature = temperature
646684
}
647685

686+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
687+
this.additionalProperties.clear()
688+
putAllAdditionalProperties(additionalProperties)
689+
}
690+
691+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
692+
additionalProperties.put(key, value)
693+
}
694+
695+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
696+
this.additionalProperties.putAll(additionalProperties)
697+
}
698+
699+
fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
700+
701+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
702+
keys.forEach(::removeAdditionalProperty)
703+
}
704+
648705
/**
649706
* Returns an immutable instance of [Body].
650707
*
@@ -665,6 +722,7 @@ private constructor(
665722
prompt,
666723
responseFormat,
667724
temperature,
725+
additionalProperties.toMutableMap(),
668726
)
669727
}
670728

@@ -696,17 +754,17 @@ private constructor(
696754
return true
697755
}
698756

699-
return /* spotless:off */ other is Body && file == other.file && model == other.model && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature /* spotless:on */
757+
return /* spotless:off */ other is Body && file == other.file && model == other.model && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature && additionalProperties == other.additionalProperties /* spotless:on */
700758
}
701759

702760
/* spotless:off */
703-
private val hashCode: Int by lazy { Objects.hash(file, model, prompt, responseFormat, temperature) }
761+
private val hashCode: Int by lazy { Objects.hash(file, model, prompt, responseFormat, temperature, additionalProperties) }
704762
/* spotless:on */
705763

706764
override fun hashCode(): Int = hashCode
707765

708766
override fun toString() =
709-
"Body{file=$file, model=$model, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature}"
767+
"Body{file=$file, model=$model, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature, additionalProperties=$additionalProperties}"
710768
}
711769

712770
/**

0 commit comments

Comments
 (0)