@azure/ai-language-text 1.1.0-alpha.20250110.1 → 1.1.0-alpha.20250114.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -13
- package/dist/browser/textAnalysisClient.d.ts +326 -152
- package/dist/browser/textAnalysisClient.d.ts.map +1 -1
- package/dist/browser/textAnalysisClient.js +5 -6
- package/dist/browser/textAnalysisClient.js.map +1 -1
- package/dist/commonjs/textAnalysisClient.d.ts +326 -152
- package/dist/commonjs/textAnalysisClient.d.ts.map +1 -1
- package/dist/commonjs/textAnalysisClient.js +5 -6
- package/dist/commonjs/textAnalysisClient.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/textAnalysisClient.d.ts +326 -152
- package/dist/esm/textAnalysisClient.d.ts.map +1 -1
- package/dist/esm/textAnalysisClient.js +5 -6
- package/dist/esm/textAnalysisClient.js.map +1 -1
- package/dist/react-native/textAnalysisClient.d.ts +326 -152
- package/dist/react-native/textAnalysisClient.d.ts.map +1 -1
- package/dist/react-native/textAnalysisClient.js +5 -6
- package/dist/react-native/textAnalysisClient.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
@@ -92,10 +92,13 @@ az cognitiveservices account keys list --resource-group <your-resource-group-nam
|
|
92
92
|
|
93
93
|
Once you have an API key and endpoint, you can use the `AzureKeyCredential` class to authenticate the client as follows:
|
94
94
|
|
95
|
-
```
|
96
|
-
|
95
|
+
```ts snippet:ReadmeSampleCreateClient_Node
|
96
|
+
import { AzureKeyCredential } from "@azure/core-auth";
|
97
|
+
import { TextAnalysisClient } from "@azure/ai-language-text";
|
97
98
|
|
98
|
-
const
|
99
|
+
const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
100
|
+
const credential = new AzureKeyCredential("<api key>");
|
101
|
+
const client = new TextAnalysisClient(endpoint, credential);
|
99
102
|
```
|
100
103
|
|
101
104
|
#### Using an Azure Active Directory Credential
|
@@ -111,11 +114,13 @@ You will also need to [register a new AAD application][register_aad_app] and gra
|
|
111
114
|
|
112
115
|
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
113
116
|
|
114
|
-
```
|
115
|
-
|
116
|
-
|
117
|
+
```ts snippet:ReadmeSampleCreateClient_ActiveDirectory
|
118
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
119
|
+
import { TextAnalysisClient } from "@azure/ai-language-text";
|
117
120
|
|
118
|
-
const
|
121
|
+
const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
122
|
+
const credential = new DefaultAzureCredential();
|
123
|
+
const client = new TextAnalysisClient(endpoint, credential);
|
119
124
|
```
|
120
125
|
|
121
126
|
## Key concepts
|
@@ -130,7 +135,7 @@ A **document** represents a single unit of input to be analyzed by the predictiv
|
|
130
135
|
|
131
136
|
For example, each document can be passed as a string in an array, e.g.
|
132
137
|
|
133
|
-
```
|
138
|
+
```ts snippet:ReadmeSample_Documents
|
134
139
|
const documents = [
|
135
140
|
"I hated the movie. It was so slow!",
|
136
141
|
"The movie made it into my top ten favorites.",
|
@@ -140,7 +145,7 @@ const documents = [
|
|
140
145
|
|
141
146
|
or, if you wish to pass in a per-item document `id` or `language`/`countryHint`, they can be given as a list of `TextDocumentInput` or `DetectLanguageInput` depending on the operation;
|
142
147
|
|
143
|
-
```
|
148
|
+
```ts snippet:ReadmeSample_TextDocumentInput
|
144
149
|
const textDocumentInputs = [
|
145
150
|
{ id: "1", language: "en", text: "I hated the movie. It was so slow!" },
|
146
151
|
{ id: "2", language: "en", text: "The movie made it into my top ten favorites." },
|
@@ -164,14 +169,35 @@ In the collection returned by an operation, errors are distinguished from succes
|
|
164
169
|
|
165
170
|
For example, to filter out all errors, you could use the following `filter`:
|
166
171
|
|
167
|
-
```
|
172
|
+
```ts snippet:ReadmeSample_FilterErrors
|
173
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
174
|
+
import { TextAnalysisClient } from "@azure/ai-language-text";
|
175
|
+
|
176
|
+
const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
177
|
+
const credential = new DefaultAzureCredential();
|
178
|
+
|
179
|
+
const client = new TextAnalysisClient(endpoint, credential);
|
180
|
+
|
181
|
+
const documents = [
|
182
|
+
"I hated the movie. It was so slow!",
|
183
|
+
"The movie made it into my top ten favorites.",
|
184
|
+
"What a great movie!",
|
185
|
+
];
|
186
|
+
|
168
187
|
const results = await client.analyze("SentimentAnalysis", documents);
|
169
188
|
const onlySuccessful = results.filter((result) => result.error === undefined);
|
170
189
|
```
|
171
190
|
|
172
191
|
**Note**: TypeScript users can benefit from better type-checking of result and error objects if `compilerOptions.strictNullChecks` is set to `true` in the `tsconfig.json` configuration. For example:
|
173
192
|
|
174
|
-
```
|
193
|
+
```ts snippet:ReadmeSample_TypeChecking
|
194
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
195
|
+
import { TextAnalysisClient } from "@azure/ai-language-text";
|
196
|
+
|
197
|
+
const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
198
|
+
const credential = new DefaultAzureCredential();
|
199
|
+
|
200
|
+
const client = new TextAnalysisClient(endpoint, credential);
|
175
201
|
const [result] = await client.analyze("SentimentAnalysis", ["Hello world!"]);
|
176
202
|
|
177
203
|
if (result.error !== undefined) {
|
@@ -219,8 +245,8 @@ if (result.error !== undefined) {
|
|
219
245
|
|
220
246
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
221
247
|
|
222
|
-
```
|
223
|
-
|
248
|
+
```ts snippet:SetLogLevel
|
249
|
+
import { setLogLevel } from "@azure/logger";
|
224
250
|
|
225
251
|
setLogLevel("info");
|
226
252
|
```
|