沃森对话 API 说:'Patterns are defined but type is not specified.'

Watson Conversation API says: 'Patterns are defined but type is not specified.'

我正在尝试使用 Node.js 的 Watson SDK 调用 Watson Conversation API 的 updateValue 方法。该请求更新 patterns 类型实体值的模式。

我的请求失败并显示 400 Bad Request 和消息:

[ { message: 'Patterns are defined but type is not specified.',
       path: '.patterns' } ],

这是我用来调用 API 的代码 - 非常标准。:

      let params = {
        workspace_id: '<redacted>',
        entity: 'myEntityType',
        type: 'patterns', // tried with and without this line
        value: 'myCanonicalValue',
        new_patterns: ['test'],
      };

      watsonApi.updateValue(params, (error, response) => {
        if (error) {
          console.log('Error returned by Watson when updating an entity value.');
          reject(error);
        } else {
          resolve(response);
        }
      });

实际上,请求所做的是尝试从模式列表中删除模式。由于没有删除模式的端点,我获取模式列表,从模式列表中删除我需要删除的模式,然后通过 updateValue 方法发送现在减少的模式列表。在上面的示例中,假设模式列表是 ['test', 'test2']。通过仅使用 ['test'] 调用 updateValue,我们将删除 test2 模式。

我使用的是以前的 API 版本,但我也在助手 API Explorer 中对其进行了测试,而版本 2018-07-10 在发送原始请求时会导致同样的问题正文组成如下:

{
  "patterns": ["test"]
}

我是做错了什么还是忘记了参数?

这似乎是 Watson Conversation Node.js SDK 中的错误。

为避免这种情况,请始终将 new_type: 'patterns' 添加到 params:

  let params = {
    workspace_id: '<redacted>',
    entity: 'myEntityType',
    new_type: 'patterns',
    value: 'myCanonicalValue',
    new_patterns: ['test'],
  };

我按以下方式阅读 Watson Assistant API for updateValue

不需要new_type参数,有效值为synonymspatterns。但是,如果您不提供该参数,则会使用默认值。根据文档,默认值为 synonyms。这将解释您传入模式时的错误。

这不是错误,但它是一个不直观的参数名称。该服务接受一个 type 参数,Node SDK 有一个名为 new_type 的包装器参数。如果您使用它来更新模式而不是同义词(默认),那么您需要将 new_type 指定为 "patterns",即使该参数被列为可选。