Skip to content

Commit e52e86c

Browse files
committed
edits
1 parent e7df63a commit e52e86c

File tree

3 files changed

+4
-168
lines changed

3 files changed

+4
-168
lines changed

articles/ai-services/openai/chatgpt-quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Use this article to get started using Azure OpenAI.
5656

5757
::: zone pivot="programming-language-typescript"
5858

59-
[!INCLUDE [JavaScript quickstart](includes/chatgpt-typescript.md)]
59+
[!INCLUDE [TypeScript quickstart](includes/chatgpt-typescript.md)]
6060

6161
::: zone-end
6262

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

Lines changed: 2 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ ms.date: 10/22
1818
1919
## Prerequisites
2020

21-
## [**TypeScript**](#tab/typescript)
22-
23-
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
24-
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
25-
- [TypeScript](https://www.typescriptlang.org/download/)
26-
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
27-
- An Azure OpenAI Service resource with a `gpt-35-turbo` or `gpt-4` series models deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
28-
29-
> [!div class="nextstepaction"]
30-
> [I ran into an issue with the prerequisites.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=JAVASCRIPT&Pillar=AOAI&Product=Chatgpt&Page=quickstart&Section=Prerequisites)
31-
32-
## [**JavaScript**](#tab/javascript)
33-
3421
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
3522
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
3623
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
@@ -39,7 +26,6 @@ ms.date: 10/22
3926
> [!div class="nextstepaction"]
4027
> [I ran into an issue with the prerequisites.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=JAVASCRIPT&Pillar=AOAI&Product=Chatgpt&Page=quickstart&Section=Prerequisites)
4128
42-
---
4329

4430
## Set up
4531

@@ -68,87 +54,8 @@ Your app's _package.json_ file will be updated with the dependencies.
6854

6955
Open a command prompt where you want the new project, and create a new file named ChatCompletion.js. Copy the following code into the ChatCompletion.js file.
7056

71-
## [**TypeScript (Microsoft Entra ID)**](#tab/typescript-keyless)
72-
73-
```typescript
74-
import { AzureOpenAI } from "openai";
75-
import {
76-
DefaultAzureCredential,
77-
getBearerTokenProvider
78-
} from "@azure/identity";
79-
import type {
80-
ChatCompletion,
81-
ChatCompletionCreateParamsNonStreaming,
82-
} from "openai/resources/index";
83-
84-
// You will need to set these environment variables or edit the following values
85-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "<endpoint>";
86-
87-
// Required Azure OpenAI deployment name and API version
88-
const apiVersion = "2024-08-01-preview";
89-
const deploymentName = "gpt-4o-mini"; //This must match your deployment name.
90-
91-
// keyless authentication
92-
const credential = new DefaultAzureCredential();
93-
const scope = "https://cognitiveservices.azure.com/.default";
94-
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
95-
96-
function getClient(): AzureOpenAI {
97-
return new AzureOpenAI({
98-
endpoint,
99-
azureADTokenProvider,
100-
apiVersion,
101-
deployment: deploymentName,
102-
});
103-
}
104-
105-
function createMessages(): ChatCompletionCreateParamsNonStreaming {
106-
return {
107-
messages: [
108-
{ role: "system", content: "You are a helpful assistant." },
109-
{
110-
role: "user",
111-
content: "Does Azure OpenAI support customer managed keys?",
112-
},
113-
{
114-
role: "assistant",
115-
content: "Yes, customer managed keys are supported by Azure OpenAI?",
116-
},
117-
{ role: "user", content: "Do other Azure AI services support this too?" },
118-
],
119-
model: "",
120-
};
121-
}
122-
async function printChoices(completion: ChatCompletion): Promise<void> {
123-
for (const choice of completion.choices) {
124-
console.log(choice.message);
125-
}
126-
}
127-
export async function main() {
128-
const client = getClient();
129-
const messages = createMessages();
130-
const result = await client.chat.completions.create(messages);
131-
await printChoices(result);
132-
}
133-
134-
main().catch((err) => {
135-
console.error("The sample encountered an error:", err);
136-
});
137-
```
138-
139-
Build the script with the following command:
14057

141-
```cmd
142-
tsc
143-
```
144-
145-
Run the script with the following command:
146-
147-
```cmd
148-
node.exe Completion.js
149-
```
150-
151-
## [**JavaScript (Microsoft Entra ID)**](#tab/javascript-keyless)
58+
## [Microsoft Entra ID](#tab/javascript-keyless)
15259

15360
```javascript
15461
const { AzureOpenAI } = require("openai");
@@ -199,79 +106,8 @@ Run the script with the following command:
199106
node.exe ChatCompletion.js
200107
```
201108

202-
## [**TypeScript (API Key)**](#tab/typescript-key)
203-
204-
```typescript
205-
import { AzureOpenAI } from "openai";
206-
import type {
207-
ChatCompletion,
208-
ChatCompletionCreateParamsNonStreaming,
209-
} from "openai/resources/index";
210-
211-
// You will need to set these environment variables or edit the following values
212-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "<endpoint>";
213-
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "<api key>";
214-
215-
// Required Azure OpenAI deployment name and API version
216-
const apiVersion = "2024-08-01-preview";
217-
const deploymentName = "gpt-4o-mini"; //This must match your deployment name.
218-
219-
function getClient(): AzureOpenAI {
220-
return new AzureOpenAI({
221-
endpoint,
222-
apiKey,
223-
apiVersion,
224-
deployment: deploymentName,
225-
});
226-
}
227-
228-
function createMessages(): ChatCompletionCreateParamsNonStreaming {
229-
return {
230-
messages: [
231-
{ role: "system", content: "You are a helpful assistant." },
232-
{
233-
role: "user",
234-
content: "Does Azure OpenAI support customer managed keys?",
235-
},
236-
{
237-
role: "assistant",
238-
content: "Yes, customer managed keys are supported by Azure OpenAI?",
239-
},
240-
{ role: "user", content: "Do other Azure AI services support this too?" },
241-
],
242-
model: "",
243-
};
244-
}
245-
async function printChoices(completion: ChatCompletion): Promise<void> {
246-
for (const choice of completion.choices) {
247-
console.log(choice.message);
248-
}
249-
}
250-
export async function main() {
251-
const client = getClient();
252-
const messages = createMessages();
253-
const result = await client.chat.completions.create(messages);
254-
await printChoices(result);
255-
}
256-
257-
main().catch((err) => {
258-
console.error("The sample encountered an error:", err);
259-
});
260-
```
261-
262-
Build the script with the following command:
263-
264-
```cmd
265-
tsc
266-
```
267-
268-
Run the script with the following command:
269-
270-
```cmd
271-
node.exe Completion.js
272-
```
273109

274-
## [**JavaScript (API key)**](#tab/javascript-key)
110+
## [API key](#tab/javascript-key)
275111

276112
```javascript
277113
const { AzureOpenAI } = require("openai");

articles/ai-services/openai/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Use this article to get started making your first calls to Azure OpenAI.
5555
::: zone-end
5656
::: zone pivot="programming-language-typescript"
5757

58-
[!INCLUDE [JavaScript quickstart](includes/typescript.md)]
58+
[!INCLUDE [TypeScript quickstart](includes/typescript.md)]
5959

6060
::: zone-end
6161

0 commit comments

Comments
 (0)