IBM Watson 对话服务错误:无法从 'method group' 转换到 'conversation.onMessage' [英] IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage'

查看:31
本文介绍了IBM Watson 对话服务错误:无法从 'method group' 转换到 'conversation.onMessage'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试统一运行 IBM Watson 对话服务

解决方案

您可以将响应转换为字典并尝试从那里获取值.使用通用对象而不是静态数据模型,您可以通过响应传递更多信息.

private void OnMessage(object resp, string customData){字典<字符串,对象>respDict = resp as Dictionary;对象意图;respDict.TryGetValue("意图",输出意图);foreach(var intentObj in (intents as List)){字典<字符串,对象>intentDict = intentObj as Dictionary;对象意图字符串;intentDict.TryGetValue("intent", out intentString);对象置信字符串;intentDict.TryGetValue("confidence", outconfidenceString);Log.Debug("ExampleConversation", "intent: {0} | confidence {1}", intentString.ToString(), confidenceString.ToString());}}

I am trying to running IBM Watson conversation service in unity and following here, code snippet

private Conversation m_Conversation = new Conversation();
    private string m_WrokspaceID = "xyz";
    private string m_input = "help";


    // Use this for initialization
    void Start () {
        Debug.Log("user : " + m_input);
        m_Conversation.Message(OnMessage, m_WrokspaceID, m_input);
    }

    void OnMessage(MessageResponse resp, string customData) {
        foreach (Intent mi in resp.intents)
        {
            Debug.Log("intent : " + mi.intent + ", confidence :" + mi.confidence);
        }

        Debug.Log("response :" + resp.output.text);
    }

But i am getting this error

cannot convert from 'method group' to 'conversation.onMessage'

What i am doing wrong? The code snippet i get from watson official github repo.

Object returning as answer suggested:

解决方案

You can cast the response as a dictionary and try to get the value from there. Using a generic object instead of a static data model, you are able to pass more through the response.

private void OnMessage(object resp, string customData)
{
    Dictionary<string, object> respDict = resp as Dictionary<string, object>;
    object intents;
    respDict.TryGetValue("intents", out intents);

    foreach(var intentObj in (intents as List<object>))
    {
        Dictionary<string, object> intentDict = intentObj as Dictionary<string, object>;

        object intentString;
        intentDict.TryGetValue("intent", out intentString);

        object confidenceString;
        intentDict.TryGetValue("confidence", out confidenceString);

        Log.Debug("ExampleConversation", "intent: {0} | confidence {1}", intentString.ToString(), confidenceString.ToString());
    }
}

这篇关于IBM Watson 对话服务错误:无法从 &amp;#39;method group&amp;#39; 转换到 &amp;#39;conversation.onMessage&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆