Watson的谈话中的上下文并没有按照它应该工作的方式工作

时间:2017-06-01 02:26:33

标签: node.js watson-conversation watson

如果我在Watson的对话中设置了上下文对象,我希望它仍然是它先前访问过的节点我的意思是:

WDT.io

在点燃'意图'之后,如果我输入'再见'(再见意图)。它应该触发一个再见的Intent,但它只适用于测试工具。

enter image description here

以下是我的Nodejs应用程序中的代码:

let context = {}
const conversation = new ConversationV1({
    username: 'myUsername',
    password: 'myPassword',
    url: 'https://gateway.watsonplatform.net/conversation/api',
    version_date: '2017-05-26'
})

conversation.message({ workspace_id: workspaceId}, function (err, response) {
    if (err) {
        console.log(err)
    } else {
        context = response.context
    }
})

sendMessage = (message = null) => new Promise((resolve, reject) => {
        conversation.message({
            input: {text: message},
            workspace_id: workspaceId,
            context: context
        }, function (err, response) {
            if (err) {
                reject(err)
            } else {
                resolve(response.output.text)
            }
        })
    }
  

虽然conversation_id总是一样的。我总是得到   anythingelse的Intent响应而不是再见'Intent。

{ intents: [ { intent: 'greetings', confidence: 1 } ],
  entities: [],
  input: { text: 'hi' },
  output: 
   { text: [ 'It is nice to talk to you, again !' ],
     nodes_visited: [ 'greetings' ],
     log_messages: [] },
  context: 
   { conversation_id: '7cc96494-d108-4dc9-95c4-63c174f20b4c',
     system: 
      { dialog_stack: [Object],
        dialog_turn_counter: 2,
        dialog_request_counter: 2,
        _node_output_map: [Object] } } }

{ intents: [ { intent: 'goodbytes', confidence: 1 } ],
  entities: [],
  input: { text: 'bye' },
  output: 
   { text: [ 'I didn\'t understand. You can try rephrasing.' ],
     nodes_visited: [ 'Anything else' ],
     log_messages: [] },
  context: 
   { conversation_id: '7cc96494-d108-4dc9-95c4-63c174f20b4c',
     system: 
      { dialog_stack: [Object],
        dialog_turn_counter: 2,
        dialog_request_counter: 2,
        _node_output_map: [Object],
        branch_exited: true,
        branch_exited_reason: 'completed' } } }

2 个答案:

答案 0 :(得分:1)

Dialog本身是无状态的,你必须使用context var来维护它。

详细解决方案:

https://developer.ibm.com/answers/questions/287623/how-do-you-maintain-the-conversation-context-when/

让我知道这是否解决了您的问题。

答案 1 :(得分:0)

我发现上下文对象的重要部分是保持对话的“上下文”并使用嵌套的意图继续传递你在每个http响应中拥有的新上下文对象。

let context = {}
sendMessage = (message = null) => new Promise((resolve, reject) => {
        conversation.message({
            input: {text: message},
            workspace_id: workspaceId,
            context: context
        }, function (err, response) {
            if (err) {
                reject(err)
            } else {
                context = response.context
                resolve(response.output.text)
            }
        })
    }

这意味着您必须更新每个http请求中的上下文对象:

  

context = response.context

正如您在每个http响应中看到的那样,您正在更新 _node_output_map

{ conversation_id: '1bb7b7e3-2bc2-4686-8f5e-8e25cdff7ff8',
  system: 
   { dialog_stack: [ [Object] ],
     dialog_turn_counter: 1,
     dialog_request_counter: 1,
     _node_output_map: { Welcome: [Object] },
     branch_exited: true,
     branch_exited_reason: 'completed' } }

{ conversation_id: '1bb7b7e3-2bc2-4686-8f5e-8e25cdff7ff8',
  system: 
   { dialog_stack: [ [Object] ],
     dialog_turn_counter: 2,
     dialog_request_counter: 2,
     _node_output_map: { Welcome: [Object], greetings: [Object] } } }