Skip to content

Commit 8c87166

Browse files
committed
JS/TS: Vision & Dall-e quickstarts
1 parent 3d67b4d commit 8c87166

File tree

3 files changed

+53
-36
lines changed

3 files changed

+53
-36
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/includes/dall-e-javascript.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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.
@@ -17,11 +17,22 @@ Use this guide to get started generating images with the Azure OpenAI SDK for Ja
1717

1818
## Prerequisites
1919

20+
#### [TypeScript](#tab/typescript)
21+
2022
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2123
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
24+
- [TypeScript](https://www.typescriptlang.org/download/)
2225
- 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).
2326

2427

28+
#### [JavaScript](#tab/javascript)
29+
30+
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
31+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
32+
- 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).
33+
34+
---
35+
2536
## Setup
2637

2738
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
@@ -39,55 +50,59 @@ 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:
54+
55+
## [**TypeScript**](#tab/typescript)
56+
57+
```console
58+
npm install openai @azure/openai @azure/identity
59+
```
60+
61+
The `@azure/openai` package provides the types the Azure service objects.
62+
63+
## [**JavaScript**](#tab/javascript)
4364

4465
```console
45-
npm install @azure/openai
66+
npm install openai @azure/identity
4667
```
4768

69+
---
70+
4871
Your app's _package.json_ file will be updated with the dependencies.
4972

5073
## Generate images with DALL-E
5174

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

77+
#### [TypeScript](#tab/typescript)
78+
79+
```typescript
80+
```
81+
82+
1. Build the application with the following command:
83+
84+
```console
85+
tsc
86+
```
87+
88+
1. Run the application with the following command:
89+
90+
```console
91+
node ImageGeneration.js
92+
```
93+
94+
95+
#### [JavaScript](#tab/javascript)
96+
5497
```javascript
55-
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
56-
57-
// 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"] ;
60-
61-
// The prompt to generate images from
62-
const prompt = "a monkey eating a banana";
63-
const size = "256x256";
64-
65-
// The number of images to generate
66-
const n = 2;
67-
68-
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}`);
79-
}
80-
81-
main().catch((err) => {
82-
console.error("The sample encountered an error:", err);
83-
});
8498
```
8599

86100
Run the script with the following command:
87101

88102
```console
89-
node _ImageGeneration.js
103+
node ImageGeneration.js
90104
```
105+
---
91106

92107
## Output
93108

articles/ai-services/openai/includes/gpt-v-javascript.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: nitinme
77
ms.service: azure-ai-openai
88
ms.topic: include
99
ms.custom: references_regions
10-
ms.date: 09/09/2024
10+
ms.date: 09/06/2024
1111
---
1212

1313
Use this article to get started using the OpenAI JavaScript SDK to deploy and use the GPT-4 Turbo with Vision model.
@@ -62,6 +62,8 @@ Install the client libraries with:
6262
npm install openai @azure/openai @azure/identity
6363
```
6464

65+
The `@azure/openai` package provides the types the Azure service objects.
66+
6567
## [**JavaScript**](#tab/javascript)
6668

6769
```console

0 commit comments

Comments
 (0)