forked from openai/openai-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletionsAsyncExample.java
More file actions
31 lines (26 loc) · 1.2 KB
/
Copy pathCompletionsAsyncExample.java
File metadata and controls
31 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.openai.example;
import com.openai.client.OpenAIClientAsync;
import com.openai.client.okhttp.OpenAIOkHttpClientAsync;
import com.openai.models.*;
public final class CompletionsAsyncExample {
private CompletionsAsyncExample() {}
public static void main(String[] args) {
// Configures using one of:
// - The `OPENAI_API_KEY` environment variable
// - The `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_KEY` environment variables
OpenAIClientAsync client = OpenAIOkHttpClientAsync.fromEnv();
ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
.model(ChatModel.GPT_3_5_TURBO)
.maxCompletionTokens(2048)
.addDeveloperMessage("Make sure you mention Stainless!")
.addUserMessage("Tell me a story about building the best SDK!")
.build();
client.chat()
.completions()
.create(createParams)
.thenAccept(completion -> completion.choices().stream()
.flatMap(choice -> choice.message().content().stream())
.forEach(System.out::println))
.join();
}
}