Skip to content

Commit 1c6e875

Browse files
feat(client): allow providing some params positionally
1 parent d9af1fb commit 1c6e875

File tree

199 files changed

+7333
-1533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+7333
-1533
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,7 @@ These methods return [`HttpResponse`](openai-java-core/src/main/kotlin/com/opena
412412
import com.openai.core.http.HttpResponse;
413413
import com.openai.models.files.FileContentParams;
414414

415-
FileContentParams params = FileContentParams.builder()
416-
.fileId("file_id")
417-
.build();
418-
HttpResponse response = client.files().content(params);
415+
HttpResponse response = client.files().content("file_id");
419416
```
420417

421418
To save the response content to a file, use the [`Files.copy(...)`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#copy-java.io.InputStream-java.nio.file.Path-java.nio.file.CopyOption...-) method:

openai-java-core/src/main/kotlin/com/openai/core/Check.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ package com.openai.core
55
import com.fasterxml.jackson.core.Version
66
import com.fasterxml.jackson.core.util.VersionUtil
77

8+
fun checkRequired(name: String, condition: Boolean) =
9+
check(condition) { "`$name` is required, but was not set" }
10+
811
fun <T : Any> checkRequired(name: String, value: T?): T =
912
checkNotNull(value) { "`$name` is required, but was not set" }
1013

openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCancelParams.kt

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ package com.openai.models.batches
44

55
import com.openai.core.JsonValue
66
import com.openai.core.Params
7-
import com.openai.core.checkRequired
87
import com.openai.core.http.Headers
98
import com.openai.core.http.QueryParams
109
import com.openai.core.toImmutable
1110
import java.util.Objects
1211
import java.util.Optional
12+
import kotlin.jvm.optionals.getOrNull
1313

1414
/**
1515
* Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes,
@@ -18,13 +18,13 @@ import java.util.Optional
1818
*/
1919
class BatchCancelParams
2020
private constructor(
21-
private val batchId: String,
21+
private val batchId: String?,
2222
private val additionalHeaders: Headers,
2323
private val additionalQueryParams: QueryParams,
2424
private val additionalBodyProperties: Map<String, JsonValue>,
2525
) : Params {
2626

27-
fun batchId(): String = batchId
27+
fun batchId(): Optional<String> = Optional.ofNullable(batchId)
2828

2929
fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties
3030

@@ -36,14 +36,9 @@ private constructor(
3636

3737
companion object {
3838

39-
/**
40-
* Returns a mutable builder for constructing an instance of [BatchCancelParams].
41-
*
42-
* The following fields are required:
43-
* ```java
44-
* .batchId()
45-
* ```
46-
*/
39+
@JvmStatic fun none(): BatchCancelParams = builder().build()
40+
41+
/** Returns a mutable builder for constructing an instance of [BatchCancelParams]. */
4742
@JvmStatic fun builder() = Builder()
4843
}
4944

@@ -63,7 +58,10 @@ private constructor(
6358
additionalBodyProperties = batchCancelParams.additionalBodyProperties.toMutableMap()
6459
}
6560

66-
fun batchId(batchId: String) = apply { this.batchId = batchId }
61+
fun batchId(batchId: String?) = apply { this.batchId = batchId }
62+
63+
/** Alias for calling [Builder.batchId] with `batchId.orElse(null)`. */
64+
fun batchId(batchId: Optional<String>) = batchId(batchId.getOrNull())
6765

6866
fun additionalHeaders(additionalHeaders: Headers) = apply {
6967
this.additionalHeaders.clear()
@@ -189,17 +187,10 @@ private constructor(
189187
* Returns an immutable instance of [BatchCancelParams].
190188
*
191189
* Further updates to this [Builder] will not mutate the returned instance.
192-
*
193-
* The following fields are required:
194-
* ```java
195-
* .batchId()
196-
* ```
197-
*
198-
* @throws IllegalStateException if any required field is unset.
199190
*/
200191
fun build(): BatchCancelParams =
201192
BatchCancelParams(
202-
checkRequired("batchId", batchId),
193+
batchId,
203194
additionalHeaders.build(),
204195
additionalQueryParams.build(),
205196
additionalBodyProperties.toImmutable(),
@@ -211,7 +202,7 @@ private constructor(
211202

212203
fun _pathParam(index: Int): String =
213204
when (index) {
214-
0 -> batchId
205+
0 -> batchId ?: ""
215206
else -> ""
216207
}
217208

openai-java-core/src/main/kotlin/com/openai/models/batches/BatchRetrieveParams.kt

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
package com.openai.models.batches
44

55
import com.openai.core.Params
6-
import com.openai.core.checkRequired
76
import com.openai.core.http.Headers
87
import com.openai.core.http.QueryParams
98
import java.util.Objects
9+
import java.util.Optional
10+
import kotlin.jvm.optionals.getOrNull
1011

1112
/** Retrieves a batch. */
1213
class BatchRetrieveParams
1314
private constructor(
14-
private val batchId: String,
15+
private val batchId: String?,
1516
private val additionalHeaders: Headers,
1617
private val additionalQueryParams: QueryParams,
1718
) : Params {
1819

19-
fun batchId(): String = batchId
20+
fun batchId(): Optional<String> = Optional.ofNullable(batchId)
2021

2122
fun _additionalHeaders(): Headers = additionalHeaders
2223

@@ -26,14 +27,9 @@ private constructor(
2627

2728
companion object {
2829

29-
/**
30-
* Returns a mutable builder for constructing an instance of [BatchRetrieveParams].
31-
*
32-
* The following fields are required:
33-
* ```java
34-
* .batchId()
35-
* ```
36-
*/
30+
@JvmStatic fun none(): BatchRetrieveParams = builder().build()
31+
32+
/** Returns a mutable builder for constructing an instance of [BatchRetrieveParams]. */
3733
@JvmStatic fun builder() = Builder()
3834
}
3935

@@ -51,7 +47,10 @@ private constructor(
5147
additionalQueryParams = batchRetrieveParams.additionalQueryParams.toBuilder()
5248
}
5349

54-
fun batchId(batchId: String) = apply { this.batchId = batchId }
50+
fun batchId(batchId: String?) = apply { this.batchId = batchId }
51+
52+
/** Alias for calling [Builder.batchId] with `batchId.orElse(null)`. */
53+
fun batchId(batchId: Optional<String>) = batchId(batchId.getOrNull())
5554

5655
fun additionalHeaders(additionalHeaders: Headers) = apply {
5756
this.additionalHeaders.clear()
@@ -155,25 +154,14 @@ private constructor(
155154
* Returns an immutable instance of [BatchRetrieveParams].
156155
*
157156
* Further updates to this [Builder] will not mutate the returned instance.
158-
*
159-
* The following fields are required:
160-
* ```java
161-
* .batchId()
162-
* ```
163-
*
164-
* @throws IllegalStateException if any required field is unset.
165157
*/
166158
fun build(): BatchRetrieveParams =
167-
BatchRetrieveParams(
168-
checkRequired("batchId", batchId),
169-
additionalHeaders.build(),
170-
additionalQueryParams.build(),
171-
)
159+
BatchRetrieveParams(batchId, additionalHeaders.build(), additionalQueryParams.build())
172160
}
173161

174162
fun _pathParam(index: Int): String =
175163
when (index) {
176-
0 -> batchId
164+
0 -> batchId ?: ""
177165
else -> ""
178166
}
179167

openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantDeleteParams.kt

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ package com.openai.models.beta.assistants
44

55
import com.openai.core.JsonValue
66
import com.openai.core.Params
7-
import com.openai.core.checkRequired
87
import com.openai.core.http.Headers
98
import com.openai.core.http.QueryParams
109
import com.openai.core.toImmutable
1110
import java.util.Objects
1211
import java.util.Optional
12+
import kotlin.jvm.optionals.getOrNull
1313

1414
/** Delete an assistant. */
1515
class AssistantDeleteParams
1616
private constructor(
17-
private val assistantId: String,
17+
private val assistantId: String?,
1818
private val additionalHeaders: Headers,
1919
private val additionalQueryParams: QueryParams,
2020
private val additionalBodyProperties: Map<String, JsonValue>,
2121
) : Params {
2222

23-
fun assistantId(): String = assistantId
23+
fun assistantId(): Optional<String> = Optional.ofNullable(assistantId)
2424

2525
fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties
2626

@@ -32,14 +32,9 @@ private constructor(
3232

3333
companion object {
3434

35-
/**
36-
* Returns a mutable builder for constructing an instance of [AssistantDeleteParams].
37-
*
38-
* The following fields are required:
39-
* ```java
40-
* .assistantId()
41-
* ```
42-
*/
35+
@JvmStatic fun none(): AssistantDeleteParams = builder().build()
36+
37+
/** Returns a mutable builder for constructing an instance of [AssistantDeleteParams]. */
4338
@JvmStatic fun builder() = Builder()
4439
}
4540

@@ -59,7 +54,10 @@ private constructor(
5954
additionalBodyProperties = assistantDeleteParams.additionalBodyProperties.toMutableMap()
6055
}
6156

62-
fun assistantId(assistantId: String) = apply { this.assistantId = assistantId }
57+
fun assistantId(assistantId: String?) = apply { this.assistantId = assistantId }
58+
59+
/** Alias for calling [Builder.assistantId] with `assistantId.orElse(null)`. */
60+
fun assistantId(assistantId: Optional<String>) = assistantId(assistantId.getOrNull())
6361

6462
fun additionalHeaders(additionalHeaders: Headers) = apply {
6563
this.additionalHeaders.clear()
@@ -185,17 +183,10 @@ private constructor(
185183
* Returns an immutable instance of [AssistantDeleteParams].
186184
*
187185
* Further updates to this [Builder] will not mutate the returned instance.
188-
*
189-
* The following fields are required:
190-
* ```java
191-
* .assistantId()
192-
* ```
193-
*
194-
* @throws IllegalStateException if any required field is unset.
195186
*/
196187
fun build(): AssistantDeleteParams =
197188
AssistantDeleteParams(
198-
checkRequired("assistantId", assistantId),
189+
assistantId,
199190
additionalHeaders.build(),
200191
additionalQueryParams.build(),
201192
additionalBodyProperties.toImmutable(),
@@ -207,7 +198,7 @@ private constructor(
207198

208199
fun _pathParam(index: Int): String =
209200
when (index) {
210-
0 -> assistantId
201+
0 -> assistantId ?: ""
211202
else -> ""
212203
}
213204

openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantRetrieveParams.kt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
package com.openai.models.beta.assistants
44

55
import com.openai.core.Params
6-
import com.openai.core.checkRequired
76
import com.openai.core.http.Headers
87
import com.openai.core.http.QueryParams
98
import java.util.Objects
9+
import java.util.Optional
10+
import kotlin.jvm.optionals.getOrNull
1011

1112
/** Retrieves an assistant. */
1213
class AssistantRetrieveParams
1314
private constructor(
14-
private val assistantId: String,
15+
private val assistantId: String?,
1516
private val additionalHeaders: Headers,
1617
private val additionalQueryParams: QueryParams,
1718
) : Params {
1819

19-
fun assistantId(): String = assistantId
20+
fun assistantId(): Optional<String> = Optional.ofNullable(assistantId)
2021

2122
fun _additionalHeaders(): Headers = additionalHeaders
2223

@@ -26,14 +27,9 @@ private constructor(
2627

2728
companion object {
2829

29-
/**
30-
* Returns a mutable builder for constructing an instance of [AssistantRetrieveParams].
31-
*
32-
* The following fields are required:
33-
* ```java
34-
* .assistantId()
35-
* ```
36-
*/
30+
@JvmStatic fun none(): AssistantRetrieveParams = builder().build()
31+
32+
/** Returns a mutable builder for constructing an instance of [AssistantRetrieveParams]. */
3733
@JvmStatic fun builder() = Builder()
3834
}
3935

@@ -51,7 +47,10 @@ private constructor(
5147
additionalQueryParams = assistantRetrieveParams.additionalQueryParams.toBuilder()
5248
}
5349

54-
fun assistantId(assistantId: String) = apply { this.assistantId = assistantId }
50+
fun assistantId(assistantId: String?) = apply { this.assistantId = assistantId }
51+
52+
/** Alias for calling [Builder.assistantId] with `assistantId.orElse(null)`. */
53+
fun assistantId(assistantId: Optional<String>) = assistantId(assistantId.getOrNull())
5554

5655
fun additionalHeaders(additionalHeaders: Headers) = apply {
5756
this.additionalHeaders.clear()
@@ -155,25 +154,18 @@ private constructor(
155154
* Returns an immutable instance of [AssistantRetrieveParams].
156155
*
157156
* Further updates to this [Builder] will not mutate the returned instance.
158-
*
159-
* The following fields are required:
160-
* ```java
161-
* .assistantId()
162-
* ```
163-
*
164-
* @throws IllegalStateException if any required field is unset.
165157
*/
166158
fun build(): AssistantRetrieveParams =
167159
AssistantRetrieveParams(
168-
checkRequired("assistantId", assistantId),
160+
assistantId,
169161
additionalHeaders.build(),
170162
additionalQueryParams.build(),
171163
)
172164
}
173165

174166
fun _pathParam(index: Int): String =
175167
when (index) {
176-
0 -> assistantId
168+
0 -> assistantId ?: ""
177169
else -> ""
178170
}
179171

0 commit comments

Comments
 (0)