【发布时间】:2019-02-10 05:42:54
【问题描述】:
我正在尝试通过 Windows 窗体应用程序(使用 C#)与我的聊天机器人进行通信。我已将 SDK 安装到 Visual Studio 中,但我无法使用它。我已经阅读了所有文档,包括 GitHub 上的文档,但是,因为这是我第一次使用 SDK,我对如何让它工作感到很困惑。此时,我只是希望能够发送“消息”并阅读聊天机器人的响应。
我必须包含哪些命名空间(即"using IBM.Watson...")?因为我尝试过身份验证但收到错误:"namespace AssistantService could not be found",根据 GitHub 上 dotnet 指南中的 IAM 身份验证。另外,什么是"_assistant" 对象以及如何创建一个对象,文档没有解释这一点,所以我不断收到错误"_assistant does not exist in the current context..."
这是我关注的 SDK 的链接:https://github.com/watson-developer-cloud/dotnet-standard-sdk
我正在尝试使用该链接上的说明进行身份验证,但没有成功。我正在尝试使用这些说明来调用 Watson Assistant:https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.Assistant.v1
****************更新******************
using System.Windows.Forms;
using IBM.WatsonDeveloperCloud.Assistant.v1.Model;
using IBM.WatsonDeveloperCloud.Assistant.v1;
using IBM.WatsonDeveloperCloud.Util;
namespace Watson_Assistant_Test
{
public partial class Form1 : Form
{
AssistantService _assistant;
string[] _questionArray = { "Hello there" };
public Form1()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamApiKey = "Y....H",
IamUrl = "https://gateway-syd.watsonplatform.net/assistant/api"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "2018-07-10");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageRequest messageRequest = new MessageRequest()
{
Input = new InputData()
{
Text = _questionArray[0]
}
};
var result = _assistant.Message("d...5", messageRequest);
label1.Text = result.ResponseJson.ToString();
}
}
}
我认为我仍然没有正确创建 AssistantObject。我收到此错误:ServiceResponseException: The API query failed with status code NotFound: Not Found。
谢谢,哈利
【问题讨论】:
标签: c# ibm-cloud ibm-watson watson-conversation