@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.
- package/README.md +3 -0
- package/lib/Predictions.d.ts +11 -45
- package/lib/Predictions.js +24 -132
- package/lib/errors/PredictionsError.d.ts +4 -0
- package/lib/errors/PredictionsError.js +15 -0
- package/lib/errors/types/validation.d.ts +14 -0
- package/lib/errors/types/validation.js +50 -0
- package/lib/errors/utils/assertValidationError.d.ts +2 -0
- package/lib/errors/utils/assertValidationError.js +14 -0
- package/lib/index.d.ts +2 -4
- package/lib/index.js +2 -9
- package/{lib-esm/Providers → lib/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
- package/lib/providers/AmazonAIConvertPredictionsProvider.js +307 -0
- package/lib/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
- package/lib/providers/AmazonAIIdentifyPredictionsProvider.js +334 -0
- package/lib/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
- package/lib/providers/AmazonAIInterpretPredictionsProvider.js +208 -0
- package/lib/providers/IdentifyTextUtils.d.ts +16 -0
- package/lib/{Providers → providers}/IdentifyTextUtils.js +97 -148
- package/lib/{Providers → providers}/Utils.d.ts +2 -2
- package/lib/{Providers → providers}/Utils.js +11 -12
- package/lib/{Providers → providers}/index.d.ts +1 -2
- package/lib/providers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AWSTypes.d.ts +8 -9
- package/lib/types/AWSTypes.js +0 -1
- package/lib/types/Predictions.d.ts +63 -59
- package/lib/types/Predictions.js +41 -28
- package/lib/types/index.js +1 -2
- package/lib-esm/Predictions.d.ts +11 -45
- package/lib-esm/Predictions.js +23 -133
- package/lib-esm/errors/PredictionsError.d.ts +4 -0
- package/lib-esm/errors/PredictionsError.js +11 -0
- package/lib-esm/errors/types/validation.d.ts +14 -0
- package/lib-esm/errors/types/validation.js +47 -0
- package/lib-esm/errors/utils/assertValidationError.d.ts +2 -0
- package/lib-esm/errors/utils/assertValidationError.js +10 -0
- package/lib-esm/index.d.ts +2 -4
- package/lib-esm/index.js +1 -5
- package/{lib/Providers → lib-esm/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
- package/lib-esm/providers/AmazonAIConvertPredictionsProvider.js +303 -0
- package/lib-esm/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
- package/lib-esm/providers/AmazonAIIdentifyPredictionsProvider.js +330 -0
- package/lib-esm/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
- package/lib-esm/providers/AmazonAIInterpretPredictionsProvider.js +204 -0
- package/lib-esm/providers/IdentifyTextUtils.d.ts +16 -0
- package/lib-esm/providers/IdentifyTextUtils.js +264 -0
- package/lib-esm/{Providers → providers}/Utils.d.ts +2 -2
- package/lib-esm/{Providers → providers}/Utils.js +10 -12
- package/lib-esm/{Providers → providers}/index.d.ts +1 -2
- package/lib-esm/{Providers → providers}/index.js +1 -3
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AWSTypes.d.ts +8 -9
- package/lib-esm/types/AWSTypes.js +1 -1
- package/lib-esm/types/Predictions.d.ts +63 -59
- package/lib-esm/types/Predictions.js +34 -27
- package/lib-esm/types/index.js +0 -1
- package/package.json +39 -48
- package/src/Predictions.ts +33 -220
- package/src/errors/PredictionsError.ts +16 -0
- package/src/errors/types/validation.ts +51 -0
- package/src/errors/utils/assertValidationError.ts +18 -0
- package/src/index.ts +16 -16
- package/src/{Providers → providers}/AmazonAIConvertPredictionsProvider.ts +210 -171
- package/src/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.ts +244 -246
- package/src/providers/AmazonAIInterpretPredictionsProvider.ts +293 -0
- package/src/{Providers → providers}/IdentifyTextUtils.ts +69 -52
- package/src/{Providers → providers}/Utils.ts +2 -2
- package/src/{Providers → providers}/index.ts +0 -2
- package/src/types/AWSTypes.ts +5 -6
- package/src/types/Predictions.ts +107 -62
- package/lib/.tsbuildinfo +0 -3
- package/lib/Predictions.js.map +0 -1
- package/lib/Providers/AmazonAIConvertPredictionsProvider.js +0 -377
- package/lib/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -441
- package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIInterpretPredictionsProvider.js +0 -321
- package/lib/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
- package/lib/Providers/AmazonAIPredictionsProvider.js +0 -43
- package/lib/Providers/AmazonAIPredictionsProvider.js.map +0 -1
- package/lib/Providers/IdentifyTextUtils.d.ts +0 -40
- package/lib/Providers/IdentifyTextUtils.js.map +0 -1
- package/lib/Providers/Utils.js.map +0 -1
- package/lib/Providers/index.js +0 -13
- package/lib/Providers/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/AWSTypes.js.map +0 -1
- package/lib/types/Predictions.js.map +0 -1
- package/lib/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
- package/lib/types/Providers/AbstractConvertPredictionsProvider.js +0 -44
- package/lib/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -44
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.js +0 -27
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
- package/lib/types/Providers/AbstractPredictionsProvider.js +0 -16
- package/lib/types/Providers/AbstractPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/index.d.ts +0 -4
- package/lib/types/Providers/index.js +0 -10
- package/lib/types/Providers/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Predictions.js.map +0 -1
- package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js +0 -375
- package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -439
- package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js +0 -319
- package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
- package/lib-esm/Providers/AmazonAIPredictionsProvider.js +0 -41
- package/lib-esm/Providers/AmazonAIPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/IdentifyTextUtils.d.ts +0 -40
- package/lib-esm/Providers/IdentifyTextUtils.js +0 -313
- package/lib-esm/Providers/IdentifyTextUtils.js.map +0 -1
- package/lib-esm/Providers/Utils.js.map +0 -1
- package/lib-esm/Providers/index.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/AWSTypes.js.map +0 -1
- package/lib-esm/types/Predictions.js.map +0 -1
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js +0 -42
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -42
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js +0 -25
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
- package/lib-esm/types/Providers/AbstractPredictionsProvider.js +0 -14
- package/lib-esm/types/Providers/AbstractPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/index.d.ts +0 -4
- package/lib-esm/types/Providers/index.js +0 -7
- package/lib-esm/types/Providers/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/Providers/AmazonAIInterpretPredictionsProvider.ts +0 -281
- package/src/Providers/AmazonAIPredictionsProvider.ts +0 -69
- package/src/types/Providers/AbstractConvertPredictionsProvider.ts +0 -55
- package/src/types/Providers/AbstractIdentifyPredictionsProvider.ts +0 -57
- package/src/types/Providers/AbstractInterpretPredictionsProvider.ts +0 -26
- package/src/types/Providers/AbstractPredictionsProvider.ts +0 -20
- 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
|
|
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
|
|
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
|
|
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
|
|
26
|
+
type: Extract<InterpretTextCategories, 'all'>;
|
|
43
27
|
}
|
|
44
28
|
export interface TextEntities {
|
|
45
|
-
type
|
|
46
|
-
text
|
|
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?:
|
|
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?: '
|
|
91
|
+
level?: 'guest' | 'private' | 'protected';
|
|
103
92
|
identityId?: string;
|
|
104
93
|
}
|
|
105
94
|
export interface FileSource {
|
|
106
95
|
file: File;
|
|
107
96
|
}
|
|
108
|
-
export
|
|
109
|
-
|
|
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
|
|
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
|
|
157
|
-
boundingBox
|
|
152
|
+
polygon?: Polygon;
|
|
153
|
+
boundingBox?: BoundingBox;
|
|
158
154
|
}
|
|
159
155
|
export interface KeyValue {
|
|
160
156
|
key: string;
|
|
161
157
|
value: Content;
|
|
162
|
-
polygon
|
|
163
|
-
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
|
|
176
|
-
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
|
|
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
|
|
200
|
-
boundingBoxes
|
|
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
|
|
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
|
|
281
|
-
export
|
|
284
|
+
export type FeatureType = 'TABLES' | 'FORMS' | string;
|
|
285
|
+
export type FeatureTypes = FeatureType[];
|
package/lib/types/Predictions.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
30
|
+
const key = 'celebrityDetection';
|
|
26
31
|
return obj && obj.hasOwnProperty(key);
|
|
27
32
|
}
|
|
28
33
|
exports.isIdentifyCelebrities = isIdentifyCelebrities;
|
|
29
34
|
function isTranslateTextInput(obj) {
|
|
30
|
-
|
|
35
|
+
const key = 'translateText';
|
|
31
36
|
return obj && obj.hasOwnProperty(key);
|
|
32
37
|
}
|
|
33
38
|
exports.isTranslateTextInput = isTranslateTextInput;
|
|
34
39
|
function isTextToSpeechInput(obj) {
|
|
35
|
-
|
|
40
|
+
const key = 'textToSpeech';
|
|
36
41
|
return obj && obj.hasOwnProperty(key);
|
|
37
42
|
}
|
|
38
43
|
exports.isTextToSpeechInput = isTextToSpeechInput;
|
|
39
44
|
function isSpeechToTextInput(obj) {
|
|
40
|
-
|
|
45
|
+
const key = 'transcription';
|
|
41
46
|
return obj && obj.hasOwnProperty(key);
|
|
42
47
|
}
|
|
43
48
|
exports.isSpeechToTextInput = isSpeechToTextInput;
|
|
44
49
|
function isStorageSource(obj) {
|
|
45
|
-
|
|
50
|
+
const key = 'key';
|
|
46
51
|
return obj && obj.hasOwnProperty(key);
|
|
47
52
|
}
|
|
48
53
|
exports.isStorageSource = isStorageSource;
|
|
49
54
|
function isFileSource(obj) {
|
|
50
|
-
|
|
55
|
+
const key = 'file';
|
|
51
56
|
return obj && obj.hasOwnProperty(key);
|
|
52
57
|
}
|
|
53
58
|
exports.isFileSource = isFileSource;
|
|
54
|
-
function
|
|
55
|
-
|
|
59
|
+
function isConvertBytesSource(obj) {
|
|
60
|
+
const key = 'bytes';
|
|
56
61
|
return obj && obj.hasOwnProperty(key);
|
|
57
62
|
}
|
|
58
|
-
exports.
|
|
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
|
-
|
|
70
|
+
const key = 'text';
|
|
61
71
|
return obj && obj.hasOwnProperty(key);
|
|
62
72
|
}
|
|
63
73
|
exports.isIdentifyTextInput = isIdentifyTextInput;
|
|
64
74
|
function isIdentifyLabelsInput(obj) {
|
|
65
|
-
|
|
75
|
+
const key = 'labels';
|
|
66
76
|
return obj && obj.hasOwnProperty(key);
|
|
67
77
|
}
|
|
68
78
|
exports.isIdentifyLabelsInput = isIdentifyLabelsInput;
|
|
69
79
|
function isIdentifyEntitiesInput(obj) {
|
|
70
|
-
|
|
80
|
+
const key = 'entities';
|
|
71
81
|
return obj && obj.hasOwnProperty(key);
|
|
72
82
|
}
|
|
73
83
|
exports.isIdentifyEntitiesInput = isIdentifyEntitiesInput;
|
|
74
84
|
function isInterpretTextInput(obj) {
|
|
75
|
-
|
|
85
|
+
const key = 'text';
|
|
76
86
|
return obj && obj.hasOwnProperty(key);
|
|
77
87
|
}
|
|
78
88
|
exports.isInterpretTextInput = isInterpretTextInput;
|
|
79
|
-
|
|
89
|
+
function isInterpretTextOthers(text) {
|
|
90
|
+
return text.source.language !== undefined;
|
|
91
|
+
}
|
|
92
|
+
exports.isInterpretTextOthers = isInterpretTextOthers;
|
package/lib/types/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
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
|
package/lib-esm/Predictions.d.ts
CHANGED
|
@@ -1,49 +1,15 @@
|
|
|
1
|
-
import {
|
|
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
|
|
5
|
-
private
|
|
6
|
-
private
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
package/lib-esm/Predictions.js
CHANGED
|
@@ -1,135 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.
|
|
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
|
-
|
|
12
|
+
getModuleName() {
|
|
16
13
|
return 'Predictions';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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,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
|
+
};
|