From 05863c8229cdfee2e8d69c35054b190ee304ad24 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Mon, 13 Apr 2020 14:24:41 -0700 Subject: [PATCH] chore: fix samples according to service resource change (#35) * chore: late breaking service change * fix: changes to location * fix: removed unnecessary set endpoint Co-authored-by: Benjamin E. Coe --- document-ai/snippets/batch_parse_form.js | 4 +++- document-ai/snippets/batch_parse_table.js | 4 +++- document-ai/snippets/parse_form.js | 9 +++------ document-ai/snippets/parse_table.js | 9 +++------ document-ai/snippets/parse_with_model.js | 10 +++------- document-ai/snippets/quickstart.js | 9 +++------ document-ai/snippets/set_endpoint.js | 9 +++------ document-ai/snippets/test/batch_parse_form.test.js | 3 ++- document-ai/snippets/test/batch_parse_table.test.js | 3 ++- document-ai/snippets/test/parse_form.test.js | 3 ++- document-ai/snippets/test/parse_table.test.js | 3 ++- document-ai/snippets/test/parse_with_model.test.js | 3 ++- document-ai/snippets/test/quickstart.test.js | 3 ++- document-ai/snippets/test/set_endpoint.test.js | 3 ++- 14 files changed, 35 insertions(+), 40 deletions(-) diff --git a/document-ai/snippets/batch_parse_form.js b/document-ai/snippets/batch_parse_form.js index 242c1c9742f..4812d4a9267 100644 --- a/document-ai/snippets/batch_parse_form.js +++ b/document-ai/snippets/batch_parse_form.js @@ -19,6 +19,7 @@ const uuid = require('uuid'); async function main( projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', gcsOutputUri = 'output-bucket', gcsOutputUriPrefix = uuid.v4(), gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' @@ -28,6 +29,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsOutputUri = 'YOUR_STORAGE_BUCKET'; // const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX'; // const gcsInputUri = 'GCS URI of the PDF to process'; @@ -42,7 +44,7 @@ async function main( const storage = new Storage(); async function parseFormGCS(inputUri, outputUri, outputUriPrefix) { - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; // Configure the batch process request. const request = { diff --git a/document-ai/snippets/batch_parse_table.js b/document-ai/snippets/batch_parse_table.js index 028cc1343f9..98136962f3a 100644 --- a/document-ai/snippets/batch_parse_table.js +++ b/document-ai/snippets/batch_parse_table.js @@ -19,6 +19,7 @@ const uuid = require('uuid'); async function main( projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', gcsOutputUri = 'output-bucket', gcsOutputUriPrefix = uuid.v4(), gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' @@ -28,6 +29,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsOutputUri = 'YOUR_STORAGE_BUCKET'; // const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX'; // const gcsInputUri = 'YOUR_SOURCE_PDF'; @@ -42,7 +44,7 @@ async function main( const storage = new Storage(); async function parseTableGCS(inputUri, outputUri, outputUriPrefix) { - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; // Configure the batch process request. const request = { diff --git a/document-ai/snippets/parse_form.js b/document-ai/snippets/parse_form.js index edac82f810f..72e27d3c441 100644 --- a/document-ai/snippets/parse_form.js +++ b/document-ai/snippets/parse_form.js @@ -15,13 +15,9 @@ 'use strict'; -/** - * Process a single PDF as a form. - * @param {string} projectId your Google Cloud project ID - * @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse - */ async function main( projectId, + location, gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' ) { // [START documentai_parse_form] @@ -29,6 +25,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsInputUri = 'YOUR_SOURCE_PDF'; const { @@ -38,7 +35,7 @@ async function main( async function parseForm() { // Configure the request for processing the PDF - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; const request = { parent, inputConfig: { diff --git a/document-ai/snippets/parse_table.js b/document-ai/snippets/parse_table.js index b8059357a49..d368ca869c4 100644 --- a/document-ai/snippets/parse_table.js +++ b/document-ai/snippets/parse_table.js @@ -15,13 +15,9 @@ 'use strict'; -/** - * Process a single PDF. - * @param {string} projectId your Google Cloud project ID - * @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse - */ async function main( projectId, + location, gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' ) { // [START documentai_parse_table] @@ -29,6 +25,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsInputUri = 'YOUR_SOURCE_PDF'; const { @@ -38,7 +35,7 @@ async function main( async function parseTable() { // Configure the request for processing the PDF - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; const request = { parent, inputConfig: { diff --git a/document-ai/snippets/parse_with_model.js b/document-ai/snippets/parse_with_model.js index 08c99a52527..32857561593 100644 --- a/document-ai/snippets/parse_with_model.js +++ b/document-ai/snippets/parse_with_model.js @@ -15,14 +15,9 @@ 'use strict'; -/** - * Process a single PDF. - * @param {string} projectId your Google Cloud project ID - * @param {string} autoMLModel AutoML Natural Language model to use - * @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse - */ async function main( projectId, + location, autoMLModel, gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' ) { @@ -31,6 +26,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const autoMLModel = 'Full resource name of AutoML Natural Language model'; // const gcsInputUri = 'YOUR_SOURCE_PDF'; @@ -41,7 +37,7 @@ async function main( async function parseWithModel() { // Configure the request for processing the PDF - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; const request = { parent, inputConfig: { diff --git a/document-ai/snippets/quickstart.js b/document-ai/snippets/quickstart.js index 9741973141d..4ac5bf66991 100644 --- a/document-ai/snippets/quickstart.js +++ b/document-ai/snippets/quickstart.js @@ -15,13 +15,9 @@ 'use strict'; -/** - * Process a single PDF. - * @param {string} projectId your Google Cloud project ID - * @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse - */ async function main( projectId, + location, gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' ) { // [START documentai_quickstart] @@ -29,6 +25,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsInputUri = 'YOUR_SOURCE_PDF'; const { @@ -38,7 +35,7 @@ async function main( async function quickstart() { // Configure the request for processing the PDF - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; const request = { parent, inputConfig: { diff --git a/document-ai/snippets/set_endpoint.js b/document-ai/snippets/set_endpoint.js index d47f64e76d8..fef1ff80d97 100644 --- a/document-ai/snippets/set_endpoint.js +++ b/document-ai/snippets/set_endpoint.js @@ -15,13 +15,9 @@ 'use strict'; -/** - * Process a single PDF. - * @param {string} projectId your Google Cloud project ID - * @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse - */ async function main( projectId, + location = 'eu', gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' ) { // [START documentai_set_endpoint] @@ -29,6 +25,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample. */ // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' // const gcsInputUri = 'YOUR_SOURCE_PDF'; const { @@ -41,7 +38,7 @@ async function main( async function setEndpoint() { // Configure the request for processing the PDF - const parent = `projects/${projectId}`; + const parent = `projects/${projectId}/locations/${location}`; const request = { parent, inputConfig: { diff --git a/document-ai/snippets/test/batch_parse_form.test.js b/document-ai/snippets/test/batch_parse_form.test.js index 55bf7a088f8..9c8b57e973d 100644 --- a/document-ai/snippets/test/batch_parse_form.test.js +++ b/document-ai/snippets/test/batch_parse_form.test.js @@ -28,6 +28,7 @@ const cmd = 'node batch_parse_form.js'; const testParseForm = { projectId: process.env.GCLOUD_PROJECT, + location: 'us', gcsOutputUriPrefix: uuid.v4(), }; @@ -44,7 +45,7 @@ describe('Document AI batch parse form', () => { it('should parse the GCS invoice example as a form', async () => { const output = execSync( - `${cmd} ${testParseForm.projectId} gs://${bucketName}` + `${cmd} ${testParseForm.projectId} ${testParseForm.location} gs://${bucketName}` ); assert.match(output, /Extracted key value pair:/); }); diff --git a/document-ai/snippets/test/batch_parse_table.test.js b/document-ai/snippets/test/batch_parse_table.test.js index 65b78ba1b32..6844b135574 100644 --- a/document-ai/snippets/test/batch_parse_table.test.js +++ b/document-ai/snippets/test/batch_parse_table.test.js @@ -28,6 +28,7 @@ const cmd = 'node batch_parse_table.js'; const testParseTable = { projectId: process.env.GCLOUD_PROJECT, + location: 'us', gcsOutputUriPrefix: uuid.v4(), }; @@ -44,7 +45,7 @@ describe('Document AI batch parse table', () => { it('should parse the GCS invoice example as as table', async () => { const output = execSync( - `${cmd} ${testParseTable.projectId} gs://${bucketName}` + `${cmd} ${testParseTable.projectId} ${testParseTable.location} gs://${bucketName}` ); assert.match(output, /First detected language:/); }); diff --git a/document-ai/snippets/test/parse_form.test.js b/document-ai/snippets/test/parse_form.test.js index 4108a23f2c7..8052ceb6322 100644 --- a/document-ai/snippets/test/parse_form.test.js +++ b/document-ai/snippets/test/parse_form.test.js @@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; +const LOCATION = 'us'; describe('Document AI parse form', () => { it('should parse the GCS invoice example as a form', async () => { - const stdout = execSync(`node ./parse_form.js ${projectId}`, { + const stdout = execSync(`node ./parse_form.js ${projectId} ${LOCATION}`, { cwd, }); assert.match(stdout, /Extracted key value pair:/); diff --git a/document-ai/snippets/test/parse_table.test.js b/document-ai/snippets/test/parse_table.test.js index fcace94dee7..060e825f4d1 100644 --- a/document-ai/snippets/test/parse_table.test.js +++ b/document-ai/snippets/test/parse_table.test.js @@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; +const LOCATION = 'us'; describe('Document AI parse table', () => { it('should parse the GCS invoice example as as table', async () => { - const stdout = execSync(`node ./parse_table.js ${projectId}`, { + const stdout = execSync(`node ./parse_table.js ${projectId} ${LOCATION}`, { cwd, }); assert.match(stdout, /Header row/); diff --git a/document-ai/snippets/test/parse_with_model.test.js b/document-ai/snippets/test/parse_with_model.test.js index b976bda61af..a2f0afed650 100644 --- a/document-ai/snippets/test/parse_with_model.test.js +++ b/document-ai/snippets/test/parse_with_model.test.js @@ -23,6 +23,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; +const LOCATION = 'us'; const MODEL_NAME = process.env.MODEL_NAME || 'projects/1046198160504/locations/us-central1/models/TCN7483069430457434112'; @@ -30,7 +31,7 @@ const MODEL_NAME = describe('Document AI parse with AutoML model', () => { it('should run use an AutoML model to parse a PDF', async () => { const stdout = execSync( - `node ./parse_with_model.js ${projectId} ${MODEL_NAME}`, + `node ./parse_with_model.js ${projectId} ${LOCATION} ${MODEL_NAME}`, { cwd, } diff --git a/document-ai/snippets/test/quickstart.test.js b/document-ai/snippets/test/quickstart.test.js index 63c2285ba69..8a44c2d6c8d 100644 --- a/document-ai/snippets/test/quickstart.test.js +++ b/document-ai/snippets/test/quickstart.test.js @@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; +const LOCATION = 'us'; describe('Quickstart', () => { it('should run quickstart', async () => { - const stdout = execSync(`node ./quickstart.js ${projectId}`, { + const stdout = execSync(`node ./quickstart.js ${projectId} ${LOCATION}`, { cwd, }); assert.match(stdout, /Entity/); diff --git a/document-ai/snippets/test/set_endpoint.test.js b/document-ai/snippets/test/set_endpoint.test.js index 92c96a11c55..f8b52acdcd1 100644 --- a/document-ai/snippets/test/set_endpoint.test.js +++ b/document-ai/snippets/test/set_endpoint.test.js @@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; +const LOCATION = 'eu'; describe('Document AI set endpoint', () => { it('should process a PDF in another region', async () => { - const stdout = execSync(`node ./set_endpoint.js ${projectId}`, { + const stdout = execSync(`node ./set_endpoint.js ${projectId} ${LOCATION}`, { cwd, }); assert.match(stdout, /Entity/);