You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGES.md
+39-25
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,42 @@ Version 1 of the SDK client only supported Node application because the final bu
4
4
5
5
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.
6
6
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
-`.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
Copy file name to clipboardExpand all lines: README.md
+9-141
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Modzy JavaScript SDK
2
2
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.
4
4
5
5
## Visit [docs.modzy.com](https://docs.modzy.com/docs/javascript) for docs, guides, API and more.
6
6
@@ -27,7 +27,9 @@ import { ModzyClient } from "@modzy/modzy-sdk";
27
27
28
28
## Initialize
29
29
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_
31
33
32
34
```javascript
33
35
// app.modzy.com
@@ -42,22 +44,11 @@ const modzyClient = new ModzyClient({
42
44
});
43
45
```
44
46
45
-
⚠️ _Warning: Keep your API key secret. Do not include it in git repo or store it on GitHub_
46
-
47
47
---
48
48
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
58
50
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:
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:
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:
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:
If you'd rather check the status of the job yourself, you can use `getJob()`
125
-
126
-
```javascript
127
-
const { status } =awaitmodzyClient.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.
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:
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.
0 commit comments