public void TestAddingIntentExample()
        {
            string    intentName             = "TestAddingIntentExample";
            string    intentExample          = "Rotate object 30 degrees to the left";
            string    entityName             = "amount";
            string    entityDirection        = "direction";
            string    entityNameExample      = "30 degrees";
            string    entityDirectionExample = "left";
            LuisModel model = new LuisModel(luisAppID, ocpAcimSubscriptionKey);

            try
            {
                model.Modify()
                .AddIntent(intentName, new List <Entitylabel>()
                {
                    Entitylabel.Create(intentExample, entityName, entityNameExample),
                    Entitylabel.Create(intentExample, entityDirection, entityDirectionExample),
                })
                .Update();

                var intentNames = model.GetIntents().Keys;
                Assert.IsTrue(intentNames.Contains(intentName));
            }
            finally
            {
                model.DeleteIntent(intentName);
            }
        }
        public void TestGettingTrainingStatus()
        {
            LuisModel model = new LuisModel(luisAppID, ocpAcimSubscriptionKey);

            model.ModelNeedsTraining();
            model.Train();
        }
        public void TestAddHierarchicalEntity()
        {
            string entityname    = "TestAddHierarchicalEntity";
            var    childEntities = new List <string>()
            {
                "ChildEntity3", "ChildEntity4"
            };
            LuisModel model = new LuisModel(luisAppID, ocpAcimSubscriptionKey);

            try
            {
                model.Modify()
                .AddHierarchicalEntity(entityname, childEntities)
                .Update();

                var entityNames = model.GetEntities().Keys;
                Assert.IsTrue(entityNames.Contains(entityname));
                foreach (var entity in childEntities)
                {
                    Assert.IsFalse(entityNames.Contains(entity));
                }
            }
            finally
            {
                model.DeleteEntity(entityname);
            }
        }
        public void TestQuery()
        {
            LuisModel model  = new LuisModel(luisAppID, ocpAcimSubscriptionKey);
            var       result = model.Query("Can I get an Uber");

            Assert.IsTrue(null != result);
        }
예제 #5
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            try
            {
                var activity = await result as Activity;

                LuisModel luisModel = new LuisModel();

                luisModel = await luisModel.Get(activity.Text);

                if (luisModel.topScoringIntent.intent == "Greeting")
                {
                    await context.Forward(new GreetingDialog(), ResumeAfterCompleted, activity, CancellationToken.None);
                }
                else if (luisModel.topScoringIntent.intent == "Quiz")
                {
                    await context.Forward(new QuizDialog(), ResumeAfterCompleted, activity, CancellationToken.None);
                }
                else if (luisModel.topScoringIntent.intent == "Finish")
                {
                    await context.Forward(new FinishDialog(), ResumeAfterCompleted, activity, CancellationToken.None);
                }
                else
                {
                    await context.Forward(new NoneDialog(), ResumeAfterCompleted, activity, CancellationToken.None);
                }
            }
            catch (TooManyAttemptsException ex)
            {
                context.Done(new ResultDialog {
                    Activity = context.Activity as Activity
                });
            }
        }
        public void TestAddClosedListEntity()
        {
            string entityname = "TestAddClosedListEntity";
            var    washington = new Dictionary <string, IEnumerable <string> > {
                { "Washington", new List <string>()
                  {
                      "WA", "Washington"
                  } }
            };
            LuisModel model = new LuisModel(luisAppID, ocpAcimSubscriptionKey);

            try
            {
                model.Modify()
                .AddClosedListEntity(entityname, washington)
                .Update();

                var entityNames = model.GetEntities().Keys;
                Assert.IsTrue(entityNames.Contains(entityname));
            }
            finally
            {
                model.DeleteEntity(entityname);
            }
        }
예제 #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <PokemonGoBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                // 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 <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(new UserState <UserState>(dataStore));

                var(modelId, subscriptionKey, url) = GetLuisConfiguration(Configuration);
                var model = new LuisModel(modelId, subscriptionKey, url);
            });
        }
예제 #8
0
        private async Task <RecognizerResult> find(string utterance)
        {
            var luisModel      = new LuisModel(ModelId, SubscriptionKey, new System.Uri(StreamUrl));
            var luisRecognizer = new LuisRecognizer(luisModel);

            return(await luisRecognizer.Recognize(utterance, CancellationToken.None));
        }
        private IEnumerable <CoffeeOrder> ProcessOrder(LuisModel result)
        {
            var orders = new List <CoffeeOrder>();

            try
            {
                foreach (var compositeEntity in result.compositeEntities)
                {
                    try
                    {
                        var coffeeOrder = compositeEntity.ToCoffeeOrder(result.entities);
                        if (coffeeOrder != null)
                        {
                            orders.Add(coffeeOrder);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Caught an error processing compositeEntity: " + e);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught an error processing LuisModel: " + e);
            }

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

                string luisModelId         = "<Your Model Here>";
                string luisSubscriptionKey = "<Your Key here>";
                Uri luisUri   = new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/");
                var luisModel = new LuisModel(luisModelId, luisSubscriptionKey, luisUri);

                // If you want to get all intents scorings, add verbose in luisOptions
                var luisOptions = new LuisRequest {
                    Verbose = true
                };
                Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >();
                patterns.Add("fr", new List <string> {
                    "mon nom est (.+)"
                });                                                     //single pattern for fr language
                var middleware = options.Middleware;
                middleware.Add(new ConversationState <CurrentUserState>(new MemoryStorage()));
                middleware.Add(new TranslationMiddleware(new string[] { "en" }, "<your translator key here>", patterns, TranslatorLocaleHelper.GetActiveLanguage, TranslatorLocaleHelper.CheckUserChangedLanguage));
                middleware.Add(new LocaleConverterMiddleware(TranslatorLocaleHelper.GetActiveLocale, TranslatorLocaleHelper.CheckUserChangedLocale, "en-us", LocaleConverter.Converter));
                middleware.Add(new LuisRecognizerMiddleware(luisModel, luisOptions: luisOptions));
            });
        }
예제 #11
0
        private async Task <DialogTurnResult> GetModelAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Read the Luis results from the calling dialog
            _luisModel = (LuisModel)stepContext.Options;

            return(await stepContext.NextAsync(cancellationToken : cancellationToken));
        }
예제 #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(_ => Configuration);
            services.AddBot <MultiBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);
                var middleware             = options.Middleware;
                middleware.Add(new ConversationState <ConversationData>(new MemoryStorage()));

                // Regex Intents
                middleware.Add(new RegExpRecognizerMiddleware()
                               .AddIntent("mainMenu", new Regex("main menu(.*)", RegexOptions.IgnoreCase))
                               .AddIntent("help", new Regex("help(.*)", RegexOptions.IgnoreCase))
                               .AddIntent("cancel", new Regex("cancel(.*)", RegexOptions.IgnoreCase)));

                // Setup LUIS Middleware
                var luisRecognizerOptions = new LuisRecognizerOptions {
                    Verbose = false
                };
                var luisModel = new LuisModel(
                    Configuration["LUIS:AppId"],
                    Configuration["LUIS:SubscriptionKey"],
                    new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"));
                middleware.Add(new LuisRecognizerMiddleware(luisModel, luisRecognizerOptions));
            });
        }
예제 #13
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <JasperEngineBot>(options =>
            {
                options.CredentialProvider      = new ConfigurationCredentialProvider(Configuration);
                options.EnableProactiveMessages = true;

                options.Middleware.Add(new ShowTypingMiddleware());

                var dataStore = new MemoryStorage();
                options.Middleware.Add(
                    new ConversationState <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(
                    new UserState <UserTravelState>(dataStore));

                var(modelId, subscriptionKey, url) = GetLuisConfiguration(Configuration);
                var model = new LuisModel(modelId, subscriptionKey, url);
                options.Middleware.Add(
                    new LuisRecognizerMiddleware(
                        model,
                        luisOptions: new LuisRequest {
                    Verbose = true, TimezoneOffset = 60
                }));
            });
        }
예제 #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <Bot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                options.Middleware.Add(new CatchExceptionMiddleware <Exception>(async(context, exception) =>
                {
                    await context.SendActivity($"Olá, ainda não estou preparado para tratar este tipo de informacão {Emojis.SmileSad}  \n" +
                                               $"Peço que utilize apenas texto para melhorar nossa interação {Emojis.SmileHappy}");
                }));

                IStorage dataStore = new MemoryStorage();
                options.Middleware.Add(new ConversationState <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(new UserState <BotUserState>(dataStore));


                var(modelId, subscriptionKey, url) = GetLuisConfiguration(Configuration);
                var model = new LuisModel(modelId, subscriptionKey, url);
                options.Middleware.Add(new LuisRecognizerMiddleware(model));
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        }
        private IRecognizer GetLuisRecognizer(bool verbose = false, ILuisOptions luisOptions = null)
        {
            var luisRecognizerOptions = new LuisRecognizerOptions {
                Verbose = verbose
            };
            var luisModel = new LuisModel(_luisAppId, _subscriptionKey, new Uri(_luisUriBase), LuisApiVersion.V2);

            return(new LuisRecognizer(luisModel, luisRecognizerOptions, luisOptions));
        }
예제 #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <DataContext>(options =>
            {
                options.UseInMemoryDatabase(databaseName: "dataContext");
            });

            services.AddBot <LuisBot>(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! Something about '{exception.Message}...'");
                }));

                // The Memory Storage used here is for local bot debugging only. When the bot
                // is restarted, anything stored in memory will be gone.
                var 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 <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(new UserState <UserState>(dataStore));

                var(modelId, subscriptionKey, url) = GetLuisConfiguration(Configuration);
                var model = new LuisModel(modelId, subscriptionKey, url);
                options.Middleware.Add(new LuisRecognizerMiddleware(model));
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
        private IRecognizer GetLuisRecognizer(HttpMessageHandler messageHandler, bool verbose = false, ILuisOptions luisOptions = null)
        {
            var client = new HttpClient(messageHandler);
            var luisRecognizerOptions = new LuisRecognizerOptions {
                Verbose = verbose
            };
            var luisModel = new LuisModel(_luisAppId, _subscriptionKey, new Uri(_luisUriBase), LuisApiVersion.V2);

            return(new LuisRecognizer(luisModel, luisRecognizerOptions, luisOptions, client));
        }
예제 #18
0
파일: Startup.cs 프로젝트: llenroc/OscarBot
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <OscarBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                //var connectionString = Configuration.GetSection("TableStorageConnectionString")?.Value;
                //options.Middleware.Add(new ConversationState<EpisodeInquiry>(new AzureTableStorage(connectionString, "conversations")));

                // 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("OscarBot 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.

                // 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");

                var cs             = Configuration.GetSection("TableStorageConnectionString")?.Value;
                IStorage dataStore = new AzureBlobStorage(cs, "conversations");

                options.Middleware.Add(new ConversationState <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(new UserState <UserState>(dataStore));

                var translationApiKey = Configuration.GetSection("TranslationApiKey")?.Value;
                options.Middleware.Add(new TranslationMiddleware(new string[] { "en" }, translationApiKey, true));

                var(modelId, subscriptionKey, url) = GetLuisConfiguration(Configuration);
                var model = new LuisModel(modelId, subscriptionKey, url);
                options.Middleware.Add(new LuisRecognizerMiddleware(model));

                TraktService.Instance.ClientID     = Configuration.GetSection("TraktClientId")?.Value;
                TraktService.Instance.ClientSecret = Configuration.GetSection("TraktClientSecret")?.Value;
                TraktService.Instance.AccessToken  = Configuration.GetSection("TraktAccessToken")?.Value;
                TmdbService.Instance.ApiKey        = Configuration.GetSection("TmdbApiKey")?.Value;
            });
        }
예제 #19
0
 public KnowledgeBot(IConfiguration config)
 {
     this.configuration = config;
     indexClient        = AzureSearchService.CreateSearchIndexClient(configuration["SearchServiceName"], configuration["SearchDialogsIndexName"], configuration["SearchServiceQueryApiKey"]);
     qnaClient          = new QnAMaker(new QnAMakerEndpoint()
     {
         EndpointKey = configuration["QnAKey"], Host = configuration["QnAEndpoint"], KnowledgeBaseId = configuration["QnAKnowledgeBaseId"]
     });
     translatorClient = new Translator(configuration["TranslationAPI"]);
     botLUISModel     = new LuisModel(configuration["LUISAppId"], configuration["LUISApiKey"], new Uri(configuration["LUISEndpointUri"]));
 }
        private LuisRecognizerMiddleware GetLuisRecognizerMiddleware(bool verbose = false, ILuisOptions luisOptions = null)
        {
            var luisRecognizerOptions = new LuisRecognizerOptions {
                Verbose = verbose
            };
            var luisModel = new LuisModel(_luisAppId, _subscriptionKey, new Uri(_luisUriBase));

            return(new LuisRecognizerMiddleware(luisModel, luisRecognizerOptions, luisOptions ?? new LuisRequest {
                Verbose = verbose
            }));
        }
        public void LuisRecognizer_ObfuscateSensitiveData()
        {
            var model      = new LuisModel(Guid.NewGuid().ToString(), "abc", new Uri("http://luis.ai"));
            var obfuscated = LuisRecognizerMiddleware.RemoveSensitiveData(model);

            Assert.AreEqual(LuisRecognizerMiddleware.Obfuscated, obfuscated.SubscriptionKey);
            Assert.AreEqual(model.ApiVersion, obfuscated.ApiVersion);
            Assert.AreEqual(model.ModelID, obfuscated.ModelID);
            Assert.AreEqual(model.Threshold, obfuscated.Threshold);
            Assert.AreEqual(model.UriBase.Host, obfuscated.UriBase.Host);
        }
예제 #22
0
        public TaskBot(IConfiguration configuration)
        {
            _taskModel = Startup.GetLuisModel(configuration, "Task");

            _functions = new Dictionary <string, Func <double, JObject, string> >
            {
                ["Greeting"] = GetGreetingMessage,
                ["Task"]     = GetTaskMessage,
                ["None"]     = GetNoneMessage
            };
        }
예제 #23
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <LuisBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var model = new LuisModel("[<LUIS Application Id>]", "[<LUIS Application Secret Key>]", new Uri("https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/"));
                options.Middleware.Add(new LuisRecognizerMiddleware(model, luisOptions: new LuisRequest {
                    Verbose = true, TimezoneOffset = 60
                }));
            });
        }
예제 #24
0
        //private readonly WeatherBotAccessors _accessors;
        //private readonly ILogger _logger;

        public WeatherBotBot(IConfiguration c)
        {
            _dialogs = ComposeRootDialog();

            var options = new LuisRecognizerOptions {
                Verbose = true
            };
            var luisModel = new LuisModel(Constantes.LuisApplicationID,
                                          Constantes.LuisAuthorizationKey,
                                          new Uri(Constantes.LuisEndpoint));

            LuisRecognizer = new LuisRecognizer(luisModel, options, null);
        }
예제 #25
0
        public LuisService(IOptions <AppSettings> appSettings, ILogger <LuisService> logger)
        {
            if (appSettings.Value.Luis == null || String.IsNullOrEmpty(appSettings.Value.Luis.ModelId))
            {
                return;
            }

            this.luisModel = new LuisModel(
                appSettings.Value.Luis.ModelId,
                appSettings.Value.Luis.SubscriptionKey,
                new Uri(appSettings.Value.Luis.ServiceUri),
                Cognitive.LUIS.LuisApiVersion.V2);
            this.logger = logger;
        }
        private async Task <bool> TextPromptValidatorAsync(PromptValidatorContext <string> promptContext, CancellationToken cancellationToken)
        {
            //throw new NotImplementedException();

            switch (promptContext.Options.Validations != null ? (Validator)promptContext.Options.Validations : (Validator)(-1))
            {
            case Validator.Name:
                luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync <LuisModel>(promptContext.Context, cancellationToken);

                PersonalDetails.Name = (luisResult.Entities.personName != null ? char.ToUpper(luisResult.Entities.personName[0][0]) + luisResult.Entities.personName[0].Substring(1) : null);

                if (PersonalDetails.Name == null)
                {
                    return(await Task.FromResult(false));
                }
                else
                {
                    return(await Task.FromResult(true));
                }

            case Validator.Age:


                luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync <LuisModel>(promptContext.Context, cancellationToken);

                //PersonalDetails.Age = (luisResult.Entities.age != null ? luisResult.Entities.age[0].Number.ToString() : Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value);
                if (luisResult.Entities.age != null)
                {
                    PersonalDetails.Age = (int?)luisResult.Entities.age[0].Number;
                }
                else if (Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value != "")
                {
                    //PersonalDetails.Age = Int32.Parse(Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value);
                    // Second check, just in case. Returns null if parse fails
                    PersonalDetails.Age = Int32.TryParse(Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value, out var tempVal) ? tempVal : (int?)null;
                }

                if (PersonalDetails.Age == null)
                {
                    return(await Task.FromResult(false));
                }
                else
                {
                    return(await Task.FromResult(true));
                }

            default:
                return(await Task.FromResult(true));
            }
        }
예제 #27
0
        private async Task <RecognizerResult> playLuis(IBotContext botContext, string utterance)
        {
            await botContext.SendActivity("Start LUIS");


            // finder
            var luisModel = new LuisModel("", "", new System.Uri(""));
            // feedback
            //var luisModel = new LuisModel("", "", new System.Uri(""));

            var luisRecognizer = new LuisRecognizer(luisModel);

            return(await luisRecognizer.Recognize(utterance, CancellationToken.None));
        }
예제 #28
0
        private static async Task <RecognizerResult> GetResults(string question, IConfiguration configuration)
        {
            var luisSettings    = configuration.GetSection("LUISSettings");
            var modelId         = luisSettings["ModelId"];
            var subscriptionKey = luisSettings["SubscriptionKey"];
            var url             = luisSettings["Url"];
            var luisModel       = new LuisModel(modelId, subscriptionKey, new System.Uri(url));

            LuisRecognizer luisRecognizer1;

            luisRecognizer1 = new LuisRecognizer(luisModel);
            var recognizerResult = await luisRecognizer1.Recognize(question, System.Threading.CancellationToken.None);

            return(recognizerResult);
        }
예제 #29
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton(Configuration);
     services.AddBot <BotHandler>(options =>
     {
         options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);
         string luisModelId         = "863ba937-e630-419c-9db6-358d78ed5f65";
         string luisSubscriptionKey = "30a9eba1e3684f75a8ed830939fca32a";
         Uri luisUri     = new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/");
         var luisModel   = new LuisModel(luisModelId, luisSubscriptionKey, luisUri);
         var luisOptions = new LuisRequest {
             Verbose = true, Staging = true
         };
         var middleware = options.Middleware;
         middleware.Add(new LuisRecognizerMiddleware(luisModel, luisOptions: luisOptions));
     });
 }
예제 #30
0
        public MainBot(IConfiguration configuration)
        {
            // Create DialogSet
            _dialogs = ComposeRootDialog();

            // Create the LUIS recognizer for our model.
            var luisRecognizerOptions = new LuisRecognizerOptions {
                Verbose = true
            };
            var luisModel = new LuisModel(
                configuration[Keys.LuisModel],
                configuration[Keys.LuisSubscriptionKey],
                new Uri(configuration[Keys.LuisUriBase]),
                LuisApiVersion.V2);

            LuisRecognizer = new LuisRecognizer(luisModel, luisRecognizerOptions, null);
        }