@azure/ai-language-text 1.1.0-beta.1 → 1.1.0-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +38 -630
- package/dist/index.js +159 -35
- package/dist/index.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/generated/generatedClient.js +2 -2
- package/dist-esm/src/generated/generatedClient.js.map +1 -1
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +2 -7
- package/dist-esm/src/generated/models/mappers.js.map +1 -1
- package/dist-esm/src/lro.js +24 -8
- package/dist-esm/src/lro.js.map +1 -1
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/src/textAnalysisClient.js +2 -2
- package/dist-esm/src/textAnalysisClient.js.map +1 -1
- package/dist-esm/src/transforms.js +114 -16
- package/dist-esm/src/transforms.js.map +1 -1
- package/dist-esm/src/util.js +15 -0
- package/dist-esm/src/util.js.map +1 -1
- package/package.json +4 -6
- package/types/ai-language-text.d.ts +7 -13
package/dist/index.js
CHANGED
@@ -41,7 +41,7 @@ const DEFAULT_COGNITIVE_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
41
41
|
/**
|
42
42
|
* @internal
|
43
43
|
*/
|
44
|
-
const SDK_VERSION = "1.1.0-beta.
|
44
|
+
const SDK_VERSION = "1.1.0-beta.2";
|
45
45
|
/**
|
46
46
|
* @internal
|
47
47
|
*/
|
@@ -166,6 +166,21 @@ function getOperationOptions(options) {
|
|
166
166
|
rest,
|
167
167
|
};
|
168
168
|
}
|
169
|
+
/**
|
170
|
+
*
|
171
|
+
* @param error - error with the target in the JSON error pointer format "#/items/0
|
172
|
+
* @returns number: the position of the task with error
|
173
|
+
*/
|
174
|
+
function extractErrorPointerIndex(error) {
|
175
|
+
if (!error.target) {
|
176
|
+
throw new Error("Unexpected response from service - no target present");
|
177
|
+
}
|
178
|
+
const position = parseInt(error.target.split("/").pop());
|
179
|
+
if (isNaN(position)) {
|
180
|
+
throw new Error(`Unexpected response from service - action pointer "${error.target}" is not a valid action pointer.`);
|
181
|
+
}
|
182
|
+
return position;
|
183
|
+
}
|
169
184
|
|
170
185
|
/*
|
171
186
|
* Copyright (c) Microsoft Corporation.
|
@@ -330,12 +345,6 @@ const AnalyzeTextJobsInput = {
|
|
330
345
|
name: "String"
|
331
346
|
}
|
332
347
|
},
|
333
|
-
defaultLanguage: {
|
334
|
-
serializedName: "defaultLanguage",
|
335
|
-
type: {
|
336
|
-
name: "String"
|
337
|
-
}
|
338
|
-
},
|
339
348
|
analysisInput: {
|
340
349
|
serializedName: "analysisInput",
|
341
350
|
type: {
|
@@ -1646,7 +1655,7 @@ const AbstractiveSummarizationTaskParametersBase = {
|
|
1646
1655
|
name: "Composite",
|
1647
1656
|
className: "AbstractiveSummarizationTaskParametersBase",
|
1648
1657
|
modelProperties: {
|
1649
|
-
|
1658
|
+
sentenceCount: {
|
1650
1659
|
serializedName: "sentenceCount",
|
1651
1660
|
type: {
|
1652
1661
|
name: "Number"
|
@@ -1697,6 +1706,7 @@ const AbstractiveSummary = {
|
|
1697
1706
|
},
|
1698
1707
|
contexts: {
|
1699
1708
|
serializedName: "contexts",
|
1709
|
+
required: true,
|
1700
1710
|
type: {
|
1701
1711
|
name: "Sequence",
|
1702
1712
|
element: {
|
@@ -4076,74 +4086,172 @@ function toHealthcareResult(docIds, results) {
|
|
4076
4086
|
/**
|
4077
4087
|
* @internal
|
4078
4088
|
*/
|
4079
|
-
function transformAnalyzeBatchResults(docIds, response = []) {
|
4080
|
-
|
4081
|
-
|
4082
|
-
|
4089
|
+
function transformAnalyzeBatchResults(docIds, response = [], errors = []) {
|
4090
|
+
const errorMap = toIndexErrorMap(errors);
|
4091
|
+
return response.map((actionData, idx) => {
|
4092
|
+
const { lastUpdateDateTime: completedOn, actionName, kind: resultKind } = actionData;
|
4093
|
+
const error = errorMap.get(idx);
|
4094
|
+
switch (resultKind) {
|
4083
4095
|
case "SentimentAnalysisLROResults": {
|
4096
|
+
const kind = "SentimentAnalysis";
|
4097
|
+
if (actionData.status === "failed") {
|
4098
|
+
return returnErrorTask(kind, error, completedOn);
|
4099
|
+
}
|
4084
4100
|
const { results } = actionData;
|
4085
4101
|
const { modelVersion, statistics } = results;
|
4086
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4102
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toSentimentAnalysisResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4087
4103
|
}
|
4088
4104
|
case "EntityRecognitionLROResults": {
|
4105
|
+
const kind = "EntityRecognition";
|
4106
|
+
if (actionData.status === "failed") {
|
4107
|
+
return returnErrorTask(kind, error, completedOn);
|
4108
|
+
}
|
4089
4109
|
const { results } = actionData;
|
4090
4110
|
const { modelVersion, statistics } = results;
|
4091
4111
|
return Object.assign(Object.assign(Object.assign({ kind: "EntityRecognition", results: toEntityRecognitionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4092
4112
|
}
|
4093
4113
|
case "PiiEntityRecognitionLROResults": {
|
4114
|
+
const kind = "PiiEntityRecognition";
|
4115
|
+
if (actionData.status === "failed") {
|
4116
|
+
return returnErrorTask(kind, error, completedOn);
|
4117
|
+
}
|
4094
4118
|
const { results } = actionData;
|
4095
4119
|
const { modelVersion, statistics } = results;
|
4096
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4120
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toPiiEntityRecognitionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4097
4121
|
}
|
4098
4122
|
case "KeyPhraseExtractionLROResults": {
|
4123
|
+
const kind = "KeyPhraseExtraction";
|
4124
|
+
if (actionData.status === "failed") {
|
4125
|
+
return returnErrorTask(kind, error, completedOn);
|
4126
|
+
}
|
4099
4127
|
const { results } = actionData;
|
4100
4128
|
const { modelVersion, statistics } = results;
|
4101
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4129
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toKeyPhraseExtractionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4102
4130
|
}
|
4103
4131
|
case "EntityLinkingLROResults": {
|
4132
|
+
const kind = "EntityLinking";
|
4133
|
+
if (actionData.status === "failed") {
|
4134
|
+
return returnErrorTask(kind, error, completedOn);
|
4135
|
+
}
|
4104
4136
|
const { results } = actionData;
|
4105
4137
|
const { modelVersion, statistics } = results;
|
4106
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4138
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toEntityLinkingResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4107
4139
|
}
|
4108
4140
|
case "HealthcareLROResults": {
|
4141
|
+
const kind = "Healthcare";
|
4142
|
+
if (actionData.status === "failed") {
|
4143
|
+
return returnErrorTask(kind, error, completedOn);
|
4144
|
+
}
|
4109
4145
|
const { results } = actionData;
|
4110
4146
|
const { modelVersion, statistics } = results;
|
4111
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4147
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toHealthcareResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4112
4148
|
}
|
4113
4149
|
case "CustomEntityRecognitionLROResults": {
|
4150
|
+
const kind = "CustomEntityRecognition";
|
4151
|
+
if (actionData.status === "failed") {
|
4152
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4153
|
+
}
|
4114
4154
|
const { results } = actionData;
|
4115
4155
|
const { deploymentName, projectName, statistics } = results;
|
4116
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4156
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4117
4157
|
projectName });
|
4118
4158
|
}
|
4119
4159
|
case "CustomSingleLabelClassificationLROResults": {
|
4160
|
+
const kind = "CustomSingleLabelClassification";
|
4161
|
+
if (actionData.status === "failed") {
|
4162
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4163
|
+
}
|
4120
4164
|
const { results } = actionData;
|
4121
4165
|
const { deploymentName, projectName, statistics } = results;
|
4122
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4166
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4123
4167
|
projectName });
|
4124
4168
|
}
|
4125
4169
|
case "CustomMultiLabelClassificationLROResults": {
|
4170
|
+
const kind = "CustomMultiLabelClassification";
|
4171
|
+
if (actionData.status === "failed") {
|
4172
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4173
|
+
}
|
4126
4174
|
const { results } = actionData;
|
4127
4175
|
const { deploymentName, projectName, statistics } = results;
|
4128
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4176
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4129
4177
|
projectName });
|
4130
4178
|
}
|
4131
4179
|
case "ExtractiveSummarizationLROResults": {
|
4180
|
+
const kind = "ExtractiveSummarization";
|
4181
|
+
if (actionData.status === "failed") {
|
4182
|
+
return returnErrorTask(kind, error, completedOn);
|
4183
|
+
}
|
4132
4184
|
const { results } = actionData;
|
4133
4185
|
const { modelVersion, statistics } = results;
|
4134
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4186
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4135
4187
|
}
|
4136
4188
|
case "AbstractiveSummarizationLROResults": {
|
4189
|
+
const kind = "AbstractiveSummarization";
|
4190
|
+
if (actionData.status === "failed") {
|
4191
|
+
return returnErrorTask(kind, error, completedOn);
|
4192
|
+
}
|
4137
4193
|
const { results } = actionData;
|
4138
4194
|
const { modelVersion, statistics } = results;
|
4139
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4195
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4140
4196
|
}
|
4141
4197
|
default: {
|
4142
|
-
throw new Error(`Unsupported results kind: ${
|
4198
|
+
throw new Error(`Unsupported results kind: ${resultKind}`);
|
4143
4199
|
}
|
4144
4200
|
}
|
4145
4201
|
});
|
4146
4202
|
}
|
4203
|
+
/**
|
4204
|
+
* @internal
|
4205
|
+
* Transform a list of error into index and error Map
|
4206
|
+
*/
|
4207
|
+
function toIndexErrorMap(errors) {
|
4208
|
+
const errorMap = new Map();
|
4209
|
+
for (const error of errors) {
|
4210
|
+
const position = extractErrorPointerIndex(error);
|
4211
|
+
const errorWithoutTarget = tslib.__rest(error, ["target"]);
|
4212
|
+
errorMap.set(position, toTextAnalysisError(errorWithoutTarget));
|
4213
|
+
}
|
4214
|
+
return errorMap;
|
4215
|
+
}
|
4216
|
+
/**
|
4217
|
+
* Return the error for non-custom task
|
4218
|
+
*
|
4219
|
+
* @param kind - non custom task kind
|
4220
|
+
* @param error - error returned from the service
|
4221
|
+
* @param failedOn - the LastUpdateDateTime from the service
|
4222
|
+
* @returns - AnalyzeBatchResult with error
|
4223
|
+
*/
|
4224
|
+
function returnErrorTask(kind, error, failedOn) {
|
4225
|
+
if (!error) {
|
4226
|
+
throw new Error("Unexpected response from service - no errors for missing action results.");
|
4227
|
+
}
|
4228
|
+
return {
|
4229
|
+
kind,
|
4230
|
+
modelVersion: "",
|
4231
|
+
failedOn,
|
4232
|
+
error,
|
4233
|
+
};
|
4234
|
+
}
|
4235
|
+
/**
|
4236
|
+
* Return the error for non-custom task
|
4237
|
+
*
|
4238
|
+
* @param kind - non custom task kind
|
4239
|
+
* @param error - error returned from the service
|
4240
|
+
* @param failedOn - the LastUpdateDateTime from the service
|
4241
|
+
* @returns AnalyzeBatchResult for custom task with error
|
4242
|
+
*/
|
4243
|
+
function returnErrorCustomTask(kind, error, failedOn) {
|
4244
|
+
if (!error) {
|
4245
|
+
throw new Error("Unexpected response from service - no errors for missing action results.");
|
4246
|
+
}
|
4247
|
+
return {
|
4248
|
+
kind,
|
4249
|
+
projectName: "",
|
4250
|
+
deploymentName: "",
|
4251
|
+
failedOn,
|
4252
|
+
error,
|
4253
|
+
};
|
4254
|
+
}
|
4147
4255
|
|
4148
4256
|
// Copyright (c) Microsoft Corporation.
|
4149
4257
|
const serializer$2 = coreClient.createSerializer(Mappers, /* isXml */ false);
|
@@ -4161,13 +4269,24 @@ const jobStatusOperationSpec$1 = {
|
|
4161
4269
|
queryParameters: [top, skip, includeStatistics],
|
4162
4270
|
serializer: serializer$2,
|
4163
4271
|
};
|
4272
|
+
function addOnResponse(options, cb) {
|
4273
|
+
return Object.assign(Object.assign({}, options), { onResponse: (rawResponse, response, error) => {
|
4274
|
+
var _a;
|
4275
|
+
cb(rawResponse, response, error);
|
4276
|
+
(_a = options.onResponse) === null || _a === void 0 ? void 0 : _a.call(options, rawResponse, response, error);
|
4277
|
+
} });
|
4278
|
+
}
|
4279
|
+
function logWarnHeader(rawResponse) {
|
4280
|
+
const warnHeader = rawResponse.headers.get("warn-text");
|
4281
|
+
if (warnHeader) {
|
4282
|
+
warnHeader.split(";").map((x) => logger.warning(x));
|
4283
|
+
}
|
4284
|
+
}
|
4164
4285
|
async function getRawResponse(getResponse, options) {
|
4165
|
-
const { onResponse } = options || {};
|
4166
4286
|
let rawResponse;
|
4167
|
-
const flatResponse = await getResponse(
|
4168
|
-
|
4169
|
-
|
4170
|
-
} }));
|
4287
|
+
const flatResponse = await getResponse(addOnResponse(options, (response) => {
|
4288
|
+
rawResponse = response;
|
4289
|
+
}));
|
4171
4290
|
return {
|
4172
4291
|
flatResponse,
|
4173
4292
|
rawResponse: {
|
@@ -4190,7 +4309,12 @@ function createSendPollRequest(settings) {
|
|
4190
4309
|
return async (path) => {
|
4191
4310
|
return throwError(sendRequest({
|
4192
4311
|
client,
|
4193
|
-
opOptions: options,
|
4312
|
+
opOptions: addOnResponse(options, (_, response) => {
|
4313
|
+
const castResponse = response;
|
4314
|
+
if (castResponse.status.toLowerCase() === "partiallysucceeded") {
|
4315
|
+
castResponse.status = "succeeded";
|
4316
|
+
}
|
4317
|
+
}),
|
4194
4318
|
path,
|
4195
4319
|
spanStr,
|
4196
4320
|
spec: jobStatusOperationSpec$1,
|
@@ -4205,7 +4329,7 @@ function createAnalyzeBatchLro(settings) {
|
|
4205
4329
|
const { client, commonOptions, documents, initialRequestOptions, pollRequestOptions, tasks, tracing, } = settings;
|
4206
4330
|
return {
|
4207
4331
|
async sendInitialRequest() {
|
4208
|
-
return tracing.withSpan(`${clientName}.beginAnalyzeBatch`, Object.assign(Object.assign({}, commonOptions), initialRequestOptions), async (finalOptions) => throwError(getRawResponse((paramOptions) => client.analyzeBatch({
|
4332
|
+
return tracing.withSpan(`${clientName}.beginAnalyzeBatch`, addOnResponse(Object.assign(Object.assign({}, commonOptions), initialRequestOptions), logWarnHeader), async (finalOptions) => throwError(getRawResponse((paramOptions) => client.analyzeBatch({
|
4209
4333
|
tasks,
|
4210
4334
|
analysisInput: {
|
4211
4335
|
documents,
|
@@ -4273,7 +4397,7 @@ function processAnalyzeResult(options) {
|
|
4273
4397
|
});
|
4274
4398
|
const flatResponse = response.flatResponse;
|
4275
4399
|
return {
|
4276
|
-
page: transformAnalyzeBatchResults(docIds, flatResponse.tasks.items),
|
4400
|
+
page: transformAnalyzeBatchResults(docIds, flatResponse.tasks.items, flatResponse.errors),
|
4277
4401
|
nextPageLink: flatResponse.nextLink,
|
4278
4402
|
};
|
4279
4403
|
},
|
@@ -4414,13 +4538,13 @@ class GeneratedClient extends coreClient__namespace.ServiceClient {
|
|
4414
4538
|
const defaults = {
|
4415
4539
|
requestContentType: "application/json; charset=utf-8"
|
4416
4540
|
};
|
4417
|
-
const packageDetails = `azsdk-js-ai-language-text/1.1.0-beta.
|
4541
|
+
const packageDetails = `azsdk-js-ai-language-text/1.1.0-beta.2`;
|
4418
4542
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
4419
4543
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
4420
4544
|
: `${packageDetails}`;
|
4421
4545
|
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
|
4422
4546
|
userAgentPrefix
|
4423
|
-
},
|
4547
|
+
}, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{Endpoint}/language" });
|
4424
4548
|
super(optionsWithDefaults);
|
4425
4549
|
// Parameter assignments
|
4426
4550
|
this.endpoint = endpoint;
|
@@ -4639,8 +4763,8 @@ class TextAnalysisClient {
|
|
4639
4763
|
throw new Error("'documents' must be a non-empty array");
|
4640
4764
|
}
|
4641
4765
|
if (isStringArray(documents)) {
|
4642
|
-
const
|
4643
|
-
realInputs = convertToTextDocumentInput(documents,
|
4766
|
+
const languageCode = (_a = languageOrOptions) !== null && _a !== void 0 ? _a : this.defaultLanguage;
|
4767
|
+
realInputs = convertToTextDocumentInput(documents, languageCode);
|
4644
4768
|
realOptions = options;
|
4645
4769
|
}
|
4646
4770
|
else {
|