@maxim_mazurok/gapi.client.ml-v1
v0.0.20241116
Published
TypeScript typings for AI Platform Training & Prediction API v1
Downloads
4,422
Readme
TypeScript typings for AI Platform Training & Prediction API v1
An API to enable creating and using machine learning models. For detailed description please check documentation.
Installing
Install typings for AI Platform Training & Prediction API:
npm install @types/gapi.client.ml-v1 --save-dev
Usage
You need to initialize Google API client in your code:
gapi.load('client', () => {
// now we can use gapi.client
// ...
});
Then load api client wrapper:
gapi.client.load('https://ml.googleapis.com/$discovery/rest?version=v1', () => {
// now we can use:
// gapi.client.ml
});
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('ml', 'v1', () => {
// now we can use:
// gapi.client.ml
});
Don't forget to authenticate your client before sending any request to resources:
// declare client_id registered in Google Developers Console
var client_id = '',
scope = [
// See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
'https://www.googleapis.com/auth/cloud-platform',
// View your data across Google Cloud services and see the email address of your Google Account
'https://www.googleapis.com/auth/cloud-platform.read-only',
],
immediate = true;
// ...
gapi.auth.authorize(
{client_id: client_id, scope: scope, immediate: immediate},
authResult => {
if (authResult && !authResult.error) {
/* handle successful authorization */
} else {
/* handle authorization error */
}
}
);
After that you can use AI Platform Training & Prediction API resources:
/*
Performs explanation on the data in the request. {% dynamic include "/ai-platform/includes/___explain-request" %}
*/
await gapi.client.ml.projects.explain({name: 'name'});
/*
Get the service account information associated with your project. You need this information in order to grant the service account permissions for the Google Cloud Storage location where you put your model training code for training the model with Google Cloud Machine Learning.
*/
await gapi.client.ml.projects.getConfig({name: 'name'});
/*
Performs online prediction on the data in the request. {% dynamic include "/ai-platform/includes/___predict-request" %}
*/
await gapi.client.ml.projects.predict({name: 'name'});