Skip to content

Commit

Permalink
Merge pull request #345 from chughts/neural
Browse files Browse the repository at this point in the history
Fetch models using neural listing
  • Loading branch information
chughts authored Oct 16, 2017
2 parents db81154 + 6faa580 commit 56868c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
29 changes: 23 additions & 6 deletions services/language_translator/v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
</select>
</div>

<div class="form-row credentials">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-neural" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-neural" style="width: 70%;"> Use Experimental Neural Translation</label>
</div>

<div class="form-row">
<label for="node-input-domain"><i class="fa fa-book"></i> Domains</label>
<select type="text" id="node-input-domain" style="display: inline-block; vertical-align:middle; width: 70%;">
Expand Down Expand Up @@ -121,12 +127,6 @@
<input type="text" id="node-input-trainid" placeholder="Model ID">
</div>

<div class="form-row credentials">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-neural" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-neural" style="width: 70%;"> Use Experimental Neural Translation</label>
</div>

<div class="form-row">
<label for="node-input-lgparams2"><i class="fa fa-cog"></i> Parameters Scope</label>
<input type="checkbox" id="node-input-lgparams2" style="display: inline-block; width: auto; vertical-align: top;">
Expand Down Expand Up @@ -232,6 +232,7 @@
'ja': 'Japanese',
'pt': 'Portuguese',
'ko': 'Korean',
'nl': 'Dutch',
'zh': 'Chinese'
};

Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -619,6 +632,10 @@
}
});

$('#node-input-neural').change(function () {
tor.flushModelCache();
});

}

// The dynamic nature of the selection fields in this node has caused problems.
Expand Down
25 changes: 16 additions & 9 deletions services/language_translator/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ 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 = 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
}
};

var lt = new LanguageTranslatorV2({
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';
}

lt = new LanguageTranslatorV2(serviceSettings);

lt.getModels({}, function (err, models) {
if (err) {
Expand Down

0 comments on commit 56868c1

Please sign in to comment.