From ae0aabb7a8ec2275b86c3ce4f81449234fb4a121 Mon Sep 17 00:00:00 2001 From: chughts Date: Mon, 16 Oct 2017 20:23:49 +0100 Subject: [PATCH 1/3] Fetch models using neural listing --- services/language_translator/v2.html | 29 ++++++++++++++++++++++------ services/language_translator/v2.js | 12 +++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/services/language_translator/v2.html b/services/language_translator/v2.html index df0d141e..a4cb07c1 100644 --- a/services/language_translator/v2.html +++ b/services/language_translator/v2.html @@ -60,6 +60,12 @@ +
+ + + +
+
-
- - - -
-
@@ -232,6 +232,7 @@ 'ja': 'Japanese', 'pt': 'Portuguese', 'ko': 'Korean', + 'nl': 'Dutch', 'zh': 'Chinese' }; @@ -288,6 +289,14 @@ return self.indexOf(value) === index; } + // Flush the cache + tor.flushModelCache = function () { + tor.models = null; + tor.domains = null; + tor.basemodels = null; + tor.custommodels = null; + tor.checkModels(); + } // Retrieve the available models from the server, if data is returned, then // can enable the dynamic selection fields. @@ -297,6 +306,10 @@ var e = $('#node-input-service-endpoint').val(); var creds = {un: u, pwd: p}; + if ($('#node-input-neural').prop('checked')) { + creds.n = 'Y'; + } + if (! $('#node-input-default-endpoint').prop('checked')) { creds.e = e; } @@ -619,6 +632,10 @@ } }); + $('#node-input-neural').change(function () { + tor.flushModelCache(); + }); + } // The dynamic nature of the selection fields in this node has caused problems. diff --git a/services/language_translator/v2.js b/services/language_translator/v2.js index faa9ea03..20dec85c 100644 --- a/services/language_translator/v2.js +++ b/services/language_translator/v2.js @@ -61,8 +61,8 @@ module.exports = function (RED) { RED.httpAdmin.get('/watson-translator/models', function (req, res) { //endpoint = sEndpoint ? sEndpoint : req.query.e; endpoint = req.query.e ? req.query.e : sEndpoint; - - var lt = new LanguageTranslatorV2({ + var neural = req.query.n ? true : false, + serviceSettings = { username: sUsername ? sUsername : req.query.un, password: sPassword ? sPassword : req.query.pwd, version: 'v2', @@ -70,7 +70,13 @@ module.exports = function (RED) { headers: { 'User-Agent': pkg.name + '-' + pkg.version } - }); + } + + if (neural) { + serviceSettings.headers['X-Watson-Technology-Preview'] = '2017-07-01'; + } + + var lt = new LanguageTranslatorV2(serviceSettings); lt.getModels({}, function (err, models) { if (err) { From 0631de2463674cb9041557abb368ce5d86d77bc1 Mon Sep 17 00:00:00 2001 From: chughts Date: Mon, 16 Oct 2017 21:10:14 +0100 Subject: [PATCH 2/3] Fetch models using neural listing --- services/language_translator/v2.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/language_translator/v2.js b/services/language_translator/v2.js index 20dec85c..59fef8bc 100644 --- a/services/language_translator/v2.js +++ b/services/language_translator/v2.js @@ -61,7 +61,8 @@ module.exports = function (RED) { RED.httpAdmin.get('/watson-translator/models', function (req, res) { //endpoint = sEndpoint ? sEndpoint : req.query.e; endpoint = req.query.e ? req.query.e : sEndpoint; - var neural = req.query.n ? true : false, + var lt = null, + neural = req.query.n ? true : false, serviceSettings = { username: sUsername ? sUsername : req.query.un, password: sPassword ? sPassword : req.query.pwd, @@ -70,13 +71,13 @@ module.exports = function (RED) { headers: { 'User-Agent': pkg.name + '-' + pkg.version } - } + }; if (neural) { serviceSettings.headers['X-Watson-Technology-Preview'] = '2017-07-01'; } - var lt = new LanguageTranslatorV2(serviceSettings); + lt = new LanguageTranslatorV2(serviceSettings); lt.getModels({}, function (err, models) { if (err) { From 6faa580e0b1999b8678a1b4595783d8d867ba4d1 Mon Sep 17 00:00:00 2001 From: chughts Date: Mon, 16 Oct 2017 21:19:08 +0100 Subject: [PATCH 3/3] Fetch models using neural listing --- services/language_translator/v2.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/language_translator/v2.js b/services/language_translator/v2.js index 59fef8bc..029dba9b 100644 --- a/services/language_translator/v2.js +++ b/services/language_translator/v2.js @@ -64,14 +64,14 @@ module.exports = function (RED) { var lt = null, neural = req.query.n ? true : false, serviceSettings = { - username: sUsername ? sUsername : req.query.un, - password: sPassword ? sPassword : req.query.pwd, - version: 'v2', - url: endpoint, - headers: { - 'User-Agent': pkg.name + '-' + pkg.version - } - }; + username: sUsername ? sUsername : req.query.un, + password: sPassword ? sPassword : req.query.pwd, + version: 'v2', + url: endpoint, + headers: { + 'User-Agent': pkg.name + '-' + pkg.version + } + }; if (neural) { serviceSettings.headers['X-Watson-Technology-Preview'] = '2017-07-01';