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 2
2
3
3
import com .openai .client .OpenAIClientAsync ;
4
4
import com .openai .client .okhttp .OpenAIOkHttpClientAsync ;
5
- import com .openai .core .http .AsyncStreamResponse ;
6
5
import com .openai .models .*;
7
- import java .util .Optional ;
8
- import java .util .concurrent .CompletableFuture ;
9
6
10
7
public final class CompletionsStreamingAsyncExample {
11
8
private CompletionsStreamingAsyncExample () {}
@@ -23,23 +20,13 @@ public static void main(String[] args) {
23
20
.addUserMessage ("Tell me a story about building the best SDK!" )
24
21
.build ();
25
22
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 ()
33
27
.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 ();
44
31
}
45
32
}
You can’t perform that action at this time.
0 commit comments