Skip to content

Commit

Permalink
chore: fix samples according to service resource change (#35)
Browse files Browse the repository at this point in the history
* chore: late breaking service change
* fix: changes to location
* fix: removed unnecessary set endpoint

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
telpirion and bcoe committed Apr 13, 2020
1 parent a2a3a65 commit 9f8e532
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 40 deletions.
4 changes: 3 additions & 1 deletion document-ai/batch_parse_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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';
Expand All @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion document-ai/batch_parse_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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';
Expand All @@ -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 = {
Expand Down
9 changes: 3 additions & 6 deletions document-ai/parse_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

'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]
/**
* 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 {
Expand All @@ -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: {
Expand Down
9 changes: 3 additions & 6 deletions document-ai/parse_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

'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]
/**
* 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 {
Expand All @@ -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: {
Expand Down
10 changes: 3 additions & 7 deletions document-ai/parse_with_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
) {
Expand All @@ -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';

Expand All @@ -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: {
Expand Down
9 changes: 3 additions & 6 deletions document-ai/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

'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]
/**
* 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 {
Expand All @@ -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: {
Expand Down
9 changes: 3 additions & 6 deletions document-ai/set_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

'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]
/**
* 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 {
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/batch_parse_form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const cmd = 'node batch_parse_form.js';

const testParseForm = {
projectId: process.env.GCLOUD_PROJECT,
location: 'us',
gcsOutputUriPrefix: uuid.v4(),
};

Expand All @@ -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:/);
});
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/batch_parse_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const cmd = 'node batch_parse_table.js';

const testParseTable = {
projectId: process.env.GCLOUD_PROJECT,
location: 'us',
gcsOutputUriPrefix: uuid.v4(),
};

Expand All @@ -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:/);
});
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/parse_form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:/);
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/parse_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/parse_with_model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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';

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,
}
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
3 changes: 2 additions & 1 deletion document-ai/test/set_endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down

0 comments on commit 9f8e532

Please sign in to comment.