feat: added endpoint samples for vision api#467
Conversation
Codecov Report
@@ Coverage Diff @@
## master #467 +/- ##
=======================================
Coverage 97.61% 97.61%
=======================================
Files 3 3
Lines 84 84
=======================================
Hits 82 82
Misses 2 2Continue to review full report at Codecov.
|
|
I believe the docs test is failing because there's a link pointing to a file that doesn't exist in the main repo yet, but is included in this PR |
bcoe
left a comment
There was a problem hiding this comment.
this looks most of the way there, but the sample format is just slightly off. I shared an example of format as documented in internal docs.
| 'use strict'; | ||
|
|
||
| async function setEndpoint() { | ||
| // [START vision_set_endpoint] |
There was a problem hiding this comment.
This is a tiny bit of, the START should be above the sendEndpoint method, so that the example code includes both the start of the function and the closing }.
The sample guidelines also suggest that we have an outer function that handles command line arguments, and then an inner async function, see:
function main(arg1 = 'default_value_one', arg2 = 1234) {
// [START your_region_tag]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const arg1 = 'default_value_one';
// const arg2 = 1234;
// Imports the Google Cloud Some API library
const {SomeApiClient} = require('@google-cloud/some-api');
// Instantiates a client
const someApiClient = new SomeApiClient();
async function doSomething() {
...
}
doSomething();
// [END your_region_tag]
}
main(...process.argv.slice(2));There was a problem hiding this comment.
The intention of the sample is to only highlight that small section of the function, the rest of the function is being left so that the tests still pass as this is a modified version of the quickstart. Sorry, should have mentioned this with the PR.
Here's the Python canonical (within the tags): https://github.com/GoogleCloudPlatform/python-docs-samples/blob/750d2f6d36b1a030f7226067922c8ac3dab3a39b/vision/cloud-client/detect/set_endpoint.py
There was a problem hiding this comment.
gotcha, what's weird to me, is I think this includes the closing brace, so you end up with:
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Specifies the location of the api endpoint
const clientOptions = {apiEndpoint: 'eu-vision.googleapis.com'};
// Creates a client
const client = new vision.ImageAnnotatorClient(clientOptions);
// Performs label detection on the image file
const [result] = await client.labelDetection('./resources/wakeupcat.jpg');
const labels = result.labelAnnotations;
console.log('Labels:');
labels.forEach(label => console.log(label.description));
}where the last } is the closing brace for async function setEndpoint() { which is out of context for the algorithm; does the END just need to be brought up a couple lines?
There was a problem hiding this comment.
Ahh yes! Good catch, it should certainly be a few lines higher. Fixed :)
These samples are being added for showing how to change the endpoint of vision api calls