@smartlayers/smlayer v0.1.16
Overview
SMLAYER JS is a library built with Parcel JS that allows developers to easily make use of Smart Layers-generated pipelines and models within their applications.
Build Dist
To create build files in the dist folder, run the command below.
npx parcel build
Installing SMLAYER
To install smlayer
within your project, run:
npm install "@smartlayers/smlayer"
Using SMLAYER
For now, the following methods are available in smlayer:
submit(formData)
: This method allows you to upload a file to a pipeline for processing. To use it, you should have form-data installed within your project.Arguments:
- Arg1 (formData): FormData allows you to create readable "multipart/form-data" streams. You should construct a form using FormData(), append a field called "file" to it, then pass it.
Return value:
{ data: [ { "request_log": "string", "machine_result": { }, "result": { }, "result_reviewed": true, "status": "Pending", "_id": "stringstringstringstrin", "pipeline_id": "string", "file_object": {}, "ocr_tokens": [], "processed_file_object": {}, "thumbnail_file_object": {}, "created_at": "string", "updated_at": "string", "attributes": { } } ], status: 200, statusText: 'OK', headers: {}, config: {}, request: {} }
sumbitSync(formData)
: This allows upload, and is obligated to wait until your result is completely processed, before returning a response. It also relies onform-data
for parsing files.Arguments:
- Arg1 (formData): FormData allows you to create readable "multipart/form-data" streams. You should construct a form using FormData(), append a field called "file" to it, then pass it.
Return value:
{ "request_log": "string", "machine_result": { }, "result": { }, "result_reviewed": true, "status": "Pending", "_id": "stringstringstringstrin", "pipeline_id": "string", "file_object": {}, "ocr_tokens": [], "processed_file_object": {}, "thumbnail_file_object": {}, "created_at": "string", "updated_at": "string", "attributes": { } }
submitFromPath(filePath)
: Another method of upload that simply requires you to just pass in the path to the file in question. It can also take in a URL.Arguments:
- Arg1 (filePath): filePath is the path to the file you wish to upload on your local machine, or a url to an external file. It shiuld be a string.
Return value:
[ { "request_log": "string", "machine_result": { }, "result": { }, "result_reviewed": true, "status": "Pending", "_id": "stringstringstringstrin", "pipeline_id": "string", "file_object": {}, "ocr_tokens": [], "processed_file_object": {}, "thumbnail_file_object": {}, "created_at": "string", "updated_at": "string", "attributes": { } } ]
getAllResults()
: Get all the results in a particular pipeline.Return value:
{ "results": [ { "request_log": "string", "machine_result": { }, "result": { }, "result_reviewed": true, "status": "Pending", "_id": "stringstringstringstrin", "pipeline_id": "string", "file_object": {}, "ocr_tokens": [], "processed_file_object": {}, "thumbnail_file_object": {}, "created_at": "string", "updated_at": "string", "attributes": { } } ], "total_pending_pipeline_results": 0, "total_results": 0 }
getSingleResult(resultId)
: Get a single result from the pipeline based on its ID.Arguments:
- Arg1 (resultId): resultId is the id of the record you're trying to get. It should be a string.
Return value:
{ "request_log": "string", "machine_result": { }, "result": { }, "result_reviewed": true, "status": "Pending", "_id": "stringstringstringstrin", "pipeline_id": "string", "file_object": {}, "ocr_tokens": [], "processed_file_object": {}, "thumbnail_file_object": {}, "created_at": "string", "updated_at": "string", "attributes": { } }
Methods in play
submit(formData)
import { Pipeline } from "smlayer";
import FormData from "form-data";
import * as fs from "fs";
let pipe = new Pipeline(pipelineId, apiKey);
let formData = new FormData();
let file = fs.createReadStream(_fileLocation_);
formData.append("file", file);
let res = await pipe.submit(formData);
console.log(res.data);
NOTE :
- Files to be uploaded via FormData are to be parsed with the name, "file".
- For uploading files from external sources, you may want to use submitFromPath() or the code below, if you insist.
const response = await axios.get(_url_, {
responseType: "stream",
});
let file = response.data;
submitSync(formData)
import { Pipeline } from "smlayer";
import FormData from "form-data";
import * as fs from "fs";
let pipe = new Pipeline(pipelineId, apiKey);
let formData = new FormData();
let file = fs.createReadStream(_fileLocation_);
formData.append("file", file);
let res = await pipe.submitSync(formData);
console.log(res);
submitFromPath(filePath)
import { Pipeline } from "smlayer";
let pipe = new Pipeline(pipelineId, apiKey);
let res = await pipe.submitFromPath(_filePath_);
console.log(res);
getAllResults()
import { Pipeline } from "smlayer";
let pipe = new Pipeline(pipelineId, apiKey);
let res = await pipe.getAllResults();
console.log(res);
getSingleResult(resultId)
import { Pipeline } from "smlayer";
let pipe = new Pipeline(pipelineId, apiKey);
let res = await pipe.getSingleResult(resultId);
console.log(res);