Skip to content

Commit 172481f

Browse files
committed
Assistants quickstart JS
1 parent f2ab553 commit 172481f

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,33 @@ For passwordless authentication, you need to
3232

3333
## Set up
3434

35+
1. Create a new folder `assistants-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
36+
37+
```shell
38+
mkdir assistants-quickstart && code assistants-quickstart
39+
```
40+
41+
42+
1. Create the `package.json` with the following command:
43+
44+
```shell
45+
npm init -y
46+
```
47+
48+
1. Update the `package.json` to ECMAScript with the following command:
49+
50+
```shell
51+
npm pkg set type=module
52+
```
53+
54+
3555
1. Install the OpenAI Assistants client library for JavaScript with:
3656

3757
```console
3858
npm install openai
3959
```
4060

41-
2. For the **recommended** passwordless authentication:
61+
1. For the **recommended** passwordless authentication:
4262

4363
```console
4464
npm install @azure/identity
@@ -104,27 +124,68 @@ An individual assistant can access up to 128 tools including `code interpreter`,
104124

105125
#### [TypeScript](#tab/typescript)
106126

107-
Sign in to Azure with `az login` then create and run an assistant with the following **recommended** passwordless TypeScript module (index.ts):
127+
Create an assistant with the following **recommended** passwordless TypeScript module (index.ts):
108128

109129
:::code language="typescript" source="~/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/ts/src/index.ts" :::
110130

111131
To use the service key for authentication, you can create and run an assistant with the following TypeScript module (index.ts):
112132

113133
:::code language="typescript" source="~/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/ts/src/index-using-password.ts" :::
114134

135+
Create the `tsconfig.json` file to transpile the TypeScript code and copy the following code for ECMAScript.
136+
137+
```json
138+
{
139+
"compilerOptions": {
140+
"target": "es2022",
141+
"module": "es2022",
142+
"moduleResolution": "node",
143+
}
144+
}
145+
```
146+
115147
#### [JavaScript](#tab/javascript)
116148

117-
Sign in to Azure with `az login` then create and run an assistant with the following **recommended** passwordless JavaScript module (index.mjs):
149+
Create an assistant with the following **recommended** passwordless JavaScript module (index.mjs):
118150

119151
:::code language="javascript" source="~/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/js/src/index.mjs" :::
120152

121153
To use the service key for authentication, you can create and run an assistant with the following JavaScript module (index.mjs):
122154

123155
:::code language="javascript" source="~/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/js/src/index-using-password.mjs" :::
124156

125-
126157
---
127158

159+
## Run the code
160+
161+
1. Sign in to Azure with `az login`.
162+
163+
2. Run the code
164+
165+
#### [TypeScript](#tab/typescript)
166+
167+
Transpile from TypeScript to JavaScript.
168+
169+
```shell
170+
tsc index.ts
171+
```
172+
173+
Run the JavaScript file.
174+
175+
```shell
176+
node index.js
177+
```
178+
179+
#### [JavaScript](#tab/javascript)
180+
181+
Run the JavaScript file.
182+
183+
```shell
184+
node index.js
185+
```
186+
187+
```
188+
128189
## Output
129190

130191
```console

0 commit comments

Comments
 (0)