@@ -127,6 +127,50 @@ main().catch((err) => {
127
127
#### [JavaScript](#tab/javascript)
128
128
129
129
```javascript
130
+ require("dotenv/config");
131
+ const { AzureOpenAI } = require("openai");
132
+
133
+ // You will need to set these environment variables or edit the following values
134
+ const endpoint = process.env["AZURE_OPENAI_ENDPOINT"];
135
+ const apiKey = process.env["AZURE_OPENAI_API_KEY"];
136
+
137
+ // Required Azure OpenAI deployment name and API version
138
+ const apiVersion = "2024-07-01";
139
+ const deploymentName = "dall-e-3";
140
+
141
+ // The prompt to generate images from
142
+ const prompt = "a monkey eating a banana";
143
+ const numberOfImagesToGenerate = 1;
144
+
145
+ function getClient() {
146
+ return new AzureOpenAI({
147
+ endpoint,
148
+ apiKey,
149
+ apiVersion,
150
+ deployment: deploymentName,
151
+ });
152
+ }
153
+ async function main() {
154
+ console.log("== Image Generation ==");
155
+
156
+ const client = getClient();
157
+
158
+ const results = await client.images.generate({
159
+ prompt,
160
+ size: "1024x1024",
161
+ n: numberOfImagesToGenerate,
162
+ model: "",
163
+ style: "vivid", // or "natural"
164
+ });
165
+
166
+ for (const image of results.data) {
167
+ console.log(`Image generation result URL: ${image.url}`);
168
+ }
169
+ }
170
+
171
+ main().catch((err) => {
172
+ console.error("The sample encountered an error:", err);
173
+ });
130
174
```
131
175
132
176
Run the script with the following command:
0 commit comments