我回来了更多问题。我使用的是Unity 5.5.1f1和Watson Developer Cloud Unity SDK v0.13.0。而不是使用小部件,我使用Watson / Examples / ServiceExamples / Scripts内部的脚本,他们运行得很好,我能够得到对话服务。但是,我很快意识到,通过这种设置,我似乎无法触及子节点。请查看下面的对话编辑器截图:
Watson: Hello, welcome to the paradise!
Me: Can you turn off the music please.
Watson: Ok, let's turn off something, you can say music, ac, and lights.
Me: music
Watson: ok, turn the music off. [child node]
但是,当我通过Unity执行此操作时,它变为:
Watson: Hello, welcome to the paradise!
Me: Can you turn off the music please.
Watson: Ok, let's turn off something, you can say music, ac, and lights.
Me: music
Watson: say what? [anything_else node]
对话似乎只停留在父节点上,并且根本不会到达子节点。或者也许服务器的每条消息都会重置服务?请帮忙!!
最好,
答案 0 :(得分:1)
要访问子节点,您需要在请求中传递上下文。在响应中,您可以传递context
属性到下一个请求。
Conversation m_Conversation = new Conversation();
private void SendInitalMessage(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");
// Send inital message to the service
m_Conversation.Message(OnInitalMessage, <workspace-id>, input);
}
private void OnInitalMessage(MessageResponse resp, string customData)
{
if (resp != null)
{
// Check response here
// Create a message request object with the context
MessageRequest messageRequest = new MessageRequest();
messageRequest.InputText = <input-text>;
messageRequest.alternate_intents = true;
messageRequest.ContextData = resp.context; // Context of the conversation
// Send the second message
SendFollowupMessage(messageRequest);
}
else
{
Debug.Log("Message Only: Failed to invoke Message();");
}
}
private void SendFollowupMessage(MessageRequest messageRequest)
{
if (messageRequest == null)
throw new ArgumentNullException("messageRequest");
m_Conversation.Message(OnFollowupMessage, <workspace-id>, messageRequest);
}
private void OnFollowupMessage(MessageResponse resp, string customData)
{
if (resp != null)
{
// Check response here
}
else
{
Debug.Log("Full Request: Failed to invoke Message();");
}
}
上下文对象包含conversationID和服务的其他数据,以跟踪用户在对话中的位置。
"context": {
"conversation_id": "<conversation-id>",
"system": {
"dialog_stack": [
{
"dialog_node": "<dialog-node>"
}
],
"dialog_turn_counter": <turn-counter>,
"dialog_request_counter": <request-counter>,
"branch_exited": <branch-exited>,
"branch_exited_reason": "<exited-reason>"
},
"defaultCounter": <default-counter>
}
编辑:数据模型似乎已更新。 resp.context.system.dialog_stack不应该是字符串数组。它应该是RuntimeDialogStack对象的数组。
[fsObject]
SystemResponse
{
public RuntimeDialogStack[] dialog_stack {get;set;}
public int dialog_turn_counter {get;set;}
public int dialog_request_counter {get;set;}
}
[fsObject]
public class RuntimeDialogStack
{
public string dialog_node {get;set;}
public bool invoked_subdialog {get;set;}
}
编辑2:看起来我一直在测试不匹配的版本字符串。请尝试使用此数据模型,并确保VisualRecognition数据模型中的版本参数为2017-02-03
。
[fsObject]
SystemResponse
{
public DialogNode[] dialog_stack {get;set;}
public int dialog_turn_counter {get;set;}
public int dialog_request_counter {get;set;}
}
[fsObject]
DialogNode
{
public string dialog_node {get;set;}
public bool invoked_subdialog {get;set;}
}