private LuisRecognizer ReadLuisRecognizer(IConfiguration configuration, string name) { try { //var services = configuration.GetSection("BotServices"); var luisService = new LuisService { AppId = configuration[$"Luis-{name}-AppId"], AuthoringKey = configuration[$"Luis-{name}-Authoringkey"], Region = configuration[$"Luis-{name}-Region"] }; return(new LuisRecognizer(new LuisApplication( luisService.AppId, luisService.AuthoringKey, luisService.GetEndpoint()), new LuisPredictionOptions { IncludeAllIntents = true, IncludeInstanceData = true }, true)); } catch (Exception) { return(null); } }
public void LuisReturnsCorrectUrl() { var luis = new LuisService() { Region = "westus" }; Assert.AreEqual(luis.GetEndpoint(), "https://westus.api.cognitive.microsoft.com"); luis = new LuisService() { Region = "virginia" }; Assert.AreEqual(luis.GetEndpoint(), "https://virginia.api.cognitive.microsoft.us"); luis = new LuisService() { Region = "usgovvirginia" }; Assert.AreEqual(luis.GetEndpoint(), "https://virginia.api.cognitive.microsoft.us"); luis = new LuisService() { Region = "usgoviowa" }; Assert.AreEqual(luis.GetEndpoint(), "https://usgoviowa.api.cognitive.microsoft.us"); }
public void TestLuisEndpoint() { var luisApp = new LuisService() { Region = "westus" }; Assert.AreEqual(luisApp.GetEndpoint(), $"https://{luisApp.Region}.api.cognitive.microsoft.com"); }
public void LuisApplication_Configuration() { var service = new LuisService { AppId = Guid.NewGuid().ToString(), SubscriptionKey = Guid.NewGuid().ToString(), Region = "westus" }; var model = new LuisApplication(service); Assert.AreEqual(service.AppId, model.ApplicationId); Assert.AreEqual(service.SubscriptionKey, model.EndpointKey); Assert.AreEqual(service.GetEndpoint(), model.Endpoint); }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="luisServices">A dictionary of named <see cref="LuisRecognizer"/> instances for usage within the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (ConnectedService service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { LuisService luis = (LuisService)service; if (luis == null) { throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file."); } LuisApplication app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); LuisRecognizer recognizer = new LuisRecognizer(app); this.LuisServices.Add(luis.Name, recognizer); break; } case ServiceTypes.Generic: { GenericService blockchainService = (GenericService)service; BlockchainEndpoint = blockchainService.Url; break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="LuisApplication"/> class. /// </summary> /// <param name="service">LUIS coonfiguration.</param> public LuisApplication(LuisService service) : this(service.AppId, service.SubscriptionKey, service.GetEndpoint()) { }
/// <summary> /// Initialize the bot's references to external services. /// /// For example, QnaMaker services are created here. /// These external services are configured /// using the <see cref="AppSettings"/> class (based on the contents of your "appsettings.json" file). /// </summary> /// <param name="appSettings"><see cref="AppSettings"/> object based on your "appsettings.json" file.</param> /// <returns>A <see cref="BotServices"/> representing client objects to access external services the bot uses.</returns> /// <seealso cref="AppSettings"/> /// <seealso cref="QnAMaker"/> /// <seealso cref="LuisService"/> public static BotServices InitBotServices(AppSettings appSettings) { var luisIntents = appSettings.luisIntents; var qnaServices = new Dictionary <string, QnAMaker>(); LuisRecognizer luisRecignizerService = null; List <string> IntentsList = appSettings.luisIntents; //Prepare Luis service LuisService luisService = new LuisService() { AppId = appSettings.luisApp.appId, AuthoringKey = appSettings.luisApp.authoringKey, Id = appSettings.luisApp.id, Name = appSettings.luisApp.name, Region = appSettings.luisApp.region, SubscriptionKey = appSettings.luisApp.subscriptionKey, Type = appSettings.luisApp.type, Version = appSettings.luisApp.version }; var luisApp = new LuisApplication(luisService.AppId, luisService.AuthoringKey, luisService.GetEndpoint()); luisRecignizerService = new LuisRecognizer(luisApp); //Prepare QnA service foreach (var qna in appSettings.qnaServices) { var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.kbId, EndpointKey = qna.endpointKey, Host = qna.hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint); qnaServices.Add(qna.name, qnaMaker); } //return new BotServices(luisRecignizerService, qnaServices, Intents); return(new BotServices() { Intents = IntentsList, LuisRecognizerService = luisRecignizerService, QnAServices = qnaServices, }); }