Skip to content

Commit 6964497

Browse files
committed
migrate to ibm-watson dependancy
1 parent 163f254 commit 6964497

File tree

9 files changed

+445
-261
lines changed

9 files changed

+445
-261
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Node-RED Watson Nodes for IBM Cloud
88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

1010
### New in version 0.8.1
11-
-
11+
- Node-RED & IBM-Watson & Use of promises on API invokation & IAM URL construct migration & Removal of default endpoint of
12+
- Speech to Text node
13+
- Speech to Text Corpus Builder node
1214

1315
### New in version 0.8.0
1416
- In the 0.8.x releases the nodes are migrated to a node-red 1.0.x input

services/speech_to_text/stt-utils.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
**/
1616

1717
const pkg = require('../../package.json'),
18-
STTV1 = require('watson-developer-cloud/speech-to-text/v1');
18+
STTV1 = require('ibm-watson/speech-to-text/v1'),
19+
{ IamAuthenticator } = require('ibm-watson/auth');
1920

2021
class STTUtils {
2122
constructor() {
@@ -24,6 +25,7 @@ class STTUtils {
2425
static initSTTService(req, sApikey, sUsername, sPassword, sEndpoint) {
2526
const endpoint = req.query.e ? req.query.e : sEndpoint;
2627

28+
let authSettings = {};
2729
let serviceSettings = {
2830
url: endpoint,
2931
headers: {
@@ -32,49 +34,55 @@ class STTUtils {
3234
};
3335

3436
if (sApikey || req.query.key) {
35-
serviceSettings.iam_apikey = sApikey ? sApikey : req.query.key;
37+
authSettings.apikey = sApikey ? sApikey : req.query.key;
3638
} else {
37-
serviceSettings.username = sUsername ? sUsername : req.query.un;
38-
serviceSettings.password = sPassword ? sPassword : req.query.pwd;
39+
authSettings.username = sUsername ? sUsername : req.query.un;
40+
authSettings.password = sPassword ? sPassword : req.query.pwd;
3941
}
42+
serviceSettings.authenticator = new IamAuthenticator(authSettings);
4043

4144
return new STTV1(serviceSettings);
4245
}
4346

4447
static determineService(apikey, username, password, endpoint) {
48+
let authSettings = {};
4549
let serviceSettings = {
4650
headers: {
4751
'User-Agent': pkg.name + '-' + pkg.version
4852
}
4953
};
5054

5155
if (apikey) {
52-
serviceSettings.iam_apikey = apikey;
56+
authSettings.apikey = apikey;
5357
} else {
54-
serviceSettings.username = username;
55-
serviceSettings.password = password;
58+
authSettings.username = username;
59+
authSettings.password = password;
5660
}
5761

5862
if (endpoint) {
5963
serviceSettings.url = endpoint;
6064
}
65+
serviceSettings.authenticator = new IamAuthenticator(authSettings);
6166

6267
return new STTV1(serviceSettings);
6368
}
6469

6570
static determineServiceFromToken(accessToken, endpoint) {
71+
let authSettings = {};
6672
let serviceSettings = {
6773
headers: {
6874
'User-Agent': pkg.name + '-' + pkg.version
6975
}
7076
};
7177

72-
serviceSettings.iam_access_token = accessToken;
78+
authSettings.accessToken = accessToken;
7379

7480
if (endpoint) {
7581
serviceSettings.url = endpoint;
7682
}
7783

84+
serviceSettings.authenticator = new IamAuthenticator(authSettings);
85+
7886
return new STTV1(serviceSettings);
7987
}
8088

services/speech_to_text/v1-corpus-builder.html

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
</div>
4545

4646
<div class="form-row credentials">
47-
<label>&nbsp;</label>
48-
<input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;">
49-
<label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label>
50-
</div>
51-
<div class="form-row">
5247
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
5348
<input type="text" id="node-input-service-endpoint" placeholder="https://stream.watsonplatform.net/speech-to-text/api">
5449
</div>
@@ -59,13 +54,21 @@
5954
<option value="createCustomisation">Create a custom language model</option>
6055
<option value="listCustomisations">List Customizations</option>
6156
<option value="getCustomisation">Get Customization</option>
57+
<option value="resetCustomisation">Reset Customization</option>
58+
<option value="upgradeCustomisation">Upgrade Customization</option>
6259
<option value="deleteCustomisation">Delete Customization</option>
60+
<option disabled>______________</option>
6361
<option value="addCorpus">Add Corpus</option>
64-
<option value="getCorpora">Get Corpora</option>
65-
<option value="train">Train</option>
66-
<option value="listCustomWords">List Custom Words</option>
67-
<option value="addWords">Add Words</option>
62+
<option value="getCorpus">Get Corpus</option>
63+
<option value="getCorpora">List Corpora</option>
6864
<option value="deleteCorpus">Delete Corpus</option>
65+
<option disabled>______________</option>
66+
<option value="addWords">Add Words</option>
67+
<option value="listCustomWords">List Custom Words</option>
68+
<option value="deleteCustomWord">Delete Custom Word</option>
69+
<option disabled>______________</option>
70+
<option value="train">Train Customization</option>
71+
6972
</select>
7073
</div>
7174

@@ -98,6 +101,11 @@
98101
<input type="text" id="node-input-stt-corpus-name" placeholder="">
99102
</div>
100103

104+
<div class="form-row">
105+
<label for="node-input-stt-word-name"><i class="fa fa-book"></i> Word Name</label>
106+
<input type="text" id="node-input-stt-word-name" placeholder="">
107+
</div>
108+
101109
<div class="form-row">
102110
<label for="node-input-stt-allow-overwrite"><i class="fa fa-book"></i> Allow Overwrite</label>
103111
<input type="checkbox" id="node-input-stt-allow-overwrite" placeholder="">
@@ -128,6 +136,17 @@
128136
<code>msg.customization</code>
129137
</p>
130138
</li>
139+
<li>Reset Customization
140+
<p>In this mode, the specified customization is reset,
141+
removing all corpora, grammars, and words from the model.
142+
</p>
143+
</li>
144+
<li>Upgrade Customization
145+
<p>In this mode, an upgrade of the custom language model
146+
to the latest version of its base language model is
147+
initialised.
148+
</p>
149+
</li>
131150
<li>Delete Customization
132151
<p>In this mode, the specified customization is deleted.
133152
</p>
@@ -146,6 +165,12 @@
146165
<code>msg.corpora</code>
147166
</p>
148167
</li>
168+
<li>Get Corpus
169+
<p>In this mode, details for the selected corporus
170+
is returned on
171+
<code>msg.corpus</code>
172+
</p>
173+
</li>
149174
<li>Train
150175
<p>In this mode, the custom model is prepared for use
151176
by the speech to text service.
@@ -207,6 +232,7 @@
207232
$('input#node-input-stt-custom-model-description').parent().hide();
208233
$('input#node-input-stt-custom-id').parent().hide();
209234
$('input#node-input-stt-corpus-name').parent().hide();
235+
$('input#node-input-stt-word-name').parent().hide();
210236
$('input#node-input-stt-allow-overwrite').parent().hide();
211237
}
212238

@@ -237,6 +263,8 @@
237263
break;
238264
case 'getCustomisation':
239265
case 'deleteCustomisation':
266+
case 'upgradeCustomisation':
267+
case 'resetCustomisation':
240268
case 'getCorpora':
241269
case 'train':
242270
case 'listCustomWords':
@@ -249,9 +277,14 @@
249277
+ ', #node-input-stt-allow-overwrite');
250278
break;
251279
case 'deleteCorpus':
252-
fields.push('#node-input-stt-custom-id'
253-
+ ', #node-input-stt-corpus-name');
254-
break;
280+
case 'getCorpus':
281+
fields.push('#node-input-stt-custom-id'
282+
+ ', #node-input-stt-corpus-name');
283+
break;
284+
case 'deleteCustomWord':
285+
fields.push('#node-input-stt-custom-id'
286+
+ ', #node-input-stt-word-name');
287+
break;
255288
}
256289
sttv1qbb.showSelectedFields(fields);
257290
}
@@ -304,15 +337,6 @@
304337
$('#node-input-stt-base-model').change(function (val) {
305338
sttv1qbb.model_selected = $('#node-input-stt-base-model').val();
306339
});
307-
308-
$('#node-input-default-endpoint').change(function () {
309-
var checked = $('#node-input-default-endpoint').prop('checked')
310-
if (checked) {
311-
$('#node-input-service-endpoint').parent().hide();
312-
} else {
313-
$('#node-input-service-endpoint').parent().show();
314-
}
315-
});
316340
}
317341

318342
// Called to complete the models table
@@ -367,9 +391,8 @@
367391
var e = $('#node-input-service-endpoint').val();
368392
var creds = {un: u, pwd: p, key: k};
369393

370-
if (! $('#node-input-default-endpoint').prop('checked')) {
371-
creds.e = e;
372-
}
394+
creds.e = e;
395+
373396
$.getJSON('watson-speech-to-text-v1-query-builder/models/', creds)
374397
.done(function (data) {
375398
if (data.error) {
@@ -430,9 +453,9 @@
430453
'stt-custom-model-description' : {value: ''},
431454
'stt-custom-id' : {value: ''},
432455
'stt-corpus-name' : {value: ''},
456+
'stt-word-name' : {value: ''},
433457
'stt-allow-overwrite' : {value: false},
434-
'default-endpoint' :{value: true},
435-
'service-endpoint' :{value: 'https://stream.watsonplatform.net/speech-to-text/api'}
458+
'service-endpoint' :{value: ''}
436459
},
437460
credentials: {
438461
username: {type:'text'} //,

0 commit comments

Comments
 (0)