File tree Expand file tree Collapse file tree 9 files changed +20
-65
lines changed
openai-java-example/src/main/java/com/openai/example Expand file tree Collapse file tree 9 files changed +20
-65
lines changed Original file line number Diff line number Diff line change 66import com .openai .client .okhttp .OpenAIOkHttpClient ;
77import com .openai .credential .BearerTokenCredential ;
88import com .openai .models .ChatCompletionCreateParams ;
9- import com .openai .models .ChatCompletionDeveloperMessageParam ;
10- import com .openai .models .ChatCompletionUserMessageParam ;
119import com .openai .models .ChatModel ;
1210
1311public 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 ()
Original file line number Diff line number Diff 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 ()
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 33import com .openai .client .OpenAIClient ;
44import com .openai .client .okhttp .OpenAIOkHttpClient ;
55import com .openai .models .ChatCompletionCreateParams ;
6- import com .openai .models .ChatCompletionDeveloperMessageParam ;
7- import com .openai .models .ChatCompletionUserMessageParam ;
86import com .openai .models .ChatModel ;
97
108public 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 ()
Original file line number Diff line number Diff 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 <>();
Original file line number Diff line number Diff 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 =
Original file line number Diff line number Diff line change 44import com .openai .client .okhttp .OpenAIOkHttpClientAsync ;
55import com .openai .core .JsonValue ;
66import com .openai .models .ChatCompletionCreateParams ;
7- import com .openai .models .ChatCompletionUserMessageParam ;
87import com .openai .models .ChatModel ;
98import com .openai .models .ResponseFormatJsonSchema ;
109import 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 ()
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments