IBM Watson Assistant:为什么 "Try It" 给我正确的结果,但我的客户端代码却没有?

IBM Watson Assistant: Why is "Try It" giving me the correct results but my client code is not?

我在 Watson Assistant 中创建了一个聊天机器人(请参阅随附的工作区文件)。在 "try it" 中它给出了正确的结果。

我已经创建了一个客户端应用程序来使用 ASP.NET Core 使用此聊天。在那里,我正在保存上下文。不过,我得到的结果与 "try it".

不同

模拟问题的步骤:

me: Hello

reply from watson: Hello, please enter your Supplier Number for authentication.

me: 135587-1239848

reply from watson: For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [135587-1239848]. Please enter the 6 digit OTP number

me: 121212

reply from watson: Welcome Richie. I am Shery from EXL. How can I help you today?

me: where is my invoice ?

reply from watson: Sure Richie, I can help with that! Can you please provide the Invoice number?

直到第 8 步,"try it" 和 ASP.NET 核心客户端应用程序 return 的结果相同。但是在第 8 步,我的客户端应用程序再次显示 "For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [135587-1239848]. Please enter the 6 digit OTP number" 而不是 Sure Richie,我可以提供帮助!能否请您提供发票号码?

求推荐。附上 asp.net 代码 (WatsonAPI.txt) 以及我传递给 WATSON 的内容 API.

public string CallConversation(string input)
        {
            if (_conversation == null)
            {
                //_conversation = new ConversationService(_username.ToString(), _password.ToString(), "2018-05-16");
                _conversation = new ConversationService(_username.ToString(), _password.ToString(), "2018-02-16");
                _conversation.Endpoint = _url.ToString();

                _workspaceID = _workspaceID.ToString();
            }

            MessageRequest messageRequest = new MessageRequest()
            {
                Input = new InputData()
                {
                    //Text = _questionArray[questionIndex]
                    Text = input//Console.ReadLine()
                },
                AlternateIntents = true
            };

            // if (_questionContext != null)
            if (Session["Context"] != null)
            {
                _questionContext = (dynamic)Session["Context"];
                messageRequest.Context = new Context();
                messageRequest.Context.ConversationId = _questionContext.conversation_id;
                messageRequest.Context.System = _questionContext.system;
            }

            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var result = _conversation.Message(_workspaceID, messageRequest);
            //Console.WriteLine(string.Format("result: {0}", JsonConvert.SerializeObject(result, Formatting.Indented)));



            string strResult = "";
            if (((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)result.Output).First) != null)
                strResult = string.Format(((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)result.Output).First).Value.ToString().Replace(Environment.NewLine, ""));
            //int intstart =  strResult.IndexOf('"');


            //Console.WriteLine(strResult.Replace("[", "").Replace("]", "").Replace("\"", "").Trim());

            string strOutput = strResult.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();


            if (strResult.Contains("Welcome Richie. I am Shery from EXL."))
            {
                strOutput = "Welcome " + Convert.ToString(Session["supplierName"]) + ". I am Shery from EXL. How can I help you today?";
            }
            if (strResult.Contains("I have sent an One Time Password (OTP) to your registered mobile number for supplier "))
            {
                List<string> lstInvoicedetais = new List<string>();
                lstInvoicedetais = strResult.Split('[').ToList<string>();

                supplierNumber = lstInvoicedetais[2].ToString();
                lstInvoicedetais = supplierNumber.Split(']').ToList<string>();
                supplierNumber = lstInvoicedetais[0].ToString();


                supplierName = ValidateSupplierByNumber(supplierNumber);

                if (string.IsNullOrEmpty(supplierName))
                {
                    strOutput = "Invalid Supplier number [" + supplierNumber + "]. Please enter correct supplier number.";

                    result.Context.supplierNumber = "0";
                    //_questionContext.supplierNumber = "";
                    setContext = false;
                    Session["supplierNumber"] = null;
                    Session["supplierName"] = null;

                }
                else
                {
                    Session["supplierNumber"] = supplierNumber;
                    Session["supplierName"] = supplierName;
                    //strOutput = "Invalid Supplier number [" + supplierName + "]. Please enter correct supplier number.";
                }
            }
            if (strResult.Contains("Sure Richie, I can help with that! Can you please provide the Invoice number?"))
            {
                strOutput = strOutput.Replace("Richie", Convert.ToString(Session["supplierName"]));
                //strOutput = strResult;
            }
            if (strResult.Contains("Let me fetch the details you requested for Invoice"))
            {

                //List<chatSummary> lstChatSummary = new List<chatSummary>();
                //lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];

                //lstChatSummary.Add(new chatSummary()
                //{
                //    ByUser = "User: ",
                //    Message = strResult
                //});

                //Session["lstChatSummary"] = lstChatSummary;
                //AddRowtoTable("User:", strResult);


                strValue.Append(Environment.NewLine + "Bot: " + strOutput.ToString());
                //textBox1.Text = strValue.ToString();

                //textBox1.Text = string.Empty;
                //textBox1.AppendText(strValue.ToString());


                string strMessage = string.Empty;

                invoiceNumber = SearchbyInvoice(strResult, (string)Session["supplierNumber"], out strMessage);

                List<chatSummary> lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];
                if (strMessage != string.Empty)
                {
                    lstChatSummary.Add(new chatSummary()
                    {
                        ByUser = "BOT: ",
                        Message = strMessage
                    });
                }
                strMessage = "Hope I provided the information you are looking for. Is there anything else that I can help you ?";

                strOutput = strMessage;
            }
            if (strResult.Contains("Please provide Invoice Amount for the invoice Dated"))
            {
                List<string> lstInvoicedetais = new List<string>();
                lstInvoicedetais = strResult.Split('[').ToList<string>();

                invoiceDate = lstInvoicedetais[2].ToString();
                lstInvoicedetais = invoiceDate.Split(']').ToList<string>();
                invoiceDate = lstInvoicedetais[0].ToString();

                SearchbyInvoiceDate(invoiceDate, supplierNumber, out string strMessage);

                List<chatSummary> lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];
                if (strMessage != string.Empty)
                {
                    lstChatSummary.Add(new chatSummary()
                    {
                        ByUser = "BOT: ",
                        Message = strMessage
                    });
                }
                strMessage = "Hope I provided the information you are looking for. Is there anything else that I can help you ?";
                strOutput = strMessage;

                //strOutput = "Commeted above";

            }
            if (strResult.Contains("Searching for the invoice with invoice date"))
            {
                strValue.Append(Environment.NewLine + "Bot: " + strOutput.ToString());
                //textBox1.Text = strValue.ToString();

                //textBox1.Text = string.Empty;
                //textBox1.AppendText(strValue.ToString());

                List<string> lstInvoicedetais = new List<string>();
                lstInvoicedetais = strResult.Split('[').ToList<string>();

                invoiceAmt = lstInvoicedetais[3].ToString();
                lstInvoicedetais = invoiceAmt.Split(']').ToList<string>();
                invoiceAmt = lstInvoicedetais[0].ToString();
            }
            _questionIndex++;

            if (setContext == true)
            {
                _questionContext = result.Context;
                Session["Context"] = result.Context;
            }
            else
            {
                setContext = true;
            }



            //if (questionIndex < 100)
            //    CallConversation(_questionIndex);

            return strOutput;
        }

{"name":"Test_VendorEnquiry","intents":[{"intent":"Notavailable","examples":[{"text":"I don�t know"},{"text":"I am not sure"},{"text":"I don�t have it"},{"text":"I do not know"},{"text":"I do not have it"},{"text":"not sure"}],"description":null},{"intent":"Invoice_Status","examples":[{"text":"Let me know status of my inovice"},{"text":"I want to know my invoice status"},{"text":"I want to know status of my Invoice"},{"text":"what is my invoice status"},{"text":"Let me know status of my invoice ?"},{"text":"where is my invoice ?"},{"text":"In what state my invoice is ?"},{"text":"Is my invoice is processed ?"}],"description":null},{"intent":"greetings","examples":[{"text":"hi"},{"text":"hi how are u"},{"text":"hi there"},{"text":"Hi watson"},{"text":"hiya"},{"text":"Hola"},{"text":"I am not feeling good"},{"text":"howdy"},{"text":"How are you doing?"},{"text":"yo"},{"text":"yello"},{"text":"namaste"},{"text":"hola como estas"},{"text":"Its not that good"},{"text":"I'm feeling good thanks"},{"text":"greetings"},{"text":"aloha"},{"text":"bad"},{"text":"bonjour"},{"text":"buenos dias"},{"text":"ciao"},{"text":"feeling bit low"},{"text":"g'day"},{"text":"good"},{"text":"good day"},{"text":"good evening"},{"text":"good how are you"},{"text":"good morning"},{"text":"Hello"},{"text":"Hello, how are you?"},{"text":"Hello Watson"},{"text":"hey"},{"text":"heya"},{"text":"hey there"}],"description":null},{"intent":"goodbyes","examples":[{"text":"adieu"},{"text":"gotta go"},{"text":"good night"},{"text":"good day"},{"text":"good bye"},{"text":"goodbye"},{"text":"farewell"},{"text":"cya"},{"text":"bye now"},{"text":"bye bye"},{"text":"BYE"},{"text":"au revoir"},{"text":"adios"},{"text":"gtg"},{"text":"have to go"},{"text":"have to leave"},{"text":"have to run"},{"text":"I'm leaving"},{"text":"later"},{"text":"laters"},{"text":"logging off"},{"text":"my time is up"},{"text":"need to go"},{"text":"need to leave"},{"text":"need to run"},{"text":"ok bye"},{"text":"out of time"},{"text":"over and out"},{"text":"see ya"},{"text":"see ya later"},{"text":"see ya soon"},{"text":"see you"},{"text":"see you later"},{"text":"see you soon"},{"text":"should be going"},{"text":"should go"},{"text":"signing off"},{"text":"signing out"},{"text":"so long"},{"text":"thanks watson"},{"text":"thank you for your help"},{"text":"then bye"},{"text":"time to go"},{"text":"toodles"},{"text":"got to go"},{"text":"gotta run"}],"description":null}],"entities":[{"entity":"OTPNumber","values":[{"type":"patterns","value":"OTPNumber","metadata":null,"patterns":["(\d{6})"]}],"metadata":null,"description":null},{"entity":"sys-person","values":[],"metadata":null,"description":null},{"entity":"sys-time","values":[],"metadata":null,"description":null},{"entity":"InvoiceNumformat","values":[{"type":"patterns","value":"invoiceNumFormat","metadata":null,"patterns":["^[a-zA-Z0-9]+$"]}],"metadata":null,"description":null},{"entity":"sys-date","values":[],"metadata":null,"description":null},{"entity":"sys-percentage","values":[],"metadata":null,"description":null},{"entity":"sys-currency","values":[],"metadata":null,"description":null},{"entity":"sys-number","values":[],"metadata":null,"description":null},{"entity":"sys-location","values":[],"metadata":null,"description":null},{"entity":"supplierNumber","values":[{"type":"patterns","value":"suppNumber","metadata":null,"patterns":["(\d{6})-(\d{7})","(\d{5})-(\d{6})","(\d{6})-(\d{6})","(\d{5})-(\d{7})","(\d{4})-(\d{7})"]}],"metadata":null,"description":null,"fuzzy_match":true}],"language":"en","metadata":{"api_version":{"major_version":"v1","minor_version":"2017-05-26"}},"description":"","dialog_nodes":[{"type":"standard","title":"Send OTP for Supplier","output":{"text":{"values":["For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [$supplierNumber]. Please enter the 6 digit OTP number"],"selection_policy":"sequential"}},"parent":"node_1_1533652772745","context":{"supplierNumber":"<? input.text ?>"},"metadata":{},"next_step":null,"conditions":"@supplierNumber","description":null,"dialog_node":"node_2_1533653340211","previous_sibling":null},{"type":"standard","title":"If invoice date is not avilable","output":{"text":{"values":["Need to have at least Invoice Number or Invoice Date."],"selection_policy":"sequential"}},"parent":"node_5_1533723730779","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_9_1533723922103","previous_sibling":"node_6_1533723769818"},{"type":"standard","title":"Search with Invoice date & Invoice Amount","output":{"text":{"values":["Please provide Invoice Amount for the invoice Dated [$InvoiceDate]."],"selection_policy":"sequential"}},"parent":"node_5_1533723730779","context":{"InvoiceDate":"@sys-date"},"metadata":{},"next_step":null,"conditions":"@sys-date","description":null,"dialog_node":"node_6_1533723769818","previous_sibling":null},{"type":"standard","title":"If invoice number is not there","output":{"text":{"values":["Please provide Invoice Date ?"],"selection_policy":"sequential"}},"parent":"node_3_1533653519184","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_5_1533723730779","previous_sibling":"node_4_1533723673094"},{"type":"standard","title":"Search with Invoice Number","output":{"text":{"values":["Let me fetch the details you requested for Invoice [$InvoiceNumber] . Please hold on for a moment..."],"selection_policy":"sequential"}},"parent":"node_3_1533653519184","context":null,"metadata":{},"next_step":null,"conditions":"@InvoiceNumformat","description":null,"dialog_node":"node_4_1533723673094","previous_sibling":null},{"type":"standard","title":"Search with Invoice Date and Amount","output":{"text":{"values":["Searching for the invoice with invoice date [$InvoiceDate] with amount [$InvoiceAmount]. Please wait..."],"selection_policy":"sequential"}},"parent":"node_6_1533723769818","context":{"InvoiceAmount":"@sys-currency"},"metadata":{},"next_step":null,"conditions":"@sys-currency","description":null,"dialog_node":"node_8_1533723852451","previous_sibling":"node_7_1533723817717"},{"type":"standard","title":"If invoice amount is not available","output":{"text":{"values":["Need to have both Invoice amount and Invoice Date to search invoice status. So please let us know Invoice Number or Invoice Date."],"selection_policy":"sequential"}},"parent":"node_6_1533723769818","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_7_1533723817717","previous_sibling":null},{"type":"standard","title":"Enter OTP and proceed with Invoice Search","output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":"node_2_1533653340211","context":{"SupplierValidated":"True"},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_3_1533653519184"},"conditions":"@OTPNumber && $InvoiceStatusRequested==2","description":null,"dialog_node":"node_4_1533714921647","previous_sibling":"node_2_1533714230483"},{"type":"standard","title":"Enter OTP and ask what user wants to know","output":{"text":{"values":["Welcome Richie. I am Shery from EXL. How can I help you today?"],"selection_policy":"sequential"}},"parent":"node_2_1533653340211","context":{"SupplierValidated":"True"},"metadata":{},"next_step":null,"conditions":"@OTPNumber && $supplierNumber!=0 && $InvoiceStatusRequested!=2","description":null,"dialog_node":"node_2_1533714230483","previous_sibling":null},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_1_1533652772745"},"conditions":"#Invoice_Status && $supplierNumber:0","description":null,"dialog_node":"node_1_1533800680816","previous_sibling":"node_1_1533652772745"},{"type":"standard","title":"Vendor Validation","output":{"text":{"values":["Hello, please enter your Supplier Number for authentication.","please provide your Supplier Number to assist you better."],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"#greetings && $supplierNumber:0","description":null,"dialog_node":"node_1_1533652772745","previous_sibling":"node_1_1533713219851"},{"type":"standard","title":"Vendor already Validated","output":{"text":{"values":["Sure Richie, I can help with that! Can you please provide the Invoice number?"],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":null,"conditions":"#Invoice_Status && $supplierNumber!=0 && $SupplierValidated==\"True\"","description":null,"dialog_node":"node_3_1533653519184","previous_sibling":"node_1_1533800680816"},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":{"behavior":"jump_to","selector":"condition","dialog_node":"node_2_1533653340211"},"conditions":"$supplierNumber:0 && @supplierNumber","description":null,"dialog_node":"node_5_1533715230884","previous_sibling":"Welcome"},{"type":"standard","title":"Goodbye","output":{"text":{"values":["Thank you. Good day"],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"#goodbyes","description":null,"dialog_node":"node_10_1533724000756","previous_sibling":"node_3_1533653519184"},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_1_1533652772745"},"conditions":"#greetings && $supplierNumber!=0","description":null,"dialog_node":"node_1_1533713219851","previous_sibling":"node_1_1533722523080"},{"type":"standard","title":"Anything else","output":{"text":{"values":["I didn't understand. You can try rephrasing.","Can you reword your statement? I'm not understanding.","I didn't get your meaning."],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"anything_else","description":null,"dialog_node":"Anything else","previous_sibling":"node_10_1533724000756"},{"type":"standard","title":"Validate OTP if not entered","output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_2_1533653340211"},"conditions":"$supplierNumber!=0 && $SupplierValidated!=\"True\" && #Invoice_Status","description":null,"dialog_node":"node_1_1533722523080","previous_sibling":"node_5_1533715230884"},{"type":"standard","title":"Welcome","output":{"text":{"values":["Hi, welcome to EXL Vendor Information Portal. Can you please provide your Supplier Number so that I can assist you better"],"selection_policy":"sequential"}},"parent":null,"context":{"supplierNumber":0,"SupplierValidated":"False","InvoiceStatusRequested":0},"metadata":{},"next_step":null,"conditions":"welcome","description":null,"dialog_node":"Welcome","previous_sibling":null}],"workspace_id":"ea8429e3-5eaa-4e94-935a-916bf3a769be","counterexamples":[],"system_settings":null,"learning_opt_out":false}

一些评论:

  • 您的客户端应用程序是否使用 same API version as the "Try it"
  • 在您的应用程序中检查准确的响应是一种糟糕的编程风格。如果您更改 Watson Assistant 中的响应或支持多种语言,会发生什么情况?使用意图和 placeholders 的组合。它也更快。
  • 您真的发回所有上下文变量以正确处理对话节点的条件吗? OTPNumber 是如何检查的?您的应用程序是否缺少它?