IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage'

心不动则不痛 提交于 2020-01-03 19:32:14

问题


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:


回答1:


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());
    }
}



回答2:


According to line 32 in the source code of Conversation, the delegate was changed to:

public delegate void OnMessage(object resp, string customData);

You'll have to change your OnMessage method to reflect that:

void OnMessage(object resp, string customData) {
    // ...
}


来源:https://stackoverflow.com/questions/45953300/ibm-watson-conversation-service-error-cannot-convert-from-method-group-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!