public ActionResult SearchFormLuisPost(string id, string db, string language, string query) { var appId = Settings.ApplicationId(Settings.IntelligentSearchItemId); if (appId == Guid.Empty) { return(Json(new { Failed = false })); } //call luis var luisResult = !string.IsNullOrWhiteSpace(query) ? LuisService.Query(appId, query, true) : null; var dialogPhrase = GetPhrase(luisResult, new List <string> { "Noun", "Adjective", "Verb", "Adverb", "Preposition" }); var knowledgePanel = BuildKnowledgePanel(luisResult, dialogPhrase); var contextParams = new ItemContextParameters { Database = db, Id = id, Language = language }; var conversationContext = ConversationContextFactory.Create( appId, Translator.Text("Chat.Clear"), Translator.Text("Chat.ConfirmMessage"), "decision - yes", "decision - no", "frustrated", "quit", contextParams, luisResult); var response = LuisConversationService.ProcessUserInput(conversationContext); //return result return(Json(new { Failed = false, KnowledgePanel = knowledgePanel, Response = response, SearchPhrase = GetPhrase(luisResult, new List <string> { "Noun", "Adjective" }), SpellCorrected = luisResult.AlteredQuery })); }
public ConversationResponse HandleMessage(Activity activity, ItemContextParameters parameters) { IConversation conversation = (ConversationHistory.Conversations.Any()) ? ConversationHistory.Conversations.Last() : null; var inConversation = conversation != null && !conversation.IsEnded; // determine which intent user wants and context var result = LuisService.Query(AppId, activity.Text); var requestedQuit = result.TopScoringIntent.Intent.ToLower().Equals("quit") && result.TopScoringIntent.Score > 0.4; var intent = IntentProvider.GetIntent(AppId, result.TopScoringIntent.Intent); // if the user is trying to end or finish a conversation if (inConversation && requestedQuit) { conversation.IsEnded = true; return(intent.Respond(null, null, null)); } // start a new conversation if not in one if (!inConversation && intent != null && result.TopScoringIntent.Score > 0.4) { conversation = ConversationFactory.Create(result, intent); ConversationHistory.Conversations.Add(conversation); inConversation = true; } if (inConversation) { // check and request all required parameters of a conversation foreach (ConversationParameter p in conversation.Intent.RequiredParameters) { if (!TryGetParam(p.ParamName, result, conversation, parameters, p.ParamGetter)) { return(RequestParam(p, conversation, parameters)); } } conversation.IsEnded = true; return(conversation.Intent.Respond(result, parameters, conversation)); } // determine mood of comment var sentiment = GetSentiment(activity.Text); var sentimentScore = (sentiment?.Documents != null && sentiment.Documents.Any()) ? sentiment.Documents.First().Score : 1; // is a user frustrated or is their intention unclear return((sentimentScore <= 0.4) ? IntentProvider.GetIntent(AppId, "frustrated user").Respond(null, null, null) : IntentProvider.GetDefaultResponse(AppId)); }
public ActionResult Post([FromBody] Activity activity) { var s = JsonConvert.SerializeObject(activity.ChannelData); var d = JsonConvert.DeserializeObject <List <string> >(s); ItemContextParameters parameters = (d.Any()) ? JsonConvert.DeserializeObject <ItemContextParameters>(d[0]) : new ItemContextParameters(); if (activity.Type != ActivityTypes.Message) { return(null); } var result = !string.IsNullOrWhiteSpace(activity.Text) ? LuisService.Query(ChatSettings.OleApplicationId, activity.Text, true) : null; var conversationContext = ConversationContextFactory.Create( ChatSettings.OleApplicationId, Translator.Text("Chat.Clear"), Translator.Text("Chat.ConfirmMessage"), "decision - yes", "decision - no", "frustrated", "profile user - quit", parameters, result); var conversation = conversationContext.GetCurrentConversation(); var inConversation = conversation?.IsEnded ?? false; var isQuestion = result.Query.Split(new char[] { ' ' }).Take(2).Any(a => QuestionWords.Contains(a)); var response = (!inConversation && isQuestion) ? IntentProvider.GetIntent(ChatSettings.OleApplicationId, "self - websearch").Respond(result, parameters, conversation); : LuisConversationService.ProcessUserInput(conversationContext); var newMessage = Regex.Replace(response.Message, "<.*?>", " "); var relativePath = $"temp\\ole-{CreateMD5Hash(newMessage)}.mp3"; var filePath = $"{Request.PhysicalApplicationPath}{relativePath}"; var locale = SpeechLocaleOptions.enUS; var voice = VoiceName.EnUsGuyNeural; var gender = GenderOptions.Male; var audioFormat = AudioOutputFormatOptions.Audio24Khz160KBitRateMonoMp3; SpeechService.TextToFile(newMessage, filePath, locale, voice, gender, audioFormat); var reply = activity.CreateReply(response.Message, "en-US"); reply.ChannelData = new ChannelData { Input = response.Input, Selections = response.Selections?.ToDictionary(a => a.Key, b => b.Value.DisplayName) ?? null, Action = response.Action, AudioFile = $"\\{relativePath}" }; return(Json(reply)); }
public bool QueryOle() { var response = LuisService.Query(OleSettings.OleApplicationId, OleSettings.TestMessage); if (response == null) { return(false); } return(true); }
public async Task <RecognitionResult> Process(string message) { try { var recognitionIntents = await _luisService.Query(message); var intent = recognitionIntents.Intents.OrderByDescending(x => x.Score).FirstOrDefault(); if (CheckIntentScore(intent)) { return(await _intentService.Execute(intent?.Name, recognitionIntents.Entities)); } } catch (Exception ex) { _logger.LogError(ex, "An exception has been caught"); } return(await _intentService.Execute(string.Empty, null)); }