Skip to content

Commit fa19e70

Browse files
Merge pull request #7 from modzy/new_samples_route_support
Support for input and output samples route
2 parents dc021e6 + 7d9fa76 commit fa19e70

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/model-client.js

+59-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class ModelClient{
278278

279279
/**
280280
*
281-
* Call the Modzy API Service that return a version list related to a model identifier
281+
* Call the Modzy API Service that return a model version
282282
*
283283
* @param {string} modelId - Identifier of the model
284284
* @param {string} versionId - Identifier of the version
@@ -305,6 +305,64 @@ class ModelClient{
305305
);
306306
}
307307

308+
/**
309+
*
310+
* Call the Modzy API Service that return the model version input sample
311+
*
312+
* @param {string} modelId - Identifier of the model
313+
* @param {string} versionId - Identifier of the version
314+
* @return {String} A json string with the input sample
315+
* @throws {ApiError} Error if there is something wrong with the service or the call
316+
*/
317+
getModelVersionInputSample(modelId, versionId){
318+
const requestURL = `${this.baseURL}/${modelId}/versions/${versionId}/sample-input`;
319+
logger.debug(`getModelVersionInputSample(${modelId}, ${versionId}) GET ${requestURL}`);
320+
return axios.get(
321+
requestURL,
322+
{headers: {'Authorization':`ApiKey ${this.apiKey}`}}
323+
)
324+
.then(
325+
( response )=>{
326+
logger.info(`getModelVersionInputSample(${modelId}, ${versionId}) :: ${response.status} ${response.statusText}`);
327+
return response.data;
328+
}
329+
)
330+
.catch(
331+
( error )=>{
332+
throw( new ApiError( error ) );
333+
}
334+
);
335+
}
336+
337+
/**
338+
*
339+
* Call the Modzy API Service that return the model version output sample
340+
*
341+
* @param {string} modelId - Identifier of the model
342+
* @param {string} versionId - Identifier of the version
343+
* @return {String} A json string with the output sample
344+
* @throws {ApiError} Error if there is something wrong with the service or the call
345+
*/
346+
getModelVersionInputSample(modelId, versionId){
347+
const requestURL = `${this.baseURL}/${modelId}/versions/${versionId}/sample-output`;
348+
logger.debug(`getModelVersionOutputSample(${modelId}, ${versionId}) GET ${requestURL}`);
349+
return axios.get(
350+
requestURL,
351+
{headers: {'Authorization':`ApiKey ${this.apiKey}`}}
352+
)
353+
.then(
354+
( response )=>{
355+
logger.info(`getModelVersionOutputSample(${modelId}, ${versionId}) :: ${response.status} ${response.statusText}`);
356+
return response.data;
357+
}
358+
)
359+
.catch(
360+
( error )=>{
361+
throw( new ApiError( error ) );
362+
}
363+
);
364+
}
365+
308366
}
309367

310368
module.exports = ModelClient;

tests/model-client.test.js

+52
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,55 @@ test(
153153
);
154154
}
155155
);
156+
157+
test(
158+
'testGetModelVersion',
159+
async () => {
160+
await modelClient.getModelVersion('c60c8dbd79', '0.0.1')
161+
.then(
162+
(version) => {
163+
expect(version).toBeDefined();
164+
logger.info( `testGetModelVersion() get ${version.version} models` );
165+
}
166+
)
167+
.catch(
168+
(error)=>{
169+
logger.error("Error: "+error);
170+
}
171+
);
172+
}
173+
);
174+
175+
test(
176+
'testGetModelVersionInputSample',
177+
async () => {
178+
await modelClient.getModelVersionInputSample('c60c8dbd79', '0.0.1')
179+
.then(
180+
(inputSample) => {
181+
expect(inputSample).toBeDefined();
182+
}
183+
)
184+
.catch(
185+
(error)=>{
186+
logger.error("Error: "+error);
187+
}
188+
);
189+
}
190+
);
191+
192+
test(
193+
'testGetModelVersionOutputSample',
194+
async () => {
195+
await modelClient.getModelVersionOutputSample('c60c8dbd79', '0.0.1')
196+
.then(
197+
(outputSample) => {
198+
expect(outputSample).toBeDefined();
199+
}
200+
)
201+
.catch(
202+
(error)=>{
203+
logger.error("Error: "+error);
204+
}
205+
);
206+
}
207+
);

0 commit comments

Comments
 (0)