File tree Expand file tree Collapse file tree 1 file changed +7
-20
lines changed
openai-java-example/src/main/java/com/openai/example Expand file tree Collapse file tree 1 file changed +7
-20
lines changed Original file line number Diff line number Diff line change 22
33import com .openai .client .OpenAIClientAsync ;
44import com .openai .client .okhttp .OpenAIOkHttpClientAsync ;
5- import com .openai .core .http .AsyncStreamResponse ;
65import com .openai .models .*;
7- import java .util .Optional ;
8- import java .util .concurrent .CompletableFuture ;
96
107public final class CompletionsStreamingAsyncExample {
118 private CompletionsStreamingAsyncExample () {}
@@ -23,23 +20,13 @@ public static void main(String[] args) {
2320 .addUserMessage ("Tell me a story about building the best SDK!" )
2421 .build ();
2522
26- CompletableFuture <Void > onCompleteFuture = new CompletableFuture <>();
27-
28- // TODO: Update this example once we support expose an `onCompleteFuture()` method.
29- client .chat ().completions ().createStreaming (createParams ).subscribe (new AsyncStreamResponse .Handler <>() {
30- @ Override
31- public void onNext (ChatCompletionChunk completion ) {
32- completion .choices ().stream ()
23+ client .chat ()
24+ .completions ()
25+ .createStreaming (createParams )
26+ .subscribe (completion -> completion .choices ().stream ()
3327 .flatMap (choice -> choice .delta ().content ().stream ())
34- .forEach (System .out ::print );
35- }
36-
37- @ Override
38- public void onComplete (Optional <Throwable > error ) {
39- onCompleteFuture .complete (null );
40- }
41- });
42-
43- onCompleteFuture .join ();
28+ .forEach (System .out ::print ))
29+ .onCompleteFuture ()
30+ .join ();
4431 }
4532}
You can’t perform that action at this time.
0 commit comments