Skip to content

Commit cd1ca0b

Browse files
[textanalytics] Migrate textanalytics projects to use snippets extraction (#33212)
### Packages impacted by this PR - @azure/ai-text-analytics ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `databoxedge` to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Deyaaeldeen Almahallawi <[email protected]>
1 parent 8c67ad6 commit cd1ca0b

22 files changed

+584
-266
lines changed

sdk/textanalytics/ai-text-analytics/MIGRATION_v5_v6.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- dev-tool snippets ignore -->
2+
13
# Migrating to `@azure/ai-text-analytics` Version 6
24

35
**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.

sdk/textanalytics/ai-text-analytics/README.md

+191-195
Large diffs are not rendered by default.

sdk/textanalytics/ai-text-analytics/package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8282
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
8383
"unit-test:node": "dev-tool run test:vitest",
84-
"update-snippets": "echo skipped"
84+
"update-snippets": "dev-tool run update-snippets"
8585
},
8686
"sideEffects": false,
8787
"autoPublish": false,
@@ -91,7 +91,7 @@
9191
"@azure/core-client": "^1.9.2",
9292
"@azure/core-lro": "^2.7.2",
9393
"@azure/core-paging": "^1.6.2",
94-
"@azure/core-rest-pipeline": "^1.18.0",
94+
"@azure/core-rest-pipeline": "^1.19.0",
9595
"@azure/core-tracing": "^1.2.0",
9696
"@azure/logger": "^1.1.4",
9797
"tslib": "^2.8.1"
@@ -102,18 +102,19 @@
102102
"@azure-tools/test-utils-vitest": "^1.0.0",
103103
"@azure/dev-tool": "^1.0.0",
104104
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
105-
"@azure/identity": "^4.0.1",
105+
"@azure/identity": "^4.7.0",
106106
"@types/node": "^18.0.0",
107-
"@vitest/browser": "^3.0.3",
108-
"@vitest/coverage-istanbul": "^3.0.3",
107+
"@vitest/browser": "^3.0.6",
108+
"@vitest/coverage-istanbul": "^3.0.6",
109109
"dotenv": "^16.0.0",
110110
"eslint": "^9.9.0",
111-
"playwright": "^1.49.0",
111+
"playwright": "^1.50.1",
112112
"typescript": "~5.7.2",
113-
"vitest": "^3.0.3"
113+
"vitest": "^3.0.6"
114114
},
115115
"type": "module",
116116
"tshy": {
117+
"project": "./tsconfig.src.json",
117118
"exports": {
118119
"./package.json": "./package.json",
119120
".": "./src/index.ts"
@@ -126,8 +127,7 @@
126127
"browser",
127128
"react-native"
128129
],
129-
"selfLink": false,
130-
"project": "./tsconfig.src.json"
130+
"selfLink": false
131131
},
132132
"exports": {
133133
"./package.json": "./package.json",
@@ -149,5 +149,6 @@
149149
"default": "./dist/commonjs/index.js"
150150
}
151151
}
152-
}
152+
},
153+
"react-native": "./dist/react-native/index.js"
153154
}

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/alternativeDocumentInput.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import {
1818
} from "@azure/ai-text-analytics";
1919

2020
// Load the .env file if it exists
21-
import * as dotenv from "dotenv";
22-
dotenv.config();
23-
21+
import "dotenv/config";
2422
// You will need to set this environment variables or edit the following values
2523
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2624
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -61,7 +59,7 @@ const textDocumentInputs: TextDocumentInput[] = [
6159
},
6260
];
6361

64-
export async function main() {
62+
export async function main(): Promise<void> {
6563
console.log("== Alternative Document Input Objects Sample ==");
6664

6765
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/analyzeSentiment.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1414

1515
// Load the .env file if it exists
16-
import * as dotenv from "dotenv";
17-
dotenv.config();
18-
16+
import "dotenv/config";
1917
// You will need to set these environment variables or edit the following values
2018
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2119
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -25,7 +23,7 @@ const documents = [
2523
"This was a waste of my time. The speaker put me to sleep.",
2624
];
2725

28-
export async function main() {
26+
export async function main(): Promise<void> {
2927
console.log("=== Analyze Sentiment Sample ===");
3028

3129
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/analyzeSentimentWithOpinionMining.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1515

1616
// Load the .env file if it exists
17-
import * as dotenv from "dotenv";
18-
dotenv.config();
19-
17+
import "dotenv/config";
2018
// You will need to set these environment variables or edit the following values
2119
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2220
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -49,7 +47,7 @@ const documents = [
4947
},
5048
];
5149

52-
export async function main() {
50+
export async function main(): Promise<void> {
5351
console.log("=== Opinion Mining Sample ===");
5452

5553
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/authenticationMethods.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytic
1616
import { DefaultAzureCredential } from "@azure/identity";
1717

1818
// Load the .env file if it exists
19-
import * as dotenv from "dotenv";
20-
dotenv.config();
21-
19+
import "dotenv/config";
2220
// You will need to set this environment variables or edit the following values
2321
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2422

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

2826
// DefaultAzureCredential expects the following three environment variables:
@@ -40,7 +38,7 @@ async function useAad() {
4038
}
4139
}
4240

43-
async function useApiKey() {
41+
async function useApiKey(): Promise<void> {
4442
console.log("-- API Key --");
4543

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

60-
export async function main() {
58+
export async function main(): Promise<void> {
6159
console.log("== Client Authentication Methods Sample ==");
6260

6361
await useAad();

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/beginAnalyzeActions.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1414

1515
// Load the .env file if it exists
16-
import * as dotenv from "dotenv";
17-
dotenv.config();
18-
16+
import "dotenv/config";
1917
// You will need to set these environment variables or edit the following values
2018
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2119
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -28,7 +26,7 @@ const documents = [
2826
"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 [email protected]! The only complaint I have is the food didn't come fast enough. Overall I highly recommend it!",
2927
];
3028

31-
export async function main() {
29+
export async function main(): Promise<void> {
3230
console.log("== Analyze Sample ==");
3331

3432
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/beginAnalyzeHealthcareEntities.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1313

1414
// Load the .env file if it exists
15-
import * as dotenv from "dotenv";
16-
dotenv.config();
17-
15+
import "dotenv/config";
1816
// You will need to set these environment variables or edit the following values
1917
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2018
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -25,7 +23,7 @@ const documents = [
2523
"Patient does not suffer from high blood pressure.",
2624
];
2725

28-
export async function main() {
26+
export async function main(): Promise<void> {
2927
console.log("== Recognize Healthcare Entities Sample ==");
3028

3129
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/detectLanguage.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1414

1515
// Load the .env file if it exists
16-
import * as dotenv from "dotenv";
17-
dotenv.config();
18-
16+
import "dotenv/config";
1917
// You will need to set these environment variables or edit the following values
2018
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2119
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -28,7 +26,7 @@ const documents = [
2826
"Detta är ett dokument skrivet på engelska.",
2927
];
3028

31-
export async function main() {
29+
export async function main(): Promise<void> {
3230
console.log("== Detect Language Sample ==");
3331

3432
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/extractKeyPhrases.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1212

1313
// Load the .env file if it exists
14-
import * as dotenv from "dotenv";
15-
dotenv.config();
16-
14+
import "dotenv/config";
1715
// You will need to set these environment variables or edit the following values
1816
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
1917
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -24,7 +22,7 @@ const documents = [
2422
"I will travel to South America in the summer.",
2523
];
2624

27-
export async function main() {
25+
export async function main(): Promise<void> {
2826
console.log("== Extract Key Phrases Sample ==");
2927

3028
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/recognizeEntities.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1313

1414
// Load the .env file if it exists
15-
import * as dotenv from "dotenv";
16-
dotenv.config();
17-
15+
import "dotenv/config";
1816
// You will need to set these environment variables or edit the following values
1917
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2018
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -25,7 +23,7 @@ const documents = [
2523
"I visited the Space Needle 2 times.",
2624
];
2725

28-
export async function main() {
26+
export async function main(): Promise<void> {
2927
console.log("== Recognize Entities Sample ==");
3028

3129
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/recognizeLinkedEntities.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
1414

1515
// Load the .env file if it exists
16-
import * as dotenv from "dotenv";
17-
dotenv.config();
18-
16+
import "dotenv/config";
1917
// You will need to set these environment variables or edit the following values
2018
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
2119
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";
@@ -25,7 +23,7 @@ const documents = [
2523
"Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.",
2624
];
2725

28-
export async function main() {
26+
export async function main(): Promise<void> {
2927
console.log("== Recognize Linked Entities Sample ==");
3028

3129
const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/recognizePii.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { TextAnalyticsClient, AzureKeyCredential, PiiEntityDomain } from "@azure
1515
import { assert } from "console";
1616

1717
// Load the .env file if it exists
18-
import * as dotenv from "dotenv";
19-
dotenv.config();
18+
import "dotenv/config";
2019

21-
export async function main() {
20+
export async function main(): Promise<void> {
2221
console.log(`Running recognizePii sample`);
2322

2423
// You will need to set these environment variables or edit the following values

sdk/textanalytics/ai-text-analytics/src/textAnalyticsClient.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,10 @@ export class TextAnalyticsClient {
341341
* Creates an instance of TextAnalyticsClient.
342342
*
343343
* Example usage:
344-
* ```ts
344+
* ```ts snippet:ReadmeSampleCreateClient_KeyCredential
345345
* import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";
346346
*
347-
* const client = new TextAnalyticsClient(
348-
* "<service endpoint>",
349-
* new AzureKeyCredential("<api key>")
350-
* );
347+
* const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
351348
* ```
352349
* @param endpointUrl - The URL to the TextAnalytics endpoint
353350
* @param credential - Used to authenticate requests to the service.

0 commit comments

Comments
 (0)