New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/prediction

Package Overview
Dependencies
Maintainers
13
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/prediction

Google Prediction API Client Library for Node.js

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57
decreased by-34.48%
Maintainers
13
Weekly downloads
 
Created
Source
Google Cloud Platform logo

Google Prediction API: Node.js Client

release level CircleCI AppVeyor codecov

Node.js idiomatic client for Prediction API.

The Cloud Prediction API provides a RESTful API to build Machine Learning models.

:warning: Deprecated Module
This library is deprecated. The API will be shut down on April 30, 2018. See the Prediction API End of Life FAQ for more information.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.

    Go to the projects page

  2. Enable billing for your project.

    Enable billing

  3. Enable the Google Prediction API API.

    Enable the API

  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install --save @google-cloud/prediction

Using the client library

var google = require('googleapis');

function auth(callback) {
  google.auth.getApplicationDefault(function(err, authClient) {
    if (err) {
      return callback(err);
    }

    // The createScopedRequired method returns true when running on GAE or a
    // local developer machine. In that case, the desired scopes must be passed
    // in manually. When the code is  running in GCE or GAE Flexible, the scopes
    // are pulled from the GCE metadata server.
    // See https://cloud.google.com/compute/docs/authentication for more
    // information.
    if (authClient.createScopedRequired && authClient.createScopedRequired()) {
      // Scopes can be specified either as an array or as a single,
      // space-delimited string.
      authClient = authClient.createScoped([
        'https://www.googleapis.com/auth/prediction',
      ]);
    }
    callback(null, authClient);
  });
}

/**
 * @param {string} phrase The phrase for which to predict sentiment,
 * e.g. "good morning".
 * @param {Function} callback Callback function.
 */
function predict(phrase, callback) {
  auth(function(err, authClient) {
    if (err) {
      return callback(err);
    }
    var hostedmodels = google.prediction({
      version: 'v1.6',
      auth: authClient,
    }).hostedmodels;
    // Predict the sentiment for the provided phrase
    hostedmodels.predict(
      {
        // Project id used for this sample
        project: '414649711441',
        hostedModelName: 'sample.sentiment',
        resource: {
          input: {
            // Predict sentiment of the provided phrase
            csvInstance: phrase.split(/\s/gi),
          },
        },
      },
      function(err, prediction) {
        if (err) {
          return callback(err);
        }

        // Received prediction result
        console.log(`Sentiment for "${phrase}": ${prediction.outputLabel}`);
        callback(null, prediction);
      }
    );
  });
}

Samples

Samples are in the samples/ directory. The samples' README.md has instructions for running the samples.

SampleSource Code
Hosted Modelssource code

The Prediction API Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning.

This library is deprecated. This means that it is no longer being actively maintained and the only updates the library will receive will be for critical security issues.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

Keywords

FAQs

Package last updated on 10 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc