Skip to content

Commit 8d5d3d5

Browse files
authored
Merge pull request #3319 from MicrosoftDocs/repo_sync_working_branch
Confirm merge from repo_sync_working_branch to main to sync with https://github.com/MicrosoftDocs/azure-ai-docs (branch main)
2 parents 38d60ee + 501c408 commit 8d5d3d5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

articles/ai-services/agents/includes/quickstart-javascript.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ ms.custom: devx-track-js
3131
| Run | Activation of an agent to begin running based on the contents of Thread. The agent uses its configuration and Thread’s Messages to perform tasks by calling models and tools. As part of a Run, the agent appends Messages to the Thread. |
3232
| Run Step | A detailed list of steps the agent took as part of a Run. An agent can call tools or create Messages during its run. Examining Run Steps allows you to understand how the agent is getting to its results. |
3333

34-
Run the following commands to install the npm packages.
34+
First, initialize a new project by running:
35+
36+
```console
37+
npm init -y
38+
```
39+
40+
Run the following commands to install the npm packages required.
3541

3642
```console
3743
npm install @azure/ai-projects
3844
npm install @azure/identity
45+
npm install dotenv
3946
```
4047

4148
Next, to authenticate your API requests and run the program, use the [az login](/cli/azure/authenticate-azure-cli-interactively) command to sign into your Azure subscription.
@@ -60,7 +67,9 @@ For example, your connection string may look something like:
6067

6168
`eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name`
6269

63-
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING`.
70+
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING` in a `.env` file.
71+
72+
Next, create an `index.js` file and paste in the code below:
6473

6574
```javascript
6675
// index.js
@@ -75,12 +84,16 @@ import {
7584
ToolUtility,
7685
} from "@azure/ai-projects";
7786
import { DefaultAzureCredential } from "@azure/identity";
87+
import dotenv from 'dotenv';
88+
89+
dotenv.config();
7890

79-
const connectionString =
80-
process.env["AZURE_AI_PROJECTS_CONNECTION_STRING"] || "<project connection string>";
91+
// Set the connection string from the environment variable
92+
const connectionString = process.env.PROJECT_CONNECTION_STRING;
8193

94+
// Throw an error if the connection string is not set
8295
if (!connectionString) {
83-
throw new Error("AZURE_AI_PROJECTS_CONNECTION_STRING must be set in the environment variables");
96+
throw new Error("Please set the PROJECT_CONNECTION_STRING environment variable.");
8497
}
8598

8699
export async function main() {
@@ -149,7 +162,7 @@ export async function main() {
149162
// messages[0] is the most recent
150163
for (let i = messages.data.length - 1; i >= 0; i--) {
151164
const m = messages.data[i];
152-
if (isOutputOfType(m.content[0], "text")) {
165+
if (m.content && m.content.length > 0 && isOutputOfType(m.content[0], "text")) {
153166
const textContent = m.content[0];
154167
console.log(`${textContent.text.value}`);
155168
console.log(`---------------------------------`);
@@ -164,3 +177,5 @@ main().catch((err) => {
164177
console.error("The sample encountered an error:", err);
165178
});
166179
```
180+
181+
Run the code using `node index.js` and observe.

0 commit comments

Comments
 (0)