Skip to content

Commit 20f6866

Browse files
committed
Merge branch 'main' of github.com:MicrosoftDocs/azure-ai-docs-pr into 245675-data-aoai-sec
2 parents 87032e1 + be9e217 commit 20f6866

15 files changed

+616
-112
lines changed

articles/ai-services/openai/dall-e-quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ description: Learn how to get started generating images with Azure OpenAI Servic
55
#services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-openai
8-
ms.custom: devx-track-python, devx-track-dotnet, devx-track-extended-java, devx-track-go, devx-track-js
8+
ms.custom: devx-track-python, devx-track-dotnet, devx-track-extended-java, devx-track-go, devx-track-js, devx-track-ts
99
ms.topic: quickstart
1010
author: PatrickFarley
1111
ms.author: pafarley
12-
ms.date: 08/21/2024
12+
ms.date: 09/06/2024
1313
zone_pivot_groups: openai-quickstart-dall-e
1414
---
1515

articles/ai-services/openai/gpt-v-quickstart.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Use this article to get started using Azure OpenAI to deploy and us
55
services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-openai
8-
ms.custom: devx-track-python
8+
ms.custom: devx-track-python, devx-track-js, devx-track-ts
99
ms.topic: quickstart
1010
author: PatrickFarley
1111
ms.author: pafarley
@@ -39,6 +39,12 @@ Get started using GPT-4 Turbo with images with the Azure OpenAI Service.
3939

4040
::: zone-end
4141

42+
::: zone pivot="programming-language-javascript"
43+
44+
[!INCLUDE [JavaScript quickstart](includes/gpt-v-javascript.md)]
45+
46+
::: zone-end
47+
4248
## Next steps
4349

4450
* Learn more about these APIs in the [GPT-4 Turbo with Vision how-to guide](./gpt-v-quickstart.md)

articles/ai-services/openai/how-to/json-mode.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ JSON mode allows you to set the models response format to return a valid JSON ob
2020
> [!NOTE]
2121
> While JSON mode is still supported, when possible we recommend using [structured outputs](./structured-outputs.md). Like JSON mode structured outputs generates valid JSON, but with the added benefit that you can constrain the model to use a specific JSON schema.
2222
23+
>[!NOTE]
24+
> Currently Structured outputs is not supported on [bring your own data](../concepts/use-your-data.md) scenario.
25+
2326
## JSON mode support
2427

2528
JSON mode is only currently supported with the following models:

articles/ai-services/openai/how-to/structured-outputs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ recommendations: false
1616

1717
Structured outputs make a model follow a [JSON Schema](https://json-schema.org/overview/what-is-jsonschema) definition that you provide as part of your inference API call. This is in contrast to the older [JSON mode](./json-mode.md) feature, which guaranteed valid JSON would be generated, but was unable to ensure strict adherence to the supplied schema. Structured outputs is recommended for function calling, extracting structured data, and building complex multi-step workflows.
1818

19+
>[!NOTE]
20+
> Currently Structured outputs is not supported on [bring your own data](../concepts/use-your-data.md) scenario.
21+
1922
## Supported models
2023

2124
Currently only `gpt-4o` version: `2024-08-06` supports structured outputs.

articles/ai-services/openai/includes/dall-e-javascript.md

Lines changed: 114 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@ ms.service: azure-ai-openai
88
ms.topic: include
99
author: PatrickFarley
1010
ms.author: pafarley
11-
ms.date: 08/24/2023
11+
ms.date: 09/06/2024
1212
---
1313

1414
Use this guide to get started generating images with the Azure OpenAI SDK for JavaScript.
1515

16-
[Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai) | [Package (npm)](https://www.npmjs.com/package/@azure/openai) | [Samples](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/tests/Samples)
16+
[Reference documentation](https://platform.openai.com/docs/api-reference/images/create) | [Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples)
1717

1818
## Prerequisites
1919

20+
#### [TypeScript](#tab/typescript)
21+
22+
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
23+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
24+
- [TypeScript](https://www.typescriptlang.org/download/)
25+
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
26+
27+
28+
#### [JavaScript](#tab/javascript)
29+
2030
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2131
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
2232
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2333

34+
---
2435

2536
## Setup
2637

@@ -39,10 +50,10 @@ npm init
3950

4051
## Install the client library
4152

42-
Install the Azure OpenAI client library for JavaScript with npm:
53+
Install the client libraries with:
4354

4455
```console
45-
npm install @azure/openai
56+
npm install openai @azure/identity
4657
```
4758

4859
Your app's _package.json_ file will be updated with the dependencies.
@@ -51,43 +62,123 @@ Your app's _package.json_ file will be updated with the dependencies.
5162

5263
Create a new file named _ImageGeneration.js_ and open it in your preferred code editor. Copy the following code into the _ImageGeneration.js_ file:
5364

54-
```javascript
55-
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
65+
#### [TypeScript](#tab/typescript)
66+
67+
```typescript
68+
import "dotenv/config";
69+
import { AzureOpenAI } from "openai";
5670

5771
// You will need to set these environment variables or edit the following values
58-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] ;
59-
const azureApiKey = process.env["AZURE_OPENAI_API_KEY"] ;
72+
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"];
73+
const apiKey = process.env["AZURE_OPENAI_API_KEY"];
74+
75+
// Required Azure OpenAI deployment name and API version
76+
const apiVersion = "2024-07-01";
77+
const deploymentName = "dall-e-3";
6078

6179
// The prompt to generate images from
6280
const prompt = "a monkey eating a banana";
63-
const size = "256x256";
81+
const numberOfImagesToGenerate = 1;
82+
83+
function getClient(): AzureOpenAI {
84+
return new AzureOpenAI({
85+
endpoint,
86+
apiKey,
87+
apiVersion,
88+
deployment: deploymentName,
89+
});
90+
}
91+
async function main() {
92+
console.log("== Image Generation ==");
93+
94+
const client = getClient();
95+
96+
const results = await client.images.generate({
97+
prompt,
98+
size: "1024x1024",
99+
n: numberOfImagesToGenerate,
100+
model: "",
101+
style: "vivid", // or "natural"
102+
});
103+
104+
for (const image of results.data) {
105+
console.log(`Image generation result URL: ${image.url}`);
106+
}
107+
}
108+
109+
main().catch((err) => {
110+
console.error("The sample encountered an error:", err);
111+
});
112+
```
113+
114+
1. Build the application with the following command:
115+
116+
```console
117+
tsc
118+
```
119+
120+
1. Run the application with the following command:
64121

65-
// The number of images to generate
66-
const n = 2;
122+
```console
123+
node ImageGeneration.js
124+
```
67125

126+
127+
#### [JavaScript](#tab/javascript)
128+
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+
}
68153
async function main() {
69-
console.log("== Batch Image Generation ==");
70-
71-
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
72-
const deploymentName = "dall-e";
73-
const results = await client.getImages(deploymentName, prompt, { n, size });
74-
75-
for (const image of results.data) {
76-
console.log(`Image generation result URL: ${image.url}`);
77-
}
78-
//console.log(`Image generation result URL: ${results.result.status}`);
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+
}
79169
}
80170

81171
main().catch((err) => {
82-
console.error("The sample encountered an error:", err);
172+
console.error("The sample encountered an error:", err);
83173
});
84174
```
85175

86176
Run the script with the following command:
87177

88178
```console
89-
node _ImageGeneration.js
179+
node ImageGeneration.js
90180
```
181+
---
91182

92183
## Output
93184

0 commit comments

Comments
 (0)