【问题标题】:I can't programmatically get the model id from google-cloud-automl with node.js client library我无法使用 node.js 客户端库以编程方式从 google-cloud-automl 获取模型 ID
【发布时间】:2020-11-07 09:18:47
【问题描述】:

如何从 getOperation 响应中获取 modelId?当我使用 operationId 运行 getOperation() 函数时,响应不包含 modelId,即使 done 为真。

我已经尝试了这个问题的所有内容:How to programmatically get model id from google-cloud-automl with node.js client library

但是返回给我的响应不同。

我的功能:

exports.testOperationStatus = async function(operationId) {
    // Construct request
    const request = {
      name: `projects/${projectId}/locations/${location}/operations/${operationId}`,
    };
  
    const [response] = await client.operationsClient.getOperation(request);
  
    console.log(`Name: ${response.name}`);
    console.log(`Operation details:`);
    console.log(`${JSON.stringify(response, null, 2)}`);
  }

我的回应:

    {
  "name": "projects/projectId/locations/us-central1/operations/operationId”,
  "metadata": {
    "type_url": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "value": {
      "type": "Buffer",
      "data": […]
    }
  },
  "done": true,
  "response": {
    "type_url": "type.googleapis.com/google.cloud.automl.v1.Model",
    "value": {
      "type": "Buffer",
      "data": […]
    }
  },
  "result": "response"
}

    

如何使用 operationId 获取我的 modelId?

【问题讨论】:

    标签: node.js reactjs google-cloud-automl automl


    【解决方案1】:

    我终于想通了!它正在返回带有模型 ID 的名称作为“值”?内的缓冲区。 为了提取模型 ID,我必须这样做

    const modelId = response.response.value.toString('utf8').replace(/projects\/[a-zA-Z0-9-]*\/locations\/[a-zA-Z0-9-]*\/models\//,''
    

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 1970-01-01
      • 2019-09-16
      • 2018-07-02
      • 2013-03-02
      • 2021-11-28
      • 2019-06-24
      • 1970-01-01
      • 2012-07-05
      相关资源
      最近更新 更多