@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,281 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
Category,
|
|
5
|
-
Credentials,
|
|
6
|
-
PredictionsAction,
|
|
7
|
-
getAmplifyUserAgentObject,
|
|
8
|
-
} from '@aws-amplify/core';
|
|
9
|
-
import { AbstractInterpretPredictionsProvider } from '../types/Providers';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
InterpretTextInput,
|
|
13
|
-
InterpretTextOutput,
|
|
14
|
-
InterpretTextCategories,
|
|
15
|
-
TextEntities,
|
|
16
|
-
TextSentiment,
|
|
17
|
-
TextSyntax,
|
|
18
|
-
KeyPhrases,
|
|
19
|
-
} from '../types';
|
|
20
|
-
import {
|
|
21
|
-
ComprehendClient,
|
|
22
|
-
DetectSyntaxCommand,
|
|
23
|
-
DetectEntitiesCommand,
|
|
24
|
-
DetectDominantLanguageCommand,
|
|
25
|
-
DetectKeyPhrasesCommand,
|
|
26
|
-
DetectSentimentCommand,
|
|
27
|
-
} from '@aws-sdk/client-comprehend';
|
|
28
|
-
|
|
29
|
-
export class AmazonAIInterpretPredictionsProvider extends AbstractInterpretPredictionsProvider {
|
|
30
|
-
private comprehendClient: ComprehendClient;
|
|
31
|
-
|
|
32
|
-
constructor() {
|
|
33
|
-
super();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getProviderName() {
|
|
37
|
-
return 'AmazonAIInterpretPredictionsProvider';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interpretText(input: InterpretTextInput): Promise<InterpretTextOutput> {
|
|
41
|
-
return new Promise(async (res, rej) => {
|
|
42
|
-
const credentials = await Credentials.get();
|
|
43
|
-
if (!credentials) return rej('No credentials');
|
|
44
|
-
const {
|
|
45
|
-
interpretText: {
|
|
46
|
-
region = '',
|
|
47
|
-
defaults: { type: interpretTypeConfig = '' } = {},
|
|
48
|
-
} = {},
|
|
49
|
-
} = this._config;
|
|
50
|
-
const {
|
|
51
|
-
text: {
|
|
52
|
-
source: { text = '' } = {},
|
|
53
|
-
type: interpretType = interpretTypeConfig,
|
|
54
|
-
} = {},
|
|
55
|
-
} = ({} = input);
|
|
56
|
-
|
|
57
|
-
const { text: { source: { language = undefined } = {} } = {} } = ({} =
|
|
58
|
-
input as any); // language is only required for specific interpret types
|
|
59
|
-
|
|
60
|
-
this.comprehendClient = new ComprehendClient({
|
|
61
|
-
credentials,
|
|
62
|
-
region,
|
|
63
|
-
customUserAgent: getAmplifyUserAgentObject({
|
|
64
|
-
category: Category.Predictions,
|
|
65
|
-
action: PredictionsAction.Interpret,
|
|
66
|
-
}),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const doAll = interpretType === InterpretTextCategories.ALL;
|
|
70
|
-
|
|
71
|
-
let languagePromise: Promise<string>;
|
|
72
|
-
if (doAll || interpretType === InterpretTextCategories.LANGUAGE) {
|
|
73
|
-
const languageDetectionParams = {
|
|
74
|
-
Text: text,
|
|
75
|
-
};
|
|
76
|
-
languagePromise = this.detectLanguage(languageDetectionParams);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let entitiesPromise: Promise<Array<TextEntities>>;
|
|
80
|
-
if (doAll || interpretType === InterpretTextCategories.ENTITIES) {
|
|
81
|
-
const LanguageCode = language || (await languagePromise);
|
|
82
|
-
if (!LanguageCode) {
|
|
83
|
-
return rej('language code is required on source for this selection');
|
|
84
|
-
}
|
|
85
|
-
const entitiesDetectionParams = {
|
|
86
|
-
Text: text,
|
|
87
|
-
LanguageCode,
|
|
88
|
-
};
|
|
89
|
-
entitiesPromise = this.detectEntities(entitiesDetectionParams);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let sentimentPromise: Promise<TextSentiment>;
|
|
93
|
-
if (doAll || interpretType === InterpretTextCategories.SENTIMENT) {
|
|
94
|
-
const LanguageCode = language || (await languagePromise);
|
|
95
|
-
if (!LanguageCode) {
|
|
96
|
-
return rej('language code is required on source for this selection');
|
|
97
|
-
}
|
|
98
|
-
const sentimentParams = {
|
|
99
|
-
Text: text,
|
|
100
|
-
LanguageCode,
|
|
101
|
-
};
|
|
102
|
-
sentimentPromise = this.detectSentiment(sentimentParams);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let syntaxPromise: Promise<Array<TextSyntax>>;
|
|
106
|
-
if (doAll || interpretType === InterpretTextCategories.SYNTAX) {
|
|
107
|
-
const LanguageCode = language || (await languagePromise);
|
|
108
|
-
if (!LanguageCode) {
|
|
109
|
-
return rej('language code is required on source for this selection');
|
|
110
|
-
}
|
|
111
|
-
const syntaxParams = {
|
|
112
|
-
Text: text,
|
|
113
|
-
LanguageCode,
|
|
114
|
-
};
|
|
115
|
-
syntaxPromise = this.detectSyntax(syntaxParams);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let keyPhrasesPromise: Promise<Array<KeyPhrases>>;
|
|
119
|
-
if (doAll || interpretType === InterpretTextCategories.KEY_PHRASES) {
|
|
120
|
-
const LanguageCode = language || (await languagePromise);
|
|
121
|
-
if (!LanguageCode) {
|
|
122
|
-
return rej('language code is required on source for this selection');
|
|
123
|
-
}
|
|
124
|
-
const keyPhrasesParams = {
|
|
125
|
-
Text: text,
|
|
126
|
-
LanguageCode,
|
|
127
|
-
};
|
|
128
|
-
keyPhrasesPromise = this.detectKeyPhrases(keyPhrasesParams);
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const results = await Promise.all([
|
|
132
|
-
languagePromise,
|
|
133
|
-
entitiesPromise,
|
|
134
|
-
sentimentPromise,
|
|
135
|
-
syntaxPromise,
|
|
136
|
-
keyPhrasesPromise,
|
|
137
|
-
]);
|
|
138
|
-
res({
|
|
139
|
-
textInterpretation: {
|
|
140
|
-
keyPhrases: results[4] || [],
|
|
141
|
-
language: results[0] || '',
|
|
142
|
-
sentiment: results[2],
|
|
143
|
-
syntax: <TextSyntax[]>results[3] || [],
|
|
144
|
-
textEntities: <TextEntities[]>results[1] || [],
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
} catch (err) {
|
|
148
|
-
rej(err);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private async detectKeyPhrases(params): Promise<Array<KeyPhrases>> {
|
|
154
|
-
try {
|
|
155
|
-
const detectKeyPhrasesCommand = new DetectKeyPhrasesCommand(params);
|
|
156
|
-
const data = await this.comprehendClient.send(detectKeyPhrasesCommand);
|
|
157
|
-
const { KeyPhrases = [] } = data || {};
|
|
158
|
-
return KeyPhrases.map(({ Text: text }) => {
|
|
159
|
-
return { text };
|
|
160
|
-
});
|
|
161
|
-
} catch (err) {
|
|
162
|
-
if (err.code === 'AccessDeniedException') {
|
|
163
|
-
Promise.reject(
|
|
164
|
-
'Not authorized, did you enable Interpret Text on predictions category Amplify CLI? try: ' +
|
|
165
|
-
'amplify predictions add'
|
|
166
|
-
);
|
|
167
|
-
} else {
|
|
168
|
-
Promise.reject(err.message);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private async detectSyntax(params): Promise<Array<TextSyntax>> {
|
|
174
|
-
try {
|
|
175
|
-
const detectSyntaxCommand = new DetectSyntaxCommand(params);
|
|
176
|
-
const data = await this.comprehendClient.send(detectSyntaxCommand);
|
|
177
|
-
const { SyntaxTokens = [] } = data || {};
|
|
178
|
-
return this.serializeSyntaxFromComprehend(SyntaxTokens);
|
|
179
|
-
} catch (err) {
|
|
180
|
-
if (err.code === 'AccessDeniedException') {
|
|
181
|
-
Promise.reject(
|
|
182
|
-
'Not authorized, did you enable Interpret Text on predictions category Amplify CLI? try: ' +
|
|
183
|
-
'amplify predictions add'
|
|
184
|
-
);
|
|
185
|
-
} else {
|
|
186
|
-
Promise.reject(err.message);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private serializeSyntaxFromComprehend(tokens): Array<TextSyntax> {
|
|
192
|
-
let response = [];
|
|
193
|
-
if (tokens && Array.isArray(tokens)) {
|
|
194
|
-
response = tokens.map(
|
|
195
|
-
({ Text: text = '', PartOfSpeech: { Tag: syntax = '' } = {} }) => {
|
|
196
|
-
return { text, syntax };
|
|
197
|
-
}
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
return response;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private async detectSentiment(params): Promise<TextSentiment> {
|
|
204
|
-
try {
|
|
205
|
-
const detectSentimentCommand = new DetectSentimentCommand(params);
|
|
206
|
-
const data = await this.comprehendClient.send(detectSentimentCommand);
|
|
207
|
-
const {
|
|
208
|
-
Sentiment: predominant = '',
|
|
209
|
-
SentimentScore: {
|
|
210
|
-
Positive: positive = 0,
|
|
211
|
-
Negative: negative = 0,
|
|
212
|
-
Neutral: neutral = 0,
|
|
213
|
-
Mixed: mixed = 0,
|
|
214
|
-
} = {},
|
|
215
|
-
} = ({} = data);
|
|
216
|
-
return { predominant, positive, negative, neutral, mixed };
|
|
217
|
-
} catch (err) {
|
|
218
|
-
if (err.code === 'AccessDeniedException') {
|
|
219
|
-
Promise.reject(
|
|
220
|
-
'Not authorized, did you enable Interpret Text on predictions category Amplify CLI? try: ' +
|
|
221
|
-
'amplify predictions add'
|
|
222
|
-
);
|
|
223
|
-
} else {
|
|
224
|
-
Promise.reject(err.message);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
private async detectEntities(params): Promise<Array<TextEntities>> {
|
|
230
|
-
try {
|
|
231
|
-
const detectEntitiesCommand = new DetectEntitiesCommand(params);
|
|
232
|
-
const data = await this.comprehendClient.send(detectEntitiesCommand);
|
|
233
|
-
const { Entities = [] } = data || {};
|
|
234
|
-
return this.serializeEntitiesFromComprehend(Entities);
|
|
235
|
-
} catch (err) {
|
|
236
|
-
if (err.code === 'AccessDeniedException') {
|
|
237
|
-
Promise.reject(
|
|
238
|
-
'Not authorized, did you enable Interpret Text on predictions category Amplify CLI? try: ' +
|
|
239
|
-
'amplify predictions add'
|
|
240
|
-
);
|
|
241
|
-
} else {
|
|
242
|
-
Promise.reject(err.message);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private serializeEntitiesFromComprehend(data): Array<TextEntities> {
|
|
248
|
-
let response = [];
|
|
249
|
-
if (data && Array.isArray(data)) {
|
|
250
|
-
response = data.map(({ Type: type, Text: text }) => {
|
|
251
|
-
return { type, text };
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
return response;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private async detectLanguage(params): Promise<string> {
|
|
258
|
-
try {
|
|
259
|
-
const detectDominantLanguageCommand = new DetectDominantLanguageCommand(
|
|
260
|
-
params
|
|
261
|
-
);
|
|
262
|
-
const data = await this.comprehendClient.send(
|
|
263
|
-
detectDominantLanguageCommand
|
|
264
|
-
);
|
|
265
|
-
const { Languages: [{ LanguageCode }] = [{}] } = ({} = data || {});
|
|
266
|
-
if (!LanguageCode) {
|
|
267
|
-
Promise.reject('Language not detected');
|
|
268
|
-
}
|
|
269
|
-
return data.Languages[0].LanguageCode;
|
|
270
|
-
} catch (err) {
|
|
271
|
-
if (err.code === 'AccessDeniedException') {
|
|
272
|
-
Promise.reject(
|
|
273
|
-
'Not authorized, did you enable Interpret Text on predictions category Amplify CLI? try: ' +
|
|
274
|
-
'amplify predictions add'
|
|
275
|
-
);
|
|
276
|
-
} else {
|
|
277
|
-
Promise.reject(err.message);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AbstractPredictionsProvider } from '../types/Providers';
|
|
4
|
-
import { AmazonAIConvertPredictionsProvider } from './AmazonAIConvertPredictionsProvider';
|
|
5
|
-
import { AmazonAIInterpretPredictionsProvider } from './AmazonAIInterpretPredictionsProvider';
|
|
6
|
-
import { AmazonAIIdentifyPredictionsProvider } from './AmazonAIIdentifyPredictionsProvider';
|
|
7
|
-
import {
|
|
8
|
-
TranslateTextInput,
|
|
9
|
-
TextToSpeechInput,
|
|
10
|
-
SpeechToTextInput,
|
|
11
|
-
PredictionsOptions,
|
|
12
|
-
IdentifyTextInput,
|
|
13
|
-
IdentifyTextOutput,
|
|
14
|
-
IdentifyLabelsInput,
|
|
15
|
-
IdentifyLabelsOutput,
|
|
16
|
-
IdentifyEntitiesInput,
|
|
17
|
-
IdentifyEntitiesOutput,
|
|
18
|
-
TranslateTextOutput,
|
|
19
|
-
TextToSpeechOutput,
|
|
20
|
-
SpeechToTextOutput,
|
|
21
|
-
InterpretTextInput,
|
|
22
|
-
InterpretTextOutput,
|
|
23
|
-
} from '../types';
|
|
24
|
-
|
|
25
|
-
export class AmazonAIPredictionsProvider extends AbstractPredictionsProvider {
|
|
26
|
-
private convertProvider: AmazonAIConvertPredictionsProvider;
|
|
27
|
-
private identifyProvider: AmazonAIIdentifyPredictionsProvider;
|
|
28
|
-
private interpretProvider: AmazonAIInterpretPredictionsProvider;
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
super();
|
|
32
|
-
this.convertProvider = new AmazonAIConvertPredictionsProvider();
|
|
33
|
-
this.identifyProvider = new AmazonAIIdentifyPredictionsProvider();
|
|
34
|
-
this.interpretProvider = new AmazonAIInterpretPredictionsProvider();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getCategory(): string {
|
|
38
|
-
return 'Predictions';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getProviderName(): string {
|
|
42
|
-
return 'AmazonAIPredictionsProvider';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
configure(config: PredictionsOptions) {
|
|
46
|
-
this.convertProvider.configure(config.convert);
|
|
47
|
-
this.identifyProvider.configure(config.identify);
|
|
48
|
-
this.interpretProvider.configure(config.interpret);
|
|
49
|
-
return config;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interpret(input: InterpretTextInput): Promise<InterpretTextOutput> {
|
|
53
|
-
return this.interpretProvider.interpret(input);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
convert(
|
|
57
|
-
input: TranslateTextInput | TextToSpeechInput | SpeechToTextInput
|
|
58
|
-
): Promise<TextToSpeechOutput | TranslateTextOutput | SpeechToTextOutput> {
|
|
59
|
-
return this.convertProvider.convert(input);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
identify(
|
|
63
|
-
input: IdentifyTextInput | IdentifyLabelsInput | IdentifyEntitiesInput
|
|
64
|
-
): Promise<
|
|
65
|
-
IdentifyTextOutput | IdentifyLabelsOutput | IdentifyEntitiesOutput
|
|
66
|
-
> {
|
|
67
|
-
return this.identifyProvider.identify(input);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
TranslateTextInput,
|
|
5
|
-
TextToSpeechInput,
|
|
6
|
-
SpeechToTextInput,
|
|
7
|
-
isTranslateTextInput,
|
|
8
|
-
isTextToSpeechInput,
|
|
9
|
-
isSpeechToTextInput,
|
|
10
|
-
TranslateTextOutput,
|
|
11
|
-
TextToSpeechOutput,
|
|
12
|
-
SpeechToTextOutput,
|
|
13
|
-
} from '../Predictions';
|
|
14
|
-
import { AbstractPredictionsProvider } from './AbstractPredictionsProvider';
|
|
15
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
16
|
-
const logger = new Logger('AbstractConvertPredictionsProvider');
|
|
17
|
-
|
|
18
|
-
export abstract class AbstractConvertPredictionsProvider extends AbstractPredictionsProvider {
|
|
19
|
-
getCategory(): string {
|
|
20
|
-
return 'Convert';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
convert(
|
|
24
|
-
input: TranslateTextInput | TextToSpeechInput | SpeechToTextInput
|
|
25
|
-
): Promise<TextToSpeechOutput | TranslateTextOutput | SpeechToTextOutput> {
|
|
26
|
-
if (isTranslateTextInput(input)) {
|
|
27
|
-
logger.debug('translateText');
|
|
28
|
-
return this.translateText(input);
|
|
29
|
-
} else if (isTextToSpeechInput(input)) {
|
|
30
|
-
logger.debug('textToSpeech');
|
|
31
|
-
return this.convertTextToSpeech(input);
|
|
32
|
-
} else if (isSpeechToTextInput(input)) {
|
|
33
|
-
logger.debug('textToSpeech');
|
|
34
|
-
return this.convertSpeechToText(input);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected translateText(
|
|
39
|
-
translateTextInput: TranslateTextInput
|
|
40
|
-
): Promise<TranslateTextOutput> {
|
|
41
|
-
throw new Error('convertText is not implemented by this provider');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected convertTextToSpeech(
|
|
45
|
-
textToSpeechInput: TextToSpeechInput
|
|
46
|
-
): Promise<TextToSpeechOutput> {
|
|
47
|
-
throw new Error('convertTextToSpeech is not implemented by this provider');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
protected convertSpeechToText(
|
|
51
|
-
speechToTextInput: SpeechToTextInput
|
|
52
|
-
): Promise<SpeechToTextOutput> {
|
|
53
|
-
throw new Error('convertSpeechToText is not implemented by this provider');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AbstractPredictionsProvider } from './AbstractPredictionsProvider';
|
|
4
|
-
import {
|
|
5
|
-
IdentifyLabelsInput,
|
|
6
|
-
IdentifyEntitiesInput,
|
|
7
|
-
isIdentifyLabelsInput,
|
|
8
|
-
isIdentifyEntitiesInput,
|
|
9
|
-
IdentifyTextInput,
|
|
10
|
-
isIdentifyTextInput,
|
|
11
|
-
IdentifyTextOutput,
|
|
12
|
-
IdentifyLabelsOutput,
|
|
13
|
-
IdentifyEntitiesOutput,
|
|
14
|
-
} from '../Predictions';
|
|
15
|
-
import { Logger } from '@aws-amplify/core';
|
|
16
|
-
const logger = new Logger('AbstractIdentifyPredictionsProvider');
|
|
17
|
-
|
|
18
|
-
export abstract class AbstractIdentifyPredictionsProvider extends AbstractPredictionsProvider {
|
|
19
|
-
getCategory(): string {
|
|
20
|
-
return 'Identify';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
identify(
|
|
24
|
-
input: IdentifyTextInput | IdentifyLabelsInput | IdentifyEntitiesInput
|
|
25
|
-
): Promise<
|
|
26
|
-
IdentifyTextOutput | IdentifyLabelsOutput | IdentifyEntitiesOutput
|
|
27
|
-
> {
|
|
28
|
-
if (isIdentifyTextInput(input)) {
|
|
29
|
-
logger.debug('identifyText');
|
|
30
|
-
return this.identifyText(input);
|
|
31
|
-
} else if (isIdentifyLabelsInput(input)) {
|
|
32
|
-
logger.debug('identifyLabels');
|
|
33
|
-
return this.identifyLabels(input);
|
|
34
|
-
} else if (isIdentifyEntitiesInput(input)) {
|
|
35
|
-
logger.debug('identifyEntities');
|
|
36
|
-
return this.identifyEntities(input);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected identifyText(
|
|
41
|
-
input: IdentifyTextInput
|
|
42
|
-
): Promise<IdentifyTextOutput> {
|
|
43
|
-
throw new Error('identifyText is not implemented by this provider.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
protected identifyLabels(
|
|
47
|
-
input: IdentifyLabelsInput
|
|
48
|
-
): Promise<IdentifyLabelsOutput> {
|
|
49
|
-
throw new Error('identifyLabels is not implemented by this provider');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected identifyEntities(
|
|
53
|
-
input: IdentifyEntitiesInput
|
|
54
|
-
): Promise<IdentifyEntitiesOutput> {
|
|
55
|
-
throw new Error('identifyEntities is not implemented by this provider');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AbstractPredictionsProvider } from './AbstractPredictionsProvider';
|
|
4
|
-
import {
|
|
5
|
-
InterpretTextInput,
|
|
6
|
-
InterpretTextOutput,
|
|
7
|
-
isInterpretTextInput,
|
|
8
|
-
} from '../Predictions';
|
|
9
|
-
|
|
10
|
-
export abstract class AbstractInterpretPredictionsProvider extends AbstractPredictionsProvider {
|
|
11
|
-
getCategory(): string {
|
|
12
|
-
return 'Interpret';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interpret(input: InterpretTextInput): Promise<InterpretTextOutput> {
|
|
16
|
-
if (isInterpretTextInput(input)) {
|
|
17
|
-
return this.interpretText(input);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
protected interpretText(
|
|
22
|
-
input: InterpretTextInput
|
|
23
|
-
): Promise<InterpretTextOutput> {
|
|
24
|
-
throw new Error('interpretText is not implement by this provider');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { PredictionsOptions } from '..';
|
|
4
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
5
|
-
|
|
6
|
-
const logger = new Logger('Amplify');
|
|
7
|
-
|
|
8
|
-
export abstract class AbstractPredictionsProvider {
|
|
9
|
-
protected _config: PredictionsOptions;
|
|
10
|
-
|
|
11
|
-
configure(config: PredictionsOptions) {
|
|
12
|
-
logger.debug('configure AbstractPredictionsProvider', { config });
|
|
13
|
-
this._config = config;
|
|
14
|
-
return config;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
abstract getProviderName(): string;
|
|
18
|
-
|
|
19
|
-
abstract getCategory(): string;
|
|
20
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export * from './AbstractPredictionsProvider';
|
|
4
|
-
export * from './AbstractConvertPredictionsProvider';
|
|
5
|
-
export * from './AbstractIdentifyPredictionsProvider';
|
|
6
|
-
export * from './AbstractInterpretPredictionsProvider';
|