npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dato-predictive-service-client

v1.0.0

Published

Dato Predictive Service Client makes it easy to make REST API calls to Dato Predictive Service.

Downloads

7

Readme

Dato-Predictive-Service-Client-Node

The purpose of the Dato Predictive Service Node.js Client is to allow Node.js applications to easily query Dato Predictive Services.

Installation

To install Dato Predictive Service Node.js Client, simply install with:

npm install dato-predictive-service-client

Requirements

  • Dato Predictive Service, launched by GraphLab-Create >= 1.4 installation

Usage

Construct Client

To use the Dato Predictive Service Node.js Client, first you need to obtain the following information from a running Dato Predictive Service:

  • Predictive Service CNAME or DNS name (endpoint)
  • API key from the Predictive Service

Once you have obtained the above information, simply construct the PredictiveServiceClient:

var PredictiveServiceClient = require('dato-predictive-service-client');

// create client
var client = new PredictiveServiceClient("<endpoint>", "<api_key>");

// create client, SSL certificate verfication is disabled
var client = new PredictiveServiceClient("<endpoint>", "<api_key>", false);

// create client, SSL certificate verification is enabled
var client = new PredictiveServiceClient("<endpoint>", "<api_key>", true);

To enable SSL certificate verification for this Predictive Service, set <should_verify_certificate> to true. However, if your Predictive Service is launched with a self-signed certificate or without certificate, please set <should_verify_certificate> to false.

The PredictiveServiceClient can also be constructed from by a Predictive Service client configuration file.

var client = new PredictiveServiceClient("path to config file");

Query

To query a model that is deployed on the Predictive Service, you will need:

  • model name
  • method to query (recommend, predict, query, etc.)
  • data used to query against the model
  • your callback function

For example, the code below demonstrates how to query a recommender model, named rec, for recommendations for user Jacob Smith:

// construct data
var data = {'users': ['Jacob Smith'] };

// construct query
var request_data = {"method": "recommend", "data": data};

// query
client.query('rec', request_data, function(err, resp) {
  console.log(resp.statusCode); // status code of the response
  console.log(resp.data); // response data
});

Notes

  • Different models could support different query methods (recommend, predict, query, etc.) and different syntax and format for data. You will need to know the supported methods and query data format before querying the model.

Set timeout

To change the request timeout when querying the Predictive Service, use the following:

client.setTimeout(500); // 500ms

The default timeout is 10 seconds.

Results

If query is successful, the response data contains the following:

  • model response
  • uuid for this query
  • version of the model
client.query('rec', request_data, function(err, resp) {
  console.log(resp.statusCode); // status code of the response
  console.log(resp.data); // response data

  // parse respose data
  var model_response = resp.data.response;
  var uuid = resp.data.uuid;
  var version = resp.data.version;
});

model_response contains the actual model output from your query.

Send feedback

Once you get the query result, you can submit feedback data corresponding to this query back to the Predictive Service. This feedback data can be used for evaluating your current model and training future models.

To submit feedback data corresponding to a particular query, you will need the UUID of the query. The UUID can be easily obtained from the query response data.

client.query('rec', request_data, function(err, resp) {
  // parse query respose data
  var model_response = resp.data.response;
  var uuid = resp.data.uuid; //uuid
});

For the feedback data, you can use any attributes or value pairs that you like.

Example:

feedback_data = { "searched_terms" : "acoommodations",
                  "num_of_clicks"  : 3 };

Now we can send this feedback data to the Predictive Service to associate this feedback with this particular query.

client.feedback(uuid, feedback_data, function(err, resp) {
  console.log(resp);
});

More Info

For more information about the Dato Predictive Service, please read the API docs and userguide.

License

The Dato Predictive Service Node.js Client is provided under the 3-clause BSD license.