@@ -21,39 +21,46 @@ import java.util.Optional
2121
2222class BatchCreateParams
2323constructor (
24- private val completionWindow: CompletionWindow ,
25- private val endpoint: Endpoint ,
26- private val inputFileId: String ,
27- private val metadata: Metadata ? ,
24+ private val body: BatchCreateBody ,
2825 private val additionalHeaders: Headers ,
2926 private val additionalQueryParams: QueryParams ,
30- private val additionalBodyProperties: Map <String , JsonValue >,
3127) {
3228
33- fun completionWindow (): CompletionWindow = completionWindow
29+ /* *
30+ * The time frame within which the batch should be processed. Currently only `24h` is supported.
31+ */
32+ fun completionWindow (): CompletionWindow = body.completionWindow()
33+
34+ /* *
35+ * The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`,
36+ * `/v1/embeddings`, and `/v1/completions` are supported. Note that `/v1/embeddings` batches are
37+ * also restricted to a maximum of 50,000 embedding inputs across all requests in the batch.
38+ */
39+ fun endpoint (): Endpoint = body.endpoint()
40+
41+ /* *
42+ * The ID of an uploaded file that contains requests for the new batch.
43+ *
44+ * See [upload file](https://platform.openai.com/docs/api-reference/files/create) for how to
45+ * upload a file.
46+ *
47+ * Your input file must be formatted as a
48+ * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input), and must be
49+ * uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up
50+ * to 200 MB in size.
51+ */
52+ fun inputFileId (): String = body.inputFileId()
3453
35- fun endpoint (): Endpoint = endpoint
36-
37- fun inputFileId (): String = inputFileId
38-
39- fun metadata (): Optional <Metadata > = Optional .ofNullable(metadata)
54+ /* * Optional custom metadata for the batch. */
55+ fun metadata (): Optional <Metadata > = body.metadata()
4056
4157 fun _additionalHeaders (): Headers = additionalHeaders
4258
4359 fun _additionalQueryParams (): QueryParams = additionalQueryParams
4460
45- fun _additionalBodyProperties (): Map <String , JsonValue > = additionalBodyProperties
46-
47- @JvmSynthetic
48- internal fun getBody (): BatchCreateBody {
49- return BatchCreateBody (
50- completionWindow,
51- endpoint,
52- inputFileId,
53- metadata,
54- additionalBodyProperties,
55- )
56- }
61+ fun _additionalBodyProperties (): Map <String , JsonValue > = body._additionalProperties ()
62+
63+ @JvmSynthetic internal fun getBody (): BatchCreateBody = body
5764
5865 @JvmSynthetic internal fun getHeaders (): Headers = additionalHeaders
5966
@@ -221,31 +228,23 @@ constructor(
221228 @NoAutoDetect
222229 class Builder {
223230
224- private var completionWindow: CompletionWindow ? = null
225- private var endpoint: Endpoint ? = null
226- private var inputFileId: String? = null
227- private var metadata: Metadata ? = null
231+ private var body: BatchCreateBody .Builder = BatchCreateBody .builder()
228232 private var additionalHeaders: Headers .Builder = Headers .builder()
229233 private var additionalQueryParams: QueryParams .Builder = QueryParams .builder()
230- private var additionalBodyProperties: MutableMap <String , JsonValue > = mutableMapOf ()
231234
232235 @JvmSynthetic
233236 internal fun from (batchCreateParams : BatchCreateParams ) = apply {
234- completionWindow = batchCreateParams.completionWindow
235- endpoint = batchCreateParams.endpoint
236- inputFileId = batchCreateParams.inputFileId
237- metadata = batchCreateParams.metadata
237+ body = batchCreateParams.body.toBuilder()
238238 additionalHeaders = batchCreateParams.additionalHeaders.toBuilder()
239239 additionalQueryParams = batchCreateParams.additionalQueryParams.toBuilder()
240- additionalBodyProperties = batchCreateParams.additionalBodyProperties.toMutableMap()
241240 }
242241
243242 /* *
244243 * The time frame within which the batch should be processed. Currently only `24h` is
245244 * supported.
246245 */
247246 fun completionWindow (completionWindow : CompletionWindow ) = apply {
248- this .completionWindow = completionWindow
247+ body .completionWindow( completionWindow)
249248 }
250249
251250 /* *
@@ -254,7 +253,7 @@ constructor(
254253 * are also restricted to a maximum of 50,000 embedding inputs across all requests in the
255254 * batch.
256255 */
257- fun endpoint (endpoint : Endpoint ) = apply { this .endpoint = endpoint }
256+ fun endpoint (endpoint : Endpoint ) = apply { body .endpoint( endpoint) }
258257
259258 /* *
260259 * The ID of an uploaded file that contains requests for the new batch.
@@ -267,10 +266,10 @@ constructor(
267266 * must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests,
268267 * and can be up to 200 MB in size.
269268 */
270- fun inputFileId (inputFileId : String ) = apply { this .inputFileId = inputFileId }
269+ fun inputFileId (inputFileId : String ) = apply { body .inputFileId( inputFileId) }
271270
272271 /* * Optional custom metadata for the batch. */
273- fun metadata (metadata : Metadata ) = apply { this .metadata = metadata }
272+ fun metadata (metadata : Metadata ) = apply { body .metadata( metadata) }
274273
275274 fun additionalHeaders (additionalHeaders : Headers ) = apply {
276275 this .additionalHeaders.clear()
@@ -371,36 +370,29 @@ constructor(
371370 }
372371
373372 fun additionalBodyProperties (additionalBodyProperties : Map <String , JsonValue >) = apply {
374- this .additionalBodyProperties.clear()
375- putAllAdditionalBodyProperties(additionalBodyProperties)
373+ body.additionalProperties(additionalBodyProperties)
376374 }
377375
378376 fun putAdditionalBodyProperty (key : String , value : JsonValue ) = apply {
379- additionalBodyProperties.put (key, value)
377+ body.putAdditionalProperty (key, value)
380378 }
381379
382380 fun putAllAdditionalBodyProperties (additionalBodyProperties : Map <String , JsonValue >) =
383381 apply {
384- this .additionalBodyProperties.putAll (additionalBodyProperties)
382+ body.putAllAdditionalProperties (additionalBodyProperties)
385383 }
386384
387- fun removeAdditionalBodyProperty (key : String ) = apply {
388- additionalBodyProperties.remove(key)
389- }
385+ fun removeAdditionalBodyProperty (key : String ) = apply { body.removeAdditionalProperty(key) }
390386
391387 fun removeAllAdditionalBodyProperties (keys : Set <String >) = apply {
392- keys.forEach(::removeAdditionalBodyProperty )
388+ body.removeAllAdditionalProperties(keys )
393389 }
394390
395391 fun build (): BatchCreateParams =
396392 BatchCreateParams (
397- checkNotNull(completionWindow) { " `completionWindow` is required but was not set" },
398- checkNotNull(endpoint) { " `endpoint` is required but was not set" },
399- checkNotNull(inputFileId) { " `inputFileId` is required but was not set" },
400- metadata,
393+ body.build(),
401394 additionalHeaders.build(),
402395 additionalQueryParams.build(),
403- additionalBodyProperties.toImmutable(),
404396 )
405397 }
406398
@@ -591,11 +583,11 @@ constructor(
591583 return true
592584 }
593585
594- return /* spotless:off */ other is BatchCreateParams && completionWindow == other.completionWindow && endpoint == other.endpoint && inputFileId == other.inputFileId && metadata == other.metadata && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
586+ return /* spotless:off */ other is BatchCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
595587 }
596588
597- override fun hashCode (): Int = /* spotless:off */ Objects .hash(completionWindow, endpoint, inputFileId, metadata, additionalHeaders, additionalQueryParams, additionalBodyProperties ) /* spotless:on */
589+ override fun hashCode (): Int = /* spotless:off */ Objects .hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
598590
599591 override fun toString () =
600- " BatchCreateParams{completionWindow= $completionWindow , endpoint= $endpoint , inputFileId= $inputFileId , metadata= $metadata , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams , additionalBodyProperties= $additionalBodyProperties }"
592+ " BatchCreateParams{body= $body , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams }"
601593}
0 commit comments