File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
openai-java-example/src/main/java/com/openai/example Expand file tree Collapse file tree 1 file changed +30
-0
lines changed 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 .images .ImageGenerateParams ;
6+ import com .openai .models .images .ImageModel ;
7+ import java .io .IOException ;
8+
9+ public final class ImageGenerationExample {
10+ private ImageGenerationExample () {}
11+
12+ public static void main (String [] args ) throws IOException {
13+ // Configures using one of:
14+ // - The `OPENAI_API_KEY` environment variable
15+ // - The `OPENAI_BASE_URL` and `AZURE_OPENAI_KEY` environment variables
16+ OpenAIClient client = OpenAIOkHttpClient .fromEnv ();
17+
18+ ImageGenerateParams imageGenerateParams = ImageGenerateParams .builder ()
19+ .responseFormat (ImageGenerateParams .ResponseFormat .URL )
20+ .prompt ("Two cats playing ping-pong" )
21+ .model (ImageModel .DALL_E_2 )
22+ .size (ImageGenerateParams .Size ._512X512 )
23+ .n (1 )
24+ .build ();
25+
26+ client .images ().generate (imageGenerateParams ).data ().orElseThrow ().stream ()
27+ .flatMap (image -> image .url ().stream ())
28+ .forEach (System .out ::println );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments