@aws-amplify/predictions 5.5.6-api-v6-models.b3abc9b.0 → 6.0.0

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.
Files changed (148) hide show
  1. package/README.md +3 -0
  2. package/lib/Predictions.d.ts +11 -45
  3. package/lib/Predictions.js +24 -132
  4. package/lib/errors/PredictionsError.d.ts +4 -0
  5. package/lib/errors/PredictionsError.js +15 -0
  6. package/lib/errors/types/validation.d.ts +14 -0
  7. package/lib/errors/types/validation.js +50 -0
  8. package/lib/errors/utils/assertValidationError.d.ts +2 -0
  9. package/lib/errors/utils/assertValidationError.js +14 -0
  10. package/lib/index.d.ts +2 -4
  11. package/lib/index.js +2 -9
  12. package/{lib-esm/Providers → lib/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
  13. package/lib/providers/AmazonAIConvertPredictionsProvider.js +307 -0
  14. package/lib/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
  15. package/lib/providers/AmazonAIIdentifyPredictionsProvider.js +334 -0
  16. package/lib/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
  17. package/lib/providers/AmazonAIInterpretPredictionsProvider.js +208 -0
  18. package/lib/providers/IdentifyTextUtils.d.ts +16 -0
  19. package/lib/{Providers → providers}/IdentifyTextUtils.js +97 -148
  20. package/lib/{Providers → providers}/Utils.d.ts +2 -2
  21. package/lib/{Providers → providers}/Utils.js +11 -12
  22. package/lib/{Providers → providers}/index.d.ts +1 -2
  23. package/lib/providers/index.js +11 -0
  24. package/lib/tsconfig.tsbuildinfo +1 -0
  25. package/lib/types/AWSTypes.d.ts +8 -9
  26. package/lib/types/AWSTypes.js +0 -1
  27. package/lib/types/Predictions.d.ts +63 -59
  28. package/lib/types/Predictions.js +41 -28
  29. package/lib/types/index.js +1 -2
  30. package/lib-esm/Predictions.d.ts +11 -45
  31. package/lib-esm/Predictions.js +23 -133
  32. package/lib-esm/errors/PredictionsError.d.ts +4 -0
  33. package/lib-esm/errors/PredictionsError.js +11 -0
  34. package/lib-esm/errors/types/validation.d.ts +14 -0
  35. package/lib-esm/errors/types/validation.js +47 -0
  36. package/lib-esm/errors/utils/assertValidationError.d.ts +2 -0
  37. package/lib-esm/errors/utils/assertValidationError.js +10 -0
  38. package/lib-esm/index.d.ts +2 -4
  39. package/lib-esm/index.js +1 -5
  40. package/{lib/Providers → lib-esm/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
  41. package/lib-esm/providers/AmazonAIConvertPredictionsProvider.js +303 -0
  42. package/lib-esm/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
  43. package/lib-esm/providers/AmazonAIIdentifyPredictionsProvider.js +330 -0
  44. package/lib-esm/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
  45. package/lib-esm/providers/AmazonAIInterpretPredictionsProvider.js +204 -0
  46. package/lib-esm/providers/IdentifyTextUtils.d.ts +16 -0
  47. package/lib-esm/providers/IdentifyTextUtils.js +264 -0
  48. package/lib-esm/{Providers → providers}/Utils.d.ts +2 -2
  49. package/lib-esm/{Providers → providers}/Utils.js +10 -12
  50. package/lib-esm/{Providers → providers}/index.d.ts +1 -2
  51. package/lib-esm/{Providers → providers}/index.js +1 -3
  52. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  53. package/lib-esm/types/AWSTypes.d.ts +8 -9
  54. package/lib-esm/types/AWSTypes.js +1 -1
  55. package/lib-esm/types/Predictions.d.ts +63 -59
  56. package/lib-esm/types/Predictions.js +34 -27
  57. package/lib-esm/types/index.js +0 -1
  58. package/package.json +39 -48
  59. package/src/Predictions.ts +33 -220
  60. package/src/errors/PredictionsError.ts +16 -0
  61. package/src/errors/types/validation.ts +51 -0
  62. package/src/errors/utils/assertValidationError.ts +18 -0
  63. package/src/index.ts +16 -16
  64. package/src/{Providers → providers}/AmazonAIConvertPredictionsProvider.ts +210 -171
  65. package/src/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.ts +244 -246
  66. package/src/providers/AmazonAIInterpretPredictionsProvider.ts +293 -0
  67. package/src/{Providers → providers}/IdentifyTextUtils.ts +69 -52
  68. package/src/{Providers → providers}/Utils.ts +2 -2
  69. package/src/{Providers → providers}/index.ts +0 -2
  70. package/src/types/AWSTypes.ts +5 -6
  71. package/src/types/Predictions.ts +107 -62
  72. package/lib/.tsbuildinfo +0 -3
  73. package/lib/Predictions.js.map +0 -1
  74. package/lib/Providers/AmazonAIConvertPredictionsProvider.js +0 -377
  75. package/lib/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
  76. package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -441
  77. package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
  78. package/lib/Providers/AmazonAIInterpretPredictionsProvider.js +0 -321
  79. package/lib/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
  80. package/lib/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
  81. package/lib/Providers/AmazonAIPredictionsProvider.js +0 -43
  82. package/lib/Providers/AmazonAIPredictionsProvider.js.map +0 -1
  83. package/lib/Providers/IdentifyTextUtils.d.ts +0 -40
  84. package/lib/Providers/IdentifyTextUtils.js.map +0 -1
  85. package/lib/Providers/Utils.js.map +0 -1
  86. package/lib/Providers/index.js +0 -13
  87. package/lib/Providers/index.js.map +0 -1
  88. package/lib/index.js.map +0 -1
  89. package/lib/types/AWSTypes.js.map +0 -1
  90. package/lib/types/Predictions.js.map +0 -1
  91. package/lib/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
  92. package/lib/types/Providers/AbstractConvertPredictionsProvider.js +0 -44
  93. package/lib/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
  94. package/lib/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
  95. package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -44
  96. package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
  97. package/lib/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
  98. package/lib/types/Providers/AbstractInterpretPredictionsProvider.js +0 -27
  99. package/lib/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
  100. package/lib/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
  101. package/lib/types/Providers/AbstractPredictionsProvider.js +0 -16
  102. package/lib/types/Providers/AbstractPredictionsProvider.js.map +0 -1
  103. package/lib/types/Providers/index.d.ts +0 -4
  104. package/lib/types/Providers/index.js +0 -10
  105. package/lib/types/Providers/index.js.map +0 -1
  106. package/lib/types/index.js.map +0 -1
  107. package/lib-esm/.tsbuildinfo +0 -3
  108. package/lib-esm/Predictions.js.map +0 -1
  109. package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js +0 -375
  110. package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
  111. package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -439
  112. package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
  113. package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js +0 -319
  114. package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
  115. package/lib-esm/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
  116. package/lib-esm/Providers/AmazonAIPredictionsProvider.js +0 -41
  117. package/lib-esm/Providers/AmazonAIPredictionsProvider.js.map +0 -1
  118. package/lib-esm/Providers/IdentifyTextUtils.d.ts +0 -40
  119. package/lib-esm/Providers/IdentifyTextUtils.js +0 -313
  120. package/lib-esm/Providers/IdentifyTextUtils.js.map +0 -1
  121. package/lib-esm/Providers/Utils.js.map +0 -1
  122. package/lib-esm/Providers/index.js.map +0 -1
  123. package/lib-esm/index.js.map +0 -1
  124. package/lib-esm/types/AWSTypes.js.map +0 -1
  125. package/lib-esm/types/Predictions.js.map +0 -1
  126. package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
  127. package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js +0 -42
  128. package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
  129. package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
  130. package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -42
  131. package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
  132. package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
  133. package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js +0 -25
  134. package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
  135. package/lib-esm/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
  136. package/lib-esm/types/Providers/AbstractPredictionsProvider.js +0 -14
  137. package/lib-esm/types/Providers/AbstractPredictionsProvider.js.map +0 -1
  138. package/lib-esm/types/Providers/index.d.ts +0 -4
  139. package/lib-esm/types/Providers/index.js +0 -7
  140. package/lib-esm/types/Providers/index.js.map +0 -1
  141. package/lib-esm/types/index.js.map +0 -1
  142. package/src/Providers/AmazonAIInterpretPredictionsProvider.ts +0 -281
  143. package/src/Providers/AmazonAIPredictionsProvider.ts +0 -69
  144. package/src/types/Providers/AbstractConvertPredictionsProvider.ts +0 -55
  145. package/src/types/Providers/AbstractIdentifyPredictionsProvider.ts +0 -57
  146. package/src/types/Providers/AbstractInterpretPredictionsProvider.ts +0 -26
  147. package/src/types/Providers/AbstractPredictionsProvider.ts +0 -20
  148. package/src/types/Providers/index.ts +0 -6
@@ -1,24 +1,8 @@
1
1
  /// <reference types="node" />
2
- /**
3
- * Base types
4
- */
5
- export interface PredictionsOptions {
6
- [key: string]: any;
7
- }
8
- export interface ProviderOptions {
9
- providerName?: string;
10
- }
11
2
  /**
12
3
  * Convert types
13
4
  */
14
- export declare enum InterpretTextCategories {
15
- ALL = "ALL",
16
- LANGUAGE = "LANGUAGE",
17
- ENTITIES = "ENTITIES",
18
- SENTIMENT = "SENTIMENT",
19
- SYNTAX = "SYNTAX",
20
- KEY_PHRASES = "KEY_PHRASES"
21
- }
5
+ export type InterpretTextCategories = 'all' | 'language' | 'entities' | 'sentiment' | 'syntax' | 'keyPhrases';
22
6
  export interface InterpretTextInput {
23
7
  text: InterpretTextInputLanguage | InterpretTextOthers | InterpretTextAll;
24
8
  }
@@ -26,28 +10,29 @@ export interface InterpretTextInputLanguage {
26
10
  source: {
27
11
  text: string;
28
12
  };
29
- type: InterpretTextCategories.LANGUAGE;
13
+ type: Extract<InterpretTextCategories, 'language'>;
30
14
  }
31
15
  export interface InterpretTextOthers {
32
16
  source: {
33
17
  text: string;
34
18
  language: string;
35
19
  };
36
- type: InterpretTextCategories.ENTITIES | InterpretTextCategories.SENTIMENT | InterpretTextCategories.SYNTAX | InterpretTextCategories.KEY_PHRASES;
20
+ type: Extract<InterpretTextCategories, 'entities' | 'sentiment' | 'syntax' | 'keyPhrases'>;
37
21
  }
38
22
  export interface InterpretTextAll {
39
23
  source: {
40
24
  text: string;
41
25
  };
42
- type: InterpretTextCategories.ALL;
26
+ type: Extract<InterpretTextCategories, 'all'>;
43
27
  }
44
28
  export interface TextEntities {
45
- type: string;
46
- text: string;
47
- }
48
- export interface KeyPhrases {
49
- text: string;
29
+ type?: string;
30
+ text?: string;
50
31
  }
32
+ export type KeyPhrases = KeyPhrase[];
33
+ export type KeyPhrase = {
34
+ text?: string;
35
+ };
51
36
  export interface TextSyntax {
52
37
  text: string;
53
38
  syntax: string;
@@ -59,11 +44,15 @@ export interface TextSentiment {
59
44
  neutral: number;
60
45
  mixed: number;
61
46
  }
47
+ export type DetectParams = {
48
+ Text: string;
49
+ LanguageCode: string;
50
+ };
62
51
  export interface InterpretTextOutput {
63
52
  textInterpretation: {
64
53
  language?: string;
65
54
  textEntities?: Array<TextEntities>;
66
- keyPhrases?: Array<KeyPhrases>;
55
+ keyPhrases?: KeyPhrases;
67
56
  sentiment?: TextSentiment;
68
57
  syntax?: Array<TextSyntax>;
69
58
  };
@@ -99,27 +88,34 @@ export interface TextToSpeechOutput {
99
88
  }
100
89
  export interface StorageSource {
101
90
  key: string;
102
- level?: 'public' | 'private' | 'protected';
91
+ level?: 'guest' | 'private' | 'protected';
103
92
  identityId?: string;
104
93
  }
105
94
  export interface FileSource {
106
95
  file: File;
107
96
  }
108
- export interface BytesSource {
109
- bytes: Buffer | ArrayBuffer | Blob | string;
97
+ export type ConvertBytes = Buffer | ArrayBuffer | string;
98
+ export type IdentifyBytes = ConvertBytes | Blob;
99
+ export interface BytesSource<T> {
100
+ bytes: T;
110
101
  }
111
102
  export interface SpeechToTextInput {
112
103
  transcription: {
113
- source: BytesSource;
104
+ source: BytesSource<ConvertBytes>;
114
105
  language?: string;
115
106
  };
116
107
  }
108
+ export type TranscribeData = {
109
+ connection: WebSocket;
110
+ raw: ConvertBytes;
111
+ languageCode: string;
112
+ };
117
113
  export interface SpeechToTextOutput {
118
114
  transcription: {
119
115
  fullText: string;
120
116
  };
121
117
  }
122
- export declare type IdentifySource = StorageSource | FileSource | BytesSource;
118
+ export type IdentifySource = StorageSource | FileSource | BytesSource<IdentifyBytes>;
123
119
  export interface IdentifyTextInput {
124
120
  text: {
125
121
  source: IdentifySource;
@@ -153,14 +149,14 @@ export interface Table {
153
149
  columns: number;
154
150
  };
155
151
  table: TableCell[][];
156
- polygon: Polygon;
157
- boundingBox: BoundingBox;
152
+ polygon?: Polygon;
153
+ boundingBox?: BoundingBox;
158
154
  }
159
155
  export interface KeyValue {
160
156
  key: string;
161
157
  value: Content;
162
- polygon: Polygon;
163
- boundingBox: BoundingBox;
158
+ polygon?: Polygon;
159
+ boundingBox?: BoundingBox;
164
160
  }
165
161
  export interface IdentifyTextOutput {
166
162
  text: {
@@ -172,8 +168,8 @@ export interface IdentifyTextOutput {
172
168
  tables?: Table[];
173
169
  selections?: {
174
170
  selected: boolean;
175
- polygon: Polygon;
176
- boundingBox: BoundingBox;
171
+ polygon?: Polygon;
172
+ boundingBox?: BoundingBox;
177
173
  }[];
178
174
  };
179
175
  }
@@ -187,7 +183,7 @@ export interface Point {
187
183
  x?: Number;
188
184
  y?: Number;
189
185
  }
190
- export declare type Polygon = Array<Point> | Iterable<Point>;
186
+ export type Polygon = Array<Point> | Iterable<Point>;
191
187
  export interface BoundingBox {
192
188
  width?: Number;
193
189
  height?: Number;
@@ -196,8 +192,8 @@ export interface BoundingBox {
196
192
  }
197
193
  export interface IdentifyLabelsOutput {
198
194
  labels?: {
199
- name: string;
200
- boundingBoxes: BoundingBox[];
195
+ name?: string;
196
+ boundingBoxes?: (BoundingBox | undefined)[];
201
197
  metadata?: Object;
202
198
  }[];
203
199
  unsafe?: 'YES' | 'NO' | 'UNKNOWN';
@@ -227,24 +223,30 @@ export interface FaceAttributes {
227
223
  mustache?: boolean;
228
224
  eyesOpen?: boolean;
229
225
  mouthOpen?: boolean;
230
- emotions?: string[];
231
- }
226
+ emotions?: (string | undefined)[];
227
+ }
228
+ export type EntityAgeRange = {
229
+ low?: Number;
230
+ high?: Number;
231
+ };
232
+ export type EntityLandmark = {
233
+ type?: string;
234
+ x?: number;
235
+ y?: number;
236
+ };
237
+ export type IdentifyEntity = {
238
+ boundingBox?: BoundingBox;
239
+ ageRange?: EntityAgeRange;
240
+ landmarks?: (EntityLandmark | undefined)[];
241
+ attributes?: FaceAttributes;
242
+ metadata?: object;
243
+ };
232
244
  export interface IdentifyEntitiesOutput {
233
- entities: {
234
- boundingBox?: BoundingBox;
235
- ageRange?: {
236
- low?: Number;
237
- high?: Number;
238
- };
239
- landmarks?: {
240
- type?: string;
241
- x?: number;
242
- y?: number;
243
- }[];
244
- attributes?: FaceAttributes;
245
- metadata?: object;
246
- }[];
245
+ entities: IdentifyEntity[];
247
246
  }
247
+ export declare function isValidConvertInput(obj: any): boolean;
248
+ export declare function isValidIdentifyInput(obj: any): boolean;
249
+ export declare function isValidInterpretInput(obj: any): boolean;
248
250
  export declare function isIdentifyFromCollection(obj: any): obj is IdentifyFromCollection;
249
251
  export declare function isIdentifyCelebrities(obj: any): obj is IdentifyCelebrities;
250
252
  export declare function isTranslateTextInput(obj: any): obj is TranslateTextInput;
@@ -252,11 +254,13 @@ export declare function isTextToSpeechInput(obj: any): obj is TextToSpeechInput;
252
254
  export declare function isSpeechToTextInput(obj: any): obj is SpeechToTextInput;
253
255
  export declare function isStorageSource(obj: any): obj is StorageSource;
254
256
  export declare function isFileSource(obj: any): obj is FileSource;
255
- export declare function isBytesSource(obj: any): obj is BytesSource;
257
+ export declare function isConvertBytesSource(obj: any): obj is BytesSource<ConvertBytes>;
258
+ export declare function isIdentifyBytesSource(obj: any): obj is BytesSource<IdentifyBytes>;
256
259
  export declare function isIdentifyTextInput(obj: any): obj is IdentifyTextInput;
257
260
  export declare function isIdentifyLabelsInput(obj: any): obj is IdentifyLabelsInput;
258
261
  export declare function isIdentifyEntitiesInput(obj: any): obj is IdentifyEntitiesInput;
259
262
  export declare function isInterpretTextInput(obj: any): obj is InterpretTextInput;
263
+ export declare function isInterpretTextOthers(text: InterpretTextInput['text']): text is InterpretTextOthers;
260
264
  export interface Geometry {
261
265
  /**
262
266
  * <p>An axis-aligned coarse representation of the detected text's location on the image.</p>
@@ -277,5 +281,5 @@ export interface Relationship {
277
281
  */
278
282
  Ids?: Array<string> | Iterable<string>;
279
283
  }
280
- export declare type FeatureType = 'TABLES' | 'FORMS' | string;
281
- export declare type FeatureTypes = FeatureType[];
284
+ export type FeatureType = 'TABLES' | 'FORMS' | string;
285
+ export type FeatureTypes = FeatureType[];
@@ -3,77 +3,90 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  /* tslint:disable:max-line-length */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- /**
7
- * Convert types
8
- */
9
- var InterpretTextCategories;
10
- (function (InterpretTextCategories) {
11
- InterpretTextCategories["ALL"] = "ALL";
12
- InterpretTextCategories["LANGUAGE"] = "LANGUAGE";
13
- InterpretTextCategories["ENTITIES"] = "ENTITIES";
14
- InterpretTextCategories["SENTIMENT"] = "SENTIMENT";
15
- InterpretTextCategories["SYNTAX"] = "SYNTAX";
16
- InterpretTextCategories["KEY_PHRASES"] = "KEY_PHRASES";
17
- })(InterpretTextCategories = exports.InterpretTextCategories || (exports.InterpretTextCategories = {}));
6
+ exports.isInterpretTextOthers = exports.isInterpretTextInput = exports.isIdentifyEntitiesInput = exports.isIdentifyLabelsInput = exports.isIdentifyTextInput = exports.isIdentifyBytesSource = exports.isConvertBytesSource = exports.isFileSource = exports.isStorageSource = exports.isSpeechToTextInput = exports.isTextToSpeechInput = exports.isTranslateTextInput = exports.isIdentifyCelebrities = exports.isIdentifyFromCollection = exports.isValidInterpretInput = exports.isValidIdentifyInput = exports.isValidConvertInput = void 0;
7
+ function isValidConvertInput(obj) {
8
+ return (isTranslateTextInput(obj) ||
9
+ isTextToSpeechInput(obj) ||
10
+ isSpeechToTextInput(obj));
11
+ }
12
+ exports.isValidConvertInput = isValidConvertInput;
13
+ function isValidIdentifyInput(obj) {
14
+ return (isIdentifyTextInput(obj) ||
15
+ isIdentifyLabelsInput(obj) ||
16
+ isIdentifyEntitiesInput(obj));
17
+ }
18
+ exports.isValidIdentifyInput = isValidIdentifyInput;
19
+ function isValidInterpretInput(obj) {
20
+ return isInterpretTextInput(obj);
21
+ }
22
+ exports.isValidInterpretInput = isValidInterpretInput;
18
23
  function isIdentifyFromCollection(obj) {
19
- var key = 'collection';
20
- var keyId = 'collectionId';
24
+ const key = 'collection';
25
+ const keyId = 'collectionId';
21
26
  return obj && (obj.hasOwnProperty(key) || obj.hasOwnProperty(keyId));
22
27
  }
23
28
  exports.isIdentifyFromCollection = isIdentifyFromCollection;
24
29
  function isIdentifyCelebrities(obj) {
25
- var key = 'celebrityDetection';
30
+ const key = 'celebrityDetection';
26
31
  return obj && obj.hasOwnProperty(key);
27
32
  }
28
33
  exports.isIdentifyCelebrities = isIdentifyCelebrities;
29
34
  function isTranslateTextInput(obj) {
30
- var key = 'translateText';
35
+ const key = 'translateText';
31
36
  return obj && obj.hasOwnProperty(key);
32
37
  }
33
38
  exports.isTranslateTextInput = isTranslateTextInput;
34
39
  function isTextToSpeechInput(obj) {
35
- var key = 'textToSpeech';
40
+ const key = 'textToSpeech';
36
41
  return obj && obj.hasOwnProperty(key);
37
42
  }
38
43
  exports.isTextToSpeechInput = isTextToSpeechInput;
39
44
  function isSpeechToTextInput(obj) {
40
- var key = 'transcription';
45
+ const key = 'transcription';
41
46
  return obj && obj.hasOwnProperty(key);
42
47
  }
43
48
  exports.isSpeechToTextInput = isSpeechToTextInput;
44
49
  function isStorageSource(obj) {
45
- var key = 'key';
50
+ const key = 'key';
46
51
  return obj && obj.hasOwnProperty(key);
47
52
  }
48
53
  exports.isStorageSource = isStorageSource;
49
54
  function isFileSource(obj) {
50
- var key = 'file';
55
+ const key = 'file';
51
56
  return obj && obj.hasOwnProperty(key);
52
57
  }
53
58
  exports.isFileSource = isFileSource;
54
- function isBytesSource(obj) {
55
- var key = 'bytes';
59
+ function isConvertBytesSource(obj) {
60
+ const key = 'bytes';
56
61
  return obj && obj.hasOwnProperty(key);
57
62
  }
58
- exports.isBytesSource = isBytesSource;
63
+ exports.isConvertBytesSource = isConvertBytesSource;
64
+ function isIdentifyBytesSource(obj) {
65
+ const key = 'bytes';
66
+ return obj && obj.hasOwnProperty(key);
67
+ }
68
+ exports.isIdentifyBytesSource = isIdentifyBytesSource;
59
69
  function isIdentifyTextInput(obj) {
60
- var key = 'text';
70
+ const key = 'text';
61
71
  return obj && obj.hasOwnProperty(key);
62
72
  }
63
73
  exports.isIdentifyTextInput = isIdentifyTextInput;
64
74
  function isIdentifyLabelsInput(obj) {
65
- var key = 'labels';
75
+ const key = 'labels';
66
76
  return obj && obj.hasOwnProperty(key);
67
77
  }
68
78
  exports.isIdentifyLabelsInput = isIdentifyLabelsInput;
69
79
  function isIdentifyEntitiesInput(obj) {
70
- var key = 'entities';
80
+ const key = 'entities';
71
81
  return obj && obj.hasOwnProperty(key);
72
82
  }
73
83
  exports.isIdentifyEntitiesInput = isIdentifyEntitiesInput;
74
84
  function isInterpretTextInput(obj) {
75
- var key = 'text';
85
+ const key = 'text';
76
86
  return obj && obj.hasOwnProperty(key);
77
87
  }
78
88
  exports.isInterpretTextInput = isInterpretTextInput;
79
- //# sourceMappingURL=Predictions.js.map
89
+ function isInterpretTextOthers(text) {
90
+ return text.source.language !== undefined;
91
+ }
92
+ exports.isInterpretTextOthers = isInterpretTextOthers;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
3
+ const tslib_1 = require("tslib");
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
6
  tslib_1.__exportStar(require("./Predictions"), exports);
7
- //# sourceMappingURL=index.js.map
@@ -1,49 +1,15 @@
1
- import { PredictionsOptions, TranslateTextInput, TranslateTextOutput, TextToSpeechInput, ProviderOptions, TextToSpeechOutput, SpeechToTextInput, SpeechToTextOutput, IdentifyTextInput, IdentifyTextOutput, IdentifyLabelsOutput, IdentifyLabelsInput, IdentifyEntitiesInput, IdentifyEntitiesOutput, InterpretTextOutput, InterpretTextInput } from './types';
2
- import { AbstractPredictionsProvider } from './types/Providers';
1
+ import { IdentifyEntitiesInput, IdentifyEntitiesOutput, IdentifyLabelsInput, IdentifyLabelsOutput, IdentifyTextInput, IdentifyTextOutput, InterpretTextInput, InterpretTextOutput, SpeechToTextInput, SpeechToTextOutput, TextToSpeechInput, TextToSpeechOutput, TranslateTextInput, TranslateTextOutput } from './types';
3
2
  export declare class PredictionsClass {
4
- private _options;
5
- private _convertPluggables;
6
- private _identifyPluggables;
7
- private _interpretPluggables;
8
- /**
9
- * Initialize Predictions with AWS configurations
10
- * @param {PredictionsOptions} options - Configuration object for Predictions
11
- */
12
- constructor(options: PredictionsOptions);
3
+ private convertProvider;
4
+ private identifyProvider;
5
+ private interpretProvider;
13
6
  getModuleName(): string;
14
- /**
15
- * add plugin/pluggable into Predictions category
16
- * @param {Object} pluggable - an instance of the plugin/pluggable
17
- **/
18
- addPluggable(pluggable: AbstractPredictionsProvider): void;
19
- /**
20
- * Get the plugin object
21
- * @param providerName - the name of the plugin
22
- */
23
- getPluggable(providerName: string): AbstractPredictionsProvider;
24
- /**
25
- * Remove the plugin object
26
- * @param providerName - the name of the plugin
27
- */
28
- removePluggable(providerName: string): void;
29
- /**
30
- * To make both top level providers and category level providers work with same interface and configuration
31
- * this method duplicates Predictions config into parent level config (for top level provider) and
32
- * category level config (such as convert, identify etc) and pass both to each provider.
33
- */
34
- configure(options: PredictionsOptions): void;
35
- interpret(input: InterpretTextInput, options?: ProviderOptions): Promise<InterpretTextOutput>;
36
- convert(input: TranslateTextInput, options?: ProviderOptions): Promise<TranslateTextOutput>;
37
- convert(input: TextToSpeechInput, options?: ProviderOptions): Promise<TextToSpeechOutput>;
38
- convert(input: SpeechToTextInput, options?: ProviderOptions): Promise<SpeechToTextOutput>;
39
- identify(input: IdentifyTextInput, options?: ProviderOptions): Promise<IdentifyTextOutput>;
40
- identify(input: IdentifyLabelsInput, options?: ProviderOptions): Promise<IdentifyLabelsOutput>;
41
- identify(input: IdentifyEntitiesInput, options?: ProviderOptions): Promise<IdentifyEntitiesOutput>;
42
- private getPluggableToExecute;
43
- private getAllProviders;
44
- private configurePluggable;
45
- private implementsConvertPluggable;
46
- private implementsIdentifyPluggable;
47
- private implementsInterpretPluggable;
7
+ interpret(input: InterpretTextInput): Promise<InterpretTextOutput>;
8
+ convert(input: TranslateTextInput): Promise<TranslateTextOutput>;
9
+ convert(input: TextToSpeechInput): Promise<TextToSpeechOutput>;
10
+ convert(input: SpeechToTextInput): Promise<SpeechToTextOutput>;
11
+ identify(input: IdentifyTextInput): Promise<IdentifyTextOutput>;
12
+ identify(input: IdentifyLabelsInput): Promise<IdentifyLabelsOutput>;
13
+ identify(input: IdentifyEntitiesInput): Promise<IdentifyEntitiesOutput>;
48
14
  }
49
15
  export declare const Predictions: PredictionsClass;
@@ -1,135 +1,25 @@
1
- import { __assign, __read, __spread } from "tslib";
2
- import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
3
- var logger = new Logger('Predictions');
4
- var PredictionsClass = /** @class */ (function () {
5
- /**
6
- * Initialize Predictions with AWS configurations
7
- * @param {PredictionsOptions} options - Configuration object for Predictions
8
- */
9
- function PredictionsClass(options) {
10
- this._options = options;
11
- this._convertPluggables = [];
12
- this._identifyPluggables = [];
13
- this._interpretPluggables = [];
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { ConsoleLogger as Logger } from '@aws-amplify/core';
4
+ import { AmazonAIConvertPredictionsProvider, AmazonAIIdentifyPredictionsProvider, AmazonAIInterpretPredictionsProvider, } from './providers';
5
+ const logger = new Logger('Predictions');
6
+ export class PredictionsClass {
7
+ constructor() {
8
+ this.convertProvider = new AmazonAIConvertPredictionsProvider();
9
+ this.identifyProvider = new AmazonAIIdentifyPredictionsProvider();
10
+ this.interpretProvider = new AmazonAIInterpretPredictionsProvider();
14
11
  }
15
- PredictionsClass.prototype.getModuleName = function () {
12
+ getModuleName() {
16
13
  return 'Predictions';
17
- };
18
- /**
19
- * add plugin/pluggable into Predictions category
20
- * @param {Object} pluggable - an instance of the plugin/pluggable
21
- **/
22
- PredictionsClass.prototype.addPluggable = function (pluggable) {
23
- if (this.getPluggable(pluggable.getProviderName())) {
24
- throw new Error("Pluggable with name " + pluggable.getProviderName() + " has already been added.");
25
- }
26
- var pluggableAdded = false;
27
- if (this.implementsConvertPluggable(pluggable)) {
28
- this._convertPluggables.push(pluggable);
29
- pluggableAdded = true;
30
- }
31
- if (this.implementsIdentifyPluggable(pluggable)) {
32
- this._identifyPluggables.push(pluggable);
33
- pluggableAdded = true;
34
- }
35
- if (this.implementsInterpretPluggable(pluggable)) {
36
- this._interpretPluggables.push(pluggable);
37
- pluggableAdded = true;
38
- }
39
- if (pluggableAdded) {
40
- this.configurePluggable(pluggable);
41
- }
42
- };
43
- /**
44
- * Get the plugin object
45
- * @param providerName - the name of the plugin
46
- */
47
- PredictionsClass.prototype.getPluggable = function (providerName) {
48
- var pluggable = this.getAllProviders().find(function (pluggable) { return pluggable.getProviderName() === providerName; });
49
- if (pluggable === undefined) {
50
- logger.debug('No plugin found with providerName=>', providerName);
51
- return null;
52
- }
53
- else
54
- return pluggable;
55
- };
56
- /**
57
- * Remove the plugin object
58
- * @param providerName - the name of the plugin
59
- */
60
- PredictionsClass.prototype.removePluggable = function (providerName) {
61
- this._convertPluggables = this._convertPluggables.filter(function (pluggable) { return pluggable.getProviderName() !== providerName; });
62
- this._identifyPluggables = this._identifyPluggables.filter(function (pluggable) { return pluggable.getProviderName() !== providerName; });
63
- this._interpretPluggables = this._interpretPluggables.filter(function (pluggable) { return pluggable.getProviderName() !== providerName; });
64
- return;
65
- };
66
- /**
67
- * To make both top level providers and category level providers work with same interface and configuration
68
- * this method duplicates Predictions config into parent level config (for top level provider) and
69
- * category level config (such as convert, identify etc) and pass both to each provider.
70
- */
71
- PredictionsClass.prototype.configure = function (options) {
72
- var _this = this;
73
- var predictionsConfig = options ? options.predictions || options : {};
74
- predictionsConfig = __assign(__assign({}, predictionsConfig), options);
75
- this._options = Object.assign({}, this._options, predictionsConfig);
76
- logger.debug('configure Predictions', this._options);
77
- this.getAllProviders().forEach(function (pluggable) {
78
- return _this.configurePluggable(pluggable);
79
- });
80
- };
81
- PredictionsClass.prototype.interpret = function (input, options) {
82
- var pluggableToExecute = this.getPluggableToExecute(this._interpretPluggables, options);
83
- return pluggableToExecute.interpret(input);
84
- };
85
- PredictionsClass.prototype.convert = function (input, options) {
86
- var pluggableToExecute = this.getPluggableToExecute(this._convertPluggables, options);
87
- return pluggableToExecute.convert(input);
88
- };
89
- PredictionsClass.prototype.identify = function (input, options) {
90
- var pluggableToExecute = this.getPluggableToExecute(this._identifyPluggables, options);
91
- return pluggableToExecute.identify(input);
92
- };
93
- // tslint:disable-next-line: max-line-length
94
- PredictionsClass.prototype.getPluggableToExecute = function (pluggables, providerOptions) {
95
- // Give preference to provider name first since it is more specific to this call, even if
96
- // there is only one provider configured to error out if the name provided is not the one matched.
97
- if (providerOptions && providerOptions.providerName) {
98
- return __spread(pluggables).find(function (pluggable) {
99
- return pluggable.getProviderName() === providerOptions.providerName;
100
- });
101
- }
102
- else {
103
- if (pluggables.length === 1) {
104
- return pluggables[0];
105
- }
106
- else {
107
- throw new Error('More than one or no providers are configured, ' +
108
- 'Either specify a provider name or configure exactly one provider');
109
- }
110
- }
111
- };
112
- PredictionsClass.prototype.getAllProviders = function () {
113
- return __spread(this._convertPluggables, this._identifyPluggables, this._interpretPluggables);
114
- };
115
- PredictionsClass.prototype.configurePluggable = function (pluggable) {
116
- var categoryConfig = Object.assign({}, this._options['predictions'], // Parent predictions config for the top level provider
117
- this._options[pluggable.getCategory().toLowerCase()] // Actual category level config
118
- );
119
- pluggable.configure(categoryConfig);
120
- };
121
- PredictionsClass.prototype.implementsConvertPluggable = function (obj) {
122
- return obj && typeof obj.convert === 'function';
123
- };
124
- PredictionsClass.prototype.implementsIdentifyPluggable = function (obj) {
125
- return obj && typeof obj.identify === 'function';
126
- };
127
- PredictionsClass.prototype.implementsInterpretPluggable = function (obj) {
128
- return obj && typeof obj.interpret === 'function';
129
- };
130
- return PredictionsClass;
131
- }());
132
- export { PredictionsClass };
133
- export var Predictions = new PredictionsClass({});
134
- Amplify.register(Predictions);
135
- //# sourceMappingURL=Predictions.js.map
14
+ }
15
+ interpret(input) {
16
+ return this.interpretProvider.interpret(input);
17
+ }
18
+ convert(input) {
19
+ return this.convertProvider.convert(input);
20
+ }
21
+ identify(input) {
22
+ return this.identifyProvider.identify(input);
23
+ }
24
+ }
25
+ export const Predictions = new PredictionsClass();
@@ -0,0 +1,4 @@
1
+ import { AmplifyError, AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
2
+ export declare class PredictionsError extends AmplifyError {
3
+ constructor(params: AmplifyErrorParams);
4
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AmplifyError, } from '@aws-amplify/core/internals/utils';
4
+ export class PredictionsError extends AmplifyError {
5
+ constructor(params) {
6
+ super(params);
7
+ // TODO: Delete the following 2 lines after we change the build target to >= es2015
8
+ this.constructor = PredictionsError;
9
+ Object.setPrototypeOf(this, PredictionsError.prototype);
10
+ }
11
+ }
@@ -0,0 +1,14 @@
1
+ import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
+ export declare enum PredictionsValidationErrorCode {
3
+ CelebrityDetectionNotEnabled = "CelebrityDetectionNotEnabled",
4
+ InvalidInput = "InvalidInput",
5
+ InvalidSource = "InvalidSource",
6
+ NoCredentials = "NoCredentials",
7
+ NoLanguage = "NoLanguage",
8
+ NoRegion = "NoRegion",
9
+ NoSource = "NoSource",
10
+ NoSourceLanguage = "NoSourceLanguage",
11
+ NoTargetLanguage = "NoTargetLanguage",
12
+ NoVoiceId = "NoVoiceId"
13
+ }
14
+ export declare const validationErrorMap: AmplifyErrorMap<PredictionsValidationErrorCode>;
@@ -0,0 +1,47 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export var PredictionsValidationErrorCode;
4
+ (function (PredictionsValidationErrorCode) {
5
+ PredictionsValidationErrorCode["CelebrityDetectionNotEnabled"] = "CelebrityDetectionNotEnabled";
6
+ PredictionsValidationErrorCode["InvalidInput"] = "InvalidInput";
7
+ PredictionsValidationErrorCode["InvalidSource"] = "InvalidSource";
8
+ PredictionsValidationErrorCode["NoCredentials"] = "NoCredentials";
9
+ PredictionsValidationErrorCode["NoLanguage"] = "NoLanguage";
10
+ PredictionsValidationErrorCode["NoRegion"] = "NoRegion";
11
+ PredictionsValidationErrorCode["NoSource"] = "NoSource";
12
+ PredictionsValidationErrorCode["NoSourceLanguage"] = "NoSourceLanguage";
13
+ PredictionsValidationErrorCode["NoTargetLanguage"] = "NoTargetLanguage";
14
+ PredictionsValidationErrorCode["NoVoiceId"] = "NoVoiceId";
15
+ })(PredictionsValidationErrorCode || (PredictionsValidationErrorCode = {}));
16
+ export const validationErrorMap = {
17
+ [PredictionsValidationErrorCode.CelebrityDetectionNotEnabled]: {
18
+ message: 'Celebrity Detection must be enabled.',
19
+ },
20
+ [PredictionsValidationErrorCode.InvalidInput]: {
21
+ message: 'Input does not conform to expected type.',
22
+ },
23
+ [PredictionsValidationErrorCode.InvalidSource]: {
24
+ message: 'Source type not supported.',
25
+ },
26
+ [PredictionsValidationErrorCode.NoCredentials]: {
27
+ message: 'Credentials should not be empty.',
28
+ },
29
+ [PredictionsValidationErrorCode.NoLanguage]: {
30
+ message: 'Missing language.',
31
+ },
32
+ [PredictionsValidationErrorCode.NoRegion]: {
33
+ message: 'Missing region.',
34
+ },
35
+ [PredictionsValidationErrorCode.NoSource]: {
36
+ message: 'Missing source.',
37
+ },
38
+ [PredictionsValidationErrorCode.NoSourceLanguage]: {
39
+ message: 'Missing source language for translation.',
40
+ },
41
+ [PredictionsValidationErrorCode.NoTargetLanguage]: {
42
+ message: 'Missing target language for translation.',
43
+ },
44
+ [PredictionsValidationErrorCode.NoVoiceId]: {
45
+ message: 'Missing voice id.',
46
+ },
47
+ };