Skip to content

Commit 7c7795c

Browse files
chore: simplify examples involving unions (#119)
1 parent 557c071 commit 7c7795c

File tree

53 files changed

+851
-2106
lines changed

Some content is hidden

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

53 files changed

+851
-2106
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ To create a new chat completion, first use the `ChatCompletionCreateParams` buil
9292
```java
9393
import com.openai.models.ChatCompletion;
9494
import com.openai.models.ChatCompletionCreateParams;
95-
import com.openai.models.ChatCompletionMessageParam;
9695
import com.openai.models.ChatCompletionUserMessageParam;
9796
import com.openai.models.ChatModel;
9897

9998
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
100-
.addMessage(ChatCompletionMessageParam.ofChatCompletionUserMessageParam(ChatCompletionUserMessageParam.builder()
99+
.addMessage(ChatCompletionUserMessageParam.builder()
101100
.role(ChatCompletionUserMessageParam.Role.USER)
102-
.content(ChatCompletionUserMessageParam.Content.ofTextContent("Say this is a test"))
103-
.build()))
101+
.content("Say this is a test")
102+
.build())
104103
.model(ChatModel.O1)
105104
.build();
106105
ChatCompletion chatCompletion = client.chat().completions().create(params);

openai-java-core/src/test/kotlin/com/openai/models/AssistantTest.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,11 @@ class AssistantTest {
2121
.name("name")
2222
.object_(Assistant.Object.ASSISTANT)
2323
.addTool(
24-
AssistantTool.ofCodeInterpreterTool(
25-
CodeInterpreterTool.builder()
26-
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
27-
.build()
28-
)
29-
)
30-
.responseFormat(
31-
AssistantResponseFormatOption.ofBehavior(
32-
AssistantResponseFormatOption.Behavior.AUTO
33-
)
24+
CodeInterpreterTool.builder()
25+
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
26+
.build()
3427
)
28+
.responseFormat(AssistantResponseFormatOption.Behavior.AUTO)
3529
.temperature(1.0)
3630
.toolResources(
3731
Assistant.ToolResources.builder()

openai-java-core/src/test/kotlin/com/openai/models/BetaAssistantCreateParamsTest.kt

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ class BetaAssistantCreateParamsTest {
1616
.instructions("instructions")
1717
.metadata(JsonValue.from(mapOf<String, Any>()))
1818
.name("name")
19-
.responseFormat(
20-
AssistantResponseFormatOption.ofBehavior(
21-
AssistantResponseFormatOption.Behavior.AUTO
22-
)
23-
)
19+
.responseFormat(AssistantResponseFormatOption.Behavior.AUTO)
2420
.temperature(1.0)
2521
.toolResources(
2622
BetaAssistantCreateParams.ToolResources.builder()
@@ -36,11 +32,9 @@ class BetaAssistantCreateParamsTest {
3632
BetaAssistantCreateParams.ToolResources.FileSearch.VectorStore
3733
.builder()
3834
.chunkingStrategy(
39-
FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam(
40-
AutoFileChunkingStrategyParam.builder()
41-
.type(AutoFileChunkingStrategyParam.Type.AUTO)
42-
.build()
43-
)
35+
AutoFileChunkingStrategyParam.builder()
36+
.type(AutoFileChunkingStrategyParam.Type.AUTO)
37+
.build()
4438
)
4539
.addFileId("string")
4640
.metadata(JsonValue.from(mapOf<String, Any>()))
@@ -51,11 +45,9 @@ class BetaAssistantCreateParamsTest {
5145
.build()
5246
)
5347
.addTool(
54-
AssistantTool.ofCodeInterpreterTool(
55-
CodeInterpreterTool.builder()
56-
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
57-
.build()
58-
)
48+
CodeInterpreterTool.builder()
49+
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
50+
.build()
5951
)
6052
.topP(1.0)
6153
.build()
@@ -70,11 +62,7 @@ class BetaAssistantCreateParamsTest {
7062
.instructions("instructions")
7163
.metadata(JsonValue.from(mapOf<String, Any>()))
7264
.name("name")
73-
.responseFormat(
74-
AssistantResponseFormatOption.ofBehavior(
75-
AssistantResponseFormatOption.Behavior.AUTO
76-
)
77-
)
65+
.responseFormat(AssistantResponseFormatOption.Behavior.AUTO)
7866
.temperature(1.0)
7967
.toolResources(
8068
BetaAssistantCreateParams.ToolResources.builder()
@@ -90,14 +78,9 @@ class BetaAssistantCreateParamsTest {
9078
BetaAssistantCreateParams.ToolResources.FileSearch.VectorStore
9179
.builder()
9280
.chunkingStrategy(
93-
FileChunkingStrategyParam
94-
.ofAutoFileChunkingStrategyParam(
95-
AutoFileChunkingStrategyParam.builder()
96-
.type(
97-
AutoFileChunkingStrategyParam.Type.AUTO
98-
)
99-
.build()
100-
)
81+
AutoFileChunkingStrategyParam.builder()
82+
.type(AutoFileChunkingStrategyParam.Type.AUTO)
83+
.build()
10184
)
10285
.addFileId("string")
10386
.metadata(JsonValue.from(mapOf<String, Any>()))
@@ -108,11 +91,9 @@ class BetaAssistantCreateParamsTest {
10891
.build()
10992
)
11093
.addTool(
111-
AssistantTool.ofCodeInterpreterTool(
112-
CodeInterpreterTool.builder()
113-
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
114-
.build()
115-
)
94+
CodeInterpreterTool.builder()
95+
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
96+
.build()
11697
)
11798
.topP(1.0)
11899
.build()
@@ -145,11 +126,9 @@ class BetaAssistantCreateParamsTest {
145126
BetaAssistantCreateParams.ToolResources.FileSearch.VectorStore
146127
.builder()
147128
.chunkingStrategy(
148-
FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam(
149-
AutoFileChunkingStrategyParam.builder()
150-
.type(AutoFileChunkingStrategyParam.Type.AUTO)
151-
.build()
152-
)
129+
AutoFileChunkingStrategyParam.builder()
130+
.type(AutoFileChunkingStrategyParam.Type.AUTO)
131+
.build()
153132
)
154133
.addFileId("string")
155134
.metadata(JsonValue.from(mapOf<String, Any>()))

openai-java-core/src/test/kotlin/com/openai/models/BetaAssistantUpdateParamsTest.kt

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ class BetaAssistantUpdateParamsTest {
1717
.metadata(JsonValue.from(mapOf<String, Any>()))
1818
.model("model")
1919
.name("name")
20-
.responseFormat(
21-
AssistantResponseFormatOption.ofBehavior(
22-
AssistantResponseFormatOption.Behavior.AUTO
23-
)
24-
)
20+
.responseFormat(AssistantResponseFormatOption.Behavior.AUTO)
2521
.temperature(1.0)
2622
.toolResources(
2723
BetaAssistantUpdateParams.ToolResources.builder()
@@ -38,11 +34,9 @@ class BetaAssistantUpdateParamsTest {
3834
.build()
3935
)
4036
.addTool(
41-
AssistantTool.ofCodeInterpreterTool(
42-
CodeInterpreterTool.builder()
43-
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
44-
.build()
45-
)
37+
CodeInterpreterTool.builder()
38+
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
39+
.build()
4640
)
4741
.topP(1.0)
4842
.build()
@@ -58,11 +52,7 @@ class BetaAssistantUpdateParamsTest {
5852
.metadata(JsonValue.from(mapOf<String, Any>()))
5953
.model("model")
6054
.name("name")
61-
.responseFormat(
62-
AssistantResponseFormatOption.ofBehavior(
63-
AssistantResponseFormatOption.Behavior.AUTO
64-
)
65-
)
55+
.responseFormat(AssistantResponseFormatOption.Behavior.AUTO)
6656
.temperature(1.0)
6757
.toolResources(
6858
BetaAssistantUpdateParams.ToolResources.builder()
@@ -79,11 +69,9 @@ class BetaAssistantUpdateParamsTest {
7969
.build()
8070
)
8171
.addTool(
82-
AssistantTool.ofCodeInterpreterTool(
83-
CodeInterpreterTool.builder()
84-
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
85-
.build()
86-
)
72+
CodeInterpreterTool.builder()
73+
.type(CodeInterpreterTool.Type.CODE_INTERPRETER)
74+
.build()
8775
)
8876
.topP(1.0)
8977
.build()

0 commit comments

Comments
 (0)