首页 > 解决方案 > GCP 文档 AI 示例不起作用 - 接收 INVALID_ARGUMENT:请求包含无效参数

问题描述

错误出现在 batchProcessDocuments 行并且有错误:

{
  code: 3,
  details: 'Request contains an invalid argument.',
  metadata: Metadata {
    internalRepr: Map { 'grpc-server-stats-bin' => [Array] },
    options: {}
  },
  note: 'Exception occurred in retry method that was not classified as transient'
}

我试图尽可能多地复制这个例子,但没有成功。有没有办法找到有关所需输入参数的更多信息?在网络上使用 Document AI 的例子很少,这是一个新产品。

这是我的代码示例:

const projectId = "95715XXXXX";
const location = "eu"; // Format is 'us' or 'eu'
const processorId = "a1e1f6a3XXXXXXXX";
const gcsInputUri = "gs://nmm-storage/test.pdf";
const gcsOutputUri = "gs://nmm-storage";
const gcsOutputUriPrefix = "out_";

// Imports the Google Cloud client library
const {
  DocumentProcessorServiceClient,
} = require("@google-cloud/documentai").v1beta3;
const { Storage } = require("@google-cloud/storage");

// Instantiates Document AI, Storage clients
const client = new DocumentProcessorServiceClient();
const storage = new Storage();

const { default: PQueue } = require("p-queue");

async function batchProcessDocument() {
  const name = `projects/${projectId}/locations/${location}/processors/${processorId}`;

  // Configure the batch process request.
  const request = {
    name,
    inputConfigs: [
      {
        gcsSource: gcsInputUri,
        mimeType: "application/pdf",
      },
    ],
    outputConfig: {
      gcsDestination: `${gcsOutputUri}/${gcsOutputUriPrefix}/`,
    },
  };

  // Batch process document using a long-running operation.
  // You can wait for now, or get results later.
  // Note: first request to the service takes longer than subsequent
  // requests.
  const [operation] = await client.batchProcessDocuments(request); //.catch(err => console.log('err', err));
  // Wait for operation to complete.
  await operation.promise();

  console.log("Document processing complete.");
}

batchProcessDocument();

标签: node.jsgoogle-cloud-platform

解决方案


我认为这是解决方案:https ://stackoverflow.com/a/66765483/15461811

(你必须设置apiEndpoint参数)


推荐阅读