Skip to content

Commit 4a02126

Browse files
telpirionbcoe
authored and
Ace Nassri
committed
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 <[email protected]>
1 parent ab14bff commit 4a02126

14 files changed

+35
-40
lines changed

document-ai/batch_parse_form.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const uuid = require('uuid');
1919

2020
async function main(
2121
projectId = 'YOUR_PROJECT_ID',
22+
location = 'YOUR_PROJECT_LOCATION',
2223
gcsOutputUri = 'output-bucket',
2324
gcsOutputUriPrefix = uuid.v4(),
2425
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
@@ -28,6 +29,7 @@ async function main(
2829
* TODO(developer): Uncomment these variables before running the sample.
2930
*/
3031
// const projectId = 'YOUR_PROJECT_ID';
32+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3133
// const gcsOutputUri = 'YOUR_STORAGE_BUCKET';
3234
// const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX';
3335
// const gcsInputUri = 'GCS URI of the PDF to process';
@@ -42,7 +44,7 @@ async function main(
4244
const storage = new Storage();
4345

4446
async function parseFormGCS(inputUri, outputUri, outputUriPrefix) {
45-
const parent = `projects/${projectId}`;
47+
const parent = `projects/${projectId}/locations/${location}`;
4648

4749
// Configure the batch process request.
4850
const request = {

document-ai/batch_parse_table.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const uuid = require('uuid');
1919

2020
async function main(
2121
projectId = 'YOUR_PROJECT_ID',
22+
location = 'YOUR_PROJECT_LOCATION',
2223
gcsOutputUri = 'output-bucket',
2324
gcsOutputUriPrefix = uuid.v4(),
2425
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
@@ -28,6 +29,7 @@ async function main(
2829
* TODO(developer): Uncomment these variables before running the sample.
2930
*/
3031
// const projectId = 'YOUR_PROJECT_ID';
32+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3133
// const gcsOutputUri = 'YOUR_STORAGE_BUCKET';
3234
// const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX';
3335
// const gcsInputUri = 'YOUR_SOURCE_PDF';
@@ -42,7 +44,7 @@ async function main(
4244
const storage = new Storage();
4345

4446
async function parseTableGCS(inputUri, outputUri, outputUriPrefix) {
45-
const parent = `projects/${projectId}`;
47+
const parent = `projects/${projectId}/locations/${location}`;
4648

4749
// Configure the batch process request.
4850
const request = {

document-ai/parse_form.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@
1515

1616
'use strict';
1717

18-
/**
19-
* Process a single PDF as a form.
20-
* @param {string} projectId your Google Cloud project ID
21-
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
22-
*/
2318
async function main(
2419
projectId,
20+
location,
2521
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
2622
) {
2723
// [START documentai_parse_form]
2824
/**
2925
* TODO(developer): Uncomment these variables before running the sample.
3026
*/
3127
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3229
// const gcsInputUri = 'YOUR_SOURCE_PDF';
3330

3431
const {
@@ -38,7 +35,7 @@ async function main(
3835

3936
async function parseForm() {
4037
// Configure the request for processing the PDF
41-
const parent = `projects/${projectId}`;
38+
const parent = `projects/${projectId}/locations/${location}`;
4239
const request = {
4340
parent,
4441
inputConfig: {

document-ai/parse_table.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@
1515

1616
'use strict';
1717

18-
/**
19-
* Process a single PDF.
20-
* @param {string} projectId your Google Cloud project ID
21-
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
22-
*/
2318
async function main(
2419
projectId,
20+
location,
2521
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
2622
) {
2723
// [START documentai_parse_table]
2824
/**
2925
* TODO(developer): Uncomment these variables before running the sample.
3026
*/
3127
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3229
// const gcsInputUri = 'YOUR_SOURCE_PDF';
3330

3431
const {
@@ -38,7 +35,7 @@ async function main(
3835

3936
async function parseTable() {
4037
// Configure the request for processing the PDF
41-
const parent = `projects/${projectId}`;
38+
const parent = `projects/${projectId}/locations/${location}`;
4239
const request = {
4340
parent,
4441
inputConfig: {

document-ai/parse_with_model.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515

1616
'use strict';
1717

18-
/**
19-
* Process a single PDF.
20-
* @param {string} projectId your Google Cloud project ID
21-
* @param {string} autoMLModel AutoML Natural Language model to use
22-
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
23-
*/
2418
async function main(
2519
projectId,
20+
location,
2621
autoMLModel,
2722
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
2823
) {
@@ -31,6 +26,7 @@ async function main(
3126
* TODO(developer): Uncomment these variables before running the sample.
3227
*/
3328
// const projectId = 'YOUR_PROJECT_ID';
29+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3430
// const autoMLModel = 'Full resource name of AutoML Natural Language model';
3531
// const gcsInputUri = 'YOUR_SOURCE_PDF';
3632

@@ -41,7 +37,7 @@ async function main(
4137

4238
async function parseWithModel() {
4339
// Configure the request for processing the PDF
44-
const parent = `projects/${projectId}`;
40+
const parent = `projects/${projectId}/locations/${location}`;
4541
const request = {
4642
parent,
4743
inputConfig: {

document-ai/quickstart.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@
1515

1616
'use strict';
1717

18-
/**
19-
* Process a single PDF.
20-
* @param {string} projectId your Google Cloud project ID
21-
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
22-
*/
2318
async function main(
2419
projectId,
20+
location,
2521
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
2622
) {
2723
// [START documentai_quickstart]
2824
/**
2925
* TODO(developer): Uncomment these variables before running the sample.
3026
*/
3127
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3229
// const gcsInputUri = 'YOUR_SOURCE_PDF';
3330

3431
const {
@@ -38,7 +35,7 @@ async function main(
3835

3936
async function quickstart() {
4037
// Configure the request for processing the PDF
41-
const parent = `projects/${projectId}`;
38+
const parent = `projects/${projectId}/locations/${location}`;
4239
const request = {
4340
parent,
4441
inputConfig: {

document-ai/set_endpoint.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@
1515

1616
'use strict';
1717

18-
/**
19-
* Process a single PDF.
20-
* @param {string} projectId your Google Cloud project ID
21-
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
22-
*/
2318
async function main(
2419
projectId,
20+
location = 'eu',
2521
gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf'
2622
) {
2723
// [START documentai_set_endpoint]
2824
/**
2925
* TODO(developer): Uncomment these variables before running the sample.
3026
*/
3127
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
3229
// const gcsInputUri = 'YOUR_SOURCE_PDF';
3330

3431
const {
@@ -41,7 +38,7 @@ async function main(
4138

4239
async function setEndpoint() {
4340
// Configure the request for processing the PDF
44-
const parent = `projects/${projectId}`;
41+
const parent = `projects/${projectId}/locations/${location}`;
4542
const request = {
4643
parent,
4744
inputConfig: {

document-ai/test/batch_parse_form.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const cmd = 'node batch_parse_form.js';
2828

2929
const testParseForm = {
3030
projectId: process.env.GCLOUD_PROJECT,
31+
location: 'us',
3132
gcsOutputUriPrefix: uuid.v4(),
3233
};
3334

@@ -44,7 +45,7 @@ describe('Document AI batch parse form', () => {
4445

4546
it('should parse the GCS invoice example as a form', async () => {
4647
const output = execSync(
47-
`${cmd} ${testParseForm.projectId} gs://${bucketName}`
48+
`${cmd} ${testParseForm.projectId} ${testParseForm.location} gs://${bucketName}`
4849
);
4950
assert.match(output, /Extracted key value pair:/);
5051
});

document-ai/test/batch_parse_table.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const cmd = 'node batch_parse_table.js';
2828

2929
const testParseTable = {
3030
projectId: process.env.GCLOUD_PROJECT,
31+
location: 'us',
3132
gcsOutputUriPrefix: uuid.v4(),
3233
};
3334

@@ -44,7 +45,7 @@ describe('Document AI batch parse table', () => {
4445

4546
it('should parse the GCS invoice example as as table', async () => {
4647
const output = execSync(
47-
`${cmd} ${testParseTable.projectId} gs://${bucketName}`
48+
`${cmd} ${testParseTable.projectId} ${testParseTable.location} gs://${bucketName}`
4849
);
4950
assert.match(output, /First detected language:/);
5051
});

document-ai/test/parse_form.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2323

2424
const cwd = path.join(__dirname, '..');
2525
const projectId = process.env.GCLOUD_PROJECT;
26+
const LOCATION = 'us';
2627

2728
describe('Document AI parse form', () => {
2829
it('should parse the GCS invoice example as a form', async () => {
29-
const stdout = execSync(`node ./parse_form.js ${projectId}`, {
30+
const stdout = execSync(`node ./parse_form.js ${projectId} ${LOCATION}`, {
3031
cwd,
3132
});
3233
assert.match(stdout, /Extracted key value pair:/);

document-ai/test/parse_table.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2323

2424
const cwd = path.join(__dirname, '..');
2525
const projectId = process.env.GCLOUD_PROJECT;
26+
const LOCATION = 'us';
2627

2728
describe('Document AI parse table', () => {
2829
it('should parse the GCS invoice example as as table', async () => {
29-
const stdout = execSync(`node ./parse_table.js ${projectId}`, {
30+
const stdout = execSync(`node ./parse_table.js ${projectId} ${LOCATION}`, {
3031
cwd,
3132
});
3233
assert.match(stdout, /Header row/);

document-ai/test/parse_with_model.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2323

2424
const cwd = path.join(__dirname, '..');
2525
const projectId = process.env.GCLOUD_PROJECT;
26+
const LOCATION = 'us';
2627
const MODEL_NAME =
2728
process.env.MODEL_NAME ||
2829
'projects/1046198160504/locations/us-central1/models/TCN7483069430457434112';
2930

3031
describe('Document AI parse with AutoML model', () => {
3132
it('should run use an AutoML model to parse a PDF', async () => {
3233
const stdout = execSync(
33-
`node ./parse_with_model.js ${projectId} ${MODEL_NAME}`,
34+
`node ./parse_with_model.js ${projectId} ${LOCATION} ${MODEL_NAME}`,
3435
{
3536
cwd,
3637
}

document-ai/test/quickstart.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2323

2424
const cwd = path.join(__dirname, '..');
2525
const projectId = process.env.GCLOUD_PROJECT;
26+
const LOCATION = 'us';
2627

2728
describe('Quickstart', () => {
2829
it('should run quickstart', async () => {
29-
const stdout = execSync(`node ./quickstart.js ${projectId}`, {
30+
const stdout = execSync(`node ./quickstart.js ${projectId} ${LOCATION}`, {
3031
cwd,
3132
});
3233
assert.match(stdout, /Entity/);

document-ai/test/set_endpoint.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2323

2424
const cwd = path.join(__dirname, '..');
2525
const projectId = process.env.GCLOUD_PROJECT;
26+
const LOCATION = 'eu';
2627

2728
describe('Document AI set endpoint', () => {
2829
it('should process a PDF in another region', async () => {
29-
const stdout = execSync(`node ./set_endpoint.js ${projectId}`, {
30+
const stdout = execSync(`node ./set_endpoint.js ${projectId} ${LOCATION}`, {
3031
cwd,
3132
});
3233
assert.match(stdout, /Entity/);

0 commit comments

Comments
 (0)