Skip to content

Commit

Permalink
fix(samples): do not pass location (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster authored and Ace Nassri committed Nov 12, 2022
1 parent fab60cc commit ab14bff
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 40 deletions.
4 changes: 1 addition & 3 deletions document-ai/batch_parse_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 @@ -29,7 +28,6 @@ async function main(
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION',
// const gcsOutputUri = 'YOUR_STORAGE_BUCKET';
// const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX';
// const gcsInputUri = 'GCS URI of the PDF to process';
Expand All @@ -44,7 +42,7 @@ async function main(
const storage = new Storage();

async function parseFormGCS(inputUri, outputUri, outputUriPrefix) {
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;

// Configure the batch process request.
const request = {
Expand Down
4 changes: 1 addition & 3 deletions document-ai/batch_parse_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 @@ -29,7 +28,6 @@ async function main(
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';
// const gcsOutputUri = 'YOUR_STORAGE_BUCKET';
// const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX';
// const gcsInputUri = 'YOUR_SOURCE_PDF';
Expand All @@ -44,7 +42,7 @@ async function main(
const storage = new Storage();

async function parseTableGCS(inputUri, outputUri, outputUriPrefix) {
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;

// Configure the batch process request.
const request = {
Expand Down
5 changes: 1 addition & 4 deletions document-ai/parse_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
/**
* Process a single PDF as a form.
* @param {string} projectId your Google Cloud project ID
* @param {string} location region to use for this operation
* @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';
// const gcsInputUri = 'YOUR_SOURCE_PDF';

const {
Expand All @@ -41,7 +38,7 @@ async function main(

async function parseForm() {
// Configure the request for processing the PDF
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;
const request = {
parent,
inputConfig: {
Expand Down
5 changes: 1 addition & 4 deletions document-ai/parse_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
/**
* Process a single PDF.
* @param {string} projectId your Google Cloud project ID
* @param {string} location region to use for this operation
* @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';
// const gcsInputUri = 'YOUR_SOURCE_PDF';

const {
Expand All @@ -41,7 +38,7 @@ async function main(

async function parseTable() {
// Configure the request for processing the PDF
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;
const request = {
parent,
inputConfig: {
Expand Down
5 changes: 1 addition & 4 deletions document-ai/parse_with_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
/**
* Process a single PDF.
* @param {string} projectId your Google Cloud project ID
* @param {string} location region to use for this operation
* @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 @@ -33,7 +31,6 @@ async function main(
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';
// const autoMLModel = 'Full resource name of AutoML Natural Language model';
// const gcsInputUri = 'YOUR_SOURCE_PDF';

Expand All @@ -44,7 +41,7 @@ async function main(

async function parseWithModel() {
// Configure the request for processing the PDF
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;
const request = {
parent,
inputConfig: {
Expand Down
5 changes: 1 addition & 4 deletions document-ai/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
/**
* Process a single PDF.
* @param {string} projectId your Google Cloud project ID
* @param {string} location region to use for this operation
* @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';
// const gcsInputUri = 'YOUR_SOURCE_PDF';

const {
Expand All @@ -41,7 +38,7 @@ async function main(

async function quickstart() {
// Configure the request for processing the PDF
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;
const request = {
parent,
inputConfig: {
Expand Down
5 changes: 1 addition & 4 deletions document-ai/set_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
/**
* Process a single PDF.
* @param {string} projectId your Google Cloud project ID
* @param {string} location region to use for this operation
* @param {string} gcsInputUri Cloud Storage URI of the PDF document to parse
*/
async function main(
projectId,
location = 'europe-west2',
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 = 'Location for operation--must match region of endpoint';
// const gcsInputUri = 'YOUR_SOURCE_PDF';

const {
Expand All @@ -44,7 +41,7 @@ async function main(

async function setEndpoint() {
// Configure the request for processing the PDF
const parent = `projects/${projectId}/locations/${location}`;
const parent = `projects/${projectId}`;
const request = {
parent,
inputConfig: {
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/batch_parse_form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const cmd = 'node batch_parse_form.js';

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

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

it('should parse the GCS invoice example as a form', async () => {
const output = execSync(
`${cmd} ${testParseForm.projectId} ${testParseForm.location} gs://${bucketName}`
`${cmd} ${testParseForm.projectId} gs://${bucketName}`
);
assert.match(output, /Extracted key value pair:/);
});
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/batch_parse_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const cmd = 'node batch_parse_table.js';

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

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

it('should parse the GCS invoice example as as table', async () => {
const output = execSync(
`${cmd} ${testParseTable.projectId} ${testParseTable.location} gs://${bucketName}`
`${cmd} ${testParseTable.projectId} gs://${bucketName}`
);
assert.match(output, /First detected language:/);
});
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/parse_form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'us-central1';

describe('Document AI parse form', () => {
it('should parse the GCS invoice example as a form', async () => {
const stdout = execSync(`node ./parse_form.js ${projectId} ${LOCATION}`, {
const stdout = execSync(`node ./parse_form.js ${projectId}`, {
cwd,
});
assert.match(stdout, /Extracted key value pair:/);
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/parse_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'us-central1';

describe('Document AI parse table', () => {
it('should parse the GCS invoice example as as table', async () => {
const stdout = execSync(`node ./parse_table.js ${projectId} ${LOCATION}`, {
const stdout = execSync(`node ./parse_table.js ${projectId}`, {
cwd,
});
assert.match(stdout, /Header row/);
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/parse_with_model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'us-central1';
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} ${LOCATION} ${MODEL_NAME}`,
`node ./parse_with_model.js ${projectId} ${MODEL_NAME}`,
{
cwd,
}
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'us-central1';

describe('Quickstart', () => {
it('should run quickstart', async () => {
const stdout = execSync(`node ./quickstart.js ${projectId} ${LOCATION}`, {
const stdout = execSync(`node ./quickstart.js ${projectId}`, {
cwd,
});
assert.match(stdout, /Entity/);
Expand Down
3 changes: 1 addition & 2 deletions document-ai/test/set_endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'europe-west2';

describe('Document AI set endpoint', () => {
it('should process a PDF in another region', async () => {
const stdout = execSync(`node ./set_endpoint.js ${projectId} ${LOCATION}`, {
const stdout = execSync(`node ./set_endpoint.js ${projectId}`, {
cwd,
});
assert.match(stdout, /Entity/);
Expand Down

0 comments on commit ab14bff

Please sign in to comment.