Skip to content

Commit 1566532

Browse files
authored
Merge pull request #3149 from eric-urban/eur/js-ts-aoai
JavaScript and TypeScript quickstart consistency
2 parents 9a689e0 + 5569a87 commit 1566532

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1300
-980
lines changed

articles/ai-services/openai/concepts/content-filter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ import * as dotenv from "dotenv";
620620
dotenv.config();
621621

622622
// You will need to set these environment variables or edit the following values
623-
const endpoint = process.env["ENDPOINT"] || "<endpoint>";
624-
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>";
623+
const endpoint = process.env["ENDPOINT"] || "Your endpoint";
624+
const azureApiKey = process.env["AZURE_API_KEY"] || "Your API key";
625625

626626
const messages = [
627627
{ role: "system", content: "You are a helpful assistant. You will talk like a pirate." },

articles/ai-services/openai/includes/assistants-javascript.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,17 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
3333
1. Create a new folder `assistants-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3434

3535
```shell
36-
mkdir assistants-quickstart && code assistants-quickstart
36+
mkdir assistants-quickstart && cd assistants-quickstart
3737
```
3838

3939

4040
1. Create the `package.json` with the following command:
4141

4242
```shell
4343
npm init -y
44-
```
45-
46-
1. Update the `package.json` to ECMAScript with the following command:
47-
48-
```shell
49-
npm pkg set type=module
50-
```
51-
44+
```
5245

53-
1. Install the OpenAI Assistants client library for JavaScript with:
46+
1. Install the OpenAI client library for JavaScript with:
5447

5548
```console
5649
npm install openai
@@ -100,14 +93,14 @@ An individual assistant can access up to 128 tools including `code interpreter`,
10093
} = require("@azure/identity");
10194
10295
// Get environment variables
103-
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT;
104-
const azureOpenAIDeployment = process.env.AZURE_OPENAI_DEPLOYMENT_NAME;
105-
const azureOpenAIVersion = process.env.OPENAI_API_VERSION;
96+
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";
97+
const azureOpenAIDeployment = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "Your deployment name";
98+
const azureOpenAIVersion = process.env.OPENAI_API_VERSION || "A supported API version";
10699
107100
// Check env variables
108101
if (!azureOpenAIEndpoint || !azureOpenAIDeployment || !azureOpenAIVersion) {
109102
throw new Error(
110-
"Please ensure to set AZURE_OPENAI_DEPLOYMENT_NAME and AZURE_OPENAI_ENDPOINT in your environment variables."
103+
"You need to set the endpoint, deployment name, and API version."
111104
);
112105
}
113106
@@ -193,8 +186,6 @@ An individual assistant can access up to 128 tools including `code interpreter`,
193186
node index.js
194187
```
195188
196-
197-
198189
#### [API key](#tab/api-key)
199190
200191
1. Create the `index.js` file with the following code:
@@ -203,15 +194,15 @@ An individual assistant can access up to 128 tools including `code interpreter`,
203194
const { AzureOpenAI } = require("openai");
204195
205196
// Get environment variables
206-
const azureOpenAIKey = process.env.AZURE_OPENAI_KEY;
207-
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT;
208-
const azureOpenAIDeployment = process.env.AZURE_OPENAI_DEPLOYMENT_NAME;
209-
const azureOpenAIVersion = process.env.OPENAI_API_VERSION;
197+
const azureOpenAIKey = process.env.AZURE_OPENAI_KEY || "Your API key";
198+
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";
199+
const azureOpenAIDeployment = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "Your deployment name";
200+
const azureOpenAIVersion = process.env.OPENAI_API_VERSION || "A supported API version";
210201
211202
// Check env variables
212203
if (!azureOpenAIKey || !azureOpenAIEndpoint || !azureOpenAIDeployment || !azureOpenAIVersion) {
213204
throw new Error(
214-
"Please set AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME in your environment variables."
205+
"You need to set the endpoint, deployment name, and API version."
215206
);
216207
}
217208

articles/ai-services/openai/includes/assistants-typescript.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
3434
1. Create a new folder `assistants-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3535

3636
```shell
37-
mkdir assistants-quickstart && code assistants-quickstart
37+
mkdir assistants-quickstart && cd assistants-quickstart
3838
```
3939

4040

@@ -51,7 +51,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
5151
```
5252

5353

54-
1. Install the OpenAI Assistants client library for JavaScript with:
54+
1. Install the OpenAI client library for JavaScript with:
5555

5656
```console
5757
npm install openai
@@ -110,15 +110,15 @@ An individual assistant can access up to 128 tools including `code interpreter`,
110110
} from "@azure/identity";
111111
112112
// Get environment variables
113-
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT as string;
113+
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint" as string;
114114
const azureOpenAIDeployment = process.env
115-
.AZURE_OPENAI_DEPLOYMENT_NAME as string;
116-
const openAIVersion = process.env.OPENAI_API_VERSION as string;
115+
.AZURE_OPENAI_DEPLOYMENT_NAME || "Your deployment name" as string;
116+
const openAIVersion = process.env.OPENAI_API_VERSION || "A supported API version" as string;
117117
118118
// Check env variables
119119
if (!azureOpenAIEndpoint || !azureOpenAIDeployment || !openAIVersion) {
120120
throw new Error(
121-
"Please ensure to set AZURE_OPENAI_DEPLOYMENT_NAME and AZURE_OPENAI_ENDPOINT in your environment variables."
121+
"You need to set the endpoint, deployment name, and API version."
122122
);
123123
}
124124
@@ -186,8 +186,6 @@ An individual assistant can access up to 128 tools including `code interpreter`,
186186
}
187187
}
188188
```
189-
190-
191189
192190
1. Create the `tsconfig.json` file to transpile the TypeScript code and copy the following code for ECMAScript.
193191
@@ -222,8 +220,6 @@ An individual assistant can access up to 128 tools including `code interpreter`,
222220
node index.js
223221
```
224222
225-
226-
227223
#### [API key](#tab/typescript-key)
228224
229225
1. Create the `index.ts` file with the following code:
@@ -240,16 +236,16 @@ An individual assistant can access up to 128 tools including `code interpreter`,
240236
import { Thread } from "openai/resources/beta/threads/threads";
241237
242238
// Get environment variables
243-
const azureOpenAIKey = process.env.AZURE_OPENAI_KEY as string;
244-
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT as string;
239+
const azureOpenAIKey = process.env.AZURE_OPENAI_KEY || "Your API key" as string;
240+
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint" as string;
245241
const azureOpenAIDeployment = process.env
246-
.AZURE_OPENAI_DEPLOYMENT_NAME as string;
247-
const openAIVersion = process.env.OPENAI_API_VERSION as string;
242+
.AZURE_OPENAI_DEPLOYMENT_NAME || "Your deployment name" as string;
243+
const openAIVersion = process.env.OPENAI_API_VERSION || "A supported API version" as string;
248244
249245
// Check env variables
250246
if (!azureOpenAIKey || !azureOpenAIEndpoint || !azureOpenAIDeployment || !openAIVersion) {
251247
throw new Error(
252-
"Please set AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME in your environment variables."
248+
"You need to set the endpoint, deployment name, and API version."
253249
);
254250
}
255251
@@ -314,7 +310,6 @@ An individual assistant can access up to 128 tools including `code interpreter`,
314310
}
315311
}
316312
```
317-
318313
319314
1. Create the `tsconfig.json` file to transpile the TypeScript code and copy the following code for ECMAScript.
320315

articles/ai-services/openai/includes/audio-completions-javascript.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
2929
1. Create a new folder `audio-completions-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3030

3131
```shell
32-
mkdir audio-completions-quickstart && code audio-completions-quickstart
32+
mkdir audio-completions-quickstart && cd audio-completions-quickstart
3333
```
3434

3535
1. Create the `package.json` with the following command:
@@ -38,13 +38,6 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
3838
npm init -y
3939
```
4040

41-
1. Update the `package.json` to ECMAScript with the following command:
42-
43-
```shell
44-
npm pkg set type=module
45-
```
46-
47-
4841
1. Install the OpenAI client library for JavaScript with:
4942

5043
```console
@@ -83,9 +76,9 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
8376
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
8477
8578
// Set environment variables or edit the corresponding values here.
86-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
87-
const apiVersion = "2025-01-01-preview";
88-
const deployment = "gpt-4o-mini-audio-preview";
79+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
80+
const deployment = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-4o-mini-audio-preview";
81+
const apiVersion = process.env.OPENAI_API_VERSION || "2025-01-01-preview";
8982
9083
const client = new AzureOpenAI({
9184
endpoint,
@@ -150,8 +143,8 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
150143
const { writeFileSync } = require("node:fs");
151144
152145
// Set environment variables or edit the corresponding values here.
153-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
154-
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
146+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
147+
const apiKey = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
155148
const apiVersion = "2025-01-01-preview";
156149
const deployment = "gpt-4o-mini-audio-preview";
157150
@@ -229,7 +222,7 @@ The script generates an audio file named _dog.wav_ in the same directory as the
229222
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
230223
231224
// Set environment variables or edit the corresponding values here.
232-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
225+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
233226
const apiVersion = "2025-01-01-preview";
234227
const deployment = "gpt-4o-mini-audio-preview";
235228
@@ -312,8 +305,8 @@ The script generates an audio file named _dog.wav_ in the same directory as the
312305
const { writeFileSync } = require("node:fs");
313306
314307
// Set environment variables or edit the corresponding values here.
315-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
316-
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
308+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
309+
const apiKey = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
317310
const apiVersion = "2025-01-01-preview";
318311
const deployment = "gpt-4o-mini-audio-preview";
319312
@@ -404,7 +397,7 @@ The script generates a transcript of the summary of the spoken audio input. It a
404397
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
405398
406399
// Set environment variables or edit the corresponding values here.
407-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
400+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
408401
const apiVersion = "2025-01-01-preview";
409402
const deployment = "gpt-4o-mini-audio-preview";
410403
@@ -508,8 +501,8 @@ The script generates a transcript of the summary of the spoken audio input. It a
508501
const fs = require('fs').promises;
509502
510503
// Set environment variables or edit the corresponding values here.
511-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
512-
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
504+
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
505+
const apiKey = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
513506
const apiVersion = "2025-01-01-preview";
514507
const deployment = "gpt-4o-mini-audio-preview";
515508

articles/ai-services/openai/includes/audio-completions-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
3131
1. Create a new folder `audio-completions-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3232

3333
```shell
34-
mkdir audio-completions-quickstart && code audio-completions-quickstart
34+
mkdir audio-completions-quickstart && cd audio-completions-quickstart
3535
```
3636

3737
1. Create a virtual environment. If you already have Python 3.10 or higher installed, you can create a virtual environment using the following commands:

articles/ai-services/openai/includes/audio-completions-rest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
2929
1. Create a new folder `audio-completions-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3030

3131
```shell
32-
mkdir audio-completions-quickstart && code audio-completions-quickstart
32+
mkdir audio-completions-quickstart && cd audio-completions-quickstart
3333
```
3434

3535
1. Create a virtual environment. If you already have Python 3.10 or higher installed, you can create a virtual environment using the following commands:

articles/ai-services/openai/includes/audio-completions-typescript.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
3030
1. Create a new folder `audio-completions-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
3131

3232
```shell
33-
mkdir audio-completions-quickstart && code audio-completions-quickstart
33+
mkdir audio-completions-quickstart && cd audio-completions-quickstart
3434
```
3535

3636

@@ -82,9 +82,9 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
8282
} from "@azure/identity";
8383
8484
// Set environment variables or edit the corresponding values here.
85-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
86-
const apiVersion: string = "2025-01-01-preview";
87-
const deployment: string = "gpt-4o-mini-audio-preview";
85+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
86+
const deployment: string = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-4o-mini-audio-preview";
87+
const apiVersion: string = process.env.OPENAI_API_VERSION || "2025-01-01-preview";
8888
8989
// Keyless authentication
9090
const getClient = (): AzureOpenAI => {
@@ -180,8 +180,8 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
180180
import { AzureOpenAI } from "openai/index.mjs";
181181
182182
// Set environment variables or edit the corresponding values here.
183-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
184-
const apiKey: string = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
183+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
184+
const apiKey: string = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
185185
const apiVersion: string = "2025-01-01-preview";
186186
const deployment: string = "gpt-4o-mini-audio-preview";
187187
@@ -280,7 +280,7 @@ The script generates an audio file named _dog.wav_ in the same directory as the
280280
} from "@azure/identity";
281281
282282
// Set environment variables or edit the corresponding values here.
283-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
283+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
284284
const apiVersion: string = "2025-01-01-preview";
285285
const deployment: string = "gpt-4o-mini-audio-preview";
286286
@@ -391,8 +391,8 @@ The script generates an audio file named _dog.wav_ in the same directory as the
391391
import { promises as fs } from 'fs';
392392
393393
// Set environment variables or edit the corresponding values here.
394-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
395-
const apiKey: string = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
394+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
395+
const apiKey: string = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
396396
const apiVersion: string = "2025-01-01-preview";
397397
const deployment: string = "gpt-4o-mini-audio-preview";
398398
@@ -503,7 +503,7 @@ The script generates a transcript of the summary of the spoken audio input. It a
503503
} from "@azure/identity";
504504
505505
// Set environment variables or edit the corresponding values here.
506-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT";
506+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT";
507507
const apiVersion: string = "2025-01-01-preview";
508508
const deployment: string = "gpt-4o-mini-audio-preview";
509509
@@ -635,8 +635,8 @@ The script generates a transcript of the summary of the spoken audio input. It a
635635
import { ChatCompletionMessageParam } from "openai/resources/index.mjs";
636636
637637
// Set environment variables or edit the corresponding values here.
638-
const endpoint: string = process.env["AZURE_OPENAI_ENDPOINT"] || "AZURE_OPENAI_ENDPOINT" as string;
639-
const apiKey: string = process.env["AZURE_OPENAI_API_KEY"] || "AZURE_OPENAI_API_KEY";
638+
const endpoint: string = process.env.AZURE_OPENAI_ENDPOINT || "AZURE_OPENAI_ENDPOINT" as string;
639+
const apiKey: string = process.env.AZURE_OPENAI_API_KEY || "AZURE_OPENAI_API_KEY";
640640
const apiVersion: string = "2025-01-01-preview";
641641
const deployment: string = "gpt-4o-mini-audio-preview";
642642

0 commit comments

Comments
 (0)