0

在 Google Cloud Platform (GCP) 上,我有一个在 PDF 上训练的 AutoML 自然语言实体提取模型。因此,它需要对 PDF 执行预测。

我有一个 PDF,我想在 GCP Bucket 中执行实体提取预测,因此我想在 NodeJS 中发出以下请求并predict使用以下命令调用PredictionServiceClient

此代码示例基于实体提取 NodeJS 文本示例中的普通文本的实体提取示例,以及 NodeJS AutoML NL 文档以查找其IPredictRequest外观:AutoML Google API 文档 IPredictRequest

const projectId = 'projectId';
const location = 'us-central1';
const datasetId = 'TEN4565454654564855555'; // randomised for this example
const srcFilename = 'file_name.pdf';

// Imports the Google Cloud AutoML library
const {PredictionServiceClient} = require('@google-cloud/automl').v1;

// Instantiates a client
const client = new PredictionServiceClient();

const request = {
    name: client.modelPath(projectId, location, datasetId),
    payload: {
      document: {
        inputConfig: {
          gcsSource: {
            inputUris: ["gs://bucket_name/" + srcFilename]
          }
        }
      }
    },
  };

const [response] = await client.predict(request);

然后我得到错误:

Error: 3 INVALID_ARGUMENT: Request contains an invalid argument. at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:179:52) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181) at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78 at processTicksAndRejections (internal/process/task_queues.js:77:11)
Error: 3 INVALID_ARGUMENT: Request contains an invalid argument. at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:179:52) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181) at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78 at processTicksAndRejections (internal/process/task_queues.js:77:11)

我也尝试过使用下划线input_config代替inputConfig和相同的gcs_sourceinput_uris。我尝试了这个,因为这是request.json NL 模型测试和使用页面上的示例(见图)。

[![示例 request.json][3]][3] 然后我得到:

Error: 3 INVALID_ARGUMENT: List of found errors: 1.Field: payload.document.document_text.content; Message: Required field not set. at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:179:52) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181) at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78 at processTicksAndRejections (internal/process/task_queues.js:77:11)
Error: 3 INVALID_ARGUMENT: List of found errors: 1.Field: payload.document.document_text.content; Message: Required field not set. at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:179:52) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181) at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78 at processTicksAndRejections (internal/process/task_queues.js:77:11)

在 NodeJS NL 文档中它说这documentText是可选的,所以我不明白这个错误。尝试通过提供该字段来修复最后document_text一个错误,再次在这篇文章中创建了第一个错误(我不想手动提供 PDF 中的文本,因为它是复印件)。

我该如何解决这个问题,更重要的是如何解析/理解文档和错误消息?为什么在某些地方使用驼峰式,而在其他地方使用下划线?

4

0 回答 0