Skip to content

Commit 54e7dcf

Browse files
committed
update
1 parent 93e3eac commit 54e7dcf

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ ms.service: azure-ai-openai
88
ms.topic: include
99
author: mrbullwinkle
1010
ms.author: mbullwin
11-
ms.date: 07/26/2023
11+
ms.date: 05/20/2024
1212
---
1313

14-
[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) | [Retrieval Augmented Generation (RAG) enterprise chat template](/azure/developer/javascript/get-started-app-chat-template)|
14+
[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/openai-azure-samples/sdk/openai/openai/samples/v1-beta/javascript)
1515

1616
## Prerequisites
1717

1818
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
1919
- Access granted to the Azure OpenAI service in the desired Azure subscription.
2020
Currently, access to this service is granted only by application. You can apply for access to Azure OpenAI Service by completing the form at [https://aka.ms/oai/access](https://aka.ms/oai/access?azure-portal=true).
2121
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
22-
- An Azure OpenAI Service resource with either the `gpt-35-turbo` or the `gpt-4` models deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
22+
- An Azure OpenAI Service resource with either 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).
2323

2424
> [!div class="nextstepaction"]
2525
> [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)
@@ -43,7 +43,7 @@ npm init
4343
Install the Azure OpenAI client library for JavaScript with npm:
4444

4545
```console
46-
npm install @azure/openai
46+
npm install openai @azure/openai dotenv
4747
```
4848

4949
Your app's _package.json_ file will be updated with the dependencies.
@@ -57,30 +57,34 @@ Open a command prompt where you want the new project, and create a new file name
5757

5858
```javascript
5959
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
60-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] ;
61-
const azureApiKey = process.env["AZURE_OPENAI_API_KEY"] ;
6260

63-
const messages = [
64-
{ role: "system", content: "You are a helpful assistant." },
65-
{ role: "user", content: "Does Azure OpenAI support customer managed keys?" },
66-
{ role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI" },
67-
{ role: "user", content: "Do other Azure AI services support this too" },
68-
];
61+
// Load the .env file if it exists
62+
const dotenv = require("dotenv");
63+
dotenv.config();
64+
65+
// You will need to set these environment variables or edit the following values
66+
const endpoint = process.env["ENDPOINT"] || "<endpoint>";
67+
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>";
6968

7069
async function main() {
7170
console.log("== Chat Completions Sample ==");
7271

7372
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
74-
const deploymentId = "gpt-35-turbo";
75-
const result = await client.getChatCompletions(deploymentId, messages);
73+
const deploymentId = "gpt-35-turbo"; //set this value to match your model deployment name
74+
const result = await client.getChatCompletions(deploymentId, [
75+
{ role: "system", content: "You are a helpful assistant." },
76+
{ role: "user", content: "Does Azure OpenAI support customer managed keys?" },
77+
{ role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI?" },
78+
{ role: "user", content: "Do other Azure AI services support this too?" },
79+
]);
7680

7781
for (const choice of result.choices) {
7882
console.log(choice.message);
7983
}
8084
}
8185

8286
main().catch((err) => {
83-
console.error("The sample encountered an error:", err);
87+
console.error("Error occurred:", err);
8488
});
8589

8690
module.exports = { main };
@@ -100,8 +104,8 @@ node.exe ChatCompletion.js
100104
```output
101105
== Chat Completions Sample ==
102106
{
103-
role: 'assistant',
104-
content: 'Yes, most Azure AI services support customer managed keys. It is always best to check the specific service documentation to confirm this.'
107+
content: 'Yes, several other Azure AI services also support customer managed keys for enhanced security and control over encryption keys.',
108+
role: 'assistant'
105109
}
106110
```
107111

0 commit comments

Comments
 (0)