Skip to content

Commit

Permalink
samples: updates v1beta3 to v1; renames v1beta2 samples (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
telpirion authored Apr 14, 2021
1 parent 0ba68c4 commit 9a8cfaf
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 37 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ async function main(
const [headerRow] = table.headerRows;

console.log('Results from first table processed:');
console.log(
`First detected language: ${page1.detectedLanguages[0].languageCode}`
);

console.log('Header row:');
for (const tableCell of headerRow.cells) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main(
// Imports the Google Cloud client library
const {
DocumentProcessorServiceClient,
} = require('@google-cloud/documentai').v1beta3;
} = require('@google-cloud/documentai').v1;
const {Storage} = require('@google-cloud/storage');

// Instantiates Document AI, Storage clients
Expand All @@ -54,14 +54,20 @@ async function main(
// Configure the batch process request.
const request = {
name,
inputConfigs: [
{
gcsSource: gcsInputUri,
mimeType: 'application/pdf',
inputDocuments: {
gcsDocuments: {
documents: [
{
gcsUri: gcsInputUri,
mimeType: 'application/pdf',
},
],
},
},
documentOutputConfig: {
gcsOutputConfig: {
gcsUri: `${gcsOutputUri}/${gcsOutputUriPrefix}/`,
},
],
outputConfig: {
gcsDestination: `${gcsOutputUri}/${gcsOutputUriPrefix}/`,
},
};

Expand All @@ -73,7 +79,6 @@ async function main(

// Wait for operation to complete.
await operation.promise();

console.log('Document processing complete.');

// Query Storage bucket for the results file(s).
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main(projectId, location, processorId, filePath) {

const {
DocumentProcessorServiceClient,
} = require('@google-cloud/documentai').v1beta3;
} = require('@google-cloud/documentai').v1;

// Instantiates a client
const client = new DocumentProcessorServiceClient();
Expand All @@ -47,7 +47,7 @@ async function main(projectId, location, processorId, filePath) {

const request = {
name,
document: {
rawDocument: {
content: encodedImage,
mimeType: 'application/pdf',
},
Expand Down
4 changes: 2 additions & 2 deletions document-ai/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main(projectId, location, processorId, filePath) {

const {
DocumentProcessorServiceClient,
} = require('@google-cloud/documentai').v1beta3;
} = require('@google-cloud/documentai').v1;

// Instantiates a client
const client = new DocumentProcessorServiceClient();
Expand All @@ -47,7 +47,7 @@ async function main(projectId, location, processorId, filePath) {

const request = {
name,
document: {
rawDocument: {
content: encodedImage,
mimeType: 'application/pdf',
},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const storage = new Storage();
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
const cmd = 'node batch_parse_form.js';
const cmd = 'node batch-parse-form.v1beta2.js';

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

describe('Document AI batch parse form', () => {
describe('Document AI batch parse form (v1beta2)', () => {
before(async () => {
await storage.createBucket(bucketName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const storage = new Storage();
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
const cmd = 'node batch_parse_table.js';
const cmd = 'node batch-parse-table.v1beta2.js';

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

describe('Document AI batch parse table', () => {
describe('Document AI batch parse table (v1beta2)', () => {
before(async () => {
await storage.createBucket(bucketName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const storage = new Storage();
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
const cmd = 'node batch-process-document.v1beta3.js';
const cmd = 'node batch-process-document.js';

const testProcessDocument = {
projectId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ 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} ${LOCATION}`, {
cwd,
});
it('should parse the GCS invoice example as a form (v1beta2)', async () => {
const stdout = execSync(
`node ./parse-form.v1beta2.js ${projectId} ${LOCATION}`,
{
cwd,
}
);
assert.match(stdout, /Extracted key value pair:/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ 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} ${LOCATION}`, {
cwd,
});
it('should parse the GCS invoice example as as table (v1beta2)', async () => {
const stdout = execSync(
`node ./parse-table.v1beta2.js ${projectId} ${LOCATION}`,
{
cwd,
}
);
assert.match(stdout, /Header row/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const MODEL_NAME =
process.env.MODEL_NAME ||
'projects/1046198160504/locations/us-central1/models/TCN7483069430457434112';

describe('Document AI parse with AutoML model', () => {
describe('Document AI parse with AutoML model (v1beta2)', () => {
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.v1beta2.js ${projectId} ${LOCATION} ${MODEL_NAME}`,
{
cwd,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ describe('Process document', () => {
before(async () => {
projectId = await client.getProjectId();
});
it('should run document (process invoice)', async () => {
it('should run document (process invoice) (v1)', async () => {
const stdout = execSync(
`node ./process-document.v1beta3.js ${projectId} ${LOCATION} ${PROCESSOR_ID} ${filePath}`,
`node ./process-document.js ${projectId} ${LOCATION} ${PROCESSOR_ID} ${filePath}`,
{
cwd,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;
const LOCATION = 'eu';

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

0 comments on commit 9a8cfaf

Please sign in to comment.