diff --git a/sdk/textanalytics/ai-text-analytics/samples-dev/modelVersion.ts b/sdk/textanalytics/ai-text-analytics/samples-dev/modelVersion.ts new file mode 100644 index 000000000000..6a6ecf8de472 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/samples-dev/modelVersion.ts @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample shows how to choose model versions to use with pre-built Text + * Analytics models. + * + * @summary shows how to choose model versions for pre-built models. + * @azsdk-weight 40 + */ + +import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +// You will need to set these environment variables or edit the following values +const endpoint = process.env["ENDPOINT"] || ""; +const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || ""; + +const documents = ["This document is written in English."]; + +export async function main() { + console.log("== Choosing Model Version Sample =="); + + const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey)); + + const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + }); + + console.log( + `The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}` + ); + + const poller = await client.beginAnalyzeActions( + documents, + { + recognizeEntitiesActions: [ + { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + } + ] + }, + "en" + ); + + const beginAnalyzeActionsResults = await poller.pollUntilDone(); + + for await (const page of beginAnalyzeActionsResults) { + const entitiesAction = page.recognizeEntitiesResults[0]; + if (!entitiesAction.error) { + console.log( + `The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}` + ); + } + } +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +}); diff --git a/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/README.md b/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/README.md index 0b8851ffe494..1c707e8079bb 100644 --- a/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/README.md +++ b/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/README.md @@ -27,6 +27,7 @@ These sample programs show how to use the JavaScript client libraries for Azure | [authenticationMethods.js][authenticationmethods] | authenticates a service client using both Azure Active Directory and an API key | | [beginAnalyzeActions.js][beginanalyzeactions] | applies multiple Text Analytics actions per document | | [customText.js][customtext] | applies multiple Custom Text Analytics actions per document | +| [modelVersion.js][modelversion] | shows how to choose model versions for pre-built models. | ## Prerequisites @@ -80,6 +81,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP [authenticationmethods]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/authenticationMethods.js [beginanalyzeactions]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/beginAnalyzeActions.js [customtext]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/customText.js +[modelversion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js [apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-text-analytics [freesub]: https://azure.microsoft.com/free/ [createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account diff --git a/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js b/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js new file mode 100644 index 000000000000..61c11ce7feb7 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample shows how to choose model versions to use with pre-built Text + * Analytics models. + * + * @summary shows how to choose model versions for pre-built models. + */ + +const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics"); + +// Load the .env file if it exists +const dotenv = require("dotenv"); +dotenv.config(); + +// You will need to set these environment variables or edit the following values +const endpoint = process.env["ENDPOINT"] || ""; +const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || ""; + +const documents = ["This document is written in English."]; + +async function main() { + console.log("== Choosing Model Version Sample =="); + + const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey)); + + const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + }); + + console.log( + `The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}` + ); + + const poller = await client.beginAnalyzeActions( + documents, + { + recognizeEntitiesActions: [ + { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + } + ] + }, + "en" + ); + + const beginAnalyzeActionsResults = await poller.pollUntilDone(); + + for await (const page of beginAnalyzeActionsResults) { + const entitiesAction = page.recognizeEntitiesResults[0]; + if (!entitiesAction.error) { + console.log( + `The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}` + ); + } + } +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +}); diff --git a/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/README.md b/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/README.md index 464b9951e7c6..c20b93ddf8ac 100644 --- a/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/README.md +++ b/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/README.md @@ -27,6 +27,7 @@ These sample programs show how to use the TypeScript client libraries for Azure | [authenticationMethods.ts][authenticationmethods] | authenticates a service client using both Azure Active Directory and an API key | | [beginAnalyzeActions.ts][beginanalyzeactions] | applies multiple Text Analytics actions per document | | [customText.ts][customtext] | applies multiple Custom Text Analytics actions per document | +| [modelVersion.ts][modelversion] | shows how to choose model versions for pre-built models. | ## Prerequisites @@ -92,6 +93,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP [authenticationmethods]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/authenticationMethods.ts [beginanalyzeactions]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/beginAnalyzeActions.ts [customtext]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/customText.ts +[modelversion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts [apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-text-analytics [freesub]: https://azure.microsoft.com/free/ [createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account diff --git a/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts b/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts new file mode 100644 index 000000000000..b41a09562fb1 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample shows how to choose model versions to use with pre-built Text + * Analytics models. + * + * @summary shows how to choose model versions for pre-built models. + */ + +import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +// You will need to set these environment variables or edit the following values +const endpoint = process.env["ENDPOINT"] || ""; +const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || ""; + +const documents = ["This document is written in English."]; + +export async function main() { + console.log("== Choosing Model Version Sample =="); + + const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey)); + + const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + }); + + console.log( + `The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}` + ); + + const poller = await client.beginAnalyzeActions( + documents, + { + recognizeEntitiesActions: [ + { + /** + * Specify the model version by setting this property. "latest" indicates + * the latest generaly availability version of the model. When not specified, + * latest will be assumed. Model versions are date based, e.g "2021-06-01". + * See the documentation for a list of all model versions: + * https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model + */ + modelVersion: "latest" + } + ] + }, + "en" + ); + + const beginAnalyzeActionsResults = await poller.pollUntilDone(); + + for await (const page of beginAnalyzeActionsResults) { + const entitiesAction = page.recognizeEntitiesResults[0]; + if (!entitiesAction.error) { + console.log( + `The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}` + ); + } + } +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +});