Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[textanalytics] Migrate textanalytics projects to use snippets extraction #33212

Merged
merged 14 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/textanalytics/ai-text-analytics/MIGRATION_v5_v6.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- dev-tool snippets ignore -->

# Migrating to `@azure/ai-text-analytics` Version 6

**Note ⚠️**: `@azure/ai-text-analytics` version 6 is currently a beta package. Certain aspects of the package's API surface and implementation may change during the course of its development, and this document is a work-in-progress and may change to reflect updates to the package. We value your feedback, and it is especially useful during the beta development cycle. Please [create an issue](https://github.com/Azure/azure-sdk-for-js/issues/new/choose) to suggest any improvements or report any problems with this guide or with the package itself.
Expand Down
401 changes: 207 additions & 194 deletions sdk/textanalytics/ai-text-analytics/README.md

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions sdk/textanalytics/ai-text-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"sideEffects": false,
"autoPublish": false,
Expand All @@ -91,7 +91,7 @@
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.7.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-tracing": "^1.2.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
Expand All @@ -102,18 +102,19 @@
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.7.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -126,8 +127,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
Expand All @@ -149,5 +149,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import {
} from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set this environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand Down Expand Up @@ -61,7 +59,7 @@ const textDocumentInputs: TextDocumentInput[] = [
},
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Alternative Document Input Objects Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -25,7 +23,7 @@ const documents = [
"This was a waste of my time. The speaker put me to sleep.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("=== Analyze Sentiment Sample ===");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand Down Expand Up @@ -49,7 +47,7 @@ const documents = [
},
];

export async function main() {
export async function main(): Promise<void> {
console.log("=== Opinion Mining Sample ===");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytic
import { DefaultAzureCredential } from "@azure/identity";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set this environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";

async function useAad() {
async function useAad(): Promise<void> {
console.log("-- Azure Active Directory --");

// DefaultAzureCredential expects the following three environment variables:
Expand All @@ -40,7 +38,7 @@ async function useAad() {
}
}

async function useApiKey() {
async function useApiKey(): Promise<void> {
console.log("-- API Key --");

// If using an API Key, you will need to set this environment variable
Expand All @@ -57,7 +55,7 @@ async function useApiKey() {
}
}

export async function main() {
export async function main(): Promise<void> {
console.log("== Client Authentication Methods Sample ==");

await useAad();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -28,7 +26,7 @@ const documents = [
"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party, and we adore the spot! They provide marvelous food and they have a great menu. The chief cook happens to be the owner (I think his name is John Doe) and he is super nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in the place! The Sirloin steak I ordered was tender and juicy, and the place was impeccably clean. You can even pre-order from their online menu at www.contososteakhouse.com, call 312-555-0176 or send email to order@contososteakhouse.com! The only complaint I have is the food didn't come fast enough. Overall I highly recommend it!",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Analyze Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -25,7 +23,7 @@ const documents = [
"Patient does not suffer from high blood pressure.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Recognize Healthcare Entities Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -28,7 +26,7 @@ const documents = [
"Detta är ett dokument skrivet på engelska.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Detect Language Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -24,7 +22,7 @@ const documents = [
"I will travel to South America in the summer.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Extract Key Phrases Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -25,7 +23,7 @@ const documents = [
"I visited the Space Needle 2 times.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Recognize Entities Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
Expand All @@ -25,7 +23,7 @@ const documents = [
"Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.",
];

export async function main() {
export async function main(): Promise<void> {
console.log("== Recognize Linked Entities Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import { TextAnalyticsClient, AzureKeyCredential, PiiEntityDomain } from "@azure
import { assert } from "console";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

export async function main() {
export async function main(): Promise<void> {
console.log(`Running recognizePii sample`);

// You will need to set these environment variables or edit the following values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,10 @@ export class TextAnalyticsClient {
* Creates an instance of TextAnalyticsClient.
*
* Example usage:
* ```ts
* ```ts snippet:ReadmeSampleCreateClient_KeyCredential
* import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
*
* const client = new TextAnalyticsClient(
* "<service endpoint>",
* new AzureKeyCredential("<api key>")
* );
* const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
* ```
* @param endpointUrl - The URL to the TextAnalytics endpoint
* @param credential - Used to authenticate requests to the service.
Expand Down
Loading
Loading