/// <summary> /// Creates a QnAMaker dialog for the correct locale if it's not already present on the dialog stack. /// Virtual method enables test mock scenarios. /// </summary> /// <param name="knowledgebaseId">Knowledgebase Identifier.</param> /// <param name="cognitiveModels">CognitiveModelSet configuration information.</param> /// <returns>QnAMakerDialog instance.</returns> protected virtual QnAMakerDialog TryCreateQnADialog(string knowledgebaseId, CognitiveModelSet cognitiveModels) { if (!cognitiveModels.QnAConfiguration.TryGetValue(knowledgebaseId, out QnAMakerEndpoint qnaEndpoint) || qnaEndpoint == null) { throw new Exception($"Could not find QnA Maker knowledge base configuration with id: {knowledgebaseId}."); } // QnAMaker dialog already present on the stack? if (Dialogs.Find(knowledgebaseId) == null) { return(new QnAMakerDialog( knowledgeBaseId: qnaEndpoint.KnowledgeBaseId, endpointKey: qnaEndpoint.EndpointKey, hostName: qnaEndpoint.Host, noAnswer: _templateManager.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateManager.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateManager.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebaseId }); } else { return(null); } }
protected override QnAMakerDialog TryCreateQnADialog(string knowledgebaseId, CognitiveModelSet cognitiveModels) { if (!cognitiveModels.QnAConfiguration.TryGetValue(knowledgebaseId, out QnAMakerEndpoint qnaEndpoint) || qnaEndpoint == null) { throw new Exception($"Could not find QnA Maker knowledge base configuration with id: {knowledgebaseId}."); } // QnAMaker dialog already present on the stack? if (Dialogs.Find(knowledgebaseId) == null) { // Return a QnAMaker dialog using our Http Mock return(new QnAMakerDialog( knowledgeBaseId: qnaEndpoint.KnowledgeBaseId, endpointKey: qnaEndpoint.EndpointKey, hostName: qnaEndpoint.Host, noAnswer: _templateManager.GenerateActivityForLocale("UnsupportedMessage"), httpClient: new HttpClient(_mockHttpHandler)) { Id = knowledgebaseId }); } else { return(null); } }
public BotServices(BotSettings settings) { foreach (var pair in settings.CognitiveModels) { var set = new CognitiveModelSet(); var language = pair.Key; var config = pair.Value; var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); set.DispatchService = new LuisRecognizer(dispatchApp); if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp)); } } foreach (var kb in config.Knowledgebases) { var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = kb.KbId, EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint); set.QnAServices.Add(kb.Id, qnaMaker); } CognitiveModelSets.Add(language, set); } }
public BotServices(BotSettings settings, IBotTelemetryClient client) { foreach (var pair in settings.CognitiveModels) { var set = new CognitiveModelSet(); var language = pair.Key; var config = pair.Value; var telemetryClient = client; LuisRecognizerOptionsV3 luisOptions; if (config.DispatchModel != null) { var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); luisOptions = new LuisRecognizerOptionsV3(dispatchApp) { TelemetryClient = telemetryClient, LogPersonalInformation = true, }; set.DispatchService = new LuisRecognizer(luisOptions); } if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); luisOptions = new LuisRecognizerOptionsV3(luisApp) { TelemetryClient = telemetryClient, LogPersonalInformation = true, PredictionOptions = new Microsoft.Bot.Builder.AI.LuisV3.LuisPredictionOptions() { IncludeInstanceData = true } }; set.LuisServices.Add(model.Id, new LuisRecognizer(luisOptions)); } } if (config.Knowledgebases != null) { foreach (var kb in config.Knowledgebases) { var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = kb.KbId, EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; set.QnAConfiguration.Add(kb.Id, qnaEndpoint); } } CognitiveModelSets.Add(language, set); } }
public BotServices(BotSettings settings, IBotTelemetryClient client) { foreach (var pair in settings.CognitiveModels) { var set = new CognitiveModelSet(); var language = pair.Key; var config = pair.Value; var telemetryClient = client; var luisOptions = new LuisPredictionOptions() { TelemetryClient = telemetryClient, LogPersonalInformation = true, SpellCheck = string.IsNullOrEmpty(settings.BingSpellCheckSubscriptionKey) ? false : true, BingSpellCheckSubscriptionKey = settings.BingSpellCheckSubscriptionKey }; if (config.DispatchModel != null) { var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); set.DispatchService = new LuisRecognizer(dispatchApp, luisOptions); } if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp, luisOptions)); } } if (config.Knowledgebases != null) { foreach (var kb in config.Knowledgebases) { var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = kb.KbId, EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint); set.QnAServices.Add(kb.Id, qnaMaker); } } CognitiveModelSets.Add(language, set); } }
// Runs when the dialog stack is empty, and a new message activity comes in. protected override async Task OnMessageActivityAsync(DialogContext innerDc, CancellationToken cancellationToken = default) { var activity = innerDc.Context.Activity.AsMessageActivity(); var userProfile = await _userProfileState.GetAsync(innerDc.Context, () => new UserProfileState()); if (!string.IsNullOrEmpty(activity.Text)) { // Get current cognitive models for the current locale. CognitiveModelSet localizedServices = _services.GetCognitiveModels(); // Get dispatch result from turn state. var dispatchResult = innerDc.Context.TurnState.Get <DispatchLuis>(StateProperties.DispatchResult); (var dispatchIntent, var dispatchScore) = dispatchResult.TopIntent(); // Check if the dispatch intent maps to a skill. var identifiedSkill = SkillRouter.IsSkill(_settings.Skills, dispatchIntent.ToString()); if (identifiedSkill != null) { // Start the skill dialog. await innerDc.BeginDialogAsync(identifiedSkill.Id); } else if (dispatchIntent == DispatchLuis.Intent.q_Faq) { await innerDc.BeginDialogAsync("Faq"); } else if (dispatchIntent == DispatchLuis.Intent.q_Chitchat) { innerDc.SuppressCompletionMessage(true); await innerDc.BeginDialogAsync("Chitchat"); } else if (dispatchIntent == DispatchLuis.Intent.q_HRBenefits) { innerDc.SuppressCompletionMessage(true); await innerDc.BeginDialogAsync("HRBenefits"); } else { innerDc.SuppressCompletionMessage(true); await innerDc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("UnsupportedMessage", userProfile)); } } }
public BotServices(BotSettings settings) { foreach (var pair in settings.CognitiveModels) { var set = new CognitiveModelSet(); var language = pair.Key; var config = pair.Value; var telemetryClient = new BotTelemetryClient(new TelemetryClient(settings.AppInsights)); var luisOptions = new LuisPredictionOptions() { TelemetryClient = telemetryClient, LogPersonalInformation = true, }; var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); set.DispatchService = new LuisRecognizer(dispatchApp, luisOptions); if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp, luisOptions)); } } foreach (var kb in config.Knowledgebases) { var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = kb.KbId, EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint, null, null, telemetryClient: telemetryClient, logPersonalInformation: true); set.QnAServices.Add(kb.Id, qnaMaker); } CognitiveModelSets.Add(language, set); } }