Share via

Azure AI Projects client library samples for JavaScript (Beta)

These sample programs show how to use the JavaScript client libraries for Azure AI Projects in some common scenarios.

File Name Description
agents/agentsBasics.js Create and delete an agent.
connections/connectionsBasics.js Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all connections, get the properties of a default connection, and get the properties of a connection by its name.
datasets/datasetsBasics.js Given an AIProjectClient, this sample demonstrates how to enumerate the properties of datasets, upload files/folders, create datasets, manage dataset versions, and delete datasets.
deployments/deploymentsBasics.js Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all deployments, get the properties of a deployment by its name, and delete a deployment.
evaluations/agentEvaluation.js This sample demonstrates how to create an agent evaluation using the Azure AI Projects SDK.
evaluations/evaluationBasics.js Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all evaluations, and perform various operations on them.
indexes/indexesBasics.js Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all indexes, get the properties of an index by its name, and delete an index.
inference/azureOpenAIChat.js Given an AIProjectClient, this sample demonstrates how to get an Azure OpenAI client and create a chat completion.
inference/chatCompletion.js Given an AIProjectClient, this sample demonstrates how to get a response from a chat model. Get the chat completions for the provided chat messages.
inference/imageEmbedding.js Given an AIProjectClient, this sample demonstrates how to get the image embeddings for a given image. Get the image embeddings for a given image.
inference/textEmbeddings.js Given an AIProjectClient, this sample demonstrates how to get the text embeddings for a given text. Get the text embeddings for arrays of given texts.
telemetry/enableTelemetryBasics.js This sample demonstrates how to enable telemetry for the AIProjectClient and send telemetry events to stdout.
telemetry/telemetryBasics.js Given the AIProjectClient, this sample shows how to get the connection string for telemetry.

Prerequisites

The sample programs are compatible with LTS versions of Node.js.

You need an Azure subscription to run these sample programs.

Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.

Adapting the samples to run in the browser may require some additional consideration. For details, please see the package README.

Setup

To run the samples using the published version of the package:

  1. Install the dependencies using npm:
npm install
  1. Edit the file sample.env, adding the correct credentials to access the Azure service and run the samples. Then rename the file from sample.env to just .env. The sample programs will read this file automatically.

  2. Run whichever samples you like (note that some samples may require additional setup, see the table above):

node agents\agentsBasics.js

Alternatively, run a single sample with the correct environment variables set (setting up the .env file is not required if you do this), for example (cross-platform):

npx dev-tool run vendored cross-env AZURE_AI_PROJECT_ENDPOINT_STRING="<azure ai project endpoint string>" node agents\agentsBasics.js

Next Steps

Take a look at our API Documentation for more information about the APIs that are available in the clients.