IBM Watson Unity 3D SDK 保护服务(即将运行!)
IBM Watson Unity 3D SDK Conservation Service (Almost working!)
在服务示例中找到了一个有效的对话脚本。再次感谢@Taj!
我觉得我非常非常接近让它发挥作用。我用 TJBot 在 Raspberry Pi 上做了同样的事情,所以我拥有所有帐户,并且我正确链接了所有凭据,包括来自 Conversation 工具的工作场所 ID。我正在使用 Unity 3D 5.5.1f1 和最新的 SDK,这是 13 天前更新的。
我将 SDK github 页面上的对话示例代码复制并粘贴到一个全新的 C# 文件中:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
public class test : MonoBehaviour {
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID = "my ID on the conversation tooling site";
private string m_Input = "Hi Alex";
// Use this for initialization
void Start () {
Debug.Log("User: " + m_Input);
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input);
}
// Update is called once per frame
void Update () {
}
void OnMessage(MessageResponse resp, string customData)
{
//Parsing resp here
//foreach (Intent mi in resp.intents)
//Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
//resp.output.text causes an error
}
}
在摸索的过程中,发现onMessage函数少了一个参数(string customData),是在朋友的帮助下加上去的。
问题第二部分:
感谢Taj 单手回答了我所有的问题!这有助于我找到问题的核心,它就在这里。我已经更新了上面的代码,以反映我在基于 IBM github 页面上提供的示例代码块的对话服务实现中所拥有的内容。
https://github.com/watson-developer-cloud/unity-sdk#conversation
Watson/Scripts/Services/conversation.cs 文件中的 Message 函数如下所示:
/// <summary>
/// Message the specified workspaceId, input and callback.
/// </summary>
/// <param name="workspaceID">Workspace identifier.</param>
/// <param name="input">Input.</param>
/// <param name="callback">Callback.</param>
/// <param name="customData">Custom data.</param>
public bool Message(OnMessage callback, string workspaceID, string input, string customData = default(string))
{
if (string.IsNullOrEmpty(workspaceID))
throw new ArgumentNullException("workspaceId");
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");
if (callback == null)
throw new ArgumentNullException("callback");
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
if (connector == null)
return false;
string reqJson = "{{\"input\": {{\"text\": \"{0}\"}}}}";
string reqString = string.Format(reqJson, input);
MessageReq req = new MessageReq();
req.Callback = callback;
req.Headers["Content-Type"] = "application/json";
req.Headers["Accept"] = "application/json";
req.Parameters["version"] = Version.VERSION;
req.Function = "/" + workspaceID + "/message";
req.Data = customData;
req.Send = Encoding.UTF8.GetBytes(reqString);
req.OnResponse = MessageResp;
return connector.Send(req);
}
我调用的时候返回true,但是之后没有任何反应,没有回调=/。
非常感谢您提供任何提示!请帮忙!
响应字符串是 resp 对象中的一个数组。
void OnMessage(MessageResponse resp, string customData)
{
foreach (Intent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
if (resp.output != null && resp.output.text.Length > 0)
foreach (string txt in resp.output.text)
Debug.Log("Output: " + txt);
}
在服务示例中找到了一个有效的对话脚本。再次感谢@Taj!
我觉得我非常非常接近让它发挥作用。我用 TJBot 在 Raspberry Pi 上做了同样的事情,所以我拥有所有帐户,并且我正确链接了所有凭据,包括来自 Conversation 工具的工作场所 ID。我正在使用 Unity 3D 5.5.1f1 和最新的 SDK,这是 13 天前更新的。
我将 SDK github 页面上的对话示例代码复制并粘贴到一个全新的 C# 文件中:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
public class test : MonoBehaviour {
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID = "my ID on the conversation tooling site";
private string m_Input = "Hi Alex";
// Use this for initialization
void Start () {
Debug.Log("User: " + m_Input);
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input);
}
// Update is called once per frame
void Update () {
}
void OnMessage(MessageResponse resp, string customData)
{
//Parsing resp here
//foreach (Intent mi in resp.intents)
//Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
//resp.output.text causes an error
}
}
在摸索的过程中,发现onMessage函数少了一个参数(string customData),是在朋友的帮助下加上去的。
问题第二部分:
感谢Taj 单手回答了我所有的问题!这有助于我找到问题的核心,它就在这里。我已经更新了上面的代码,以反映我在基于 IBM github 页面上提供的示例代码块的对话服务实现中所拥有的内容。 https://github.com/watson-developer-cloud/unity-sdk#conversation
Watson/Scripts/Services/conversation.cs 文件中的 Message 函数如下所示:
/// <summary>
/// Message the specified workspaceId, input and callback.
/// </summary>
/// <param name="workspaceID">Workspace identifier.</param>
/// <param name="input">Input.</param>
/// <param name="callback">Callback.</param>
/// <param name="customData">Custom data.</param>
public bool Message(OnMessage callback, string workspaceID, string input, string customData = default(string))
{
if (string.IsNullOrEmpty(workspaceID))
throw new ArgumentNullException("workspaceId");
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");
if (callback == null)
throw new ArgumentNullException("callback");
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
if (connector == null)
return false;
string reqJson = "{{\"input\": {{\"text\": \"{0}\"}}}}";
string reqString = string.Format(reqJson, input);
MessageReq req = new MessageReq();
req.Callback = callback;
req.Headers["Content-Type"] = "application/json";
req.Headers["Accept"] = "application/json";
req.Parameters["version"] = Version.VERSION;
req.Function = "/" + workspaceID + "/message";
req.Data = customData;
req.Send = Encoding.UTF8.GetBytes(reqString);
req.OnResponse = MessageResp;
return connector.Send(req);
}
我调用的时候返回true,但是之后没有任何反应,没有回调=/。
非常感谢您提供任何提示!请帮忙!
响应字符串是 resp 对象中的一个数组。
void OnMessage(MessageResponse resp, string customData)
{
foreach (Intent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
if (resp.output != null && resp.output.text.Length > 0)
foreach (string txt in resp.output.text)
Debug.Log("Output: " + txt);
}