IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage'
IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage'
我正在尝试 运行 IBM Watson conversation service 和 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 repo 获得的代码片段。
对象作为建议的答案返回:
根据Conversation
源代码中的line 32,委托修改为:
public delegate void OnMessage(object resp, string customData);
您必须更改 OnMessage
方法以反映这一点:
void OnMessage(object resp, string customData) {
// ...
}
您可以将响应转换为字典并尝试从中获取值。使用通用对象而不是静态数据模型,您可以通过响应传递更多信息。
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 service 和 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 repo 获得的代码片段。
对象作为建议的答案返回:
根据Conversation
源代码中的line 32,委托修改为:
public delegate void OnMessage(object resp, string customData);
您必须更改 OnMessage
方法以反映这一点:
void OnMessage(object resp, string customData) {
// ...
}
您可以将响应转换为字典并尝试从中获取值。使用通用对象而不是静态数据模型,您可以通过响应传递更多信息。
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());
}
}