@@ -21,39 +21,46 @@ import java.util.Optional
21
21
22
22
class BatchCreateParams
23
23
constructor (
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 ,
28
25
private val additionalHeaders: Headers ,
29
26
private val additionalQueryParams: QueryParams ,
30
- private val additionalBodyProperties: Map <String , JsonValue >,
31
27
) {
32
28
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()
34
53
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()
40
56
41
57
fun _additionalHeaders (): Headers = additionalHeaders
42
58
43
59
fun _additionalQueryParams (): QueryParams = additionalQueryParams
44
60
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
57
64
58
65
@JvmSynthetic internal fun getHeaders (): Headers = additionalHeaders
59
66
@@ -221,31 +228,23 @@ constructor(
221
228
@NoAutoDetect
222
229
class Builder {
223
230
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()
228
232
private var additionalHeaders: Headers .Builder = Headers .builder()
229
233
private var additionalQueryParams: QueryParams .Builder = QueryParams .builder()
230
- private var additionalBodyProperties: MutableMap <String , JsonValue > = mutableMapOf ()
231
234
232
235
@JvmSynthetic
233
236
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()
238
238
additionalHeaders = batchCreateParams.additionalHeaders.toBuilder()
239
239
additionalQueryParams = batchCreateParams.additionalQueryParams.toBuilder()
240
- additionalBodyProperties = batchCreateParams.additionalBodyProperties.toMutableMap()
241
240
}
242
241
243
242
/* *
244
243
* The time frame within which the batch should be processed. Currently only `24h` is
245
244
* supported.
246
245
*/
247
246
fun completionWindow (completionWindow : CompletionWindow ) = apply {
248
- this .completionWindow = completionWindow
247
+ body .completionWindow( completionWindow)
249
248
}
250
249
251
250
/* *
@@ -254,7 +253,7 @@ constructor(
254
253
* are also restricted to a maximum of 50,000 embedding inputs across all requests in the
255
254
* batch.
256
255
*/
257
- fun endpoint (endpoint : Endpoint ) = apply { this .endpoint = endpoint }
256
+ fun endpoint (endpoint : Endpoint ) = apply { body .endpoint( endpoint) }
258
257
259
258
/* *
260
259
* The ID of an uploaded file that contains requests for the new batch.
@@ -267,10 +266,10 @@ constructor(
267
266
* must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests,
268
267
* and can be up to 200 MB in size.
269
268
*/
270
- fun inputFileId (inputFileId : String ) = apply { this .inputFileId = inputFileId }
269
+ fun inputFileId (inputFileId : String ) = apply { body .inputFileId( inputFileId) }
271
270
272
271
/* * Optional custom metadata for the batch. */
273
- fun metadata (metadata : Metadata ) = apply { this .metadata = metadata }
272
+ fun metadata (metadata : Metadata ) = apply { body .metadata( metadata) }
274
273
275
274
fun additionalHeaders (additionalHeaders : Headers ) = apply {
276
275
this .additionalHeaders.clear()
@@ -371,36 +370,29 @@ constructor(
371
370
}
372
371
373
372
fun additionalBodyProperties (additionalBodyProperties : Map <String , JsonValue >) = apply {
374
- this .additionalBodyProperties.clear()
375
- putAllAdditionalBodyProperties(additionalBodyProperties)
373
+ body.additionalProperties(additionalBodyProperties)
376
374
}
377
375
378
376
fun putAdditionalBodyProperty (key : String , value : JsonValue ) = apply {
379
- additionalBodyProperties.put (key, value)
377
+ body.putAdditionalProperty (key, value)
380
378
}
381
379
382
380
fun putAllAdditionalBodyProperties (additionalBodyProperties : Map <String , JsonValue >) =
383
381
apply {
384
- this .additionalBodyProperties.putAll (additionalBodyProperties)
382
+ body.putAllAdditionalProperties (additionalBodyProperties)
385
383
}
386
384
387
- fun removeAdditionalBodyProperty (key : String ) = apply {
388
- additionalBodyProperties.remove(key)
389
- }
385
+ fun removeAdditionalBodyProperty (key : String ) = apply { body.removeAdditionalProperty(key) }
390
386
391
387
fun removeAllAdditionalBodyProperties (keys : Set <String >) = apply {
392
- keys.forEach(::removeAdditionalBodyProperty )
388
+ body.removeAllAdditionalProperties(keys )
393
389
}
394
390
395
391
fun build (): BatchCreateParams =
396
392
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(),
401
394
additionalHeaders.build(),
402
395
additionalQueryParams.build(),
403
- additionalBodyProperties.toImmutable(),
404
396
)
405
397
}
406
398
@@ -591,11 +583,11 @@ constructor(
591
583
return true
592
584
}
593
585
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 */
595
587
}
596
588
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 */
598
590
599
591
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 }"
601
593
}
0 commit comments