Skip to content

Commit b323066

Browse files
committed
update
1 parent 93e3eac commit b323066

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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

1414
[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-js/tree/main/sdk/openai/openai/samples)
@@ -30,19 +30,14 @@ ms.date: 07/26/2023
3030

3131
[!INCLUDE [environment-variables](environment-variables.md)]
3232

33-
34-
In a console window (such as cmd, PowerShell, or Bash), create a new directory for your app, and navigate to it. Then run the `npm init` command to create a node application with a _package.json_ file.
35-
36-
```console
37-
npm init
38-
```
33+
In a console window (such as cmd, PowerShell, or Bash), create a new directory for your app, and navigate to it.
3934

4035
## Install the client library
4136

42-
Install the Azure OpenAI client library for JavaScript with npm:
37+
Install the Azure OpenAI client library for JavaScript with npm from within the context of your new directory:
4338

4439
```console
45-
npm install @azure/openai
40+
npm install openai @azure/openai dotenv
4641
```
4742

4843
Your app's _package.json_ file will be updated with the dependencies.
@@ -56,25 +51,31 @@ Open a command prompt where you created the new project, and create a new file n
5651

5752
```javascript
5853
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
59-
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] ;
60-
const azureApiKey = process.env["AZURE_OPENAI_API_KEY"] ;
54+
55+
// Load the .env file if it exists
56+
const dotenv = require("dotenv");
57+
dotenv.config();
58+
59+
// You will need to set these environment variables or edit the following values
60+
const endpoint = process.env["ENDPOINT"] || "<endpoint>";
61+
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>";
6162

6263
const prompt = ["When was Microsoft founded?"];
6364

6465
async function main() {
6566
console.log("== Get completions Sample ==");
6667

6768
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
68-
const deploymentId = "gpt-35-turbo-instruct";
69-
const result = await client.getCompletions(deploymentId, prompt);
69+
const deploymentId = "gpt-35-turbo-instruct"; //The deployment name for your completions API model. The instruct model is the only new model that supports the legacy API.
70+
const result = await client.getCompletions(deploymentId, prompt, { maxTokens: 128 });
7071

7172
for (const choice of result.choices) {
7273
console.log(choice.text);
7374
}
7475
}
7576

7677
main().catch((err) => {
77-
console.error("The sample encountered an error:", err);
78+
console.error("Error occurred:", err);
7879
});
7980

8081
module.exports = { main };

0 commit comments

Comments
 (0)