JavaScript
Modzy's JavaScript SDK provides a convenient wrapper around many of Modzy's most popular API routes. SDK functions include querying models, submitting inference jobs, and returning results directly to your IDE or browser.
Installation
Use yarn to package and install the SDK in an existing project:
$ yarn add @modzy/modzy-sdk
Or you can use npm:
$ npm install @modzy/modzy-sdk
Usage
Get Your API key
Once you have a model and version identified, get authenticated with your API key.
API keys are security credentials required to perform API requests to Modzy. Our API keys are composed of an ID that is split by a dot into two parts: a public and private part.
The public part is the API keys' visible part only used to identify the key and by itself, it’s unable to perform API requests.
The private part is the public part's complement and it’s required to perform API requests. Since it’s not stored on Modzy’s servers, it cannot be recovered. Make sure to save it securely. If lost, you can replace the API key.
Find your API key in your user profile. To get your full API key click on "Get key".
Initialize
Once you have a model
and version
identified, get authenticated with your API key.
const modzy = require('@modzy/modzy-sdk');
const modzyClient = new modzy.ModzyClient('https://trial.app.modzy.com/api', 'API Key');
Basic usage
Submit a job providing the model, version, and input text:
let job = await modzyClient.submitJobText(
"ed542963de",
"0.0.27",
{
'input-1':{'input.txt':'Modzy is great'},
'input-2':{'input.txt':'Modzy is great'},
}
);
Hold until the inference is complete and results become available
job = await modzyClient.blockUntilComplete(job);
Get the output results:
let results = await modzyClient.getResult(job.jobIdentifier);
Fetch errors
Errors may arise for different reasons. Fetch errors to know what is their cause and how to fix them.
Error | Description |
---|---|
ApiError | Wrapper for different errors, check code, message, url attributes. |
Functions & Methods
Currently the Javascript SDK support the following API Routes
Function or Method | Description |
---|---|
modzyClient.getAllModels | Retrieve all the models |
modzyClient.getModels | Retrieve some models |
modzyClient.getModel | Retrieve model details by identifier |
modzyClient.getModelByName | Retrieve model details by name |
modzyClient.getRelatedModels | Retrieve the list of related models |
modzyClient.getModelVersions | Retrieve the versions of a model by identifier |
modzyClient.getModelVersion | Retrieve the version details |
modzyClient.getModelVersionInputSample | Retrieve the raw JSON input sample of a model and version |
modzyClient.getModelVersionOutputSample | Retrieve the output sample of a model and version |
modzyClient.getJobHistory | Get the job history |
modzyClient.submitJobText | Submit a job using text as inputs |
modzyClient.submitJobFile | Submit a job using files as inputs |
modzyClient.submitJobEmbedded | Submit a job using bytes or byte arrays as inputs |
modzyClient.submitJobAWSS3 | Submit a job using aws s3 files as inputs |
modzyClient.submitJobJDBC | Submits a job using a SQL query with JDBC access params |
modzyClient.getJob | Retrieve the job information from Modzy |
modzyClient.cancelJob | Send a request to cancel the job processing |
modzyClient.getResult | Retrieve the results of a job |
Updated over 1 year ago