Skip to content

Commit 2c2ccbc

Browse files
committed
docs: simpliy param construction
1 parent ec756b9 commit 2c2ccbc

9 files changed

+20
-65
lines changed

openai-java-example/src/main/java/com/openai/example/AzureEntraIdExample.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import com.openai.client.okhttp.OpenAIOkHttpClient;
77
import com.openai.credential.BearerTokenCredential;
88
import com.openai.models.ChatCompletionCreateParams;
9-
import com.openai.models.ChatCompletionDeveloperMessageParam;
10-
import com.openai.models.ChatCompletionUserMessageParam;
119
import com.openai.models.ChatModel;
1210

1311
public final class AzureEntraIdExample {
@@ -25,12 +23,8 @@ public static void main(String[] args) {
2523
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
2624
.model(ChatModel.GPT_3_5_TURBO)
2725
.maxCompletionTokens(2048)
28-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
29-
.content("Make sure you mention Stainless!")
30-
.build())
31-
.addMessage(ChatCompletionUserMessageParam.builder()
32-
.content("Tell me a story about building the best SDK!")
33-
.build())
26+
.addDeveloperMessage("Make sure you mention Stainless!")
27+
.addUserMessage("Tell me a story about building the best SDK!")
3428
.build();
3529

3630
client.chat().completions().create(createParams).choices().stream()

openai-java-example/src/main/java/com/openai/example/CompletionsAsyncExample.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ public static void main(String[] args) {
1616
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
1717
.model(ChatModel.GPT_3_5_TURBO)
1818
.maxCompletionTokens(2048)
19-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
20-
.content("Make sure you mention Stainless!")
21-
.build())
22-
.addMessage(ChatCompletionUserMessageParam.builder()
23-
.content("Tell me a story about building the best SDK!")
24-
.build())
19+
.addDeveloperMessage("Make sure you mention Stainless!")
20+
.addUserMessage("Tell me a story about building the best SDK!")
2521
.build();
2622

2723
client.chat()

openai-java-example/src/main/java/com/openai/example/CompletionsConversationAsyncExample.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ public static void main(String[] args) {
2222
ChatCompletionCreateParams.Builder createParamsBuilder = ChatCompletionCreateParams.builder()
2323
.model(ChatModel.GPT_3_5_TURBO)
2424
.maxCompletionTokens(2048)
25-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
26-
.content("Make sure you mention Stainless!")
27-
.build())
28-
.addMessage(ChatCompletionUserMessageParam.builder()
29-
.content("Tell me a story about building the best SDK!")
30-
.build());
25+
.addDeveloperMessage("Make sure you mention Stainless!")
26+
.addUserMessage("Tell me a story about building the best SDK!");
3127

3228
CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
3329
for (int i = 0; i < 4; i++) {
@@ -47,12 +43,8 @@ public static void main(String[] args) {
4743

4844
messages.forEach(createParamsBuilder::addMessage);
4945
createParamsBuilder
50-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
51-
.content("Be as snarky as possible when replying!" + "!".repeat(index))
52-
.build())
53-
.addMessage(ChatCompletionUserMessageParam.builder()
54-
.content("But why?" + "?".repeat(index))
55-
.build());
46+
.addDeveloperMessage("Be as snarky as possible when replying!" + "!".repeat(index))
47+
.addUserMessage("But why?" + "?".repeat(index));
5648
});
5749
}
5850

openai-java-example/src/main/java/com/openai/example/CompletionsConversationExample.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ public static void main(String[] args) {
2121
ChatCompletionCreateParams.Builder createParamsBuilder = ChatCompletionCreateParams.builder()
2222
.model(ChatModel.GPT_3_5_TURBO)
2323
.maxCompletionTokens(2048)
24-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
25-
.content("Make sure you mention Stainless!")
26-
.build())
27-
.addMessage(ChatCompletionUserMessageParam.builder()
28-
.content("Tell me a story about building the best SDK!")
29-
.build());
24+
.addDeveloperMessage("Make sure you mention Stainless!")
25+
.addUserMessage("Tell me a story about building the best SDK!");
3026

3127
for (int i = 0; i < 4; i++) {
3228
List<ChatCompletionMessage> messages =
@@ -40,12 +36,8 @@ public static void main(String[] args) {
4036

4137
messages.forEach(createParamsBuilder::addMessage);
4238
createParamsBuilder
43-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
44-
.content("Be as snarky as possible when replying!" + "!".repeat(i))
45-
.build())
46-
.addMessage(ChatCompletionUserMessageParam.builder()
47-
.content("But why?" + "?".repeat(i))
48-
.build());
39+
.addDeveloperMessage("Be as snarky as possible when replying!" + "!".repeat(i))
40+
.addUserMessage("But why?" + "?".repeat(i));
4941
}
5042
}
5143
}

openai-java-example/src/main/java/com/openai/example/CompletionsExample.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.openai.client.OpenAIClient;
44
import com.openai.client.okhttp.OpenAIOkHttpClient;
55
import com.openai.models.ChatCompletionCreateParams;
6-
import com.openai.models.ChatCompletionDeveloperMessageParam;
7-
import com.openai.models.ChatCompletionUserMessageParam;
86
import com.openai.models.ChatModel;
97

108
public final class CompletionsExample {
@@ -19,12 +17,8 @@ public static void main(String[] args) {
1917
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
2018
.model(ChatModel.GPT_3_5_TURBO)
2119
.maxCompletionTokens(2048)
22-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
23-
.content("Make sure you mention Stainless!")
24-
.build())
25-
.addMessage(ChatCompletionUserMessageParam.builder()
26-
.content("Tell me a story about building the best SDK!")
27-
.build())
20+
.addDeveloperMessage("Make sure you mention Stainless!")
21+
.addUserMessage("Tell me a story about building the best SDK!")
2822
.build();
2923

3024
client.chat().completions().create(createParams).choices().stream()

openai-java-example/src/main/java/com/openai/example/CompletionsStreamingAsyncExample.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ public static void main(String[] args) throws Exception {
1919
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
2020
.model(ChatModel.GPT_3_5_TURBO)
2121
.maxCompletionTokens(2048)
22-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
23-
.content("Make sure you mention Stainless!")
24-
.build())
25-
.addMessage(ChatCompletionUserMessageParam.builder()
26-
.content("Tell me a story about building the best SDK!")
27-
.build())
22+
.addDeveloperMessage("Make sure you mention Stainless!")
23+
.addUserMessage("Tell me a story about building the best SDK!")
2824
.build();
2925

3026
CompletableFuture<Void> onCompleteFuture = new CompletableFuture<>();

openai-java-example/src/main/java/com/openai/example/CompletionsStreamingExample.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ public static void main(String[] args) throws Exception {
1717
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
1818
.model(ChatModel.GPT_3_5_TURBO)
1919
.maxCompletionTokens(2048)
20-
.addMessage(ChatCompletionDeveloperMessageParam.builder()
21-
.content("Make sure you mention Stainless!")
22-
.build())
23-
.addMessage(ChatCompletionUserMessageParam.builder()
24-
.content("Tell me a story about building the best SDK!")
25-
.build())
20+
.addDeveloperMessage("Make sure you mention Stainless!")
21+
.addUserMessage("Tell me a story about building the best SDK!")
2622
.build();
2723

2824
try (StreamResponse<ChatCompletionChunk> streamResponse =

openai-java-example/src/main/java/com/openai/example/StructuredOutputsAsyncExample.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.openai.client.okhttp.OpenAIOkHttpClientAsync;
55
import com.openai.core.JsonValue;
66
import com.openai.models.ChatCompletionCreateParams;
7-
import com.openai.models.ChatCompletionUserMessageParam;
87
import com.openai.models.ChatModel;
98
import com.openai.models.ResponseFormatJsonSchema;
109
import com.openai.models.ResponseFormatJsonSchema.JsonSchema;
@@ -34,9 +33,7 @@ public static void main(String[] args) {
3433
.schema(schema)
3534
.build())
3635
.build())
37-
.addMessage(ChatCompletionUserMessageParam.builder()
38-
.content("Who works at OpenAI?")
39-
.build())
36+
.addUserMessage("Who works at OpenAI?")
4037
.build();
4138

4239
client.chat()

openai-java-example/src/main/java/com/openai/example/StructuredOutputsExample.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public static void main(String[] args) {
3131
.schema(schema)
3232
.build())
3333
.build())
34-
.addMessage(ChatCompletionUserMessageParam.builder()
35-
.content("Who works at OpenAI?")
36-
.build())
34+
.addUserMessage("Who works at OpenAI?")
3735
.build();
3836

3937
client.chat().completions().create(createParams).choices().stream()

0 commit comments

Comments
 (0)