/// <summary>
        /// Gets an <see cref="IQnAMakerClient"/> to use to access the QnA Maker knowledge base.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <remarks>If the task is successful, the result contains the QnA Maker client to use.</remarks>
        protected async override Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
        {
            var qnaClient = dc.Context.TurnState.Get <IQnAMakerClient>();

            if (qnaClient != null)
            {
                // return mock client
                return(qnaClient);
            }

            var(epKey, _) = this.EndpointKey.TryGetValue(dc.State);
            var(hn, _)    = this.HostName.TryGetValue(dc.State);
            var(kbId, _)  = this.KnowledgeBaseId.TryGetValue(dc.State);
            var(logPersonalInformation, _) = this.LogPersonalInformation.TryGetValue(dc.State);

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey     = epKey,
                Host            = hn,
                KnowledgeBaseId = kbId
            };
            var options = await GetQnAMakerOptionsAsync(dc).ConfigureAwait(false);

            return(new QnAMaker(endpoint, options, this.HttpClient, this.TelemetryClient, (bool)logPersonalInformation));
        }
Example #2
0
        public FAQ2Dialog(string dialogId) : base(dialogId)
        {
            // ID of the child dialog that should be started anytime the component is started.
            this.InitialDialogId = dialogId;
            this.AddDialog(new ChoicePrompt("choicePrompt"));
            this.AddDialog(new TextPrompt(FAQPROMPT));

            var qnAMakerEndpoint = new QnAMakerEndpoint();

            qnAMakerEndpoint.EndpointKey     = "d519e1d0-972c-400b-90d7-a519b83f16b6";
            qnAMakerEndpoint.Host            = "https://itsbot.azurewebsites.net/qnamaker";
            qnAMakerEndpoint.KnowledgeBaseId = "b109859c-6e69-4971-9b37-2dcb77521552";

            qnaMaker = new QnAMaker(qnAMakerEndpoint);

            // Adds a waterfall dialog that prompts users with the top level menu to the dialog set.
            // Define the steps of the waterfall dialog and add it to the set.
            this.AddDialog(new WaterfallDialog(
                               dialogId,
                               new WaterfallStep[]
            {
                this.PromptForQuestion,
                this.AnswerQuestion
            }));
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <QnAMakerBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var qnaEndpoint = new QnAMakerEndpoint
                {
                    EndpointKey     = "xxxxxx",
                    KnowledgeBaseId = "xxxxxx",
                };

                var middleware = options.Middleware;
                Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >();
                patterns.Add("fr", new List <string> {
                    "mon nom est (.+)"
                });                                                         //single pattern for fr language
                middleware.Add(new ConversationState <CurrentUserState>(new MemoryStorage()));
                CustomDictionary userCustomDictonaries       = new CustomDictionary();
                Dictionary <string, string> frenctDictionary = new Dictionary <string, string>
                {
                    { "content", "excited" }
                };
                userCustomDictonaries.AddNewLanguageDictionary("fr", frenctDictionary);
                middleware.Add(new LocaleConverterMiddleware(TranslatorLocaleHelper.GetActiveLocale, TranslatorLocaleHelper.CheckUserChangedLanguageOrLocale, "en-us", LocaleConverter.Converter));
                middleware.Add(new TranslationMiddleware(new string[] { "en" }, "<your translator key here>", patterns, userCustomDictonaries, TranslatorLocaleHelper.GetActiveLanguage, TranslatorLocaleHelper.CheckUserChangedLanguageOrLocale, true));
                middleware.Add(new QnAMakerMiddleware(qnaEndpoint));
            });
        }
Example #4
0
        public LuisDispatchBot(IConfiguration configuration)
        {
            var qnaUrl          = "https://jvdqna.azurewebsites.net/qnamaker/knowledgebases";
            var subscriptionKey = "394ca826-fc83-47c5-b6b9-c445eef41494";

            var kb1 = "1d510f66 - 435b - 4fea - a8fb - b5ddc2e2c37c";

            //           var (kb1, kb2, subscriptionKey, qnaUrl) = Startup.GetQnAMakerConfig(configuration);
            this.qnaEndpoint1 = new QnAMakerEndpoint
            {
                // add subscription key for QnA and knowledge base ID
                EndpointKey     = subscriptionKey,
                KnowledgeBaseId = kb1,
                Host            = qnaUrl
            };
            //this.qnaEndpoint2 = new QnAMakerEndpoint
            //{
            //    // add subscription key for QnA and knowledge base ID
            //    EndpointKey = subscriptionKey,
            //    KnowledgeBaseId = kb2,
            //    Host = qnaUrl
            //};

            qnaMap.Add("MyBotQnA", qnaEndpoint1);
//            qnaMap.Add("MyBotQnA2", qnaEndpoint2);
        }
Example #5
0
        /// <summary>
        /// Gets an <see cref="IQnAMakerClient"/> to use to access the QnA Maker knowledge base.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <remarks>If the task is successful, the result contains the QnA Maker client to use.</remarks>
        protected async virtual Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
        {
            var qnaClient = dc.Context.TurnState.Get <IQnAMakerClient>();

            if (qnaClient != null)
            {
                // return mock client
                return(qnaClient);
            }

            var httpClient = dc.Context.TurnState.Get <HttpClient>();

            if (httpClient == null)
            {
                httpClient = HttpClient;
            }

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey     = this.EndpointKey.GetValue(dc.State),
                Host            = this.HostName.GetValue(dc.State),
                KnowledgeBaseId = this.KnowledgeBaseId.GetValue(dc.State)
            };
            var options = await GetQnAMakerOptionsAsync(dc).ConfigureAwait(false);

            return(new QnAMaker(endpoint, options, httpClient, this.TelemetryClient, this.LogPersonalInformation.GetValue(dc.State)));
        }
Example #6
0
        protected async override Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
        {
            var dcState = dc.GetState();

            var qnaClient = dc.Context.TurnState.Get <IQnAMakerClient>();

            if (qnaClient != null)
            {
                // return mock client
                return(qnaClient);
            }

            var(epKey, error) = this.EndpointKey.TryGetValue(dcState);
            var(hn, error2)   = this.HostName.TryGetValue(dcState);
            var(kbId, error3) = this.KnowledgeBaseId.TryGetValue(dcState);

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey     = (string)epKey,
                Host            = (string)hn,
                KnowledgeBaseId = (string)kbId
            };
            var options = await GetQnAMakerOptionsAsync(dc).ConfigureAwait(false);

            return(new QnAMaker(endpoint, options, this.HttpClient));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TelemetryQnaMaker"/> class.
 /// </summary>
 /// <param name="endpoint">The endpoint of the knowledge base to query.</param>
 /// <param name="options">The options for the QnA Maker knowledge base.</param>
 /// <param name="logUserName">Option to log user name to Application Insights (PII consideration).</param>
 /// <param name="logOriginalMessage">Option to log the original message to Application Insights (PII consideration).</param>
 /// <param name="httpClient">An alternate client with which to talk to QnAMaker.
 /// If null, a default client is used for this instance.</param>
 public TelemetryQnaMaker(QnAMakerEndpoint endpoint, QnAMakerOptions options = null, bool logUserName = true, bool logOriginalMessage = true, HttpClient httpClient = null)
     : base(endpoint, options, httpClient)
 {
     LogUserName        = logUserName;
     LogOriginalMessage = logOriginalMessage;
     Endpoint           = endpoint;
 }
Example #8
0
        private QnAMaker Init(BotConfiguration config)
        {
            var service = config.Services.FirstOrDefault(s => s.Type == ServiceTypes.QnA && s.Name == Name);
            var qna     = (QnAMakerService)service;

            if (qna == null)
            {
                throw new InvalidOperationException("The QnA service is not configured correctly in your '.bot' file.");
            }
            if (string.IsNullOrWhiteSpace(qna.KbId))
            {
                throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required to run this sample.Please update your '.bot' file.");
            }
            if (string.IsNullOrWhiteSpace(qna.EndpointKey))
            {
                throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required to run this sample.Please update your '.bot' file.");
            }
            if (string.IsNullOrWhiteSpace(qna.Hostname))
            {
                throw new InvalidOperationException("The QnA Host ('hostname') is required to run this sample.Please update your '.bot' file.");
            }
            var qnaEndpoint = new QnAMakerEndpoint()
            {
                KnowledgeBaseId = qna.KbId,
                EndpointKey     = qna.EndpointKey,
                Host            = qna.Hostname,
            };
            var qnaMaker = new QnAMaker(qnaEndpoint);

            return(qnaMaker);
        }
Example #9
0
        private static (QnAMakerOptions options, QnAMakerEndpoint endpoint) InitQnAService(IConfiguration configuration)
        {
            var options = new QnAMakerOptions
            {
                Top = 3
            };

            var hostname = configuration["QnAEndpointHostName"];

            if (!hostname.StartsWith("https://"))
            {
                hostname = string.Concat("https://", hostname);
            }

            if (!hostname.EndsWith("/qnamaker"))
            {
                hostname = string.Concat(hostname, "/qnamaker");
            }

            var endpoint = new QnAMakerEndpoint
            {
                KnowledgeBaseId = configuration["QnAKnowledgebaseId"],
                EndpointKey     = configuration["QnAAuthKey"],
                Host            = hostname
            };

            return(options, endpoint);
        }
Example #10
0
        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);
            }
        }
Example #11
0
        public BotServices(BotConfiguration botConfiguration)
        {
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.Luis:
                {
                    var luis = (LuisService)service;
                    if (luis == null)
                    {
                        throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file.");
                    }

                    var app        = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint());
                    var recognizer = new LuisRecognizer(app);
                    LuisServices.Add(luis.Name, recognizer);
                    break;
                }

                case ServiceTypes.QnA:
                {
                    // Create a QnA Maker that is initialized and suitable for passing
                    // into the IBot-derived class (QnABot).
                    var qna = (QnAMakerService)service;
                    if (qna == null)
                    {
                        throw new InvalidOperationException("The QnA service is not configured correctly in your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.KbId))
                    {
                        throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required to run this sample. Please update your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.EndpointKey))
                    {
                        throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required to run this sample. Please update your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.Hostname))
                    {
                        throw new InvalidOperationException("The QnA Host ('hostname') is required to run this sample. Please update your '.bot' file.");
                    }

                    var qnaEndpoint = new QnAMakerEndpoint()
                    {
                        KnowledgeBaseId = qna.KbId,
                        EndpointKey     = qna.EndpointKey,
                        Host            = qna.Hostname,
                    };

                    var qnaMaker = new QnAMaker(qnaEndpoint);
                    QnaServices.Add(qna.Name, qnaMaker);

                    break;
                }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TelemetryQnAMaker"/> class.
        /// </summary>
        /// <param name="endpoint">The endpoint of the knowledge base to query.</param>
        /// <param name="options">The options for the QnA Maker knowledge base.</param>
        /// <param name="logPersonalInformation">TRUE to include personally indentifiable information.</param>
        /// <param name="httpClient">An alternate client with which to talk to QnAMaker.
        /// If null, a default client is used for this instance.</param>
        public TelemetryQnAMaker(QnAMakerEndpoint endpoint, QnAMakerOptions options = null, bool logPersonalInformation = false, HttpClient httpClient = null)
            : base(endpoint, options, httpClient)
        {
            LogPersonalInformation = logPersonalInformation;

            _endpoint = endpoint;
        }
Example #13
0
        public FAQ2Dialog(string dialogId) : base(dialogId)
        {
            // ID of the child dialog that should be started anytime the component is started.
            this.InitialDialogId = dialogId;
            this.AddDialog(new ChoicePrompt("choicePrompt"));
            this.AddDialog(new TextPrompt(FAQPROMPT));

            var qnAMakerEndpoint = new QnAMakerEndpoint();

            qnAMakerEndpoint.EndpointKey     = "d069e7cb-0fe1-46a0-8d91-19aac112b7fb";
            qnAMakerEndpoint.Host            = "https://kbforpilot.azurewebsites.net/qnamaker";
            qnAMakerEndpoint.KnowledgeBaseId = "595a0d27-b768-4a75-8710-c5fa6629d1f8";

            qnaMaker = new QnAMaker(qnAMakerEndpoint);

            // Adds a waterfall dialog that prompts users with the top level menu to the dialog set.
            // Define the steps of the waterfall dialog and add it to the set.
            this.AddDialog(new WaterfallDialog(
                               dialogId,
                               new WaterfallStep[]
            {
                this.PromptForQuestion,
                this.AnswerQuestion
            }));
        }
Example #14
0
        /// <summary>
        /// Gets an <see cref="IQnAMakerClient"/> to use to access the QnA Maker knowledge base.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <remarks>If the task is successful, the result contains the QnA Maker client to use.</remarks>
        protected virtual async Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
        {
            var qnaClient = dc.Context.TurnState.Get <IQnAMakerClient>();

            if (qnaClient != null)
            {
                // return mock client
                return(qnaClient);
            }

            var httpClient = dc.Context.TurnState.Get <HttpClient>() ?? HttpClient;

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey     = this.EndpointKey.GetValue(dc.State),
                Host            = this.HostName.GetValue(dc.State),
                KnowledgeBaseId = KnowledgeBaseId.GetValue(dc.State),
                QnAServiceType  = QnAServiceType.GetValue(dc.State)
            };

            var options = await GetQnAMakerOptionsAsync(dc).ConfigureAwait(false);

            if (endpoint.QnAServiceType == ServiceType.Language)
            {
                return(new CustomQuestionAnswering(endpoint, options, httpClient, TelemetryClient, LogPersonalInformation.GetValue(dc.State)));
            }

            return(new QnAMaker(endpoint, options, httpClient, TelemetryClient, LogPersonalInformation.GetValue(dc.State)));
        }
        public AdenSolutionDialog(IConfiguration configuration, IBotTelemetryClient telemetryClient, HttpClient http, RequestHelper request) : base(nameof(AdenSolutionDialog))
        {
            _request        = request;
            TelemetryClient = telemetryClient;
            var endpoint = new QnAMakerEndpoint()
            {
                Host            = configuration["AdenSolutionsQnAMaker:EndpointHostName"],
                EndpointKey     = configuration["AdenSolutionsQnAMaker:EndpointKey"],
                KnowledgeBaseId = configuration["AdenSolutionsQnAMaker:KnowledgebaseId"]
            };
            var options = new QnAMakerOptions
            {
                Top            = configuration.GetValue("AdenSolutionsQnAMaker:Top", 5),
                ScoreThreshold = configuration.GetValue("AdenSolutionsQnAMaker:ScoreThreshold", 0.3f)
            };

            _qna = new QnAMaker(endpoint, options, http, telemetryClient);

            var steps = new List <WaterfallStep>
            {
                FindSolutionAsync,
                NoAnswerAsync
            };

            AddDialog(new WaterfallDialog(nameof(AdenSolutionDialog), steps));

            InitialDialogId = nameof(AdenSolutionDialog);
        }
Example #16
0
        private async Task getQnAResult(ITurnContext context)
        {
            var qEndpoint = new QnAMakerEndpoint()
            {
                Host            = "https://contosocafeqnab8.azurewebsites.net/qnamaker",
                EndpointKey     = "0fa7f711-6a82-4155-9cf9-5c8168967df6",
                KnowledgeBaseId = "dfa449da-1fb7-449e-b753-53af1b1f7b5b"
            };
            var qOptions = new QnAMakerOptions()
            {
                ScoreThreshold = 0.4F,
                Top            = 1
            };
            var qnamaker = new QnAMaker(qEndpoint, qOptions);

            QueryResult[] qResult = await qnamaker.GetAnswers(context.Activity.Text);

            if (qResult.Length == 0)
            {
                await context.SendActivity("Sorry, I do not understand.");

                await context.SendActivity("You can say hi or book table or find locations");
            }
            else
            {
                await context.SendActivity(qResult[0].Answer);
            }
        }
        private void InitQnAService()
        {
            this._options = new QnAMakerOptions
            {
                Top = 3
            };

            var hostname = this._configuration["QnAEndpointHostName"];

            if (!hostname.StartsWith("https://"))
            {
                hostname = string.Concat("https://", hostname);
            }

            if (!hostname.EndsWith("/qnamaker"))
            {
                hostname = string.Concat(hostname, "/qnamaker");
            }

            this._endpoint = new QnAMakerEndpoint
            {
                KnowledgeBaseId = this._configuration["QnAKnowledgebaseId"],
                EndpointKey     = this._configuration["QnAAuthKey"],
                Host            = hostname
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BotServices"/> class.
        /// </summary>
        /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param>
        public BotServices(BotConfiguration botConfiguration)
        {
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.AppInsights:
                {
                    var appInsights = service as AppInsightsService;
                    TelemetryClient = new TelemetryClient();
                    break;
                }

                case ServiceTypes.Dispatch:
                {
                    var dispatch    = service as DispatchService;
                    var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
                    DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
                    break;
                }

                case ServiceTypes.Luis:
                {
                    var luis    = service as LuisService;
                    var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
                    LuisServices.Add(service.Name, new TelemetryLuisRecognizer(luisApp));
                    break;
                }

                case ServiceTypes.QnA:
                {
                    var qna         = service as QnAMakerService;
                    var qnaEndpoint = new QnAMakerEndpoint()
                    {
                        KnowledgeBaseId = qna.KbId,
                        EndpointKey     = qna.EndpointKey,
                        Host            = qna.Hostname,
                    };
                    var qnaMaker = new TelemetryQnAMaker(qnaEndpoint);
                    QnAServices.Add(qna.Name, qnaMaker);
                    break;
                }

                case ServiceTypes.Generic:
                {
                    if (service.Name == "Authentication")
                    {
                        var authentication = service as GenericService;

                        if (!string.IsNullOrEmpty(authentication.Configuration["Azure Active Directory v2"]))
                        {
                            AuthConnectionName = authentication.Configuration["Azure Active Directory v2"];
                        }
                    }

                    break;
                }
                }
            }
        }
        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 MultiturnQnAMaker(QnAMakerEndpoint endpoint, HttpClient httpClient, IBotTelemetryClient telemetryClient, bool logPersonalInformation = false) : base(endpoint, null, httpClient, telemetryClient, logPersonalInformation)
 {
     _httpClient = httpClient;
     _endpoint   = endpoint;
     _options    = new QnAMakerOptions {
         Top = 3
     };
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LanguageServiceUtils"/> class.
 /// </summary>
 /// <param name="telemetryClient">The IBotTelemetryClient used for logging telemetry events.</param>
 /// <param name="endpoint">Language Service endpoint details.</param>
 /// <param name="options">The options for the QnA Maker knowledge base.</param>
 /// <param name="httpClient">A client with which to talk to Language Service.</param>
 public LanguageServiceUtils(IBotTelemetryClient telemetryClient, HttpClient httpClient, QnAMakerEndpoint endpoint, QnAMakerOptions options)
 {
     _telemetryClient = telemetryClient;
     _endpoint        = endpoint;
     _httpClient      = httpClient;
     _options         = options ?? new QnAMakerOptions();
     ValidateOptions(_options);
     _httpClient = httpClient;
 }
Example #22
0
        private static void InitQnA()
        {
            var credencial = new QnAMakerEndpoint()
            {
                EndpointKey = APIKEY, KnowledgeBaseId = KBID, Host = HOST
            };

            Qna = new QnAMaker(credencial);
        }
Example #23
0
            protected override async Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
            {
                var endpoint = new QnAMakerEndpoint
                {
                    KnowledgeBaseId = _configuration["QnAMaker:KnowledgebaseId"],
                    EndpointKey     = _configuration["QnAMaker:EndpointKey"],
                    Host            = _configuration["QnAMaker:EndpointHostName"]
                };

                return(new QnAMaker(endpoint, null, null, TelemetryClient));
            }
Example #24
0
        public static IServiceCollection AddQnAService(this IServiceCollection services, Action <QnAMakerEndpoint> setup)
        {
            var qnAMakerEndpoint = new QnAMakerEndpoint();

            setup(qnAMakerEndpoint);

            services.TryAddSingleton <QnAMakerEndpoint>(qnAMakerEndpoint);
            services.TryAddSingleton <QnAMaker>();

            return(services);
        }
Example #25
0
        /// <summary>
        /// Initialize the bot's references to external services.
        /// For example, Application Insights and QnaMaker services
        /// are created here.  These external services are configured
        /// using the <see cref="BotConfiguration"/> class (based on the contents of your ".bot" file).
        /// </summary>
        /// <param name="config">The <see cref="BotConfiguration"/> object based on your ".bot" file.</param>
        /// <returns>A <see cref="BotConfiguration"/> representing client objects to access external services the bot uses.</returns>
        /// <seealso cref="BotConfiguration"/>
        /// <seealso cref="QnAMaker"/>
        private static BotServices InitBotServices(BotConfiguration config)
        {
            var qnaServices = new Dictionary <string, QnAMaker>();
            var qnaEndpoint = new QnAMakerEndpoint();

            foreach (var service in config.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.QnA:
                {
                    // Create a QnA Maker that is initialized and suitable for passing
                    // into the IBot-derived class (QnABot).
                    var qna = (QnAMakerService)service;
                    if (qna == null)
                    {
                        throw new InvalidOperationException("The QnA service is not configured correctly in your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.KbId))
                    {
                        throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required to run this sample.  Please update your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.EndpointKey))
                    {
                        throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required to run this sample.  Please update your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(qna.Hostname))
                    {
                        throw new InvalidOperationException("The QnA Host ('hostname') is required to run this sample.  Please update your '.bot' file.");
                    }

                    qnaEndpoint = new QnAMakerEndpoint()
                    {
                        KnowledgeBaseId = qna.KbId,
                        EndpointKey     = qna.EndpointKey,
                        Host            = qna.Hostname,
                    };

                    var qnaMaker = new QnAMaker(qnaEndpoint);
                    qnaServices.Add(qna.Name, qnaMaker);

                    break;
                }
                }
            }

            var connectedServices = new BotServices(qnaServices, qnaEndpoint);

            return(connectedServices);
        }
Example #26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <CafeBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                // The CatchExceptionMiddleware provides a top-level exception handler for your bot.
                // Any exceptions thrown by other Middleware, or by your OnTurn method, will be
                // caught here. To facillitate debugging, the exception is sent out, via Trace,
                // to the emulator. Trace activities are NOT displayed to users, so in addition
                // an "Ooops" message is sent.
                options.Middleware.Add(new CatchExceptionMiddleware <Exception>(async(context, exception) =>
                {
                    await context.TraceActivity("EchoBot Exception", exception);
                    await context.SendActivity("Sorry, it looks like something went wrong!");
                }));

                // The Memory Storage used here is for local bot debugging only. When the bot
                // is restarted, anything stored in memory will be gone.
                IStorage conversationDataStore = new MemoryStorage();
                IStorage userDataStore         = new MemoryStorage();

                // The File data store, shown here, is suitable for bots that run on
                // a single machine and need durable state across application restarts.
                // IStorage dataStore = new FileStorage(System.IO.Path.GetTempPath());

                // For production bots use the Azure Table Store, Azure Blob, or
                // Azure CosmosDB storage provides, as seen below. To include any of
                // the Azure based storage providers, add the Microsoft.Bot.Builder.Azure
                // Nuget package to your solution. That package is found at:
                //      https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/

                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureTableStorage("AzureTablesConnectionString", "TableName");
                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage("AzureBlobConnectionString", "containerName");

                options.Middleware.Add(new ConversationState <CafeBotConvState>(conversationDataStore));
                options.Middleware.Add(new UserState <CafeBotUserState>(userDataStore));

                var qEndpoint = new QnAMakerEndpoint()
                {
                    Host            = "https://contosocafeqnamaker.azurewebsites.net/qnamaker",
                    EndpointKey     = "09e2d55b-a44c-41b6-a08a-76a7df9ddffe",
                    KnowledgeBaseId = "b5534d70-bded-45e1-998a-5945174d4ff3"
                };
                var qOptions = new QnAMakerMiddlewareOptions()
                {
                    ScoreThreshold = 0.4F,
                    Top            = 1
                };
                var qnamaker = new QnAMaker(qEndpoint, qOptions);
                options.Middleware.Add(new QnAMakerMiddleware(qEndpoint, qOptions));
            });
        }
        private void InitQnAService()
        {
            this._options = new QnAMakerOptions
            {
                Top = 3,
            };

            this._endpoint = new QnAMakerEndpoint
            {
                KnowledgeBaseId = "c25afea7-0ca0-44e7-a630-cce73b121087",
                EndpointKey     = "d3e7780b-fa03-4366-ab55-eaed70e97de4",
                Host            = "https://rokulka-test.azurewebsites.net/qnamaker",
            };
        }
        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);
            }
        }
Example #29
0
        /// <summary>
        /// Registers a new knowledge base instance.
        /// </summary>
        /// <param name="service">Service instance to register.</param>
        private void RegisterKnowledgebase(ConnectedService service)
        {
            var qnaMakerService = (QnAMakerService)service;

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey     = qnaMakerService.EndpointKey,
                Host            = qnaMakerService.Hostname,
                KnowledgeBaseId = qnaMakerService.KbId,
            };

            var qna = new QnAMaker(endpoint);

            Knowledgebases.Add(qnaMakerService.Name, qna);
        }
Example #30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <EchoBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                // The CatchExceptionMiddleware provides a top-level exception handler for your bot.
                // Any exceptions thrown by other Middleware, or by your OnTurn method, will be
                // caught here. To facillitate debugging, the exception is sent out, via Trace,
                // to the emulator. Trace activities are NOT displayed to users, so in addition
                // an "Ooops" message is sent.
                options.Middleware.Add(new CatchExceptionMiddleware <Exception>(async(context, exception) =>
                {
                    await context.TraceActivity("EchoBot Exception", exception);
                    await context.SendActivity("Sorry, it looks like something went wrong!");
                }));

                var endpoint = new QnAMakerEndpoint
                {
                    KnowledgeBaseId = "f7fe8537-a1e7-4bc4-b4a3-d3618a1eff0d",
                    // Get the Host from the HTTP request example at https://www.qnamaker.ai
                    // For GA services: https://<Service-Name>.azurewebsites.net/qnamaker
                    // For Preview services: https://westus.api.cognitive.microsoft.com/qnamaker/v2.0
                    Host        = "https://dvndemo.azurewebsites.net/qnamaker",
                    EndpointKey = "61924e48-5514-44dd-ae66-ae362081ea8e"
                };
                options.Middleware.Add(new QnAMakerMiddleware(endpoint));

                // The Memory Storage used here is for local bot debugging only. When the bot
                // is restarted, anything stored in memory will be gone.
                IStorage dataStore = new MemoryStorage();

                // The File data store, shown here, is suitable for bots that run on
                // a single machine and need durable state across application restarts.
                // IStorage dataStore = new FileStorage(System.IO.Path.GetTempPath());

                // For production bots use the Azure Table Store, Azure Blob, or
                // Azure CosmosDB storage provides, as seen below. To include any of
                // the Azure based storage providers, add the Microsoft.Bot.Builder.Azure
                // Nuget package to your solution. That package is found at:
                //      https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/

                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureTableStorage("AzureTablesConnectionString", "TableName");
                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage("AzureBlobConnectionString", "containerName");

                options.Middleware.Add(new ConversationState <EchoState>(dataStore));
            });
        }