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

问题描述

我正在尝试统一运行IBM Watson 对话服务,并且 此处是代码段

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

但是我遇到了这个错误

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

我做错了什么?我从Watson官方github存储库获得的代码段.

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对话服务错误:无法从“方法组"转换为"conversation.onMessage"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:45