You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This article has been updated to use the [latest OpenAI npm package](https://www.npmjs.com/package/openai) which now fully supports Azure OpenAI.If you are looking for code examples for the legacy Azure OpenAI JavaScript SDK they are currently still [1available in this repo](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples/v1-beta/javascript).
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
-
```
36
+
In a console window (such as cmd, PowerShell, or Bash), create a new directory for your app, and navigate to it.
39
37
40
38
## Install the client library
41
39
42
-
Install the Azure OpenAI client library for JavaScript with npm:
40
+
Install the required packages for JavaScript with npm from within the context of your new directory:
43
41
44
42
```console
45
-
npm install @azure/openai
43
+
npm install openai dotenv @azure/identity
46
44
```
47
45
48
46
Your app's _package.json_ file will be updated with the dependencies.
@@ -55,34 +53,39 @@ Your app's _package.json_ file will be updated with the dependencies.
55
53
Open a command prompt where you created the new project, and create a new file named Completion.js. Copy the following code into the Completion.js file.
constdeployment="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.
console.error("The sample encountered an error:", err);
83
+
console.error("Error occurred:", err);
78
84
});
79
85
80
86
module.exports= { main };
81
87
```
82
88
83
-
> [!IMPORTANT]
84
-
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.
85
-
86
89
Run the script with the following command:
87
90
88
91
```cmd
@@ -97,6 +100,47 @@ node.exe Completion.js
97
100
Microsoft was founded on April 4, 1975.
98
101
```
99
102
103
+
## Microsoft Entra ID
104
+
105
+
> [!IMPORTANT]
106
+
> In the previous example we are demonstrating key-based authentication. Once you have tested with key-based authentication successfully, we recommend using the more secure [Microsoft Entra ID](/entra/fundamentals/whatis) for authentication which is demonstrated in the next code sample. Getting started with [Microsoft Entra ID] will require some additional [prerequisites](https://www.npmjs.com/package/@azure/identity).
> If your receive the error: *Error occurred: OpenAIError: The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.* You may need to remove a pre-existing environment variable for the API key from your system. Even though the Microsoft Entra ID code sample is not explicitly referencing the API key environment variable, if one is present on the system executing this sample, this error will still be generated.
143
+
100
144
> [!div class="nextstepaction"]
101
145
> [I ran into an issue when running the code sample.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=JAVASCRIPT&Pillar=AOAI&&Product=gpt&Page=quickstart&Section=Create-application)
0 commit comments