Skip to content

Commit ec756b9

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(client): helpers for discriminated union variants with one required prop (#182)
1 parent b7ebe5d commit ec756b9

26 files changed

+418
-42
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ To create a new chat completion, first use the `ChatCompletionCreateParams` buil
9393
```java
9494
import com.openai.models.ChatCompletion;
9595
import com.openai.models.ChatCompletionCreateParams;
96-
import com.openai.models.ChatCompletionUserMessageParam;
9796
import com.openai.models.ChatModel;
9897

9998
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
100-
.addMessage(ChatCompletionUserMessageParam.builder()
101-
.content("Say this is a test")
102-
.build())
99+
.addUserMessage("Say this is a test")
103100
.model(ChatModel.O1)
104101
.build();
105102
ChatCompletion chatCompletion = client.chat().completions().create(params);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ private constructor(
423423
*/
424424
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))
425425

426+
/**
427+
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
428+
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
429+
*/
430+
fun addFunctionTool(function: FunctionDefinition) =
431+
addTool(FunctionTool.builder().function(function).build())
432+
426433
/**
427434
* Specifies the format that the model must output. Compatible with
428435
* [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,13 @@ private constructor(
786786
*/
787787
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))
788788

789+
/**
790+
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
791+
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
792+
*/
793+
fun addFunctionTool(function: FunctionDefinition) =
794+
addTool(FunctionTool.builder().function(function).build())
795+
789796
/**
790797
* An alternative to sampling with temperature, called nucleus sampling, where the model
791798
* considers the results of the tokens with top_p probability mass. So 0.1 means only
@@ -1205,6 +1212,12 @@ private constructor(
12051212
*/
12061213
fun addTool(function: FunctionTool) = apply { body.addTool(function) }
12071214

1215+
/**
1216+
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
1217+
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
1218+
*/
1219+
fun addFunctionTool(function: FunctionDefinition) = apply { body.addFunctionTool(function) }
1220+
12081221
/**
12091222
* An alternative to sampling with temperature, called nucleus sampling, where the model
12101223
* considers the results of the tokens with top_p probability mass. So 0.1 means only the
@@ -1941,6 +1954,15 @@ private constructor(
19411954
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
19421955
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
19431956

1957+
/**
1958+
* The chunking strategy used to chunk the file(s). If not set, will use the
1959+
* `auto` strategy. Only applicable if `file_ids` is non-empty.
1960+
*/
1961+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
1962+
chunkingStrategy(
1963+
StaticFileChunkingStrategyObjectParam.builder().static_(static_).build()
1964+
)
1965+
19441966
/**
19451967
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
19461968
* add to the vector store. There can be a maximum of 10000 files in a vector

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,13 @@ private constructor(
788788
*/
789789
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))
790790

791+
/**
792+
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
793+
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
794+
*/
795+
fun addFunctionTool(function: FunctionDefinition) =
796+
addTool(FunctionTool.builder().function(function).build())
797+
791798
/**
792799
* An alternative to sampling with temperature, called nucleus sampling, where the model
793800
* considers the results of the tokens with top_p probability mass. So 0.1 means only
@@ -1203,6 +1210,12 @@ private constructor(
12031210
*/
12041211
fun addTool(function: FunctionTool) = apply { body.addTool(function) }
12051212

1213+
/**
1214+
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
1215+
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
1216+
*/
1217+
fun addFunctionTool(function: FunctionDefinition) = apply { body.addFunctionTool(function) }
1218+
12061219
/**
12071220
* An alternative to sampling with temperature, called nucleus sampling, where the model
12081221
* considers the results of the tokens with top_p probability mass. So 0.1 means only the

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,17 @@ private constructor(
35533553
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
35543554
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
35553555

3556+
/**
3557+
* The chunking strategy used to chunk the file(s). If not set, will use the
3558+
* `auto` strategy. Only applicable if `file_ids` is non-empty.
3559+
*/
3560+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
3561+
chunkingStrategy(
3562+
StaticFileChunkingStrategyObjectParam.builder()
3563+
.static_(static_)
3564+
.build()
3565+
)
3566+
35563567
/**
35573568
* A list of [file](https://platform.openai.com/docs/api-reference/files)
35583569
* IDs to add to the vector store. There can be a maximum of 10000 files in

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,15 @@ private constructor(
18721872
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
18731873
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
18741874

1875+
/**
1876+
* The chunking strategy used to chunk the file(s). If not set, will use the
1877+
* `auto` strategy. Only applicable if `file_ids` is non-empty.
1878+
*/
1879+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
1880+
chunkingStrategy(
1881+
StaticFileChunkingStrategyObjectParam.builder().static_(static_).build()
1882+
)
1883+
18751884
/**
18761885
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
18771886
* add to the vector store. There can be a maximum of 10000 files in a vector

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,13 @@ private constructor(
12261226
*/
12271227
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))
12281228

1229+
/**
1230+
* Override the tools the assistant can use for this run. This is useful for modifying
1231+
* the behavior on a per-run basis.
1232+
*/
1233+
fun addFunctionTool(function: FunctionDefinition) =
1234+
addTool(FunctionTool.builder().function(function).build())
1235+
12291236
/**
12301237
* An alternative to sampling with temperature, called nucleus sampling, where the model
12311238
* considers the results of the tokens with top_p probability mass. So 0.1 means only
@@ -1885,6 +1892,12 @@ private constructor(
18851892
*/
18861893
fun addTool(function: FunctionTool) = apply { body.addTool(function) }
18871894

1895+
/**
1896+
* Override the tools the assistant can use for this run. This is useful for modifying the
1897+
* behavior on a per-run basis.
1898+
*/
1899+
fun addFunctionTool(function: FunctionDefinition) = apply { body.addFunctionTool(function) }
1900+
18881901
/**
18891902
* An alternative to sampling with temperature, called nucleus sampling, where the model
18901903
* considers the results of the tokens with top_p probability mass. So 0.1 means only the

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ private constructor(
230230
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
231231
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
232232

233+
/**
234+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
235+
* strategy. Only applicable if `file_ids` is non-empty.
236+
*/
237+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
238+
chunkingStrategy(
239+
StaticFileChunkingStrategyObjectParam.builder().static_(static_).build()
240+
)
241+
233242
/** The expiration policy for a vector store. */
234243
fun expiresAfter(expiresAfter: ExpiresAfter) = expiresAfter(JsonField.of(expiresAfter))
235244

@@ -384,6 +393,14 @@ private constructor(
384393
body.chunkingStrategy(static_)
385394
}
386395

396+
/**
397+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
398+
* strategy. Only applicable if `file_ids` is non-empty.
399+
*/
400+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) = apply {
401+
body.staticChunkingStrategy(static_)
402+
}
403+
387404
/** The expiration policy for a vector store. */
388405
fun expiresAfter(expiresAfter: ExpiresAfter) = apply { body.expiresAfter(expiresAfter) }
389406

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ private constructor(
215215
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
216216
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
217217

218+
/**
219+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
220+
* strategy. Only applicable if `file_ids` is non-empty.
221+
*/
222+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
223+
chunkingStrategy(
224+
StaticFileChunkingStrategyObjectParam.builder().static_(static_).build()
225+
)
226+
218227
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
219228
this.additionalProperties.clear()
220229
putAllAdditionalProperties(additionalProperties)
@@ -340,6 +349,14 @@ private constructor(
340349
body.chunkingStrategy(static_)
341350
}
342351

352+
/**
353+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
354+
* strategy. Only applicable if `file_ids` is non-empty.
355+
*/
356+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) = apply {
357+
body.staticChunkingStrategy(static_)
358+
}
359+
343360
fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
344361
body.additionalProperties(additionalBodyProperties)
345362
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ private constructor(
199199
fun chunkingStrategy(static_: StaticFileChunkingStrategyObjectParam) =
200200
chunkingStrategy(FileChunkingStrategyParam.ofStatic(static_))
201201

202+
/**
203+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
204+
* strategy. Only applicable if `file_ids` is non-empty.
205+
*/
206+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) =
207+
chunkingStrategy(
208+
StaticFileChunkingStrategyObjectParam.builder().static_(static_).build()
209+
)
210+
202211
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
203212
this.additionalProperties.clear()
204213
putAllAdditionalProperties(additionalProperties)
@@ -317,6 +326,14 @@ private constructor(
317326
body.chunkingStrategy(static_)
318327
}
319328

329+
/**
330+
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
331+
* strategy. Only applicable if `file_ids` is non-empty.
332+
*/
333+
fun staticChunkingStrategy(static_: StaticFileChunkingStrategy) = apply {
334+
body.staticChunkingStrategy(static_)
335+
}
336+
320337
fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
321338
body.additionalProperties(additionalBodyProperties)
322339
}

0 commit comments

Comments
 (0)