【问题标题】:IBM WATSON Unity SDK can't reach child nodeIBM WATSON Unity SDK 无法访问子节点
【发布时间】:2017-08-12 18:55:34
【问题描述】:

我带着更多问题回来了。我正在使用 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]

似乎对话只停留在父节点,根本没有到达子节点。或者,发给服务器的每条消息都会重置服务?请帮忙!!

最好的,

【问题讨论】:

  • 发现了一个类似的问题,stackoverflow.com/questions/42180038/…
  • "我编写了一段简单的代码,用于存储按 Slack 的 user_id 分组的现有上下文。如果此 user_id 的上下文已经存在,那么我的应用程序将调用 Watson API 并将此上下文附加到请求中,所以 Watson 知道这个新用户的输入跟在前一个用户的输入之后。”我们如何在 C# Unity 中真正实现这一点?

标签: watson-conversation watson


【解决方案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();");
    }
}

上下文对象包含会话 ID 和其他数据,以便服务跟踪用户在会话中的位置。

"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;}
}

【讨论】:

  • 嗨@taj,我意识到并做到了,但它仍然无法正常工作,所以我做了一些调试,发现我的 resp.context.system.dialog_stack 总是为空(长度 = 0) .我还在我的 respberry Pi 上使用 TJbot 代码尝试了相同的工作场所,它按照预期的方式工作,所以我从那里取出 dialog_stack 数组并手动写入 dialog_stack 中,然后分配给 messageRequest resp.context.system.dialog_stack = new string[] { "node_4_1489256441002" }; 它以这种方式完美运行。所以我认为 Unity 中的 dialog_stack 有问题!?
  • @Ghettokon 数据模型似乎已更新。我更新了答案 - 请试一试。
  • I Debug.Log dialog_stack,它在控制台中显示为System.String[]...
  • 调试 dialog_stack 应该显示为 string[] 类型,因为这是它在数据模型中输入的内容。您需要更改模型以使用 DialogNode[] 而不是 string[]。请参阅上面的编辑 2,并将数据模型中的 Version 参数更改为 2017-02-03
猜你喜欢
  • 1970-01-01
  • 2018-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多