2017-06-01 43 views
0

如果我设置在沃森的对话上下文对象的方式工作,我希望它保持它以前访问过的节点我的意思是:语境在沃森的谈话是不是在它应该工作

enter image description here

在发出问候意图后,如果我输入'再见'(再见意图)。它应该激发一个再见的意图,但它只是在测试工具中工作。

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响应 ,而不是告别的意图。

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

回答

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请求的上下文对象:

上下文= 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] } } }