0.1.4 • Published 3 months ago

@coherentglobal/wasm-runner v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

About the Project

Run wasm models on browser, on server, on mobile

Demo

Link: https://jeengine.s3.ap-southeast-1.amazonaws.com/wasm/index.html

Getting Started

Install

To use WasmRunner SDK, run

npm install "@coherentglobal/wasm-runner"

or

yarn add "@coherentglobal/wasm-runner"

Usage

Browser ( HTML )

First we call the SDK

<script src="https://wasm-runner-sdk.s3.ap-southeast-1.amazonaws.com/wasmrunner.min.js"></script>

Then create our javascript that initializes the model and runs it.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

// Do something with the response

React

We can call the SDK directly, then follow the normal process of initializing a model then calling the execute method for calculation.

import { WasmRunner } from "@coherentglobal/wasm-runner";

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

// Do something the response

NODE JS

We can call the SDK directly, then follow the normal process of initializing a model then calling the execute method for calculation.

const { WasmRunner } = require("@coherentglobal/wasm-runner");

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Different Scenarios to Initialize a Model

Scenario 1

Config is initialized directly on WasmRunner instance.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Scenario 2

Config is initialized via the append method.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner();
await wasmRunner.append(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Scenario 3

Config is initialized directly on WasmRunner instance and append a new model via the append method.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const param2 = {
  id: "e8ba9e7e-169c-4752-8a8e-d6eb0c78cb01",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
await wasmRunner.append(param2);

const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Development

Setup

Clone the repo, then install the dependencies

$ git clone https://github.com/CoherentCapital/wasm-runner-js.git
$ yarn install

Methods

(async) append(modelConfig)

Append and initialized new model to runner

await wasmRunner.append(param);

(async) execute(input)

Perform calculation. The runner will use request_meta.version_uuid of input argument to locate model

const response = await wasmRunner.execute(payload).catch((err) => {
  // Do something here
});

isExist(id)

Check if model existed

if (wasmRunner.isExist(id)) {
  // Do something here
}

remove(id)

Remove model from runner

wasmRunner.remove(id);

Initialize Model

There are two ways to initialize a model. First is when you instantiating a class,

const wasmRunner = new WasmRunner(param);

And the second way is by using the append method.

await wasmRunner.append(param);

Limitations

Lower Level Error

Please note that if there's lower level error that occurs, wasm runner can't handle that kind of exception.

FootNote

Sample Payload

{
  "request_data": {
    "inputs": {
      "age": 60,
      "insure": "Insure",
      "medical": "Yes",
      "plan": "Plan 1"
    }
  },
  "request_meta": {
    "service_uri": "",
    "service_uuid": "",
    "version": "",
    "version_uuid": "<model id>",
    "transaction_date": "2021-08-18T04:17:17.142Z",
    "call_purpose": "postman_request",
    "source_system": "",
    "correlation_id": "",
    "requested_output": ""
  }
}
0.1.4

3 months ago

0.0.95

10 months ago

0.0.97

10 months ago

0.0.103

8 months ago

0.0.99

10 months ago

0.0.102

8 months ago

0.0.101

9 months ago

0.0.100

9 months ago

0.0.91

11 months ago

0.0.88

12 months ago

0.0.85

1 year ago

0.0.82

1 year ago

0.0.83

1 year ago

0.0.80

1 year ago

0.0.79

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.75

1 year ago

0.0.76

1 year ago

0.0.77

1 year ago

0.0.78

1 year ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.65

1 year ago

0.0.60

1 year ago

0.0.55

2 years ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.51

2 years ago

0.0.50

2 years ago

0.0.47

2 years ago

0.0.49

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.40

2 years ago

0.0.37

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.27

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago