aimpedapi-js

1.0.1 • Public • Published

aimped

aimped is a Nodejs library used for Aimped Api integrations.

Installation

Use the package manager npm to install aimped.

npm install aimpedapi-js

Documentation

A folder named docs will be genereated. You can examine the documentation by selecting the index.html in this folder.

npm i -g jsdoc
yarn doc

Clone

Use the git to clone aimpedapijs.

git clone https://github.com/aimped-ai/aimpedapi-js.git

Configuration of the Library

// require aimped
const Aimped = require('aimpedapi-js');

// Create new class Aimped
const userKey = ''; // Userkey received from A3M.
const userSecret = ''; // userSecret received from A3M.
const BASE_URL = 'https://aimped.ai', // Aimped domain url

const Aimped = new Aimped(userKey, userSecret, {
  baseUrl: BASE_URL,
});

Preparation of the model input data

const modelId = "" ; // id of the model to run
const inputData = {...} ;// input information, can be checked from model description

Usage of API Function

const runModel = async () => {
  try {
    const result = await Aimped.runModel(modelId, inputData);
    console.log(JSON.stringify(result));
  } catch (error) {
    console.log(error);
  }
};

Usage of API Callback Function

// return callback function

const runModelCallback = async () => {
  Aimped.runModelCallback(modelId, inputData, (e) => {
    const { event, message, time, data } = e;
    switch (event) {
      case 'start':
        console.log(modelId, time, message);
        break;

      case 'proccess':
        console.log(modelId, time, message);
        break;

      case 'error':
        console.log(modelId, time, message);
        break;
      case 'end':
        console.log(modelId, time, message, JSON.stringify(data));
        break;

      default:
        break;
    }
  });
};

Usage of API File Upload

Some of the models supports file inputs. These inputs are accepted as URIs. Here is the usage of API for file uploads.

const runModelFileUpload = async () => {
  await Aimped.getAllData();
  const result = await AIMPED.fileUpload(
    modelId,
    '/Users/joe/Downloads/xyz.pdf' // sample file path to upload
  );
  console.log(await result);
};

Usage of API File Download

Some of the models supports file outputs as result. These outputs are created as URIs. Here is the usage of API for file downloads.

const runModelFileDownload = async () => {
  const result = await AIMPED.fileDownloadAndSave(
    'input/application/model_{{modelId}}/user_{{userId}}/file_name', // URI of the model input file or model run output file in the result
    `/Users/joe/Downloads/${new Date().getTime()}file_name` // sample local file path to save
  );
  console.log(await result);
};

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Package Sidebar

Install

npm i aimpedapi-js

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

16.6 kB

Total Files

9

Last publish

Collaborators

  • aimped.ai