@@ -11,7 +11,7 @@ logger.level = "info";
11
11
// The MODZY_BASE_URL should point to the API services route which may be different from the Modzy page URL.
12
12
// (ie: https://modzy.example.com/api).
13
13
const BASE_URL = process . env . MODZY_BASE_URL ;
14
- // The MODZY_API_KEY is your own personal API key. It is composed by a public part, a dot character and a private part
14
+ // The MODZY_API_KEY is your own personal API key. It is composed by a public part, a dot character, and a private part
15
15
// (ie: AzQBJ3h4B1z60xNmhAJF.uQyQh8putLIRDi1nOldh).
16
16
const API_KEY = process . env . MODZY_API_KEY ;
17
17
@@ -26,7 +26,7 @@ async function createJobWithEmbeddedInput(){
26
26
try {
27
27
// Get the model object:
28
28
// If you already know the model identifier (i.e.: you got from the URL of the model details page or the input sample),
29
- // you can skip this step. If you don't you can find the model identifier by using its name as follows:
29
+ // you can skip this step. If you don't, you can find the model identifier by using its name as follows:
30
30
let model = await modzyClient . getModelByName ( "Multi-Language OCR" ) ;
31
31
// Or if you already know the model id and want to know more about the model, you can use this instead:
32
32
//let model = await modzyClient.getModel("c60c8dbd79");
@@ -37,7 +37,7 @@ async function createJobWithEmbeddedInput(){
37
37
logger . info ( `The model identifier is ${ model . modelId } and the latest version is ${ model . latestVersion } ` ) ;
38
38
// Get the model version object:
39
39
// If you already know the model version and the input key(s) of the model version you can skip this step. Also, you can
40
- // use the following code block to know about the inputs keys and skip the call on future job submissions.
40
+ // use the following code block to know about the input keys and skip the call on future job submissions.
41
41
let modelVersion = await modzyClient . getModelVersion ( model . modelId , model . latestVersion ) ;
42
42
// The info stored in modelVersion provides insights about the amount of time that the model can spend processing, the inputs, and
43
43
// output keys of the model.
@@ -56,7 +56,7 @@ async function createJobWithEmbeddedInput(){
56
56
57
57
// Send the job:
58
58
// An embedded input is a byte array encoded as a string in Base64, that's very handy for small to middle size files, for
59
- // bigger files can be a memory issue because you need to load the file in memory (load + encode), use submitJobFiles instead .
59
+ // bigger files can cause memory issues because you need to load the file in the memory (load + encode).
60
60
const imageBytes = fs . readFileSync ( 'samples/image.png' ) ;
61
61
let configBytes = fs . readFileSync ( 'samples/config.json' ) ;
62
62
// With the info about the model (identifier), the model version (version string, input/output keys), you are ready to
@@ -65,10 +65,10 @@ async function createJobWithEmbeddedInput(){
65
65
// An inference job groups input data that you send to a model. You can send any amount of inputs to
66
66
// process and you can identify and refer to a specific input by the key that you assign, for example we can add:
67
67
sources [ "second-key" ] = { "input" : imageBytes , "config.json" :configBytes }
68
- // You don' t need to load all the inputs from files, just convert to bytes as follows:
68
+ // You don’ t need to load all the inputs from the files, just convert to bytes as follows:
69
69
configBytes = Buffer . from ( JSON . stringify ( { "languages" :[ "spa" ] } ) ) ;
70
70
sources [ "another-key" ] = { "input" : imageBytes , "config.json" :configBytes }
71
- // If you send a wrong input key, the model fails to process the input.
71
+ // If you send an incorrect input key, the model fails to process the input.
72
72
sources [ "wrong-key" ] = { "a.wrong.key" : imageBytes , "config.json" :configBytes }
73
73
// If you send a correct input key, but some wrong values, the model fails to process the input.
74
74
sources [ "wrong-value" ] = { "input" : configBytes , "config.json" :imageBytes }
@@ -78,20 +78,20 @@ async function createJobWithEmbeddedInput(){
78
78
// of the process, the most important being the job identifier and the job status.
79
79
logger . info ( "job: " + job . jobIdentifier + " " + job . status ) ;
80
80
// The job moves to SUBMITTED, meaning that Modzy acknowledged the job and sent it to the queue to be processed.
81
- // We provide a helper method to listen until the job finishes processing. it will listen until the job finishes
81
+ // We provide a helper method to listen until the job finishes processing. It will listen until the job finishes
82
82
// and moves to COMPLETED, CANCELED, or TIMEOUT.
83
83
job = await modzyClient . blockUntilComplete ( job ) ;
84
84
// Get the results:
85
85
// Check the status of the job. Jobs may be canceled or may reach a timeout.
86
86
if ( job . status === "COMPLETED" ) {
87
87
// A completed job means that all the inputs were processed by the model. Check the results for each
88
- // input keys provided in the source object to see the model output.
88
+ // input key provided in the source object to see the model output.
89
89
let result = await modzyClient . getResult ( job . jobIdentifier ) ;
90
90
// The result object has some useful info:
91
91
logger . info ( `Result: finished: ${ result . finished } , total: ${ result . total } , completed: ${ result . completed } , failed: ${ result . failed } ` ) ;
92
92
// Notice that we are iterating through the same input sources keys
93
93
for ( key in sources ) {
94
- // The result object has the individual results of each job input. In this case the output key is called
94
+ // The result object has the individual results of each job input. In this case, the output key is called
95
95
// results.json, so we can get the results as follows:
96
96
if ( result . results [ key ] ) {
97
97
let model_res = result . results [ key ] [ "results.json" ] ;
0 commit comments