Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing request for a function #15

Open
O-Hahn opened this issue Jan 8, 2019 · 6 comments
Open

missing request for a function #15

O-Hahn opened this issue Jan 8, 2019 · 6 comments

Comments

@O-Hahn
Copy link

O-Hahn commented Jan 8, 2019

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
Copy link
Member

chughts commented Jan 9, 2019

@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
Copy link
Author

O-Hahn commented Jan 10, 2019

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
Copy link
Member

chughts commented Jan 10, 2019

@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
Copy link
Author

O-Hahn commented Jan 10, 2019

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
Copy link
Author

O-Hahn commented Jan 16, 2019

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
Copy link
Member

chughts commented Jan 22, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants