简体   繁体   English

Google Document AI - 不一致的长期运行操作的元数据 JSON 表示

[英]Google Document AI - Inconsistent Long Running Operation's metadata JSON representation

While checking the status of Document AI - Long Running Operation (Form processor), the JSON representation of decodedOperation.metadata seems to vary during the execution.在检查 Document AI - Long Running Operation (Form processor) 的状态时, decodedOperation.metadata的 JSON 表示在执行期间似乎有所不同。 I suspect that operation response does not resolve straight away despite using then() on checkBatchProcessDocumentsProgress(operation.name) .我怀疑尽管在checkBatchProcessDocumentsProgress(operation.name)上使用了then() ,但operation响应并没有立即解决。

This behaviour does not happen using similar code for Google Speech's LROs.使用 Google Speech 的 LRO 的类似代码不会发生此行为。

Context:语境:

At console.log line #24 of implemented code (below), as expected , decodedOperation.metadata resolves toconsole.log已实现代码的第 24 行(下方),如预期的那样decodedOperation.metadata解析为

{
   "state":"RUNNING",
   "createTime":{
      "seconds":"1669278029",
      "nanos":500249000
   },
   "updateTime":{
      "seconds":"1669278029",
      "nanos":500249000
   }
}

Current behaviour:当前行为:

At console.log line #27, decodedOperation.metadata.state returns 2 (??)console.log第 27 行, decodedOperation.metadata.state返回2 (??)

Expected behaviour:预期行为:

decodedOperation.metadata.state should return RUNNING . decodedOperation.metadata.state应该返回RUNNING

More details of output in the code below.下面代码中输出的更多细节。

Reproduction details:再现细节:

Environment: node.js 12.02环境: node.js 12.02

Package.json:包.json:

{
    "dependencies": {
        "@google-cloud/documentai": "latest",
    }
}

Code:代码:

function run() {

    const documentai = require('@google-cloud/documentai').v1;

    // Create a promise on object
    let options = {
        credentials: {
            client_email: ** ** ** ,
            private_key: ** ** * ,
        },
        projectId: ** ** *
    };

    return async (async callback => {

        const client = new documentai.DocumentProcessorServiceClient(options);
        client.checkBatchProcessDocumentsProgress(properties.operation)
            .then(
                (decodedOperation) => {

                    console.log("METADATA " + JSON.stringify(decodedOperation.metadata));
                    /* logs to console:  
                        {
                           "state":"RUNNING",
                           "createTime":{
                              "seconds":"1669278029",
                              "nanos":500249000
                           },
                           "updateTime":{
                              "seconds":"1669278029",
                              "nanos":500249000
                           }
                        }
                    /// then 
                        {
                         "state":"SUCCEEDED",
                         "createTime":{
                            "seconds":"1669278029",
                            "nanos":500249000
                         },
                         "updateTime":{
                            "seconds":"1669278048",
                            "nanos":758825000
                         },
                         "individualProcessStatuses":[
                            {
                               "inputGcsSource":"gs://bucket/intake-form.pdf",
                               "status":{

                               },
                               "outputGcsDestination":"gs://bucket/ocr/7371120297544371692/0",
                               "humanReviewStatus":{
                                  "state":"SKIPPED",
                                  "stateMessage":"HumanReviewConfig is DISABLED, skipping human review."
                               }
                            }
                         ]
                      }
                      */
                    console.log("STATE " + JSON.stringify(decodedOperation.metadata.state));
                    /* log to console: 2 
                     when above is "RUNNING" */

                    /* log to console: 3
                    when above is "SUCCEEDED" */

                    if (decodedOperation.metadata.state == "SUCCEEDED") { // Never triggers as decodedOperation.metadata.state evaluates to an integer at this line

                    };
                    let response = {
                        "operationStatus": decodedOperation.metadata.state
                    };
                    callback(undefined, response);
                })
            .catch(
                (err) => {
                    callback(err);
                });
    })
} 

Update on investigation调查更新

util.inspect(decodedOperation.metadata, { showHidden: false }) returns: util.inspect(decodedOperation.metadata, { showHidden: false })返回:

BatchProcessMetadata {
   {
      "individualProcessStatuses":[
         "IndividualProcessStatus"{
            "inputGcsSource":"gs://bucketxxx/intake-form.pdf",
            "status":[
               "Status"
            ],
            "outputGcsDestination":"gs://bucketxxx/ocr/7999521463088838887/0",
            "humanReviewStatus":[
               "HumanReviewStatus"
            ]
         }
      ],
      "state":3,
      "createTime":"Timestamp"{
         "seconds":"Long"{
            "low":1670011754,
            "high":0,
            "unsigned":false
         },
         "nanos":105214000
      },
      "updateTime":"Timestamp"{
         "seconds":"Long"{
            "low":1670011773,
            "high":0,
            "unsigned":false
         },
         "nanos":489028000
      }
   }

util.inspect(decodedOperation.metadata, { showHidden: true }) returns (section of interest only): util.inspect(decodedOperation.metadata, { showHidden: true })返回(仅感兴趣的部分):

[...] [root]: [Getter], [fullName]: [Getter] }, State: { STATE_UNSPECIFIED: 0, WAITING: 1, RUNNING: 2, SUCCEEDED: 3, CANCELLING: 4, CANCELLED: 5, FAILED: 6, '0': 'STATE_UNSPECIFIED', '1': 'WAITING', '2': 'RUNNING', '3': 'SUCCEEDED', '4': 'CANCELLING', '5': 'CANCELLED', '6': 'FAILED' }, encode: <ref *5> [Function: BatchProcessMetadata$encode] [...]

To fix this issue, you can access the string representation of the state enum value by using the documentai.v1.BatchProcessMetadata.State object.要解决此问题,您可以使用 documentai.v1.BatchProcessMetadata.State 对象访问状态枚举值的字符串表示形式。 For example:例如:

console.log("STATE " + documentai.v1.BatchProcessMetadata.State[decodedOperation.metadata.state]);

instead of代替

console.log("STATE " + JSON.stringify(decodedOperation.metadata.state));

Read more about it.阅读更多相关信息。 https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.BatchProcessMetadata.State https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.BatchProcessMetadata.State

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 PHP 中获取表单字段的 Google Cloud Document AI 处理响应 - Google Cloud Document AI processing response impossible to get Form Fields in PHP 获取从 Invoice Parser google Document AI Processor 检测到的字段列表 - Getting list of fields detected from Invoice Parser google Document AI Processor 尝试使用 Google Cloud 文档 AI API 请求 Python 中的 field_mask 获取特定字段 - Trying to get specific fields using field_mask in Google Cloud document AI API request Python Firestore 创建的文档 Eventarc 审计日志方法不一致 - Firestore created document Eventarc audit log methods are inconsistent Document.AI python 客户端不返回表 - Document.AI python client does not return tables 从 python 后端调用 Google Vertex AI 端点时出错 - Error call Google Vertex AI endpoint from a python backend Google Vertex AI Matching 引擎拒绝列表如何工作? - How does Google Vertex AI Matching engine deny list work? 使用 Vertex AI Pipelines 通过 GPU 运行自定义 Docker 容器 - 如何安装 NVIDIA 驱动程序? - Running custom Docker container with GPU using Vertex AI Pipelines - how to install NVIDIA driver? 并行运行 Google Workflows - Running Google Workflows in Parallel 导入谷歌云 ai 平台时无法从 'shapely.geos' 导入名称 'WKBWriter' - cannot import name 'WKBWriter' from 'shapely.geos' when import google cloud ai platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM