@@ -40,6 +40,7 @@ const fs = require('fs');
40
40
const util = require (' util' );
41
41
const TrainingApi = require (" @azure/cognitiveservices-customvision-training" );
42
42
const PredictionApi = require (" @azure/cognitiveservices-customvision-prediction" );
43
+ const msRest = require (" @azure/ms-rest-js" );
43
44
44
45
const setTimeoutPromise = util .promisify (setTimeout);
45
46
@@ -52,7 +53,8 @@ const endPoint = "https://<my-resource-name>.cognitiveservices.azure.com/"
52
53
53
54
const publishIterationName = " detectModel" ;
54
55
55
- const trainer = new TrainingApi.TrainingAPIClient (trainingKey, endPoint);
56
+ const credentials = new msRest.ApiKeyCredentials ({ inHeader: { " Training-key" : trainingKey } });
57
+ const trainer = new TrainingApi.TrainingAPIClient (credentials, endPoint);
56
58
57
59
/* Helper function to let us use await inside a forEach loop.
58
60
* This lets us insert delays between image uploads to accommodate the rate limit.
@@ -192,7 +194,9 @@ await trainer.publishIteration(sampleProject.id, trainingIteration.id, publishIt
192
194
To send an image to the prediction endpoint and retrieve the prediction, add the following code to the end of the file:
193
195
194
196
` ` ` javascript
195
- const predictor = new PredictionApi.PredictionAPIClient (predictionKey, endPoint);
197
+ const predictor_credentials = new msRest.ApiKeyCredentials ({ inHeader: { " Prediction-key" : predictionKey } });
198
+ const predictor = new PredictionApi.PredictionAPIClient (predictor_credentials, endPoint);
199
+
196
200
const testFile = fs .readFileSync (` ${ sampleDataRoot} /Test/test_od_image.jpg` );
197
201
198
202
const results = await predictor .detectImage (sampleProject .id , publishIterationName, testFile)
0 commit comments