File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
openai-java-example/src/main/java/com/openai/example Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .openai .example ;
2+
3+ import com .openai .client .OpenAIClientAsync ;
4+ import com .openai .client .okhttp .OpenAIOkHttpClientAsync ;
5+ import com .openai .models .ModerationCreateParams ;
6+ import com .openai .models .ModerationModel ;
7+
8+ public final class ModerationsAsyncExample {
9+ private ModerationsAsyncExample () {}
10+
11+ public static void main (String [] args ) {
12+ // Configures using one of:
13+ // - The `OPENAI_API_KEY` environment variable
14+ // - The `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_KEY` environment variables
15+ OpenAIClientAsync client = OpenAIOkHttpClientAsync .fromEnv ();
16+
17+ ModerationCreateParams createParams = ModerationCreateParams .builder ()
18+ .input ("I want to kill them." )
19+ .model (ModerationModel .OMNI_MODERATION_LATEST )
20+ .build ();
21+
22+ client .moderations ()
23+ .create (createParams )
24+ .thenAccept (System .out ::println )
25+ .join ();
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ package com .openai .example ;
2+
3+ import com .openai .client .OpenAIClient ;
4+ import com .openai .client .okhttp .OpenAIOkHttpClient ;
5+ import com .openai .models .ModerationCreateParams ;
6+ import com .openai .models .ModerationModel ;
7+
8+ public final class ModerationsExample {
9+ private ModerationsExample () {}
10+
11+ public static void main (String [] args ) {
12+ // Configures using one of:
13+ // - The `OPENAI_API_KEY` environment variable
14+ // - The `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_KEY` environment variables
15+ OpenAIClient client = OpenAIOkHttpClient .fromEnv ();
16+
17+ ModerationCreateParams createParams = ModerationCreateParams .builder ()
18+ .input ("I want to kill them." )
19+ .model (ModerationModel .OMNI_MODERATION_LATEST )
20+ .build ();
21+
22+ System .out .println (client .moderations ().create (createParams ));
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments