The `Javascript` SDK for `OpenPAI`
npm install @microsoft/openpai-js-sdkJavaScript SDK is designed to facilitate the developers of OpenPAI to offer user friendly experience.
Python SDK and command line tool. The whole functionality of this SDK will be ready soon.
bash
npm install --save @microsoft/openpai-js-sdk
`
Initialize the openPAIClient
`ts
import { PAIV2 } from '@microsoft/openpai-js-sdk';
const cluster: PAIV2.IPAICluster = {
username: '',
token: '',
rest_server_uri: '/rest-server'
};
const openPAIClient = new PAIV2.OpenPAIClient(cluster);
`
$3
The SDK offers a command line interface (CLI) prefixed by pai. For end users that use CLI only, we provide an easy way to install it via pip and the Python package nodeenv.
`bash
pip install nodeenv
nodeenv myenv
source myenv/bin/activate # use myenv/Scripts/activate instead on Windows
npm i -g @microsoft/openpai-js-sdk
`
This installation commands will generate a virtual environment with latest node in the directory ./myenv, and install the CLI in it. Then user could use pai command by any of below methods
- activate the virtual environment first
`bash
source myenv/bin/activate # use myenv/Scripts/activate instead on Windows
pai -h
`
- use a absolute path to pai
`bash
myenv/bin/pai -h # use myenv/Scripts/pai instead on Windows
`
- add myenv/bin to environment variable path
RESTful API
The SDK provides ease-of-use JavaScript and TypeScript wrapping of OpenPAI RESTful APIs.
Details are in rest-api.md.
Storage Operations
Multiple types of storages are supported by OpenPAI, however, the end user and developers should not be bothered by too much details of it. The SDK provides an abstract storage accessing methods to let users access the storages.
User could get the IStorageNode object for each cluster provisioned storage by
`ts
// get a storage object with its name
let storageDetail: IStorageDetail = await opanPAIClient.storage.getStorageByName(name)
let storageNode: IStorageNode = new StorageNode(storageDetail)
`
It would provide storage accessing methods (getinfo, listdir, makedir, upload, download, delete) and CLI storage operations.
Details are in storage.md.
Local Cluster Management
In some scenarios (e.g. cli or notebook extension), it is required to store the cluster information locally.
Unified error handling
The SDK will center the error handling, thus all front ends depending on it could share the same way to warn users.
Common job config processing
The interoperation of OpenPAI` components depends on the job protocol, and there have been some common operations of it, such as validation, preprocessing before submission (e.g. embedding essential user information). The SDK will provide essential common operations for all the front ends.