首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我无法使用node.js客户端库以编程方式从google-cloud-automl获取模型id

我无法使用node.js客户端库以编程方式从google-cloud-automl获取模型id
EN

Stack Overflow用户
提问于 2020-07-17 22:31:13
回答 1查看 39关注 0票数 0

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

我从这个问题开始尝试了所有的方法:How to programmatically get model id from google-cloud-automl with node.js client library

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

我的函数:

代码语言:javascript
运行
复制
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)}`);
  }

我的回答是:

代码语言:javascript
运行
复制
    {
  "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?

EN

回答 1

Stack Overflow用户

发布于 2020-07-29 07:46:20

我终于弄明白这个问题了!它返回带有模型Id的名称,作为“值”?内的缓冲区。为了提取模型Id,我必须这样做

代码语言:javascript
运行
复制
const modelId = response.response.value.toString('utf8').replace(/projects\/[a-zA-Z0-9-]*\/locations\/[a-zA-Z0-9-]*\/models\//,''
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62956141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档