Git Product home page Git Product logo

sdk-javascript's Introduction

Installation

Intall Modzy's JavaScript SDK with NPM

npm install @modzy/modzy-sdk

or YARN

yarn add @modzy/modzy-sdk

Usage/Examples

Initializing the SDK

Initialize your client by authenticating with an API key. You can download an API Key from your instance of Modzy.

import { ModzyClient } from "@modzy/modzy-sdk";

const modzyClient = new ModzyClient({
  apiKey: "Valid Modzy API Key", //e.g., "JbFkWZMx4Ea3epIrxSgA.a2fR36fZi3sdFPoztAXT"
  url: "Valid Modzy URL", //e.g., "https://trial.app.modzy.com"
});

Running Inferences

Raw Text Inputs

Submit an inference job to a text-based model by providing the model ID, version, and raw input text.

//Submit text to v1.0.1 of a Sentiment Analysis model, and to make the job explainable, change explain=True
const { jobIdentifier } = await modzyClient.submitJobText({
  modelId: "ed542963de",
  version: "1.0.1",
  sources: {
    firstPhoneCall: {
      "input.txt": "Mr Watson, come here. I want to see you.",
    },
  },
});

File Inputs

Pass a file from your local directory to a model by providing the model ID, version, and the filepath of your sample data:

// Submit a job to the Image-Based Geolocation model
const { jobIdentifier } = await modzyClient.submitJobFile({
  modelId: "aevbu1h3yw",
  version: "1.0.1",
  sources: {
    nyc-skyline: {
      image: "./images/nyc-skyline.jpg",
    },
  },
});

Embedded Inputs

Convert images and other large inputs to base64 embedded data and submit to a model by providing a model ID, version number, and dictionary with one or more base64 encoded inputs:

const fs = require('fs');

//Embed input as a string in base64
const imageBytes = fs.readFileSync('images/tower-bridge.jpg');
//Prepare the source dictionary
let sources = { "tower-bridge": { "image": imageBytes } };

//Submit the image to v1.0.1 of an Imaged-based Geolocation model
const { jobIdentifier } = await modzyClient.submitJobEmbedded("aevbu1h3yw", "1.0.1", "application/octet-stream", sources);

Inputs from Databases

Submit data from a SQL database to a model by providing a model ID, version, a SQL query, and database connection credentials:

//Add database connection and query information
const dbUrl = "jdbc:postgresql://db.bit.io:5432/bitdotio"
const dbUserName = DB_USER_NAME;
const dbPassword = DB_PASSWORD;
const dbDriver = "org.postgresql.Driver";
//Select as "input.txt" becase that is the required input name for this model
const dbQuery = "SELECT \"mailaddr\" as \"input.txt\" FROM \"user/demo_repo\".\"atl_parcel_attr\" LIMIT 10;";

//Submit the database query to v0.0.12 of a Named Entity Recognition model
const { jobIdentifier } = await modzyClient.submitJobJDBC("a92fc413b5", "0.0.12", dbUrl, dbUserName, dbPassword, dbDriver, dbQuery)}

Inputs from Cloud Storage

Submit data directly from your cloud storage bucket (Amazon S3 supported) by providing a model ID, version, and storage-blob-specific parameters.

AWS S3

//Define sources dictionary with bucket and key that points to the correct file in your s3 bucket
const bucketName = "s3-bucket-name";
const fileKey = "key-to-file.txt";
let sources = { "sampleText": { "input.txt": { 'bucket': bucketName, 'key': fileKey } } };

const accessKey = ACCESS_KEY_ID;
const secretAccessKey = SECRET_KEY;
const region = "us-east-1";

//Submit s3 input to v1.0.1 of a Sentiment Analysis model
const { jobIdentifier } = await modzyClient.submitJobAWSS3("ed542963de", "1.0.1", accessKey, secretAccessKey, region, sources)

Getting Results

Hold until the inference is complete:

await modzyClient.blockUntilJobComplete(jobIdentifier);

Get the output results:

const result = await modzyClient.getResult(jobIdentifier);

SDK Code Examples

  • samples provides details for specific use cases and are intended to be run using Node.js, but most can also run in the browser
  • react examples contains react components that can be used to the browser to send files to, or retrieve files from Modzy.

To run these examples, make sure to update API_KEY and MODZY_URL to valid values.

Running Tests

The Jest tests expect that there is a .env file at the root of the repo that contains a valid Modzy api key like this:

API_KEY=xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxx

Documentation

Modzy's SDK is built on top of the Modzy HTTP/REST API. For a full list of features and supported routes visit JavaScript SDK on docs.modzy.com

Support

For support, email [email protected] or join our Slack.

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

We are happy to receive contributions from all of our users. Check out our contributing file to learn more.

Contributor Covenant

sdk-javascript's People

Contributors

arod7533 avatar caradoxical avatar cbatis avatar marcelosureira avatar mstanaland avatar nathan-mellis avatar raul-casallas avatar sonejah21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sdk-javascript's Issues

Request: JavaScript function for downloading non-text inference results

Checklist

Please review first that the issue is fully related with this SDK by checking the relevant checkboxes ([x]).

  • [x ] I have a Modzy API Key active and have the entitlements to perform the desired action.
  • [x ] I review that have access to Modzy API host.
  • [x ] I think that is a error specific to the SDK.
  • [x ] I review the documentation and existing issues in order to not duplicate existing ones.
  • [x ] I am willing to follow-up on comments in a timely manner.

Info

  • Modzy SDK version: 1.0.7
  • Javascript version:
  • Operating System: macOS Catalina (10.15.7)

Description

When you use models that produce a file output, Modzy saves that file, and then returns the location in the results object. To download that file, you need to do an authenticated GET request using cURL. It would be nice if Modzy's JavaScript SDK had a method that automatically downloaded that file, or maybe let you send it to a specific location? Maybe something like...

modzyClient.downloadResult(nameOfFile, fileSaveLocation)

Just an idea.

Steps to reproduce

Paste the command(s) you ran and the output.

Expected results:

Actual results:

Traceback

Logs
Paste the logs that you consider useful for diagnostic.

Request: Add support for job submission of entire S3 folder

Checklist

Please review first that the issue is fully related with this SDK by checking the relevant checkboxes ([x]).

  • I have a Modzy API Key active and have the entitlements to perform the desired action.
  • I review that have access to Modzy API host.
  • I think that is a error specific to the SDK.
  • I review the documentation and existing issues in order to not duplicate existing ones.
  • I am willing to follow-up on comments in a timely manner.

Info

  • Modzy SDK version: 1.0.7
  • Javascript version:
  • Operating System: MacOS

Description

I'd like to use Modzy's JavaScript SDK to process an entire folder of inputs on S3 through a model all at once. Modzy's API supports this via the input type aws-s3-folder but the JavaScript SDK does not have a function that supports this input type. The .submitJobAWSS3 function only supports the aws-s3 input type, which requires you to list individual inputs, rather than a target folder. See here for information on how the Modzy API supports both the aws-s3 and aws-s3-folder input types: https://docs.modzy.com/reference/jobs#aws-s3-inputs

Steps to reproduce

Paste the command(s) you ran and the output.

Expected results:

Actual results:

Traceback

Logs
Paste the logs that you consider useful for diagnostic.

Confusing authentication documentation

Checklist

Please review first that the issue is fully related with this SDK by checking the relevant checkboxes ([x]).

  • I have a Modzy API Key active and have the entitlements to perform the desired action.
  • I review that have access to Modzy API host.
  • I think that is a error specific to the SDK.
  • I review the documentation and existing issues in order to not duplicate existing ones.
  • I am willing to follow-up on comments in a timely manner.

Info

  • Modzy SDK version: 1.0.6
  • Python version:
  • Operating System:

Description

While trying to use RunKit to follow along with the SDK documentation I found it somewhat confusing to understand where to add my Modzy API Key so that I could authenticate my client and begin using the API. I realize now that my API key needed to replace the section entitled "prefix.body" in the code sample below:
const modzyClient = new modzy.ModzyClient("http://url.to.modzy/api", "prefix.body");

These terms "prefix" and "body" don't intuitively make me think of API Keys. Instead, it might be easier to follow along if this code sample instead read as:
const modzyClient = new modzy.ModzyClient("http://url.to.modzy/api", "API Key");

Then, separately, the documentation could describe the format of the API Key being composed of a public and a private portion with example such as:
Example API Key = "5BCqGvZmjTnlP13Fr5p5.CggGi6ty9plSQhR3MGTI"

Just a few changes to the authentication section would make it much easier to get started using Modzy's JavaScript SDK.

Steps to reproduce

Paste the command(s) you ran and the output.

Expected results:

Actual results:

Traceback

Logs
Paste the logs that you consider useful for diagnostic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.