ibm-early-programs / node-red-contrib-watson-machine-learning

Apache License 2.0
2 stars 9 forks source link

missing request for a function #15

Open O-Hahn opened 5 years ago

O-Hahn commented 5 years ago

our watson service also support the creation of a function which is very usefull if you do the data transformation before calling the prediction. with the current implementation you can only call the model and not a function. Is it possible to create a mode to call instead of a model for prediction the function as in the API implemented ? That would be greate because in node red you dont have the necessary numpy and statistical functions (e.g. interpolation)..

chughts commented 5 years ago

@O-Hahn Please provide more details. I don't see a function call out option in the Watson Machine Learning API - http://watson-ml-api.mybluemix.net

If you have a function that performs data transformation, then you could expose that as an API and invoke it using of the node-red http request node.

O-Hahn commented 5 years ago

Hi chughts, In the documentation there is the availability of functions described in : https://dataplatform.cloud.ibm.com/docs/content/analyze-data/ml-deploy-functions.html?context=analytics

With the MNIST tutorial you can see the implementation: https://dataplatform.cloud.ibm.com/docs/content/analyze-data/ml-deployed-func-mnist-tutorial.html?context=analytics

This is nice - because the computationen of the payload (data refinery) could be done within the service.

You are right, i can do it with the HTTP nodes - but in my education on the university it would be fine if i can reduce it to the WML node...

Thx for your support !

chughts commented 5 years ago

@O-Hahn I see that the key code in invoking the functions is obtaining a client, from which you get the function endpoint.

# Instantiate WatsonMachineLearningAPIClient
from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient( wml_credentials )

...

function_deployment_endpoint_url = client.deployments.get_scoring_url( function_deployment_details )

This is however a python implementation. Is there an equivalent Node.js or native REST version to obtain the function endpoint ?

O-Hahn commented 5 years ago

Yes you are right - if i use the python client to get the url - i also can do the request within Node-Red - but in the deployment API i could not see any request to get the functions URL like the python client does. But it would also be helpful if i could provide this ulr into the config node or when the function call is selected - as an parameter ? I will also try to open an ticket for that in support as an question to the product owner ...

O-Hahn commented 5 years ago

This is the code from the support / dev Team of the service:

One of our team member provided this starter code to get endpoint, this owuld require you to provide function id, deployment id to get endpoint:-

var g_instance_id = ''; // <-- Get these values for your IBM Watson var g_password = ''; // <-- Machine Learning service credentials var g_url = ''; // var g_username = ''; // var g_model_id = ''; // (Or function ID) var g_deployment_id = '';

getAuthToken( g_username, g_password ).then( function( token ) { getScoringEndpoint( token, g_model_id, g_deployment_id ).then( function( result ) { console.log( "Deployment info:\n" + JSON.stringify( result, null, 3 ) );

} ).catch( function( error ) { console.log( "Get endpoint error:\n" + error );

} );

} ).catch( function( token_error ) { console.log( "Generate token error:\n" + token_error );

} );

function getAuthToken( username, password ) { // http://watson-ml-aisphere-api-beta.mybluemix.net/#!/Token/generateToken

return new Promise( function( resolve, reject ) { var btoa = require( 'btoa' ); var options = { url : g_url + '/v3/identity/token', headers : { 'Authorization' : 'Basic ' + btoa( username + ":" + password ) } };

var request = require('request'); request.get( options, function( error, response, body ) { if( error ) { reject( error ); } else { resolve( JSON.parse( body ).token ); }

} );

} );

}

function getScoringEndpoint( token, model_id, deployment_id ) { // https://watson-ml-api.mybluemix.net/#!/Deployments/getDeployment

return new Promise( function( resolve, reject ) { var options = { url : g_url + '/v3/wml_instances/' + g_instance_id + '/published_models/' + model_id + '/deployments/' + deployment_id, headers : { 'Authorization' : 'Bearer ' + token, 'Content-type' : 'application/json' } };

var request = require('request'); request.get( options, function( error, response, body ) { if( error ) { reject( error ); } else { resolve( JSON.parse( body ) ); }

} );

} ); }

I guess a function call of this provided GUID will also be the same..

Is it possible to enhance this functionality ?! This would be helpful because the data enrichment and data refinary cloud be done in this function (see also MIST char example - python function in notebook)...

chughts commented 5 years ago

That gets you the scoring endpoint, which the node already does. What it doesn't do is get you a data transformation function endpoint.