@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
package/src/Predictions.ts
CHANGED
|
@@ -1,251 +1,64 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
4
|
+
import {
|
|
5
|
+
AmazonAIConvertPredictionsProvider,
|
|
6
|
+
AmazonAIIdentifyPredictionsProvider,
|
|
7
|
+
AmazonAIInterpretPredictionsProvider,
|
|
8
|
+
} from './providers';
|
|
3
9
|
import {
|
|
4
|
-
PredictionsOptions,
|
|
5
|
-
TranslateTextInput,
|
|
6
|
-
TranslateTextOutput,
|
|
7
|
-
TextToSpeechInput,
|
|
8
|
-
ProviderOptions,
|
|
9
|
-
TextToSpeechOutput,
|
|
10
|
-
SpeechToTextInput,
|
|
11
|
-
SpeechToTextOutput,
|
|
12
|
-
IdentifyTextInput,
|
|
13
|
-
IdentifyTextOutput,
|
|
14
|
-
IdentifyLabelsOutput,
|
|
15
|
-
IdentifyLabelsInput,
|
|
16
10
|
IdentifyEntitiesInput,
|
|
17
11
|
IdentifyEntitiesOutput,
|
|
18
|
-
|
|
12
|
+
IdentifyLabelsInput,
|
|
13
|
+
IdentifyLabelsOutput,
|
|
14
|
+
IdentifyTextInput,
|
|
15
|
+
IdentifyTextOutput,
|
|
19
16
|
InterpretTextInput,
|
|
17
|
+
InterpretTextOutput,
|
|
18
|
+
SpeechToTextInput,
|
|
19
|
+
SpeechToTextOutput,
|
|
20
|
+
TextToSpeechInput,
|
|
21
|
+
TextToSpeechOutput,
|
|
22
|
+
TranslateTextInput,
|
|
23
|
+
TranslateTextOutput,
|
|
20
24
|
} from './types';
|
|
21
|
-
import {
|
|
22
|
-
AbstractConvertPredictionsProvider,
|
|
23
|
-
AbstractIdentifyPredictionsProvider,
|
|
24
|
-
AbstractInterpretPredictionsProvider,
|
|
25
|
-
AbstractPredictionsProvider,
|
|
26
|
-
} from './types/Providers';
|
|
27
|
-
import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
28
25
|
|
|
29
26
|
const logger = new Logger('Predictions');
|
|
30
27
|
|
|
31
28
|
export class PredictionsClass {
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
private _identifyPluggables: AbstractIdentifyPredictionsProvider[];
|
|
36
|
-
private _interpretPluggables: AbstractInterpretPredictionsProvider[];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Initialize Predictions with AWS configurations
|
|
40
|
-
* @param {PredictionsOptions} options - Configuration object for Predictions
|
|
41
|
-
*/
|
|
42
|
-
constructor(options: PredictionsOptions) {
|
|
43
|
-
this._options = options;
|
|
44
|
-
this._convertPluggables = [];
|
|
45
|
-
this._identifyPluggables = [];
|
|
46
|
-
this._interpretPluggables = [];
|
|
47
|
-
}
|
|
29
|
+
private convertProvider = new AmazonAIConvertPredictionsProvider();
|
|
30
|
+
private identifyProvider = new AmazonAIIdentifyPredictionsProvider();
|
|
31
|
+
private interpretProvider = new AmazonAIInterpretPredictionsProvider();
|
|
48
32
|
|
|
49
33
|
public getModuleName() {
|
|
50
34
|
return 'Predictions';
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @param {Object} pluggable - an instance of the plugin/pluggable
|
|
56
|
-
**/
|
|
57
|
-
public addPluggable(pluggable: AbstractPredictionsProvider) {
|
|
58
|
-
if (this.getPluggable(pluggable.getProviderName())) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`Pluggable with name ${pluggable.getProviderName()} has already been added.`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
let pluggableAdded: boolean = false;
|
|
64
|
-
if (this.implementsConvertPluggable(pluggable)) {
|
|
65
|
-
this._convertPluggables.push(pluggable);
|
|
66
|
-
pluggableAdded = true;
|
|
67
|
-
}
|
|
68
|
-
if (this.implementsIdentifyPluggable(pluggable)) {
|
|
69
|
-
this._identifyPluggables.push(pluggable);
|
|
70
|
-
pluggableAdded = true;
|
|
71
|
-
}
|
|
72
|
-
if (this.implementsInterpretPluggable(pluggable)) {
|
|
73
|
-
this._interpretPluggables.push(pluggable);
|
|
74
|
-
pluggableAdded = true;
|
|
75
|
-
}
|
|
76
|
-
if (pluggableAdded) {
|
|
77
|
-
this.configurePluggable(pluggable);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Get the plugin object
|
|
83
|
-
* @param providerName - the name of the plugin
|
|
84
|
-
*/
|
|
85
|
-
public getPluggable(providerName: string): AbstractPredictionsProvider {
|
|
86
|
-
const pluggable = this.getAllProviders().find(
|
|
87
|
-
pluggable => pluggable.getProviderName() === providerName
|
|
88
|
-
);
|
|
89
|
-
if (pluggable === undefined) {
|
|
90
|
-
logger.debug('No plugin found with providerName=>', providerName);
|
|
91
|
-
return null;
|
|
92
|
-
} else return pluggable;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Remove the plugin object
|
|
97
|
-
* @param providerName - the name of the plugin
|
|
98
|
-
*/
|
|
99
|
-
public removePluggable(providerName: string) {
|
|
100
|
-
this._convertPluggables = this._convertPluggables.filter(
|
|
101
|
-
pluggable => pluggable.getProviderName() !== providerName
|
|
102
|
-
);
|
|
103
|
-
this._identifyPluggables = this._identifyPluggables.filter(
|
|
104
|
-
pluggable => pluggable.getProviderName() !== providerName
|
|
105
|
-
);
|
|
106
|
-
this._interpretPluggables = this._interpretPluggables.filter(
|
|
107
|
-
pluggable => pluggable.getProviderName() !== providerName
|
|
108
|
-
);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* To make both top level providers and category level providers work with same interface and configuration
|
|
114
|
-
* this method duplicates Predictions config into parent level config (for top level provider) and
|
|
115
|
-
* category level config (such as convert, identify etc) and pass both to each provider.
|
|
116
|
-
*/
|
|
117
|
-
configure(options: PredictionsOptions) {
|
|
118
|
-
let predictionsConfig = options ? options.predictions || options : {};
|
|
119
|
-
predictionsConfig = { ...predictionsConfig, ...options };
|
|
120
|
-
this._options = Object.assign({}, this._options, predictionsConfig);
|
|
121
|
-
logger.debug('configure Predictions', this._options);
|
|
122
|
-
this.getAllProviders().forEach(pluggable =>
|
|
123
|
-
this.configurePluggable(pluggable)
|
|
124
|
-
);
|
|
37
|
+
public interpret(input: InterpretTextInput): Promise<InterpretTextOutput> {
|
|
38
|
+
return this.interpretProvider.interpret(input);
|
|
125
39
|
}
|
|
126
40
|
|
|
127
|
-
public
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
): Promise<InterpretTextOutput>;
|
|
131
|
-
public interpret(
|
|
132
|
-
input: InterpretTextInput,
|
|
133
|
-
options?: ProviderOptions
|
|
134
|
-
): Promise<InterpretTextOutput> {
|
|
135
|
-
const pluggableToExecute = this.getPluggableToExecute(
|
|
136
|
-
this._interpretPluggables,
|
|
137
|
-
options
|
|
138
|
-
);
|
|
139
|
-
return pluggableToExecute.interpret(input);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public convert(
|
|
143
|
-
input: TranslateTextInput,
|
|
144
|
-
options?: ProviderOptions
|
|
145
|
-
): Promise<TranslateTextOutput>;
|
|
41
|
+
public convert(input: TranslateTextInput): Promise<TranslateTextOutput>;
|
|
42
|
+
public convert(input: TextToSpeechInput): Promise<TextToSpeechOutput>;
|
|
43
|
+
public convert(input: SpeechToTextInput): Promise<SpeechToTextOutput>;
|
|
146
44
|
public convert(
|
|
147
|
-
input: TextToSpeechInput
|
|
148
|
-
options?: ProviderOptions
|
|
149
|
-
): Promise<TextToSpeechOutput>;
|
|
150
|
-
public convert(
|
|
151
|
-
input: SpeechToTextInput,
|
|
152
|
-
options?: ProviderOptions
|
|
153
|
-
): Promise<SpeechToTextOutput>;
|
|
154
|
-
public convert(
|
|
155
|
-
input: TranslateTextInput | TextToSpeechInput | SpeechToTextInput,
|
|
156
|
-
options?: ProviderOptions
|
|
45
|
+
input: TranslateTextInput | TextToSpeechInput | SpeechToTextInput
|
|
157
46
|
): Promise<TranslateTextOutput | TextToSpeechOutput | SpeechToTextOutput> {
|
|
158
|
-
|
|
159
|
-
this._convertPluggables,
|
|
160
|
-
options
|
|
161
|
-
);
|
|
162
|
-
return pluggableToExecute.convert(input);
|
|
47
|
+
return this.convertProvider.convert(input);
|
|
163
48
|
}
|
|
164
49
|
|
|
50
|
+
public identify(input: IdentifyTextInput): Promise<IdentifyTextOutput>;
|
|
51
|
+
public identify(input: IdentifyLabelsInput): Promise<IdentifyLabelsOutput>;
|
|
165
52
|
public identify(
|
|
166
|
-
input:
|
|
167
|
-
options?: ProviderOptions
|
|
168
|
-
): Promise<IdentifyTextOutput>;
|
|
169
|
-
public identify(
|
|
170
|
-
input: IdentifyLabelsInput,
|
|
171
|
-
options?: ProviderOptions
|
|
172
|
-
): Promise<IdentifyLabelsOutput>;
|
|
173
|
-
public identify(
|
|
174
|
-
input: IdentifyEntitiesInput,
|
|
175
|
-
options?: ProviderOptions
|
|
53
|
+
input: IdentifyEntitiesInput
|
|
176
54
|
): Promise<IdentifyEntitiesOutput>;
|
|
177
55
|
public identify(
|
|
178
|
-
input: IdentifyTextInput | IdentifyLabelsInput | IdentifyEntitiesInput
|
|
179
|
-
options: ProviderOptions
|
|
56
|
+
input: IdentifyTextInput | IdentifyLabelsInput | IdentifyEntitiesInput
|
|
180
57
|
): Promise<
|
|
181
58
|
IdentifyTextOutput | IdentifyLabelsOutput | IdentifyEntitiesOutput
|
|
182
59
|
> {
|
|
183
|
-
|
|
184
|
-
this._identifyPluggables,
|
|
185
|
-
options
|
|
186
|
-
);
|
|
187
|
-
return pluggableToExecute.identify(input);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// tslint:disable-next-line: max-line-length
|
|
191
|
-
private getPluggableToExecute<T extends AbstractPredictionsProvider>(
|
|
192
|
-
pluggables: T[],
|
|
193
|
-
providerOptions: ProviderOptions
|
|
194
|
-
): T {
|
|
195
|
-
// Give preference to provider name first since it is more specific to this call, even if
|
|
196
|
-
// there is only one provider configured to error out if the name provided is not the one matched.
|
|
197
|
-
if (providerOptions && providerOptions.providerName) {
|
|
198
|
-
return [...pluggables].find(
|
|
199
|
-
pluggable =>
|
|
200
|
-
pluggable.getProviderName() === providerOptions.providerName
|
|
201
|
-
);
|
|
202
|
-
} else {
|
|
203
|
-
if (pluggables.length === 1) {
|
|
204
|
-
return pluggables[0];
|
|
205
|
-
} else {
|
|
206
|
-
throw new Error(
|
|
207
|
-
'More than one or no providers are configured, ' +
|
|
208
|
-
'Either specify a provider name or configure exactly one provider'
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private getAllProviders() {
|
|
215
|
-
return [
|
|
216
|
-
...this._convertPluggables,
|
|
217
|
-
...this._identifyPluggables,
|
|
218
|
-
...this._interpretPluggables,
|
|
219
|
-
];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private configurePluggable(pluggable: AbstractPredictionsProvider) {
|
|
223
|
-
const categoryConfig = Object.assign(
|
|
224
|
-
{},
|
|
225
|
-
this._options['predictions'], // Parent predictions config for the top level provider
|
|
226
|
-
this._options[pluggable.getCategory().toLowerCase()] // Actual category level config
|
|
227
|
-
);
|
|
228
|
-
pluggable.configure(categoryConfig);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private implementsConvertPluggable(
|
|
232
|
-
obj: any
|
|
233
|
-
): obj is AbstractConvertPredictionsProvider {
|
|
234
|
-
return obj && typeof obj.convert === 'function';
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private implementsIdentifyPluggable(
|
|
238
|
-
obj: any
|
|
239
|
-
): obj is AbstractIdentifyPredictionsProvider {
|
|
240
|
-
return obj && typeof obj.identify === 'function';
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private implementsInterpretPluggable(
|
|
244
|
-
obj: any
|
|
245
|
-
): obj is AbstractInterpretPredictionsProvider {
|
|
246
|
-
return obj && typeof obj.interpret === 'function';
|
|
60
|
+
return this.identifyProvider.identify(input);
|
|
247
61
|
}
|
|
248
62
|
}
|
|
249
63
|
|
|
250
|
-
export const Predictions = new PredictionsClass(
|
|
251
|
-
Amplify.register(Predictions);
|
|
64
|
+
export const Predictions = new PredictionsClass();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import {
|
|
4
|
+
AmplifyError,
|
|
5
|
+
AmplifyErrorParams,
|
|
6
|
+
} from '@aws-amplify/core/internals/utils';
|
|
7
|
+
|
|
8
|
+
export class PredictionsError extends AmplifyError {
|
|
9
|
+
constructor(params: AmplifyErrorParams) {
|
|
10
|
+
super(params);
|
|
11
|
+
|
|
12
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
13
|
+
this.constructor = PredictionsError;
|
|
14
|
+
Object.setPrototypeOf(this, PredictionsError.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
|
|
6
|
+
export enum PredictionsValidationErrorCode {
|
|
7
|
+
CelebrityDetectionNotEnabled = 'CelebrityDetectionNotEnabled',
|
|
8
|
+
InvalidInput = 'InvalidInput',
|
|
9
|
+
InvalidSource = 'InvalidSource',
|
|
10
|
+
NoCredentials = 'NoCredentials',
|
|
11
|
+
NoLanguage = 'NoLanguage',
|
|
12
|
+
NoRegion = 'NoRegion',
|
|
13
|
+
NoSource = 'NoSource',
|
|
14
|
+
NoSourceLanguage = 'NoSourceLanguage',
|
|
15
|
+
NoTargetLanguage = 'NoTargetLanguage',
|
|
16
|
+
NoVoiceId = 'NoVoiceId',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const validationErrorMap: AmplifyErrorMap<PredictionsValidationErrorCode> =
|
|
20
|
+
{
|
|
21
|
+
[PredictionsValidationErrorCode.CelebrityDetectionNotEnabled]: {
|
|
22
|
+
message: 'Celebrity Detection must be enabled.',
|
|
23
|
+
},
|
|
24
|
+
[PredictionsValidationErrorCode.InvalidInput]: {
|
|
25
|
+
message: 'Input does not conform to expected type.',
|
|
26
|
+
},
|
|
27
|
+
[PredictionsValidationErrorCode.InvalidSource]: {
|
|
28
|
+
message: 'Source type not supported.',
|
|
29
|
+
},
|
|
30
|
+
[PredictionsValidationErrorCode.NoCredentials]: {
|
|
31
|
+
message: 'Credentials should not be empty.',
|
|
32
|
+
},
|
|
33
|
+
[PredictionsValidationErrorCode.NoLanguage]: {
|
|
34
|
+
message: 'Missing language.',
|
|
35
|
+
},
|
|
36
|
+
[PredictionsValidationErrorCode.NoRegion]: {
|
|
37
|
+
message: 'Missing region.',
|
|
38
|
+
},
|
|
39
|
+
[PredictionsValidationErrorCode.NoSource]: {
|
|
40
|
+
message: 'Missing source.',
|
|
41
|
+
},
|
|
42
|
+
[PredictionsValidationErrorCode.NoSourceLanguage]: {
|
|
43
|
+
message: 'Missing source language for translation.',
|
|
44
|
+
},
|
|
45
|
+
[PredictionsValidationErrorCode.NoTargetLanguage]: {
|
|
46
|
+
message: 'Missing target language for translation.',
|
|
47
|
+
},
|
|
48
|
+
[PredictionsValidationErrorCode.NoVoiceId]: {
|
|
49
|
+
message: 'Missing voice id.',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { PredictionsError } from '../PredictionsError';
|
|
5
|
+
import {
|
|
6
|
+
PredictionsValidationErrorCode,
|
|
7
|
+
validationErrorMap,
|
|
8
|
+
} from '../types/validation';
|
|
9
|
+
|
|
10
|
+
export function assertValidationError(
|
|
11
|
+
assertion: boolean,
|
|
12
|
+
name: PredictionsValidationErrorCode
|
|
13
|
+
): asserts assertion {
|
|
14
|
+
if (!assertion) {
|
|
15
|
+
const { message, recoverySuggestion } = validationErrorMap[name];
|
|
16
|
+
throw new PredictionsError({ name, message, recoverySuggestion });
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AmazonAIConvertPredictionsProvider,
|
|
7
|
-
AmazonAIIdentifyPredictionsProvider,
|
|
8
|
-
AmazonAIPredictionsProvider,
|
|
9
|
-
AmazonAIInterpretPredictionsProvider,
|
|
10
|
-
} from './Providers';
|
|
11
|
-
|
|
12
|
-
export * from './types';
|
|
3
|
+
export { Predictions } from './Predictions';
|
|
13
4
|
|
|
14
5
|
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
IdentifyEntitiesInput,
|
|
7
|
+
IdentifyEntitiesOutput,
|
|
8
|
+
IdentifyLabelsInput,
|
|
9
|
+
IdentifyLabelsOutput,
|
|
10
|
+
IdentifyTextInput,
|
|
11
|
+
IdentifyTextOutput,
|
|
12
|
+
InterpretTextInput,
|
|
13
|
+
InterpretTextOutput,
|
|
14
|
+
SpeechToTextInput,
|
|
15
|
+
SpeechToTextOutput,
|
|
16
|
+
TextToSpeechInput,
|
|
17
|
+
TextToSpeechOutput,
|
|
18
|
+
TranslateTextInput,
|
|
19
|
+
TranslateTextOutput,
|
|
20
|
+
} from './types';
|