@azure/ai-text-analytics 5.2.0-alpha.20211027.1 → 5.2.0-beta.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/CHANGELOG.md CHANGED
@@ -1,17 +1,23 @@
1
1
  # Release History
2
2
 
3
- ## 5.2.0-beta.2 (Unreleased)
3
+ ## 5.2.0-beta.2 (2021-11-02)
4
4
 
5
5
  ### Features Added
6
6
 
7
7
  - We are now targeting the service's v3.2-preview.2 API as the default instead of v3.2-preview.1.
8
8
  - Adding support for a three new actions in `beginAnalyzeActions`: `recognizeCustomEntities`, `singleCategoryClassify`, and `multiCategoryClassify`. The new actions allow you to use custom models to perform entity recognition and classification actions.
9
9
 
10
- ### Breaking Changes
10
+ ### Other Changes
11
11
 
12
- ### Bugs Fixed
12
+ - `beginAnalyzeActions` supports actions to be named and the name is now accessible in each action result.
13
+ - `beginAnalyzeActions` supports multiple actions of the same type so you can pass a list of any particular action type, e.g.
13
14
 
14
- ### Other Changes
15
+ ```typescript
16
+ await client.beginAnalyzeActions(docs, { recognizePiiEntitiesActions: [
17
+ { modelVersion: "latest", actionName: "action1" },
18
+ { modelVersion: "2021-01-15", actionName: "action2" }]
19
+ });
20
+ ```
15
21
 
16
22
  ## 5.2.0-beta.1 (2021-08-09)
17
23
 
package/dist/index.js CHANGED
@@ -239,6 +239,12 @@ const EntitiesTask = {
239
239
  name: "Composite",
240
240
  className: "EntitiesTaskParameters"
241
241
  }
242
+ },
243
+ taskName: {
244
+ serializedName: "taskName",
245
+ type: {
246
+ name: "String"
247
+ }
242
248
  }
243
249
  }
244
250
  }
@@ -282,6 +288,12 @@ const PiiTask = {
282
288
  name: "Composite",
283
289
  className: "PiiTaskParameters"
284
290
  }
291
+ },
292
+ taskName: {
293
+ serializedName: "taskName",
294
+ type: {
295
+ name: "String"
296
+ }
285
297
  }
286
298
  }
287
299
  }
@@ -346,6 +358,12 @@ const KeyPhrasesTask = {
346
358
  name: "Composite",
347
359
  className: "KeyPhrasesTaskParameters"
348
360
  }
361
+ },
362
+ taskName: {
363
+ serializedName: "taskName",
364
+ type: {
365
+ name: "String"
366
+ }
349
367
  }
350
368
  }
351
369
  }
@@ -383,6 +401,12 @@ const EntityLinkingTask = {
383
401
  name: "Composite",
384
402
  className: "EntityLinkingTaskParameters"
385
403
  }
404
+ },
405
+ taskName: {
406
+ serializedName: "taskName",
407
+ type: {
408
+ name: "String"
409
+ }
386
410
  }
387
411
  }
388
412
  }
@@ -426,6 +450,12 @@ const SentimentAnalysisTask = {
426
450
  name: "Composite",
427
451
  className: "SentimentAnalysisTaskParameters"
428
452
  }
453
+ },
454
+ taskName: {
455
+ serializedName: "taskName",
456
+ type: {
457
+ name: "String"
458
+ }
429
459
  }
430
460
  }
431
461
  }
@@ -476,6 +506,12 @@ const ExtractiveSummarizationTask = {
476
506
  name: "Composite",
477
507
  className: "ExtractiveSummarizationTaskParameters"
478
508
  }
509
+ },
510
+ taskName: {
511
+ serializedName: "taskName",
512
+ type: {
513
+ name: "String"
514
+ }
479
515
  }
480
516
  }
481
517
  }
@@ -533,6 +569,12 @@ const CustomEntitiesTask = {
533
569
  name: "Composite",
534
570
  className: "CustomEntitiesTaskParameters"
535
571
  }
572
+ },
573
+ taskName: {
574
+ serializedName: "taskName",
575
+ type: {
576
+ name: "String"
577
+ }
536
578
  }
537
579
  }
538
580
  }
@@ -583,6 +625,12 @@ const CustomSingleClassificationTask = {
583
625
  name: "Composite",
584
626
  className: "CustomSingleClassificationTaskParameters"
585
627
  }
628
+ },
629
+ taskName: {
630
+ serializedName: "taskName",
631
+ type: {
632
+ name: "String"
633
+ }
586
634
  }
587
635
  }
588
636
  }
@@ -627,6 +675,12 @@ const CustomMultiClassificationTask = {
627
675
  name: "Composite",
628
676
  className: "CustomMultiClassificationTaskParameters"
629
677
  }
678
+ },
679
+ taskName: {
680
+ serializedName: "taskName",
681
+ type: {
682
+ name: "String"
683
+ }
630
684
  }
631
685
  }
632
686
  }
@@ -1000,6 +1054,13 @@ const TaskState = {
1000
1054
  name: "DateTime"
1001
1055
  }
1002
1056
  },
1057
+ taskName: {
1058
+ serializedName: "taskName",
1059
+ required: true,
1060
+ type: {
1061
+ name: "String"
1062
+ }
1063
+ },
1003
1064
  status: {
1004
1065
  serializedName: "status",
1005
1066
  required: true,
@@ -4063,32 +4124,42 @@ function addParamsToTask(action) {
4063
4124
  const { actionName } = action, params = tslib.__rest(action, ["actionName"]);
4064
4125
  return { parameters: params, taskName: actionName };
4065
4126
  }
4127
+ function appendReadableErrorMessage(currentMessage, innerMessage) {
4128
+ let message = currentMessage;
4129
+ if (message.slice(-1) !== ".") {
4130
+ message = message + ".";
4131
+ }
4132
+ return message + " " + innerMessage;
4133
+ }
4066
4134
  /**
4067
4135
  * @internal
4068
4136
  * parses incoming errors from the service and if the inner error code is
4069
4137
  * InvalidDocumentBatch, it exposes that as the statusCode instead.
4070
4138
  * @param error - the incoming error
4071
4139
  */
4072
- function handleInvalidDocumentBatch(error) {
4073
- var _a, _b, _c, _d, _e, _f, _g, _h;
4074
- const castError = error;
4075
- const innerCode = (_d = (_c = (_b = (_a = castError.response) === null || _a === void 0 ? void 0 : _a.parsedBody) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.innererror) === null || _d === void 0 ? void 0 : _d.code;
4076
- const innerMessage = (_h = (_g = (_f = (_e = castError.response) === null || _e === void 0 ? void 0 : _e.parsedBody) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.innererror) === null || _h === void 0 ? void 0 : _h.message;
4077
- if (innerMessage) {
4078
- return innerCode === "InvalidDocumentBatch"
4079
- ? new coreRestPipeline.RestError(innerMessage, { code: innerCode, statusCode: castError.statusCode })
4080
- : error;
4081
- }
4082
- else {
4083
- // unfortunately, the service currently does not follow the swagger definition
4084
- // for errors in some cases.
4085
- // Issue: https://msazure.visualstudio.com/Cognitive%20Services/_workitems/edit/8775003/?workitem=8972164
4086
- // throw new Error(
4087
- // `The error coming from the service does not follow the expected structure: ${error}`
4088
- // );
4089
- logger.warning(`The error coming from the service does not follow the expected structure: ${error}`);
4140
+ function compileError(errorResponse) {
4141
+ var _a;
4142
+ const castErrorResponse = errorResponse;
4143
+ const topLevelError = (_a = castErrorResponse.response.parsedBody) === null || _a === void 0 ? void 0 : _a.error;
4144
+ if (!topLevelError)
4145
+ return errorResponse;
4146
+ let errorMessage = topLevelError.message || "";
4147
+ let invalidDocumentBatchCode = false;
4148
+ function unwrap(error) {
4149
+ if ((error === null || error === void 0 ? void 0 : error.innererror) !== undefined && error.innererror.message !== undefined) {
4150
+ if (error.innererror.code === "InvalidDocumentBatch") {
4151
+ invalidDocumentBatchCode = true;
4152
+ }
4153
+ errorMessage = appendReadableErrorMessage(errorMessage, error.innererror.message);
4154
+ return unwrap(error.innererror);
4155
+ }
4090
4156
  return error;
4091
4157
  }
4158
+ unwrap(topLevelError);
4159
+ return new coreRestPipeline.RestError(errorMessage, {
4160
+ code: invalidDocumentBatchCode ? "InvalidDocumentBatch" : topLevelError.code,
4161
+ statusCode: castErrorResponse.statusCode
4162
+ });
4092
4163
  }
4093
4164
  /**
4094
4165
  * @internal
@@ -4534,7 +4605,7 @@ class HealthLro {
4534
4605
  };
4535
4606
  }
4536
4607
  catch (e) {
4537
- const exception = handleInvalidDocumentBatch(e);
4608
+ const exception = compileError(e);
4538
4609
  span.setStatus({
4539
4610
  code: coreTracing.SpanStatusCode.ERROR,
4540
4611
  message: exception.message
@@ -4834,8 +4905,12 @@ function categorizeActionErrors(erredActions, recognizeEntitiesActionErrors, rec
4834
4905
  * @param error - the error the service sent for a task
4835
4906
  * @param lastUpdateDateTime - the time when this task failed
4836
4907
  */
4837
- function createErredAction(error, lastUpdateDateTime) {
4838
- return { error: intoTextAnalyticsError(error), failedOn: lastUpdateDateTime };
4908
+ function createErredAction(error, lastUpdateDateTime, taskName) {
4909
+ return {
4910
+ error: intoTextAnalyticsError(error),
4911
+ failedOn: lastUpdateDateTime,
4912
+ actionName: taskName
4913
+ };
4839
4914
  }
4840
4915
  /**
4841
4916
  * Creates a list of results for any action.
@@ -4848,19 +4923,23 @@ function createErredAction(error, lastUpdateDateTime) {
4848
4923
  function makeActionResult(documents, makeResultsArray, succeededTasks, erredActions) {
4849
4924
  let errorIndex = 0;
4850
4925
  function convertTasksToActions(actions, task) {
4851
- const { results: actionResults, lastUpdateDateTime } = task;
4926
+ const { results: actionResults, lastUpdateDateTime, taskName } = task;
4852
4927
  if (actionResults !== undefined) {
4853
4928
  const recognizeEntitiesResults = makeResultsArray(documents, actionResults);
4854
4929
  return [
4855
4930
  ...actions,
4856
4931
  {
4857
4932
  results: recognizeEntitiesResults,
4858
- completedOn: lastUpdateDateTime
4933
+ completedOn: lastUpdateDateTime,
4934
+ actionName: taskName
4859
4935
  }
4860
4936
  ];
4861
4937
  }
4862
4938
  else {
4863
- return [...actions, createErredAction(erredActions[errorIndex++], lastUpdateDateTime)];
4939
+ return [
4940
+ ...actions,
4941
+ createErredAction(erredActions[errorIndex++], lastUpdateDateTime, taskName)
4942
+ ];
4864
4943
  }
4865
4944
  }
4866
4945
  return succeededTasks.reduce(convertTasksToActions, []);
@@ -4945,7 +5024,7 @@ class AnalyzeLro {
4945
5024
  };
4946
5025
  }
4947
5026
  catch (e) {
4948
- const exception = handleInvalidDocumentBatch(e);
5027
+ const exception = compileError(e);
4949
5028
  span.setStatus({
4950
5029
  code: coreTracing.SpanStatusCode.ERROR,
4951
5030
  message: exception.message
@@ -5132,7 +5211,7 @@ class TextAnalyticsClient {
5132
5211
  * earlier versions were throwing an exception that included the inner
5133
5212
  * code only.
5134
5213
  */
5135
- const backwardCompatibleException = handleInvalidDocumentBatch(e);
5214
+ const backwardCompatibleException = compileError(e);
5136
5215
  span.setStatus({
5137
5216
  code: coreTracing.SpanStatusCode.ERROR,
5138
5217
  message: backwardCompatibleException.message
@@ -5324,7 +5403,6 @@ class TextAnalyticsClient {
5324
5403
  realInputs = documents;
5325
5404
  realOptions = languageOrOptions || {};
5326
5405
  }
5327
- validateActions(actions);
5328
5406
  const compiledActions = compileAnalyzeInput(actions);
5329
5407
  const { updateIntervalInMs, resumeFrom, displayName, includeStatistics, onResponse, requestOptions, serializerOptions, abortSignal, tracingOptions } = realOptions;
5330
5408
  const lro = new AnalyzeLro(this.client, {
@@ -5352,20 +5430,6 @@ class TextAnalyticsClient {
5352
5430
  return poller;
5353
5431
  }
5354
5432
  }
5355
- function validateActions(actions) {
5356
- function validateActionType(actionList, actionType) {
5357
- var _a;
5358
- if (((_a = actionList === null || actionList === void 0 ? void 0 : actionList.length) !== null && _a !== void 0 ? _a : 0) > 1) {
5359
- throw new Error(`beginAnalyzeActions: Currently, the service can accept up to one action only for ${actionType} actions.`);
5360
- }
5361
- }
5362
- validateActionType(actions.analyzeSentimentActions, `analyzeSentiment`);
5363
- validateActionType(actions.extractKeyPhrasesActions, `extractKeyPhrases`);
5364
- validateActionType(actions.recognizeEntitiesActions, `recognizeEntities`);
5365
- validateActionType(actions.recognizeLinkedEntitiesActions, `recognizeLinkedEntities`);
5366
- validateActionType(actions.recognizePiiEntitiesActions, `recognizePiiEntities`);
5367
- validateActionType(actions.extractSummaryActions, `extractSummary`);
5368
- }
5369
5433
  /**
5370
5434
  * @internal
5371
5435
  */