Skip to content

Commit 74686a8

Browse files
authored
Merge pull request #26 from modzy/mds/docs
Add docs, minor type fixes
2 parents 3a867b0 + a58d798 commit 74686a8

33 files changed

+1818
-186
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ node_modules
2626
# build
2727
dist
2828
types
29-
docs
3029

3130
# misc
3231
.DS_Store

CHANGES.md

+39-25
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@ Version 1 of the SDK client only supported Node application because the final bu
44

55
The previous documentation often incorrectly showed the results of the methods having direct returns. In reality, all methods return a promise that resolves to the data shown.
66

7-
- modzyClient initialization parameter change to single object. The `url` key is optional as it defaults to app.modzy.com
8-
- Removed `.getAllModels`. use getActiveModels() or call getModels() with no params.
9-
- Added `.getActiveModels`. Returns only the active models with more useful details
10-
- `.getModels` parameter change to single object.
11-
- `.getModel` renamed to `.getModelById`
12-
- `.getModelByName` unchanged
13-
- `.getRelatedModels` removed because not useful
14-
- `.getModelVersions` renamed `.getModelVersionsById`
15-
- `.getModelVersion` renamed to `.getModelDetails`; parameter change to single object
16-
- `.getModelVersionInputSample` parameter change to single object
17-
- `.getModelVersionOutputSample` parameter change to single object
18-
- `.getJobHistory` parameter change to single object
19-
- `.submitJobText` parameter change to single object
20-
- `.submitJobEmbedded` parameter change to single object. No longer handles any parsing of the embedded file, assumes that the sources object has the file as a proper data URL. Use the utility `pathToDataUrl(path, mimeType)` for Node and `fileToDataUrl(file)` for browser.
21-
- `.submitJobFile` parameter change to single object. For the browser, the file needs to be base64 encoded. The modzyClient includes a built-in utility `.fileToDataUrl` to convert a File blob to base64. For Node JS, you specify the relative path as a string.
22-
- `.submitJobAWSS3` renamed to `.submitJobAwsS3`; parameter change to single object
23-
- `.submitJobJDBC` parameter change to single object
24-
- `.getJob` unchanged
25-
- `.cancelJob` unchanged
26-
- `.getResult` unchanged
27-
- Added `.getOutputContents` which gets the contents of a specific job output
28-
- `.blockUntilComplete` renamed to `.blockUntilJobComplete`; takes just the jobId as a parameter; adds an optional second parameter that is a config object. Currently the only config key is `timeout` where you specify the number of milliseconds between checks for job completion.
29-
- Adds `.getProcessingEngineStatus` which returns an array of actively running processing engines and their statuses
30-
- Adds `.fileToDataUrl`, (browser only) a utility to convert a File blob to a base64 data URL
31-
- Adds `.pathToDataUrl`, (Node only) a utility to convert a file to a base64 data URL
7+
### Client initialization
8+
9+
- `ModzyClient` constructor parameter changed to single object. The `url` key is optional as it defaults to app.modzy.com
10+
11+
### Model methods
12+
13+
- Added `getActiveModels`. It always returns _all_ active models with more useful details. This api call does not support pagination.
14+
- Removed `getAllModels`. Use `getModels` with no params to get the first 500 models or `getActiveModels()`.
15+
- Removed `getRelatedModels` as the results were most often not useful
16+
- Renamed `getModel` to `getModelById`
17+
- Rename `getModelVersions` to `getModelVersionsById`
18+
- Renamed `getModelVersion` to `getModelDetails`; parameter change to single object
19+
- `getModels` parameter change to single object.
20+
- `getModelVersionInputSample` parameter change to single object
21+
- `getModelVersionOutputSample` parameter change to single object
22+
23+
### Job status and result methods
24+
25+
- Added `getOutputContents` which gets the contents of a specific job output - especially useful if the output is a binary file
26+
- Added `getProcessingEngineStatus` which returns an array of actively running processing engines and their statuses
27+
- Renamed `blockUntilComplete` to `blockUntilJobComplete`. It takes just the jobId as a parameter; adds an optional second parameter that is a config object to specify the number of milliseconds between checks for job completion.
28+
- `getJobHistory` parameter change to single object
29+
30+
### Job submission methods
31+
32+
- `submitJobText` parameter change to single object
33+
- `submitJobEmbedded` parameter change to single object. This method no longer handles any parsing of the embedded file and assumes that the sources object has the file as a proper data URL. You can use the new utilities `pathToDataUrl(path, mimeType)` for Node or `fileToDataUrl(file)` for browser to construct the `sources` object.
34+
- `submitJobFile` parameter change to single object. For the browser, the file needs to be base64 encoded. The modzyClient includes a built-in utility `fileToDataUrl` to convert a File blob to base64. For Node JS, you specify the relative path as a string.
35+
- `submitJobAWSS3` renamed to `submitJobAwsS3`; parameter change to single object
36+
- `submitJobJDBC` parameter change to single object
37+
38+
### New utilities
39+
40+
- Added `fileToDataUrl`, (browser only) a utility to convert a File blob to a base64 data URL
41+
- Added `pathToDataUrl`, (Node only) a utility to convert a file to a base64 data URL
42+
43+
### Samples
44+
45+
- Added sample React components

README.md

+9-141
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Modzy JavaScript SDK
22

3-
Modzy's Javascript SDK simplifies tasks such as querying models, submitting jobs, and returning results. It supports both NodeJS and browser JavaScript applications using the output target of your build system to know which code to use.
3+
Modzy's Javascript SDK simplifies tasks such as querying models, submitting jobs, and returning results. It supports both Node.js and browser JavaScript applications using the output target of your build system to know which code to use.
44

55
## Visit [docs.modzy.com](https://docs.modzy.com/docs/javascript) for docs, guides, API and more.
66

@@ -27,7 +27,9 @@ import { ModzyClient } from "@modzy/modzy-sdk";
2727

2828
## Initialize
2929

30-
To initialize the modzy client you need an [api key](https://docs.modzy.com/docs/getting-started#key-download-your-api-key). If using an installation of Modzy other than app.modzy.com, you'll also need the url for your instance of Modzy.
30+
To initialize `ModzyClient`, you need an [api key](https://docs.modzy.com/docs/getting-started#key-download-your-api-key). If using an installation of Modzy other than app.modzy.com, you'll also need to provide the url for your instance of Modzy. For debugging purposes, you can also turn on logging.
31+
32+
⚠️ _Warning: Keep your API key secret. Do not include it in a git repo or store it on GitHub_
3133

3234
```javascript
3335
// app.modzy.com
@@ -42,22 +44,11 @@ const modzyClient = new ModzyClient({
4244
});
4345
```
4446

45-
⚠️ _Warning: Keep your API key secret. Do not include it in git repo or store it on GitHub_
46-
4747
---
4848

49-
## Submit a job
50-
51-
The ModzyClient has several methods for creating jobs based on the input type:
52-
53-
- `submitJobText()`: For text inputs
54-
- `submitJobFile()`: For binaries
55-
- `submitJobEmbedded()`: For Base64 strings
56-
- `submitJobAwsS3()`: For inputs stored in S3
57-
- `submitJobJDBC()`: For inputs stored in databases
49+
## Basic usage
5850

59-
The return of each of these methods is a promise that resolves to an object describing the submitted job, _not the job result!_
60-
The most important item in the job object is the `jobIdentifier` - you'll use this to check the status of the job and get the job results.
51+
Submit a job providing the model, version and input text:
6152

6253
```javascript
6354
const { jobIdentifier } = await modzyClient.submitJobText({
@@ -71,147 +62,24 @@ const { jobIdentifier } = await modzyClient.submitJobText({
7162
});
7263
```
7364

74-
In the sources object above, the key `"yourInputKey"` is named by you and can be anything, but "input.txt" is the required input name set by this particular model. You can find the input name(s) by going to model details > API for the model you want to use.
75-
76-
Your can submit multiple input sets in a single job rather than submitting multiple jobs with a single input set. An example using the same model as above:
77-
78-
```javascript
79-
const { jobIdentifier } = await modzyClient.submitJobText({
80-
modelId: "ed542963de",
81-
version: "1.0.1",
82-
sources: {
83-
myFirstInput: {
84-
"input.txt": "Rain is the worst weather",
85-
},
86-
mySecondInput: {
87-
"input.txt": "Partly cloudy is the best weather",
88-
},
89-
},
90-
});
91-
```
92-
93-
Some models require 2 or more inputs to run. In that case, the sources object would look something like this:
94-
95-
```javascript
96-
{
97-
yourInputKey: {
98-
"inputA": // ...contents of inputA,
99-
"inputB": // ...contents of inputB,
100-
},
101-
};
102-
```
103-
104-
[Learn more about creating jobs.](https://docs.modzy.com/reference/create-a-job-1)
105-
106-
---
107-
108-
## Wait for the job to complete
109-
110-
Before you can get your job's result, you first have to wait for the job to finish. How long will that take? Well ... it's complicated. A job might finish in a few milliseconds, or it may take several minutes to finish running. How long depends on a numbers of factors such as model type, job queue length, how many processing engines are running, and the hardware being used.
111-
112-
The JavaScript SDK has the method `blockUntilJobComplete()` to simplify waiting:
65+
Hold until the inference is complete:
11366

11467
```javascript
11568
await modzyClient.blockUntilJobComplete(jobIdentifier);
11669
```
11770

118-
As the name implies, this will block any subsequent code from running until the job is complete. It does this by creating a loop that checks the job status every two seconds until the job status comes back as finish. You can change the interval by passing in a new timeout value in milliseconds:
119-
120-
```javascript
121-
await modzyClient.blockUntilJobComplete(jobIdentifier, { timeout: 500 });
122-
```
123-
124-
If you'd rather check the status of the job yourself, you can use `getJob()`
125-
126-
```javascript
127-
const { status } = await modzyClient.getJob(jobIdentifier);
128-
129-
// status of "SUBMITTED" or "IN_PROGRESS" means the job hasn't finished
130-
// "COMPLETED", "COMPLETED_WITH_ERROR" or "TIMEDOUT" indicates the job has finished
131-
```
132-
133-
---
134-
135-
## Get job results
136-
137-
Once the job is done, you can fetch the result using `getResult()`. This returns a large object containing information about the job as well as the results. If the model returns multiple outputs, they will all be included in this single object.
71+
Get the output results:
13872

13973
```javascript
14074
const result = await modzyClient.getResult(jobIdentifier);
14175
```
14276

14377
---
14478

145-
## Getting a specific result output
146-
147-
You can use `getOutputContents()` to fetch only the contents of a specific model output. This is especially useful if the output is a binary file. You need to know the model's output name(s), which you can get from the model details.
148-
149-
Let's use the Text to Speech model on app.modzy.com as an example:
150-
151-
```javascript
152-
// This code sample is for the browser, not Node
153-
154-
// Submit the job
155-
const { jobIdentifier } = await modzyClient.submitJobText({
156-
modelId: "uvdncymn6q",
157-
version: "0.0.3",
158-
sources: {
159-
myInput: {
160-
"input.txt": "I love the sound of robot voices!",
161-
},
162-
},
163-
});
164-
165-
// Wait for the job to finish
166-
await modzyClient.blockUntilJobComplete(jobIdentifier);
167-
168-
// Get the contents of the output named "results.wav" that the user submitted
169-
// with the key "myInput".
170-
// Note that the responseType is "blob" because this model output is a binary file.
171-
// The default responseType is "json".
172-
const speechContents = await modzyClient.getOutputContents({
173-
jobId: jobIdentifier,
174-
inputKey: "myInput",
175-
outputName: "results.wav", // The output name must match the model's api!
176-
responseType: "blob",
177-
});
178-
179-
// create a link to download the file from the browser
180-
const url = window.URL.createObjectURL(
181-
new Blob([speechContents], { type: "audio/wav" })
182-
);
183-
const link = document.createElement("a");
184-
link.href = url;
185-
link.setAttribute("download", "results.wav");
186-
document.body.appendChild(link);
187-
link.click();
188-
link.remove();
189-
```
190-
191-
If you're writing a Node app, set the `responseType` to `"arraybuffer"`.
192-
193-
```javascript
194-
// Node JS
195-
196-
// Get the contents of the output named "results.wav" that the user submitted
197-
// with the key `myInput`.
198-
const speechContents = await modzyClient.getOutputContents({
199-
jobId: speechJob.jobIdentifier,
200-
inputKey: "myInput",
201-
outputName: "results.wav",
202-
responseType: "arraybuffer",
203-
});
204-
205-
// write the file to disk
206-
fs.writeFileSync("./results.wav", speechContents);
207-
```
208-
209-
---
210-
21179
## Samples
21280

21381
Check out our [samples](https://github.com/modzy/sdk-javascript/tree/main/samples) for details on specific use cases.
214-
Samples are intended to be run using Node, but most can also run in the browser. The `react examples` directory contains a couple of react components to show how you can use the browser to send files to, or retrieve files from Modzy. To run the samples using app.modzy.com, make sure to update the line `const API_KEY = process.env.MODZY_API_KEY;` to contain a real api key from your account.
82+
Samples are intended to be run using Node.js, but most can also run in the browser. The `react examples` directory contains a couple of react components to show how you can use the browser to send files to, or retrieve files from Modzy. To run the samples using app.modzy.com, make sure to update the line `const API_KEY = process.env.MODZY_API_KEY;` to contain a real api key from your account.
21583

21684
---
21785

0 commit comments

Comments
 (0)