diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/README.md b/sdk/ai/ai-projects/samples/v1-beta/javascript/README.md deleted file mode 100644 index 96ac396ed4d7..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/README.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -page_type: sample -languages: - - javascript -products: - - azure -urlFragment: ai-projects-javascript-beta ---- - -# 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][agents_agentsbasics] | Create and delete an agent. | -| [connections/connectionsBasics.js][connections_connectionsbasics] | 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][datasets_datasetsbasics] | 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][deployments_deploymentsbasics] | 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][evaluations_agentevaluation] | This sample demonstrates how to create an agent evaluation using the Azure AI Projects SDK. | -| [evaluations/evaluationBasics.js][evaluations_evaluationbasics] | Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all evaluations, and perform various operations on them. | -| [indexes/indexesBasics.js][indexes_indexesbasics] | 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][inference_azureopenaichat] | Given an AIProjectClient, this sample demonstrates how to get an Azure OpenAI client and create a chat completion. | -| [inference/chatCompletion.js][inference_chatcompletion] | 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][inference_imageembedding] | 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][inference_textembeddings] | 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/inferenceTelemetry.js][telemetry_inferencetelemetry] | This sample demonstrates how to enable telemetry for inference operations using AIProjectClient. | -| [telemetry/telemetryBasics.js][telemetry_telemetrybasics] | 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](https://github.com/nodejs/release#release-schedule). - -You need [an Azure subscription][freesub] 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][package]. - -## Setup - -To run the samples using the published version of the package: - -1. Install the dependencies using `npm`: - -```bash -npm install -``` - -2. 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. - -3. Run whichever samples you like (note that some samples may require additional setup, see the table above): - -```bash -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): - -```bash -cross-env AZURE_AI_PROJECT_ENDPOINT_STRING="" node agents\agentsBasics.js -``` - -## Next Steps - -Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. - -[agents_agentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBasics.js -[connections_connectionsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/connections/connectionsBasics.js -[datasets_datasetsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/datasets/datasetsBasics.js -[deployments_deploymentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/deployments/deploymentsBasics.js -[evaluations_agentevaluation]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/agentEvaluation.js -[evaluations_evaluationbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/evaluationBasics.js -[indexes_indexesbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/indexes/indexesBasics.js -[inference_azureopenaichat]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/azureOpenAIChat.js -[inference_chatcompletion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/chatCompletion.js -[inference_imageembedding]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/imageEmbedding.js -[inference_textembeddings]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/textEmbeddings.js -[telemetry_inferencetelemetry]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceTelemetry.js -[telemetry_telemetrybasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/telemetryBasics.js -[apiref]: https://learn.microsoft.com/javascript/api/@azure/ai-projects -[freesub]: https://azure.microsoft.com/free/ -[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects/README.md diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBasics.js deleted file mode 100644 index 670d7699cfce..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBasics.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to create and delete an agent using the Azure AI Projects SDK. - * @summary Create and delete an agent. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -async function main() { - const client = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const agent = await client.agents.createAgent("gpt-4o", { - name: "my-agent", - instructions: "You are a helpful agent", - }); - - console.log(`Created agent, agent ID : ${agent.id}`); - - await client.agents.deleteAgent(agent.id); - - console.log(`Deleted agent, agent ID: ${agent.id}`); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/connections/connectionsBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/connections/connectionsBasics.js deleted file mode 100644 index d08cc0a3d7ef..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/connections/connectionsBasics.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use basic connections operations. - * - * @summary 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. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // List the details of all the connections - const connections = []; - const connectionNames = []; - for await (const connection of project.connections.list()) { - connections.push(connection); - connectionNames.push(connection.name); - } - console.log(`Retrieved connections: ${connectionNames}`); - - // Get the details of a connection, without credentials - const connectionName = connections[0].name; - const connection = await project.connections.get(connectionName); - console.log( - "connection.type: ", - connection.type, - "connection.name: ", - connection.name, - "connection.target: ", - connection.target, - ); - - const connectionWithCredentials = await project.connections.getWithCredentials(connectionName); - const credentials = connectionWithCredentials.credentials; - console.log("credentials.type: ", credentials.type, "credentials", credentials); - - // List all connections of a specific type - const azureAIConnections = []; - for await (const azureOpenAIConnection of project.connections.list({ - connectionType: "AzureOpenAI", - defaultConnection: true, - })) { - azureAIConnections.push(azureOpenAIConnection); - } - console.log(`Retrieved ${azureAIConnections.length} Azure OpenAI connections`); - - // Get the details of a default connection - const defaultConnection = await project.connections.getDefault("AzureOpenAI", true); - console.log(`Retrieved default connection ${JSON.stringify(defaultConnection, null, 2)}`); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/datasets/datasetsBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/datasets/datasetsBasics.js deleted file mode 100644 index e846dc44287d..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/datasets/datasetsBasics.js +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use basic dataset operations. - * - * @summary Given an AIProjectClient, this sample demonstrates how to enumerate the properties of datasets, - * upload files/folders, create datasets, manage dataset versions, and delete datasets. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -const path = require("path"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const containerConnectionName = - process.env["AZURE_STORAGE_CONNECTION_NAME"] || ""; -const VERSION1 = "1.0"; -const VERSION1_UPDATE = "1.1"; -const VERSION2 = "2.0"; -const VERSION3 = "3.0"; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // sample files to use in the demonstration - const sampleFolder = "sample_folder"; - - // Create a unique dataset name for this sample run - const datasetName = `sample-dataset-basic`; - const folderDatasetName = `${datasetName}-folder`; - - console.log("Upload a single file and create a new Dataset to reference the file."); - console.log("Here we explicitly specify the dataset version."); - const dataset1 = await project.datasets.uploadFile( - datasetName, - VERSION1, - path.join(__dirname, sampleFolder, "sample_file1.txt"), - { - connectionName: containerConnectionName, - }, - ); - console.log("Dataset1 created:", JSON.stringify(dataset1, null, 2)); - - const updatedDataset1 = await project.datasets.createOrUpdate( - datasetName, - VERSION1_UPDATE, - dataset1, - ); - console.log("Dataset1 updated:", JSON.stringify(updatedDataset1, null, 2)); - - const credential = await project.datasets.getCredentials(dataset1.name, dataset1.version, {}); - console.log("Credential for the dataset:", credential); - - console.log( - "Upload all files in a folder (including subfolders) to the existing Dataset to reference the folder.", - ); - console.log("Here again we explicitly specify a new dataset version"); - const dataset2 = await project.datasets.uploadFolder( - folderDatasetName, - VERSION2, - path.join(__dirname, sampleFolder), - { - connectionName: containerConnectionName, - // only upload sample_file1.txt and sample_file2.txt - filePattern: /sample_file[1-2]\.txt$/, - }, - ); - console.log("Dataset2 created:", JSON.stringify(dataset2, null, 2)); - - console.log( - "Upload a single file to the existing dataset, while letting the service increment the version", - ); - const dataset3 = await project.datasets.uploadFile( - datasetName, - VERSION3, - path.join(__dirname, sampleFolder, "sample_file2.txt"), - { - connectionName: containerConnectionName, - }, - ); - console.log("Dataset3 created:", JSON.stringify(dataset3, null, 2)); - - console.log("Get an existing Dataset version `1`:"); - const datasetVersion1 = await project.datasets.get(datasetName, VERSION1); - console.log("Dataset version 1:", JSON.stringify(datasetVersion1, null, 2)); - - console.log(`Listing all versions of the Dataset named '${datasetName}':`); - const datasetVersions = project.datasets.listVersions(datasetName); - for await (const version of datasetVersions) { - console.log("List versions:", version); - } - - console.log("List latest versions of all Datasets:"); - const latestDatasets = project.datasets.list(); - for await (const dataset of latestDatasets) { - console.log("List datasets:", dataset); - } - - // List the details of all the datasets - const datasets = project.datasets.listVersions(datasetName); - const allDatasets = []; - for await (const dataset of datasets) { - allDatasets.push(dataset); - } - console.log(`Retrieved ${allDatasets.length} datasets`); - - console.log("Delete all Datasets created above:"); - await project.datasets.delete(datasetName, VERSION1); - await project.datasets.delete(folderDatasetName, VERSION2); - await project.datasets.delete(datasetName, dataset3.version); - console.log("All specified Datasets have been deleted."); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/deployments/deploymentsBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/deployments/deploymentsBasics.js deleted file mode 100644 index 125690b26c62..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/deployments/deploymentsBasics.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage deployments. - * - * @summary 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. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const modelPublisher = process.env["MODEL_PUBLISHER"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // List all deployments - console.log("List all deployments:"); - const deployments = []; - const properties = []; - - for await (const deployment of project.deployments.list()) { - // Check if this is a ModelDeployment (has the required properties) - if ( - deployment.type === "ModelDeployment" && - "modelName" in deployment && - "modelPublisher" in deployment && - "modelVersion" in deployment - ) { - deployments.push(deployment); - properties.push({ - name: deployment.name, - modelPublisher: deployment.modelPublisher, - modelName: deployment.modelName, - }); - } - } - console.log(`Retrieved deployments: ${JSON.stringify(properties, null, 2)}`); - - // List all deployments by a specific model publisher (assuming we have one from the list) - console.log(`List all deployments by the model publisher '${modelPublisher}':`); - const filteredDeployments = []; - for await (const deployment of project.deployments.list({ - modelPublisher, - })) { - // Check if this is a ModelDeployment - if ( - deployment.type === "ModelDeployment" && - "modelName" in deployment && - "modelPublisher" in deployment && - "modelVersion" in deployment - ) { - filteredDeployments.push(deployment); - } - } - console.log( - `Retrieved ${filteredDeployments.length} deployments from model publisher '${modelPublisher}'`, - ); - - // Get a single deployment by name - if (deployments.length > 0) { - const deploymentName = deployments[0].name; - console.log(`Get a single deployment named '${deploymentName}':`); - const singleDeployment = await project.deployments.get(deploymentName); - console.log(`Retrieved deployment: ${JSON.stringify(singleDeployment, null, 2)}`); - } -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/agentEvaluation.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/agentEvaluation.js deleted file mode 100644 index 8b278f486451..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/agentEvaluation.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to create an agent evaluation using the Azure AI Projects SDK. - */ - -const { AIProjectClient, EvaluatorIds } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - // create an agent evaluation - const agent = await project.agents.createAgent("gpt-4o", { - name: "agent-evaluation-test", - instructions: "You are helpful agent", - }); - console.log(`Created agent, agent ID: ${agent.id}`); - - const thread = await project.agents.threads.create(); - console.log(`Created thread, thread ID: ${thread.id}`); - const message = await project.agents.messages.create(thread.id, "user", "Hello, tell me a joke"); - console.log(`Created message, message ID: ${message.id}`); - // Create and poll a run - console.log("Creating run..."); - const run = await project.agents.runs.createAndPoll(thread.id, agent.id, { - pollingOptions: { - intervalInMs: 2000, - }, - }); - console.log(`Run finished with status: ${run.status}`); - - const agentEvaluationRequest = { - runId: run.id, - threadId: thread.id, - evaluators: { - violence: { - id: EvaluatorIds.VIOLENCE, - }, - }, - samplingConfiguration: { - name: "test", - samplingPercent: 100, - maxRequestRate: 100, - }, - redactionConfiguration: { - redactScoreProperties: false, - }, - appInsightsConnectionString: await project.telemetry.getConnectionString(), - }; - - const agentEvaluationResponse = - await project.evaluations.createAgentEvaluation(agentEvaluationRequest); - console.log(`Created agent evaluation, evaluation ID: ${agentEvaluationResponse.id}`); -} - -main().catch((err) => { - console.error("An error occurred:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/evaluationBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/evaluationBasics.js deleted file mode 100644 index e2cdef327fbc..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/evaluations/evaluationBasics.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage evaluations. - * - * @summary Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all evaluations, - * and perform various operations on them. - */ - -const { AIProjectClient, EvaluatorIds } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -const path = require("path"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const evaluationDeploymentName = - process.env["EVALUATION_DEPLOYMENT_NAME"] || ""; -const containerConnectionName = - process.env["AZURE_STORAGE_CONNECTION_NAME"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const filePath = path.join(__dirname, "sample_data_evaluation.jsonl"); - // upload a file to the dataset - const dataset = await project.datasets.uploadFile("data-evaluation-test", "1.0.5", filePath, { - connectionName: containerConnectionName, - }); - console.log("Dataset created:", JSON.stringify(dataset, null, 2)); - // create a new evaluation - const newEvaluation = { - displayName: "Evaluation 1", - description: "This is a test evaluation", - data: { - type: "dataset", - id: dataset.id, - }, - evaluators: { - relevance: { - id: EvaluatorIds.RELEVANCE, - initParams: { - deploymentName: evaluationDeploymentName, - }, - dataMapping: { - query: "${data.query}", - response: "${data.response}", - }, - }, - }, - }; - - const evalResp = await project.evaluations.create(newEvaluation); - console.log("Create a new evaluation:", JSON.stringify(evalResp, null, 2)); - // get the evaluation by ID - const eval2 = await project.evaluations.get(evalResp.name); - console.log("Get the evaluation by ID:", eval2); - - const evaluations = []; - const evaluationNames = []; - for await (const evaluation of project.evaluations.list()) { - evaluations.push(evaluation); - evaluationNames.push(evaluation.displayName ?? ""); - } - console.log("List of evaluation display names:", evaluationNames); - - const name = evaluations[0].name; - const evaluation = await project.evaluations.get(name); - console.log("Get an evaluation by ID:", JSON.stringify(evaluation, null, 2)); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/indexes/indexesBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/indexes/indexesBasics.js deleted file mode 100644 index d7505bdedf10..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/indexes/indexesBasics.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage indexes. - * - * @summary 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. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const azureAIIndexName = process.env["AZURE_AI_SEARCH_INDEX_NAME"] || ""; -const azureAIIndexVersion = process.env["AZURE_AI_SEARCH_INDEX_VERSION"] || ""; -const azureAIConnectionName = process.env["AZURE_AI_SEARCH_CONNECTION_NAME"] || ""; -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - const name = "my-azure-search-index"; - const azureAIConnectionConfig = { - name, - type: "AzureSearch", - version: azureAIIndexVersion, - indexName: azureAIIndexName, - connectionName: azureAIConnectionName, - }; - - // Create a new Index - const newIndex = await project.indexes.createOrUpdate(name, "1.0", azureAIConnectionConfig); - console.log("Created a new Index:", newIndex); - console.log(`Get an existing Index version '${newIndex.version}':`); - const index = await project.indexes.get(name, newIndex.version); - console.log(index); - - console.log(`Listing all versions of the Index named '${name}':`); - const indexVersions = project.indexes.listVersions(name); - for await (const indexVersion of indexVersions) { - console.log(indexVersion); - } - - console.log("List all Indexes:"); - const allIndexes = project.indexes.list(); - for await (const i of allIndexes) { - console.log("Index:", i); - } - - console.log("Delete the Index versions created above:"); - await project.indexes.delete(name, newIndex.version); - - console.log("Index operations completed successfully"); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/azureOpenAIChat.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/azureOpenAIChat.js deleted file mode 100644 index 286eebbfc484..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/azureOpenAIChat.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to create a chat completion using the Azure OpenAI client. - * @summary Given an AIProjectClient, this sample demonstrates how to get an Azure OpenAI client and create a chat completion. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_GPT_MODEL"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - const client = await project.inference.azureOpenAI({ - // The API version should match the version of the Azure OpenAI resource. - apiVersion: "2025-01-01-preview", - }); - const response = await client.chat.completions.create({ - model: deploymentName, - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, // System role not supported for some models - { role: "user", content: "Tell me a joke?" }, - ], - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/chatCompletion.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/chatCompletion.js deleted file mode 100644 index d9c72b025b4b..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/chatCompletion.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the chat completions API to get a response from a chat model. - * @summary Given an AIProjectClient, this sample demonstrates how to get a response from a chat model. - * Get the chat completions for the provided chat messages. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { isUnexpected } = require("@azure/ai-projects/inference"); -const { DefaultAzureCredential } = require("@azure/identity"); -const { createRestError } = require("@azure-rest/core-client"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential({})); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await client.post({ - body: { - model: deploymentName, - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - }); - - console.log("response = ", JSON.stringify(response, null, 2)); - if (isUnexpected(response)) { - throw createRestError( - `chatCompletions failed with unexpected statusCode ${response.status}`, - response, - ); - } - console.log(response.body.choices[0].message.content); -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/imageEmbedding.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/imageEmbedding.js deleted file mode 100644 index 188fc4e1e24a..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/imageEmbedding.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use image embeddings client to get the image embeddings for a given image. - * @summary Given an AIProjectClient, this sample demonstrates how to get the image embeddings for a given image. - * Get the image embeddings for a given image. - */ -const path = require("path"); -const fs = require("fs"); -const { AIProjectClient } = require("@azure/ai-projects"); -const { isUnexpected } = require("@azure/ai-projects/inference"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = - process.env["IMAGE_EMBEDDING_DEPLOYMENT_NAME"] || ""; -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential(), { - apiVersion: "2024-05-01-preview", - }); - const client = project.inference.imageEmbeddings(); - const imagePath = path.resolve(__dirname, "sample1.png"); - const ext = path.extname(imagePath).slice(1); // e.g., 'png', 'jpg', 'jpeg' - const mineType = `image/${ext === "jpg" ? "jpeg" : ext}`; - const imageBuffer = fs.readFileSync(imagePath); - // base64 url encoded image - const base64Data = imageBuffer.toString("base64"); - const imageUrl = `data:${mineType};base64,${base64Data}`; - const response = await client.post({ - body: { - model: deploymentName, - input: [{ image: imageUrl }], - }, - }); - - console.log("response = ", response); - if (isUnexpected(response)) { - throw response.body.error; - } - - for (const item of response.body.data) { - console.log(item.embedding.length); - console.log(item.embedding); - } -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/textEmbeddings.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/textEmbeddings.js deleted file mode 100644 index e620efef34c7..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/inference/textEmbeddings.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the text embeddings client to get the text embeddings for a given text. - * @summary 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. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { isUnexpected } = require("@azure/ai-projects/inference"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const embeddingDeploymentName = - process.env["EMBEDDING_DEPLOYMENT_NAME"] || ""; -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.embeddings({ - apiVersion: "2024-05-01-preview", - }); - const response = await client.post({ - body: { - model: embeddingDeploymentName, - input: ["first phrase", "second phrase", "third phrase"], - }, - }); - - console.log("response = ", response); - if (isUnexpected(response)) { - throw response.body.error; - } - console.log(response.body.data); -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/package.json b/sdk/ai/ai-projects/samples/v1-beta/javascript/package.json deleted file mode 100644 index b7e18c8c9e59..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "@azure-samples/ai-projects-js-beta", - "private": true, - "version": "1.0.0", - "description": "Azure AI Projects client library samples for JavaScript (Beta)", - "engines": { - "node": ">=20.0.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-sdk-for-js.git", - "directory": "sdk/ai/ai-projects" - }, - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic" - ], - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects", - "dependencies": { - "@azure/ai-projects": "next", - "dotenv": "latest", - "@azure/identity": "^4.3.0", - "@azure-rest/core-client": "^2.1.0", - "@opentelemetry/api": "^1.9.0", - "@azure/monitor-opentelemetry": "^1.11.1", - "@opentelemetry/instrumentation": "^0.57.0", - "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7", - "@opentelemetry/sdk-trace-node": "^2.0.0" - } -} diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/sample.env b/sdk/ai/ai-projects/samples/v1-beta/javascript/sample.env deleted file mode 100644 index 0d9bbe518d6f..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/sample.env +++ /dev/null @@ -1,3 +0,0 @@ -AZURE_AI_PROJECTS_CONNECTION_STRING="" - -APPLICATIONINSIGHTS_CONNECTION_STRING="" diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceRemoteTelemetry.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceRemoteTelemetry.js deleted file mode 100644 index 864e71499cfd..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceRemoteTelemetry.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to enable remote telemetry for inference operations using AIProjectClient. - */ - -const { trace, context } = require("@opentelemetry/api"); -const { useAzureMonitor } = require("@azure/monitor-opentelemetry"); -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -const options = { - azureMonitorExporterOptions: { - connectionString: process.env["TELEMETRY_CONNECTION_STRING"] || "", - }, -}; -useAzureMonitor(options); - -async function main() { - const tracer = trace.getTracer("inference-sample", "0.1.0"); - - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await tracer.startActiveSpan("chatCompletions", async (span) => { - const res = await client.post({ - body: { - model: deploymentName, - messages: [ - { - role: "system", - content: "You are a helpful assistant. You will talk like a pirate.", - }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - tracingOptions: { - tracingContext: context.active(), - }, - }); - span.end(); - return res; - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceTelemetry.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceTelemetry.js deleted file mode 100644 index 5a0f30f41c19..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/inferenceTelemetry.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to enable telemetry for inference operations using AIProjectClient. - */ - -const { trace, context } = require("@opentelemetry/api"); -const { registerInstrumentations } = require("@opentelemetry/instrumentation"); -const { createAzureSdkInstrumentation } = require("@azure/opentelemetry-instrumentation-azure-sdk"); -const { - ConsoleSpanExporter, - NodeTracerProvider, - SimpleSpanProcessor, -} = require("@opentelemetry/sdk-trace-node"); -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -const provider = new NodeTracerProvider({ - spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())], -}); - -provider.register(); - -registerInstrumentations({ - instrumentations: [createAzureSdkInstrumentation()], -}); - -async function main() { - const tracer = trace.getTracer("inference-sample", "0.1.0"); - - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await tracer.startActiveSpan("chatCompletions", async (span) => { - const res = await client.post({ - body: { - model: deploymentName, - messages: [ - { - role: "system", - content: "You are a helpful assistant. You will talk like a pirate.", - }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - tracingOptions: { - tracingContext: context.active(), - }, - }); - span.end(); - return res; - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/telemetryBasics.js b/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/telemetryBasics.js deleted file mode 100644 index 3de12f7a9a44..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/javascript/telemetry/telemetryBasics.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use AIProjectClient to get the connection string for telemetry. - * @summary Given the AIProjectClient, this sample shows how to get the connection string for telemetry. - */ - -const { AIProjectClient } = require("@azure/ai-projects"); -const { DefaultAzureCredential } = require("@azure/identity"); -require("dotenv/config"); - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -async function main() { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // get connection string for application insights - const connectionString = await project.telemetry.getConnectionString(); - console.log("Connection string for telemetry: ", connectionString); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); - -module.exports = { main }; diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/README.md b/sdk/ai/ai-projects/samples/v1-beta/typescript/README.md deleted file mode 100644 index fde24082588c..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/README.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -page_type: sample -languages: - - typescript -products: - - azure -urlFragment: ai-projects-typescript-beta ---- - -# Azure AI Projects client library samples for TypeScript (Beta) - -These sample programs show how to use the TypeScript client libraries for Azure AI Projects in some common scenarios. - -| **File Name** | **Description** | -| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| [agents/agentsBasics.ts][agents_agentsbasics] | Create and delete an agent. | -| [connections/connectionsBasics.ts][connections_connectionsbasics] | 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.ts][datasets_datasetsbasics] | 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.ts][deployments_deploymentsbasics] | 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.ts][evaluations_agentevaluation] | This sample demonstrates how to create an agent evaluation using the Azure AI Projects SDK. | -| [evaluations/evaluationBasics.ts][evaluations_evaluationbasics] | Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all evaluations, and perform various operations on them. | -| [indexes/indexesBasics.ts][indexes_indexesbasics] | 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.ts][inference_azureopenaichat] | Given an AIProjectClient, this sample demonstrates how to get an Azure OpenAI client and create a chat completion. | -| [inference/chatCompletion.ts][inference_chatcompletion] | 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.ts][inference_imageembedding] | 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.ts][inference_textembeddings] | 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/inferenceTelemetry.ts][telemetry_inferencetelemetry] | This sample demonstrates how to enable telemetry for inference operations using AIProjectClient. | -| [telemetry/telemetryBasics.ts][telemetry_telemetrybasics] | 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](https://github.com/nodejs/release#release-schedule). - -Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using: - -```bash -npm install -g typescript -``` - -You need [an Azure subscription][freesub] 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][package]. - -## Setup - -To run the samples using the published version of the package: - -1. Install the dependencies using `npm`: - -```bash -npm install -``` - -2. Compile the samples: - -```bash -npm run build -``` - -3. 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. - -4. Run whichever samples you like (note that some samples may require additional setup, see the table above): - -```bash -node dist/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): - -```bash -cross-env AZURE_AI_PROJECT_ENDPOINT_STRING="" node dist/agents\agentsBasics.js -``` - -## Next Steps - -Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. - -[agents_agentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/agents/agentsBasics.ts -[connections_connectionsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/connections/connectionsBasics.ts -[datasets_datasetsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/datasets/datasetsBasics.ts -[deployments_deploymentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/deployments/deploymentsBasics.ts -[evaluations_agentevaluation]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/agentEvaluation.ts -[evaluations_evaluationbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/evaluationBasics.ts -[indexes_indexesbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/indexes/indexesBasics.ts -[inference_azureopenaichat]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/azureOpenAIChat.ts -[inference_chatcompletion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/chatCompletion.ts -[inference_imageembedding]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/imageEmbedding.ts -[inference_textembeddings]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/textEmbeddings.ts -[telemetry_inferencetelemetry]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceTelemetry.ts -[telemetry_telemetrybasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/telemetryBasics.ts -[apiref]: https://learn.microsoft.com/javascript/api/@azure/ai-projects -[freesub]: https://azure.microsoft.com/free/ -[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects/README.md -[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/package.json b/sdk/ai/ai-projects/samples/v1-beta/typescript/package.json deleted file mode 100644 index 20762763ceea..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@azure-samples/ai-projects-ts-beta", - "private": true, - "version": "1.0.0", - "description": "Azure AI Projects client library samples for TypeScript (Beta)", - "engines": { - "node": ">=20.0.0" - }, - "scripts": { - "build": "tsc", - "prebuild": "rimraf dist/" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-sdk-for-js.git", - "directory": "sdk/ai/ai-projects" - }, - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic" - ], - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects", - "dependencies": { - "@azure/ai-projects": "next", - "dotenv": "latest", - "@azure/identity": "^4.3.0", - "@azure-rest/core-client": "^2.1.0", - "@opentelemetry/api": "^1.9.0", - "@azure/monitor-opentelemetry": "^1.11.1", - "@opentelemetry/instrumentation": "^0.57.0", - "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7", - "@opentelemetry/sdk-trace-node": "^2.0.0" - }, - "devDependencies": { - "@types/node": "^20.0.0", - "typescript": "~5.8.2", - "rimraf": "latest" - } -} diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/sample.env b/sdk/ai/ai-projects/samples/v1-beta/typescript/sample.env deleted file mode 100644 index 0d9bbe518d6f..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/sample.env +++ /dev/null @@ -1,3 +0,0 @@ -AZURE_AI_PROJECTS_CONNECTION_STRING="" - -APPLICATIONINSIGHTS_CONNECTION_STRING="" diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/agents/agentsBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/agents/agentsBasics.ts deleted file mode 100644 index 51e5904bdbb2..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/agents/agentsBasics.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to create and delete an agent using the Azure AI Projects SDK. - * @summary Create and delete an agent. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -export async function main(): Promise { - const client = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const agent = await client.agents.createAgent("gpt-4o", { - name: "my-agent", - instructions: "You are a helpful agent", - }); - - console.log(`Created agent, agent ID : ${agent.id}`); - - await client.agents.deleteAgent(agent.id); - - console.log(`Deleted agent, agent ID: ${agent.id}`); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/connections/connectionsBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/connections/connectionsBasics.ts deleted file mode 100644 index d8d46b359ad3..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/connections/connectionsBasics.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use basic connections operations. - * - * @summary 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. - */ - -import type { Connection } from "@azure/ai-projects"; -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // List the details of all the connections - const connections: Connection[] = []; - const connectionNames: string[] = []; - for await (const connection of project.connections.list()) { - connections.push(connection); - connectionNames.push(connection.name); - } - console.log(`Retrieved connections: ${connectionNames}`); - - // Get the details of a connection, without credentials - const connectionName = connections[0].name; - const connection = await project.connections.get(connectionName); - console.log( - "connection.type: ", - connection.type, - "connection.name: ", - connection.name, - "connection.target: ", - connection.target, - ); - - const connectionWithCredentials = await project.connections.getWithCredentials(connectionName); - const credentials = connectionWithCredentials.credentials; - console.log("credentials.type: ", credentials.type, "credentials", credentials); - - // List all connections of a specific type - const azureAIConnections: Connection[] = []; - for await (const azureOpenAIConnection of project.connections.list({ - connectionType: "AzureOpenAI", - defaultConnection: true, - })) { - azureAIConnections.push(azureOpenAIConnection); - } - console.log(`Retrieved ${azureAIConnections.length} Azure OpenAI connections`); - - // Get the details of a default connection - const defaultConnection = await project.connections.getDefault("AzureOpenAI", { - includeCredentials: true, - }); - console.log(`Retrieved default connection ${JSON.stringify(defaultConnection, null, 2)}`); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/datasets/datasetsBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/datasets/datasetsBasics.ts deleted file mode 100644 index d36274f3b9c1..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/datasets/datasetsBasics.ts +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use basic dataset operations. - * - * @summary Given an AIProjectClient, this sample demonstrates how to enumerate the properties of datasets, - * upload files/folders, create datasets, manage dataset versions, and delete datasets. - */ - -import type { DatasetVersionUnion } from "@azure/ai-projects"; -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import * as path from "path"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const containerConnectionName = - process.env["AZURE_STORAGE_CONNECTION_NAME"] || ""; -const VERSION1 = "1.0"; -const VERSION1_UPDATE = "1.1"; -const VERSION2 = "2.0"; -const VERSION3 = "3.0"; - -async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // sample files to use in the demonstration - const sampleFolder = "sample_folder"; - - // Create a unique dataset name for this sample run - const datasetName = `sample-dataset-basic`; - const folderDatasetName = `${datasetName}-folder`; - - console.log("Upload a single file and create a new Dataset to reference the file."); - console.log("Here we explicitly specify the dataset version."); - const dataset1 = await project.datasets.uploadFile( - datasetName, - VERSION1, - path.join(__dirname, sampleFolder, "sample_file1.txt"), - { - connectionName: containerConnectionName, - }, - ); - console.log("Dataset1 created:", JSON.stringify(dataset1, null, 2)); - - const updatedDataset1 = await project.datasets.createOrUpdate( - datasetName, - VERSION1_UPDATE, - dataset1, - ); - console.log("Dataset1 updated:", JSON.stringify(updatedDataset1, null, 2)); - - const credential = await project.datasets.getCredentials(dataset1.name, dataset1.version, {}); - console.log("Credential for the dataset:", credential); - - console.log( - "Upload all files in a folder (including subfolders) to the existing Dataset to reference the folder.", - ); - console.log("Here again we explicitly specify a new dataset version"); - const dataset2 = await project.datasets.uploadFolder( - folderDatasetName, - VERSION2, - path.join(__dirname, sampleFolder), - { - connectionName: containerConnectionName, - // only upload sample_file1.txt and sample_file2.txt - filePattern: /sample_file[1-2]\.txt$/, - }, - ); - console.log("Dataset2 created:", JSON.stringify(dataset2, null, 2)); - - console.log( - "Upload a single file to the existing dataset, while letting the service increment the version", - ); - const dataset3 = await project.datasets.uploadFile( - datasetName, - VERSION3, - path.join(__dirname, sampleFolder, "sample_file2.txt"), - { - connectionName: containerConnectionName, - }, - ); - console.log("Dataset3 created:", JSON.stringify(dataset3, null, 2)); - - console.log("Get an existing Dataset version `1`:"); - const datasetVersion1 = await project.datasets.get(datasetName, VERSION1); - console.log("Dataset version 1:", JSON.stringify(datasetVersion1, null, 2)); - - console.log(`Listing all versions of the Dataset named '${datasetName}':`); - const datasetVersions = project.datasets.listVersions(datasetName); - for await (const version of datasetVersions) { - console.log("List versions:", version); - } - - console.log("List latest versions of all Datasets:"); - const latestDatasets = project.datasets.list(); - for await (const dataset of latestDatasets) { - console.log("List datasets:", dataset); - } - - // List the details of all the datasets - const datasets = project.datasets.listVersions(datasetName); - const allDatasets: DatasetVersionUnion[] = []; - for await (const dataset of datasets) { - allDatasets.push(dataset); - } - console.log(`Retrieved ${allDatasets.length} datasets`); - - console.log("Delete all Datasets created above:"); - await project.datasets.delete(datasetName, VERSION1); - await project.datasets.delete(folderDatasetName, VERSION2); - await project.datasets.delete(datasetName, dataset3.version); - console.log("All specified Datasets have been deleted."); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/deployments/deploymentsBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/deployments/deploymentsBasics.ts deleted file mode 100644 index c2b324a706ca..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/deployments/deploymentsBasics.ts +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage deployments. - * - * @summary 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. - */ - -import type { ModelDeployment } from "@azure/ai-projects"; -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const modelPublisher = process.env["MODEL_PUBLISHER"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // List all deployments - console.log("List all deployments:"); - const deployments: ModelDeployment[] = []; - const properties: Array> = []; - - for await (const deployment of project.deployments.list()) { - // Check if this is a ModelDeployment (has the required properties) - if ( - deployment.type === "ModelDeployment" && - "modelName" in deployment && - "modelPublisher" in deployment && - "modelVersion" in deployment - ) { - deployments.push(deployment); - properties.push({ - name: deployment.name, - modelPublisher: deployment.modelPublisher, - modelName: deployment.modelName, - }); - } - } - console.log(`Retrieved deployments: ${JSON.stringify(properties, null, 2)}`); - - // List all deployments by a specific model publisher (assuming we have one from the list) - console.log(`List all deployments by the model publisher '${modelPublisher}':`); - const filteredDeployments: ModelDeployment[] = []; - for await (const deployment of project.deployments.list({ - modelPublisher, - })) { - // Check if this is a ModelDeployment - if ( - deployment.type === "ModelDeployment" && - "modelName" in deployment && - "modelPublisher" in deployment && - "modelVersion" in deployment - ) { - filteredDeployments.push(deployment); - } - } - console.log( - `Retrieved ${filteredDeployments.length} deployments from model publisher '${modelPublisher}'`, - ); - - // Get a single deployment by name - if (deployments.length > 0) { - const deploymentName = deployments[0].name; - console.log(`Get a single deployment named '${deploymentName}':`); - const singleDeployment = await project.deployments.get(deploymentName); - console.log(`Retrieved deployment: ${JSON.stringify(singleDeployment, null, 2)}`); - } -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/agentEvaluation.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/agentEvaluation.ts deleted file mode 100644 index cde95d5b0055..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/agentEvaluation.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to create an agent evaluation using the Azure AI Projects SDK. - */ - -import { AIProjectClient, EvaluatorIds, AgentEvaluationRequest } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - // create an agent evaluation - const agent = await project.agents.createAgent("gpt-4o", { - name: "agent-evaluation-test", - instructions: "You are helpful agent", - }); - console.log(`Created agent, agent ID: ${agent.id}`); - - const thread = await project.agents.threads.create(); - console.log(`Created thread, thread ID: ${thread.id}`); - const message = await project.agents.messages.create(thread.id, "user", "Hello, tell me a joke"); - console.log(`Created message, message ID: ${message.id}`); - // Create and poll a run - console.log("Creating run..."); - const run = await project.agents.runs.createAndPoll(thread.id, agent.id, { - pollingOptions: { - intervalInMs: 2000, - }, - }); - console.log(`Run finished with status: ${run.status}`); - - const agentEvaluationRequest: AgentEvaluationRequest = { - runId: run.id, - threadId: thread.id, - evaluators: { - violence: { - id: EvaluatorIds.VIOLENCE, - }, - }, - samplingConfiguration: { - name: "test", - samplingPercent: 100, - maxRequestRate: 100, - }, - redactionConfiguration: { - redactScoreProperties: false, - }, - appInsightsConnectionString: await project.telemetry.getConnectionString(), - }; - - const agentEvaluationResponse = - await project.evaluations.createAgentEvaluation(agentEvaluationRequest); - console.log(`Created agent evaluation, evaluation ID: ${agentEvaluationResponse.id}`); -} - -main().catch((err) => { - console.error("An error occurred:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/evaluationBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/evaluationBasics.ts deleted file mode 100644 index 820e8dd91e05..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/evaluations/evaluationBasics.ts +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage evaluations. - * - * @summary Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all evaluations, - * and perform various operations on them. - */ - -import { AIProjectClient, EvaluatorIds } from "@azure/ai-projects"; -import type { Evaluation, EvaluationWithOptionalName } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import * as path from "path"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const evaluationDeploymentName = - process.env["EVALUATION_DEPLOYMENT_NAME"] || ""; -const containerConnectionName = - process.env["AZURE_STORAGE_CONNECTION_NAME"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const filePath = path.join(__dirname, "sample_data_evaluation.jsonl"); - // upload a file to the dataset - const dataset = await project.datasets.uploadFile("data-evaluation-test", "1.0.5", filePath, { - connectionName: containerConnectionName, - }); - console.log("Dataset created:", JSON.stringify(dataset, null, 2)); - // create a new evaluation - const newEvaluation: EvaluationWithOptionalName = { - displayName: "Evaluation 1", - description: "This is a test evaluation", - data: { - type: "dataset", - id: dataset.id, - }, - evaluators: { - relevance: { - id: EvaluatorIds.RELEVANCE, - initParams: { - deploymentName: evaluationDeploymentName, - }, - dataMapping: { - query: "${data.query}", - response: "${data.response}", - }, - }, - }, - }; - - const evalResp = await project.evaluations.create(newEvaluation); - console.log("Create a new evaluation:", JSON.stringify(evalResp, null, 2)); - // get the evaluation by ID - const eval2 = await project.evaluations.get(evalResp.name); - console.log("Get the evaluation by ID:", eval2); - - const evaluations: Evaluation[] = []; - const evaluationNames: string[] = []; - for await (const evaluation of project.evaluations.list()) { - evaluations.push(evaluation); - evaluationNames.push(evaluation.displayName ?? ""); - } - console.log("List of evaluation display names:", evaluationNames); - - const name = evaluations[0].name; - const evaluation = await project.evaluations.get(name); - console.log("Get an evaluation by ID:", JSON.stringify(evaluation, null, 2)); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/indexes/indexesBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/indexes/indexesBasics.ts deleted file mode 100644 index fadda18267d3..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/indexes/indexesBasics.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the AIProjectClient to manage indexes. - * - * @summary 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. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import type { AzureAISearchIndex } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const azureAIIndexName = process.env["AZURE_AI_SEARCH_INDEX_NAME"] || ""; -const azureAIIndexVersion = process.env["AZURE_AI_SEARCH_INDEX_VERSION"] || ""; -const azureAIConnectionName = process.env["AZURE_AI_SEARCH_CONNECTION_NAME"] || ""; -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - const name = "my-azure-search-index"; - const azureAIConnectionConfig: AzureAISearchIndex = { - name, - type: "AzureSearch", - version: azureAIIndexVersion, - indexName: azureAIIndexName, - connectionName: azureAIConnectionName, - }; - - // Create a new Index - const newIndex = await project.indexes.createOrUpdate(name, "1.0", azureAIConnectionConfig); - console.log("Created a new Index:", newIndex); - console.log(`Get an existing Index version '${newIndex.version}':`); - const index = await project.indexes.get(name, newIndex.version); - console.log(index); - - console.log(`Listing all versions of the Index named '${name}':`); - const indexVersions = project.indexes.listVersions(name); - for await (const indexVersion of indexVersions) { - console.log(indexVersion); - } - - console.log("List all Indexes:"); - const allIndexes = project.indexes.list(); - for await (const i of allIndexes) { - console.log("Index:", i); - } - - console.log("Delete the Index versions created above:"); - await project.indexes.delete(name, newIndex.version); - - console.log("Index operations completed successfully"); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/azureOpenAIChat.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/azureOpenAIChat.ts deleted file mode 100644 index b78e4bf18efe..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/azureOpenAIChat.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to create a chat completion using the Azure OpenAI client. - * @summary Given an AIProjectClient, this sample demonstrates how to get an Azure OpenAI client and create a chat completion. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_GPT_MODEL"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - const client = await project.inference.azureOpenAI({ - // The API version should match the version of the Azure OpenAI resource. - apiVersion: "2025-01-01-preview", - }); - const response = await client.chat.completions.create({ - model: deploymentName, - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, // System role not supported for some models - { role: "user", content: "Tell me a joke?" }, - ], - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/chatCompletion.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/chatCompletion.ts deleted file mode 100644 index 8a0fa944c5ac..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/chatCompletion.ts +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the chat completions API to get a response from a chat model. - * @summary Given an AIProjectClient, this sample demonstrates how to get a response from a chat model. - * Get the chat completions for the provided chat messages. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import { isUnexpected } from "@azure/ai-projects/inference"; -import { DefaultAzureCredential } from "@azure/identity"; -import { createRestError } from "@azure-rest/core-client"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential({})); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await client.post({ - body: { - model: deploymentName, - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - }); - - console.log("response = ", JSON.stringify(response, null, 2)); - if (isUnexpected(response)) { - throw createRestError( - `chatCompletions failed with unexpected statusCode ${response.status}`, - response, - ); - } - console.log(response.body.choices[0].message.content); -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/imageEmbedding.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/imageEmbedding.ts deleted file mode 100644 index 0fc673bcaca2..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/imageEmbedding.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use image embeddings client to get the image embeddings for a given image. - * @summary Given an AIProjectClient, this sample demonstrates how to get the image embeddings for a given image. - * Get the image embeddings for a given image. - */ -import * as path from "path"; -import * as fs from "fs"; -import { AIProjectClient } from "@azure/ai-projects"; -import { isUnexpected } from "@azure/ai-projects/inference"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = - process.env["IMAGE_EMBEDDING_DEPLOYMENT_NAME"] || ""; -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential(), { - apiVersion: "2024-05-01-preview", - }); - const client = project.inference.imageEmbeddings(); - const imagePath = path.resolve(__dirname, "sample1.png"); - const ext = path.extname(imagePath).slice(1); // e.g., 'png', 'jpg', 'jpeg' - const mineType = `image/${ext === "jpg" ? "jpeg" : ext}`; - const imageBuffer = fs.readFileSync(imagePath); - // base64 url encoded image - const base64Data = imageBuffer.toString("base64"); - const imageUrl = `data:${mineType};base64,${base64Data}`; - const response = await client.post({ - body: { - model: deploymentName, - input: [{ image: imageUrl }], - }, - }); - - console.log("response = ", response); - if (isUnexpected(response)) { - throw response.body.error; - } - - for (const item of response.body.data) { - console.log(item.embedding.length); - console.log(item.embedding); - } -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/textEmbeddings.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/textEmbeddings.ts deleted file mode 100644 index 8e5631327e2d..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/inference/textEmbeddings.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use the text embeddings client to get the text embeddings for a given text. - * @summary 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. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import { isUnexpected } from "@azure/ai-projects/inference"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const embeddingDeploymentName = - process.env["EMBEDDING_DEPLOYMENT_NAME"] || ""; -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.embeddings({ - apiVersion: "2024-05-01-preview", - }); - const response = await client.post({ - body: { - model: embeddingDeploymentName, - input: ["first phrase", "second phrase", "third phrase"], - }, - }); - - console.log("response = ", response); - if (isUnexpected(response)) { - throw response.body.error; - } - console.log(response.body.data); -} -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceRemoteTelemetry.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceRemoteTelemetry.ts deleted file mode 100644 index 64d642e5fb35..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceRemoteTelemetry.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to enable remote telemetry for inference operations using AIProjectClient. - */ - -import { trace, context } from "@opentelemetry/api"; -import { AzureMonitorOpenTelemetryOptions, useAzureMonitor } from "@azure/monitor-opentelemetry"; -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -const options: AzureMonitorOpenTelemetryOptions = { - azureMonitorExporterOptions: { - connectionString: process.env["TELEMETRY_CONNECTION_STRING"] || "", - }, -}; -useAzureMonitor(options); - -export async function main(): Promise { - const tracer = trace.getTracer("inference-sample", "0.1.0"); - - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await tracer.startActiveSpan("chatCompletions", async (span) => { - const res = await client.post({ - body: { - model: deploymentName, - messages: [ - { - role: "system", - content: "You are a helpful assistant. You will talk like a pirate.", - }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - tracingOptions: { - tracingContext: context.active(), - }, - }); - span.end(); - return res; - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceTelemetry.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceTelemetry.ts deleted file mode 100644 index 48bc70a8dd6c..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/inferenceTelemetry.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to enable telemetry for inference operations using AIProjectClient. - */ - -import { trace, context } from "@opentelemetry/api"; -import { registerInstrumentations } from "@opentelemetry/instrumentation"; -import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk"; -import { - ConsoleSpanExporter, - NodeTracerProvider, - SimpleSpanProcessor, -} from "@opentelemetry/sdk-trace-node"; -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; -const deploymentName = process.env["DEPLOYMENT_NAME"] || ""; - -const provider = new NodeTracerProvider({ - spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())], -}); - -provider.register(); - -registerInstrumentations({ - instrumentations: [createAzureSdkInstrumentation()], -}); - -export async function main(): Promise { - const tracer = trace.getTracer("inference-sample", "0.1.0"); - - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - const client = project.inference.chatCompletions({ - apiVersion: "2024-05-01-preview", - }); - const response = await tracer.startActiveSpan("chatCompletions", async (span) => { - const res = await client.post({ - body: { - model: deploymentName, - messages: [ - { - role: "system", - content: "You are a helpful assistant. You will talk like a pirate.", - }, // System role not supported for some models - { role: "user", content: "How many feet are in a mile?" }, - ], - }, - tracingOptions: { - tracingContext: context.active(), - }, - }); - span.end(); - return res; - }); - - console.log("response = ", JSON.stringify(response, null, 2)); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/telemetryBasics.ts b/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/telemetryBasics.ts deleted file mode 100644 index 9a7c6fca5ddc..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/src/telemetry/telemetryBasics.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * This sample demonstrates how to use AIProjectClient to get the connection string for telemetry. - * @summary Given the AIProjectClient, this sample shows how to get the connection string for telemetry. - */ - -import { AIProjectClient } from "@azure/ai-projects"; -import { DefaultAzureCredential } from "@azure/identity"; -import "dotenv/config"; - -const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || ""; - -export async function main(): Promise { - const project = new AIProjectClient(endpoint, new DefaultAzureCredential()); - - // get connection string for application insights - const connectionString = await project.telemetry.getConnectionString(); - console.log("Connection string for telemetry: ", connectionString); -} - -main().catch((err) => { - console.error("Error running sample:", err); -}); diff --git a/sdk/ai/ai-projects/samples/v1-beta/typescript/tsconfig.json b/sdk/ai/ai-projects/samples/v1-beta/typescript/tsconfig.json deleted file mode 100644 index 400db87cf648..000000000000 --- a/sdk/ai/ai-projects/samples/v1-beta/typescript/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2023", - "module": "commonjs", - "lib": [], - "importHelpers": true, - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "moduleResolution": "node10", - "esModuleInterop": true, - "outDir": "./dist", - "resolveJsonModule": true - }, - "include": [ - "./src" - ] -}