-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathimages.ts
43 lines (34 loc) · 1.39 KB
/
images.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Demonstrates how to generate images from prompts using Azure OpenAI Batch Image Generation.
*
* @summary generates images from prompts using Azure OpenAI Batch Image Generation.
* @azsdk-weight 100
*/
import { AzureOpenAI } from "openai";
import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";
// Set AZURE_OPENAI_ENDPOINT to the endpoint of your
// OpenAI resource. You can find this in the Azure portal.
// Load the .env file if it exists
import "dotenv/config";
// The prompt to generate images from
const prompt = "a monkey eating a banana";
const size = "1024x1024";
// The number of images to generate
const n = 1;
export async function main(): Promise<void> {
console.log("== Batch Image Generation ==");
const scope = "https://cognitiveservices.azure.com/.default";
const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope);
const deployment = "dall-e-3";
const apiVersion = "2025-03-01-preview";
const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion });
const results = await client.images.generate({ prompt, model: "", n, size });
for (const image of results.data) {
console.log(`Image generation result URL: ${image.url}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});