简体   繁体   中英

I can't programmatically get the model id from google-cloud-automl with node.js client library

How can I get the modelId from the getOperation response? When I run getOperation() function using the operationId, the response does not contain the modelId, even though done is true.

I have tried everything from this question: How to programmatically get model id from google-cloud-automl with node.js client library

But the response that is returned to me is different.

My Function:

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)}`);
  }

My Response:

    {
  "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"
}

    

How do I get my modelId using the operationId?

I finally figured this one out. It was returning the name with the model-Id in it as a Buffer inside the "value" . In order to extract the model-Id I had to do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM