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
- 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).
27
+
28
+
> [!div class="nextstepaction"]
29
+
> [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)
30
+
31
+
## [**JavaScript**](#tab/javascript)
32
+
21
33
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
22
34
-[LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
23
35
- 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).
24
36
25
37
> [!div class="nextstepaction"]
26
38
> [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)
@@ -52,6 +66,67 @@ Your app's _package.json_ file will be updated with the dependencies.
52
66
53
67
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.
const result =awaitclient.chat.completions.create(messages);
108
+
awaitgetChoices(result);
109
+
}
110
+
111
+
main().catch((err) => {
112
+
console.error("The sample encountered an error:", err);
113
+
});
114
+
```
115
+
116
+
Build the script with the following command:
117
+
118
+
```cmd
119
+
tsc
120
+
```
121
+
122
+
Run the script with the following command:
123
+
124
+
```cmd
125
+
node.exe Completion.js
126
+
```
127
+
128
+
## [**JavaScript**](#tab/javascript)
129
+
55
130
```javascript
56
131
const { AzureOpenAI } =require("openai");
57
132
@@ -97,6 +172,8 @@ Run the script with the following command:
97
172
node.exe ChatCompletion.js
98
173
```
99
174
175
+
---
176
+
100
177
## Output
101
178
102
179
```output
@@ -112,6 +189,56 @@ node.exe ChatCompletion.js
112
189
> [!IMPORTANT]
113
190
> 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.
0 commit comments