From 469755534ad3b040f399cbc397176bf6f003c355 Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 22 Apr 2018 17:03:54 +0100 Subject: [PATCH 1/5] Correct Discovery Implementation of passages --- README.md | 5 ++++ package.json | 4 +-- services/discovery/discovery-utils.js | 31 ++++++++++++++++++++++++ services/discovery/v1-document-loader.js | 15 ++++++------ services/discovery/v1-query-builder.js | 2 +- services/discovery/v1.js | 2 +- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3f2ae4e5..641ad021 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ Node-RED Watson Nodes for IBM Cloud CLA assistant +### New in version 0.6.8 +- Move all Discovery calls to latest API version - 2017-11-07 +- Updated calls to deprecated discovery methods addJsonDocument and getCollections +- Correct implemetation of passages related options + ### New in version 0.6.7 - Enable Opt-out option for Conversation Node. - Implement time out option for response from Conversation Node. diff --git a/package.json b/package.json index e49abf0d..ae188ce4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-watson", - "version": "0.6.7", + "version": "0.6.8", "description": "A collection of Node-RED nodes for IBM Watson services", "dependencies": { "async": "^1.5.2", @@ -10,7 +10,7 @@ "temp": "^0.8.3", "qs": "6.x", "image-type": "^2.0.2", - "watson-developer-cloud": "^3.2.1", + "watson-developer-cloud": "^3.3.0", "kuromoji": "^0.1.1", "word-count": "^0.2.2", "is-docx": "^0.0.3", diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js index 29de768d..54045eeb 100644 --- a/services/discovery/discovery-utils.js +++ b/services/discovery/discovery-utils.js @@ -71,6 +71,35 @@ DiscoveryUtils.prototype = { return params; }, + buildParamsForPassages: function (me, msg, config, params) { + let passagesFound = false; + + // Allow the passages parameters to be passed in two ways + // 1. As the API is expecting + ['passages.fields', 'passages.count', 'passages.characters' + ].forEach(function(f) { + params = me.buildParamsFor(msg, config, params, f); + passagesFound = true; + }); + + // 2. As anyone misreading the documentation might do it. + if (msg.discoveryparams && msg.discoveryparams.passages) { + passagesFound = true; + ['fields', 'count', 'characters' + ].forEach(function(f) { + if (msg.discoveryparams.passages[f]) { + params['passages.' + f] = msg.discoveryparams.passages[f]; + } + }); + } + + if (passagesFound) { + params.passages = true; + } + + return params; + }, + buildParamsFromConfig: function(config, params, field) { if (config[field]) { params[field] = config[field]; @@ -101,6 +130,8 @@ DiscoveryUtils.prototype = { params = me.buildParamsFor(msg, config, params, f); }); + params = me.buildParamsForPassages(me, msg, config, params); + ['count', 'filter', 'aggregation', 'return'].forEach(function(f) { params = me.buildParamsFromConfig(config, params, f); }); diff --git a/services/discovery/v1-document-loader.js b/services/discovery/v1-document-loader.js index b58b0661..72a62bb4 100644 --- a/services/discovery/v1-document-loader.js +++ b/services/discovery/v1-document-loader.js @@ -130,7 +130,7 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-09-01', + version_date: '2017-11-07', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -141,12 +141,13 @@ module.exports = function (RED) { } discovery = new DiscoveryV1(serviceSettings); - - if ('.json' === suffix) { - method = 'addJsonDocument'; - } else { - method = 'addDocument'; - } + // addJsonDocument is deprecated + //if ('.json' === suffix) { + // method = 'addJsonDocument'; + //} else { + // method = 'addDocument'; + //} + method = 'addDocument'; discovery[method](params, function (err, response) { if (err) { diff --git a/services/discovery/v1-query-builder.js b/services/discovery/v1-query-builder.js index 38e72619..fe44210e 100644 --- a/services/discovery/v1-query-builder.js +++ b/services/discovery/v1-query-builder.js @@ -70,7 +70,7 @@ module.exports = function(RED) { } }); - discovery.getCollections({ + discovery.listCollections({ environment_id: req.query.environment_id }, function(err, response) { diff --git a/services/discovery/v1.js b/services/discovery/v1.js index e598917e..6df6a25a 100644 --- a/services/discovery/v1.js +++ b/services/discovery/v1.js @@ -251,7 +251,7 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-09-01', + version_date: '2017-11-07', headers: { 'User-Agent': pkg.name + '-' + pkg.version } From 94317c9e540c0e3d7e5a3bf8b4a02c518d26ee35 Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 22 Apr 2018 17:39:08 +0100 Subject: [PATCH 2/5] Detect the option highlight in Discovery node --- README.md | 3 ++- services/discovery/discovery-utils.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 641ad021..d2a59064 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,9 @@ Node-RED Watson Nodes for IBM Cloud ### New in version 0.6.8 - Move all Discovery calls to latest API version - 2017-11-07 -- Updated calls to deprecated discovery methods addJsonDocument and getCollections +- Updated calls to deprecated discovery methods addJsonDocument and getCollections - Correct implemetation of passages related options +- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams ### New in version 0.6.7 - Enable Opt-out option for Conversation Node. diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js index 54045eeb..ff235139 100644 --- a/services/discovery/discovery-utils.js +++ b/services/discovery/discovery-utils.js @@ -125,7 +125,8 @@ DiscoveryUtils.prototype = { ['environment_id', 'collection_id', 'configuration_id', 'collection_name', 'language_code', - 'passages', 'description', 'size', 'filename' + 'passages', 'description', 'size', 'filename', + 'highlight' ].forEach(function(f) { params = me.buildParamsFor(msg, config, params, f); }); From 6b0f2f6c72497ac0b4fa111c69649642b7e08ad2 Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 22 Apr 2018 18:37:39 +0100 Subject: [PATCH 3/5] Migrate Conversation to Assistant --- README.md | 5 ++- .../conversation/v1-workspace-manager.html | 10 +++--- services/conversation/v1-workspace-manager.js | 34 +++++++++++-------- services/conversation/v1.html | 8 ++--- services/conversation/v1.js | 13 ++++--- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d2a59064..1bf84f2b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Node-RED Watson Nodes for IBM Cloud - Move all Discovery calls to latest API version - 2017-11-07 - Updated calls to deprecated discovery methods addJsonDocument and getCollections - Correct implemetation of passages related options -- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams +- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams +- Rename Conversation Nodes to Assistant +- Use Assistant endpoint +- Move all Assistant calls to latest API version - 2018-02-16 ### New in version 0.6.7 - Enable Opt-out option for Conversation Node. diff --git a/services/conversation/v1-workspace-manager.html b/services/conversation/v1-workspace-manager.html index 33b31e71..973db218 100644 --- a/services/conversation/v1-workspace-manager.html +++ b/services/conversation/v1-workspace-manager.html @@ -45,7 +45,7 @@
- +
@@ -351,7 +351,7 @@
  • msg.params.password -
  • +
  • msg.params.workspace_id
  • @@ -592,7 +592,7 @@ 'cwm-dialog-node': {value:""}, 'cwm-export-content': {value:false}, 'cwm-default-endpoint' :{value: true}, - 'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'} + 'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/assistant/api'} }, credentials: { username: {type:'text'}, @@ -602,9 +602,9 @@ inputs: 1, outputs: 1, icon: 'conversation-v1-25x25.png', - paletteLabel: 'conversation workspace manager', + paletteLabel: 'assistant workspace manager', label: function() { - return this.name || 'conversation workspace manager'; + return this.name || 'assistant workspace manager'; }, labelStyle: function() { return this.name ? 'node_label_italic' : ''; diff --git a/services/conversation/v1-workspace-manager.js b/services/conversation/v1-workspace-manager.js index c1fe056a..148c1f3f 100644 --- a/services/conversation/v1-workspace-manager.js +++ b/services/conversation/v1-workspace-manager.js @@ -15,17 +15,22 @@ **/ module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant'; + const OLD_SERVICE_IDENTIFIER = 'conversation'; var pkg = require('../../package.json'), temp = require('temp'), fs = require('fs'), serviceutils = require('../../utilities/service-utils'), payloadutils = require('../../utilities/payload-utils'), - ConversationV1 = require('watson-developer-cloud/conversation/v1'), + AssistantV1 = require('watson-developer-cloud/assistant/v1'), service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), username = '', password = '', sUsername = '', sPassword = '', endpoint = '', sEndpoint = ''; + if (!service) { + service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER); + } + temp.track(); // Require the Cloud Foundry Module to pull credentials from bound service @@ -117,7 +122,7 @@ module.exports = function (RED) { function executeListIntents(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getIntents(params, function (err, response) { + conv.listIntents(params, function (err, response) { if (err) { reject(err); } else { @@ -193,7 +198,7 @@ module.exports = function (RED) { // response function executeListExamples(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getExamples(params, function (err, response) { + conv.listExamples(params, function (err, response) { if (err) { reject(err); } else { @@ -236,7 +241,7 @@ module.exports = function (RED) { function executeListCounterExamples(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getCounterExamples(params, function (err, response) { + conv.listCounterexamples(params, function (err, response) { if (err) { reject(err); } else { @@ -251,7 +256,7 @@ module.exports = function (RED) { function executeCreateCounterExample(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.createCounterExample(params, function (err, response) { + conv.createCounterexample(params, function (err, response) { if (err) { reject(err); } else { @@ -265,7 +270,7 @@ module.exports = function (RED) { function executeDeleteCounterExample(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.deleteCounterExample(params, function (err, response) { + conv.deleteCounterexample(params, function (err, response) { if (err) { reject(err); } else { @@ -279,7 +284,7 @@ module.exports = function (RED) { function executeListEntities(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getEntities(params, function (err, response) { + conv.listEntities(params, function (err, response) { if (err) { reject(err); } else { @@ -352,7 +357,7 @@ module.exports = function (RED) { function executeListEntityValues(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getValues(params, function (err, response) { + conv.listValues(params, function (err, response) { if (err) { reject(err); } else { @@ -422,7 +427,7 @@ module.exports = function (RED) { function executeListDialogNodes(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getDialogNodes(params, function (err, response) { + conv.listDialogNodes(params, function (err, response) { if (err) { reject(err); } else { @@ -499,7 +504,8 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-05-26', + version_date: '2018-02-16', + version: '2018-02-16', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -509,7 +515,7 @@ module.exports = function (RED) { serviceSettings.url = endpoint; } - conv = new ConversationV1(serviceSettings); + conv = new AssistantV1(serviceSettings); node.status({fill:'blue', shape:'dot', text:'executing'}); @@ -1068,12 +1074,12 @@ module.exports = function (RED) { params = {}; username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password || config.password; + password = sPassword || this.credentials.password || config.password; // All method to be overridden if (msg.params) { if (msg.params.method) { - method = msg.params.method; + method = msg.params.method; } if (msg.params.username) { username = msg.params.username; diff --git a/services/conversation/v1.html b/services/conversation/v1.html index f3079616..fbaa10c6 100644 --- a/services/conversation/v1.html +++ b/services/conversation/v1.html @@ -42,7 +42,7 @@
    - +
    @@ -159,7 +159,7 @@ context: {value: true}, 'empty-payload': {value: false}, 'default-endpoint' : {value: true}, - 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/conversation/api'}, + 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'}, timeout: {value: '', validate: RED.validators.number(true)}, 'optout-learning': {value: false} }, @@ -171,9 +171,9 @@ inputs: 1, outputs: 1, icon: 'conversation-v1-25x25.png', - paletteLabel: 'conversation', + paletteLabel: 'assistant', label: function() { - return this.name || 'conversation'; + return this.name || 'assistant'; }, labelStyle: function() { return this.name ? 'node_label_italic' : ''; diff --git a/services/conversation/v1.js b/services/conversation/v1.js index c5a97811..164139c8 100644 --- a/services/conversation/v1.js +++ b/services/conversation/v1.js @@ -15,15 +15,19 @@ **/ module.exports = function(RED) { - const SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant'; + const OLD_SERVICE_IDENTIFIER = 'conversation'; var pkg = require('../../package.json'), - ConversationV1 = require('watson-developer-cloud/conversation/v1'), + AssistantV1 = require('watson-developer-cloud/assistant/v1'), serviceutils = require('../../utilities/service-utils'), service = null, sUsername = null, sPassword = null; service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER); + if (!service) { + service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER); + } if (service) { sUsername = service.username; @@ -136,7 +140,8 @@ module.exports = function(RED) { // If msg.params contain credentials then these will Overridde // the bound or configured credentials. const serviceSettings = { - version_date: '2017-05-26', + version_date: '2018-02-16', + version: '2018-02-16', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -203,7 +208,7 @@ module.exports = function(RED) { serviceSettings.timeout = parseInt(msg.params.timeout); } - node.service = new ConversationV1(serviceSettings); + node.service = new AssistantV1(serviceSettings); return true; } From 29e78b16f245ee733fe448f6c5232d9563c705f5 Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 22 Apr 2018 18:57:08 +0100 Subject: [PATCH 4/5] Add French as option to Visual Recognition --- README.md | 2 ++ services/visual_recognition/v3.html | 1 + services/visual_recognition/v3.js | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bf84f2b..87abef31 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Node-RED Watson Nodes for IBM Cloud - Rename Conversation Nodes to Assistant - Use Assistant endpoint - Move all Assistant calls to latest API version - 2018-02-16 +- Move all Visual Recognition calls to lates API version - 2018-03-19 +- Add French as a Visual Recognition classification response language ### New in version 0.6.7 - Enable Opt-out option for Conversation Node. diff --git a/services/visual_recognition/v3.html b/services/visual_recognition/v3.html index f3072be2..ce8f70bf 100644 --- a/services/visual_recognition/v3.html +++ b/services/visual_recognition/v3.html @@ -41,6 +41,7 @@ + diff --git a/services/visual_recognition/v3.js b/services/visual_recognition/v3.js index 694bd52e..be982bfb 100644 --- a/services/visual_recognition/v3.js +++ b/services/visual_recognition/v3.js @@ -144,7 +144,7 @@ module.exports = function(RED) { var serviceSettings = { api_key: node.apikey, - version_date: VisualRecognitionV3.VERSION_DATE_2016_05_20, + version_date: '2018-03-19', headers: { 'User-Agent': pkg.name + '-' + pkg.version } From 7f2d26c8f03924bed5e91497ac52a3c2c74b8114 Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 22 Apr 2018 19:51:04 +0100 Subject: [PATCH 5/5] Combine Const declarations --- services/conversation/v1-workspace-manager.js | 5 +++-- services/conversation/v1.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/conversation/v1-workspace-manager.js b/services/conversation/v1-workspace-manager.js index 148c1f3f..5d4279dd 100644 --- a/services/conversation/v1-workspace-manager.js +++ b/services/conversation/v1-workspace-manager.js @@ -15,8 +15,9 @@ **/ module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'assistant'; - const OLD_SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant', + OLD_SERVICE_IDENTIFIER = 'conversation'; + var pkg = require('../../package.json'), temp = require('temp'), fs = require('fs'), diff --git a/services/conversation/v1.js b/services/conversation/v1.js index 164139c8..bc829884 100644 --- a/services/conversation/v1.js +++ b/services/conversation/v1.js @@ -15,8 +15,9 @@ **/ module.exports = function(RED) { - const SERVICE_IDENTIFIER = 'assistant'; - const OLD_SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant', + OLD_SERVICE_IDENTIFIER = 'conversation'; + var pkg = require('../../package.json'), AssistantV1 = require('watson-developer-cloud/assistant/v1'), serviceutils = require('../../utilities/service-utils'),