public async Task <string> GetTips(LUISModel model, string fromUser, string toUser) { Intent[] maxscore_intent = await GetTipIntent(model.query); int count = maxscore_intent.Count(); string infoStr = string.Format(ReplyType.Message_News_Item, BotParameters.WEIXIN_TITLE, BotParameters.WEIXIN_TITLE, BotParameters.WEIXIN_PICURL, BotParameters.WEIXIN_MAINURL); int cnt = 1; for (int i = 0; i < count; i++) { if (maxscore_intent[i] != null) { infoStr += GetKB(maxscore_intent[i].intent); cnt++; if (cnt > BotParameters.max_intent_display) { break; } } } string responseContent = string.Format(ReplyType.Message_News_Main, fromUser, toUser, DateTime.Now.Ticks, cnt.ToString(), infoStr); return(responseContent); }
public async Task <Intent[]> GetTipIntent(string Query) { int model_count = BotParameters.LUIS_model_count; LUISModel[] models = new LUISModel[model_count - 1]; // start from 1, 0 = main model for (int m = 0; m < model_count - 1; m++) { models[m] = await GetModel(BotParameters.LUIS_model_Ids[m], BotParameters.LUIS_sub_key, Query); } Intent[] score_intent = new Intent[LUISModel.MAX_INTENT * 4]; int i = 0; for (int m = 0; m < model_count - 1; m++) { foreach (Intent intent in models[m].intents) { if (intent.score > BotParameters.model_threshold && intent.intent != "None") { score_intent[i++] = intent; } } } //Array.Sort(score_intent); return(score_intent); }
//接受文本消息 public async Task <string> TextHandle(XmlDocument xmldoc) { string responseContent = ""; XmlNode ToUserName = xmldoc.SelectSingleNode("/xml/ToUserName"); XmlNode FromUserName = xmldoc.SelectSingleNode("/xml/FromUserName"); XmlNode Content = xmldoc.SelectSingleNode("/xml/Content"); // MessageDBLog(xmldoc, false, null); if (Content != null) { string returnString; LuisHelp cognitive = new weixin_bot.LuisHelp(); LUISModel model = await LuisHelp.GetEntityFromLUIS(Content.InnerText); if (model.intents.Count() > 0) { Intent maxscore_intent = model.intents.Max(); switch (maxscore_intent.intent) { case "Tips": returnString = await cognitive.GetTips(model, FromUserName.InnerText, ToUserName.InnerText); return(returnString); default: if (BotParameters.use_binsearch) { returnString = await cognitive.GetBingSearch(Content.InnerText, BotParameters.WEIXIN_TITLE, BotParameters.WEIXIN_DEFAULTMSG, FromUserName.InnerText, ToUserName.InnerText); } else { returnString = cognitive.GetTunling123(Content.InnerText, BotParameters.WEIXIN_TITLE, BotParameters.WEIXIN_DEFAULTMSG, FromUserName.InnerText, ToUserName.InnerText); } return(returnString); } } else { returnString = BotParameters.WEIXIN_DEFAULTMSG; } responseContent = string.Format(ReplyType.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, returnString); } return(responseContent); }
public async Task <LUISModel> GetModel(string appId, string subKey, string Query) { Query = Uri.EscapeDataString(Query); LUISModel Model = new LUISModel(); using (HttpClient client = new HttpClient()) { string RequestURI = "https://api.projectoxford.ai/luis/v1/application?id=" + appId + "&subscription-key=" + subKey + "&q=" + Query; HttpResponseMessage msg = await client.GetAsync(RequestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); Model = JsonConvert.DeserializeObject <LUISModel>(JsonDataResponse); } } return(Model); }
public static async Task <LUISModel> GetEntityFromLUIS(string Query) { string appId = BotParameters.LUIS_app_Id; string subKey = BotParameters.LUIS_sub_key; Query = Uri.EscapeDataString(Query); LUISModel Data = new LUISModel(); using (HttpClient client = new HttpClient()) { string RequestURI = "https://api.projectoxford.ai/luis/v1/application?id=" + appId + "&subscription-key=" + subKey + "&q=" + Query; HttpResponseMessage msg = await client.GetAsync(RequestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); Data = JsonConvert.DeserializeObject <LUISModel>(JsonDataResponse); } } return(Data); }