public async Task LuisPredictionOptionsAreUsedInTheRequest(bool?includeAllIntents, double?timezoneOffset, bool?spellCheck, string bingSpellCheckSubscriptionKey, bool?log, bool?staging) { // Arrange var expectedOptions = new LuisPredictionOptions() { IncludeAllIntents = includeAllIntents, TimezoneOffset = timezoneOffset, SpellCheck = spellCheck, BingSpellCheckSubscriptionKey = bingSpellCheckSubscriptionKey, Log = log ?? true, Staging = staging, }; var opts = new LuisRecognizerOptionsV2(_luisApp) { PredictionOptions = expectedOptions, }; var sut = new LuisRecognizer(opts, clientHandler: _mockHttpClientHandler); // Act await sut.RecognizeAsync(BuildTurnContextForUtterance("hi"), CancellationToken.None); // Assert AssertLuisRequest(_mockHttpClientHandler.RequestMessage, expectedOptions); }
public BotService(IConfiguration configuration) { var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAppKey"], $"https://{configuration["LuisAPIHostName"]}.api.cognitive.microsoft.com"); var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; Dispatch = new LuisRecognizer(recognizerOptions); POHowToQnA = new QnAMaker(new QnAMakerEndpoint { KnowledgeBaseId = configuration["QnAKnowlegebaseId"], EndpointKey = configuration["QnAEnpointKey"], Host = configuration["QnAEndpointHostName"] }); }
public Recognizer(IConfiguration configuration) { var luisIsConfigured = !string.IsNullOrEmpty(configuration["LuisAppId"]) && !string.IsNullOrEmpty(configuration["LuisAPIKey"]) && !string.IsNullOrEmpty(configuration["LuisAPIHostName"]); if (luisIsConfigured) { var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], $"https://{configuration["LuisAPIHostName"]}.api.cognitive.microsoft.com"); //using v2 endpoint var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; _recognizer = new LuisRecognizer(recognizerOptions); } }
public async Task Telemetry_ConvertParms() { // Arrange // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key // theses are GUIDs edited to look right to the parsing and validation code. var endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="; var clientHandler = new EmptyLuisResponseClientHandler(); var luisApp = new LuisApplication(endpoint); var telemetryClient = new Mock <IBotTelemetryClient>(); var adapter = new NullAdapter(); var activity = new Activity { Type = ActivityTypes.Message, Text = "please book from May 5 to June 6", Recipient = new ChannelAccount(), // to no where From = new ChannelAccount(), // from no one Conversation = new ConversationAccount(), // on no conversation }; var turnContext = new TurnContext(adapter, activity); var options = new LuisRecognizerOptionsV2(luisApp) { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, }; var recognizer = new LuisRecognizer(options, clientHandler); // Act var additionalProperties = new Dictionary <string, string> { { "test", "testvalue" }, { "foo", "foovalue" }, }; var additionalMetrics = new Dictionary <string, double> { { "moo", 3.14159 }, { "luis", 1.0001 }, }; var result = await recognizer.RecognizeAsync <TelemetryConvertResult>(turnContext, additionalProperties, additionalMetrics, CancellationToken.None).ConfigureAwait(false); // Assert Assert.IsNotNull(result); Assert.AreEqual(telemetryClient.Invocations.Count, 1); Assert.AreEqual(telemetryClient.Invocations[0].Arguments[0].ToString(), "LuisResult"); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("test")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["test"] == "testvalue"); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("foo")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["foo"] == "foovalue"); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("applicationId")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("fromId")); Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("entities")); Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("moo")); Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["moo"], 3.14159); Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("luis")); Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["luis"], 1.0001); }
public BotServices(IConfiguration configuration) { // Read the setting for cognitive services (LUIS, QnA) from the appsettings.json // If includeApiResults is set to true, the full response from the LUIS api (LuisResult) // will be made available in the properties collection of the RecognizerResult var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], $"https://{configuration["LuisAPIHostName"]}.api.cognitive.microsoft.com"); // Set the recognizer options depending on which endpoint version you want to use. // More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3 var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; Dispatch = new LuisRecognizer(recognizerOptions); SampleQnA = new QnAMaker(new QnAMakerEndpoint { KnowledgeBaseId = configuration["QnAKnowledgebaseId"], EndpointKey = configuration["QnAEndpointKey"], Host = configuration["QnAEndpointHostName"] }); }
public BotService(IConfiguration configuration) { var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], $"https://{configuration["LuisAPIHostName"]}.api.cognitive.microsoft.com"); //var luisApplication = new LuisApplication("c977157a-9296-454f-bc8b-10d9fea979e3", "0c053144d5c74dc4bf12bc61dcb544e1", "https://westus.api.cognitive.microsoft.com"); var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; //Dispatch = new LuisRecognizer(luisApplication); Dispatch = new LuisRecognizer(recognizerOptions); SampleQnA = new QnAMaker(new QnAMakerEndpoint { KnowledgeBaseId = configuration["QnAKnowledgebaseId"], EndpointKey = configuration["QnAEndpointKey"], Host = configuration["QnAEndpointHostName"] }); }
public DialogSkillBotRecognizer(IConfiguration configuration) { var luisIsConfigured = !string.IsNullOrEmpty(configuration["LuisAppId"]) && !string.IsNullOrEmpty(configuration["LuisAPIKey"]) && !string.IsNullOrEmpty(configuration["LuisAPIHostName"]); if (luisIsConfigured) { var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], "https://" + configuration["LuisAPIHostName"]); var luisOptions = new LuisRecognizerOptionsV2(luisApplication); _recognizer = new LuisRecognizer(luisOptions); } }
public void LuisRecognizer_Timeout() { var endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="; var expectedTimeout = 300; var opts = new LuisRecognizerOptionsV2(new LuisApplication(endpoint)) { Timeout = 300, }; var recognizerWithTimeout = new LuisRecognizer(opts); Assert.IsNotNull(recognizerWithTimeout); Assert.AreEqual(expectedTimeout, LuisRecognizer.DefaultHttpClient.Timeout.Milliseconds); }
private static IRecognizer CreateRecognizer(IConfiguration configuration) { if (string.IsNullOrEmpty(configuration["LuisAppId"]) || string.IsNullOrEmpty(configuration["LuisAPIKey"]) || string.IsNullOrEmpty(configuration["LuisAPIHostName"])) { throw new Exception("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file."); } // Create the LUIS settings from configuration. var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], "https://" + configuration["LuisAPIHostName"] ); var luisRecognizerOptions = new LuisRecognizerOptionsV2(luisApplication); return(new LuisRecognizer(luisRecognizerOptions)); }
public async Task Telemetry_PiiLoggedAsync() { // Arrange // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key // theses are GUIDs edited to look right to the parsing and validation code. var endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q="; var clientHandler = new EmptyLuisResponseClientHandler(); var luisApp = new LuisApplication(endpoint); var telemetryClient = new Mock <IBotTelemetryClient>(); var adapter = new NullAdapter(); var activity = new Activity { Type = ActivityTypes.Message, Text = "please book from May 5 to June 6", Recipient = new ChannelAccount(), // to no where From = new ChannelAccount(), // from no one Conversation = new ConversationAccount(), // on no conversation }; var turnContext = new TurnContext(adapter, activity); var opts = new LuisRecognizerOptionsV2(luisApp) { TelemetryClient = telemetryClient.Object, LogPersonalInformation = true, }; var recognizer = new LuisRecognizer(opts, clientHandler); // Act var result = await recognizer.RecognizeAsync(turnContext, null).ConfigureAwait(false); // Assert Assert.NotNull(result); Assert.Single(telemetryClient.Invocations); Assert.Equal("LuisResult", telemetryClient.Invocations[0].Arguments[0].ToString()); Assert.Equal(8, ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).Count); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("applicationId")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent2")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore2")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("fromId")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("entities")); Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("question")); }
public LuisBotRecognizer(IConfiguration configuration) { var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], $"{configuration["LuisAPIHostName"]}"); var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; Dispatch = new LuisRecognizer(recognizerOptions); }
private LuisRecognizer CreateLuisRecognizer(IConfiguration configuration, string appIdKey) { var luisApplication = new LuisApplication( configuration[appIdKey], configuration["LuisAPIKey"], configuration["LuisAPIHostName"]); // Set the recognizer options depending on which endpoint version you want to use. // More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3 var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; return(new LuisRecognizer(recognizerOptions)); }
public LuisTaskRecognizer() { var service = new LuisService() { AppId = "5e7068ca-eaa8-42f8-b6b0-f603b070c5ee", SubscriptionKey = "2760aa3227d8414f9e948ac5eb1849fb", Region = "westus", Version = "2.0", }; var app = new LuisApplication(service); var regOptions = new LuisRecognizerOptionsV2(app) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; _luisRecognizer = new Microsoft.Bot.Builder.AI.Luis.LuisRecognizer(regOptions); }
public static async Task <BookingDetails> ExecuteLuisQuery(IConfiguration configuration, ILogger logger, ITurnContext turnContext, CancellationToken cancellationToken) { var bookingDetails = new BookingDetails(); try { // Create the LUIS settings from configuration. var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], "https://" + configuration["LuisAPIHostName"] ); var luisRecognizerOptions = new LuisRecognizerOptionsV2(luisApplication); var recognizer = new LuisRecognizer(luisRecognizerOptions); // The actual call to LUIS var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken); var(intent, score) = recognizerResult.GetTopScoringIntent(); if (intent == "Book_flight") { // We need to get the result from the LUIS JSON which at every level returns an array. bookingDetails.Destination = recognizerResult.Entities["To"]?.FirstOrDefault()?["Airport"]?.FirstOrDefault()?.FirstOrDefault()?.ToString(); bookingDetails.Origin = recognizerResult.Entities["From"]?.FirstOrDefault()?["Airport"]?.FirstOrDefault()?.FirstOrDefault()?.ToString(); // This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part. // TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year. bookingDetails.TravelDate = recognizerResult.Entities["datetime"]?.FirstOrDefault()?["timex"]?.FirstOrDefault()?.ToString().Split('T')[0]; } } catch (Exception e) { logger.LogWarning($"LUIS Exception: {e.Message} Check your LUIS configuration."); } return(bookingDetails); }
public LuisHelper() { var service = new LuisService() { AppId = "a4fe9ae0-be39-4837-b2d9-ed3ca0b33af2", SubscriptionKey = "127183aa64af4de893cc822599f2a4ec", Region = "eastus", Version = "0.1" }; var app = new LuisApplication(service); var regOptions = new LuisRecognizerOptionsV2(app) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; _luisRecognizer = new LuisRecognizer(regOptions); }
public BotServices(IConfiguration configuration) { // Read the setting for cognitive services (LUIS, QnA) from the appsettings.json // If includeApiResults is set to true, the full response from the LUIS api (LuisResult) // will be made available in the properties collection of the RecognizerResult var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], $"https://{configuration["LuisAPIHostName"]}"); var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; recognizer = new LuisRecognizer(recognizerOptions); }
public LuisHelper() { var service = new LuisService() { AppId = "", SubscriptionKey = "", Region = "westus", Version = "2.0" }; var app = new LuisApplication(service); var regOptions = new LuisRecognizerOptionsV2(app) { IncludeAPIResults = true, PredictionOptions = new LuisPredictionOptions() { IncludeAllIntents = true, IncludeInstanceData = true } }; _luisRecognizer = new LuisRecognizer(regOptions); }
public static IServiceCollection AddLuisService(this IServiceCollection services, Action <LuisApplication> setup = null) { services.AddSingleton <LuisRecognizerMiddleware>(); services.AddOptions(); if (setup != null) { services.Configure <LuisApplication>(setup); } services.TryAddEnumerable( ServiceDescriptor.Singleton <IPostConfigureOptions <LuisApplication>, LuisPostConfigureOptions>()); services.AddSingleton(serviceProvider => { var luisApplication = serviceProvider.GetRequiredService <IOptions <LuisApplication> >().Value; var luisRecognizerOptions = new LuisRecognizerOptionsV2(luisApplication); luisRecognizerOptions.PredictionOptions.IncludeAllIntents = false; return(new LuisRecognizer(luisRecognizerOptions)); }); return(services); }
public async Task ShouldOverridePredictionOptionsIfProvided(bool?includeAllIntents, double?timezoneOffset, bool?spellCheck, string bingSpellCheckSubscriptionKey, bool?log, bool?staging) { // Arrange // Initialize options with non default values so we can assert they have been overriden. var constructorOptions = new LuisPredictionOptions() { IncludeAllIntents = true, TimezoneOffset = 42, SpellCheck = true, BingSpellCheckSubscriptionKey = "Fake2806-EC0A-472D-95B7-A7132D159E03", Log = false, Staging = true, }; // Create overriden options for call var overridenOptions = new LuisPredictionOptions() { IncludeAllIntents = includeAllIntents, TimezoneOffset = timezoneOffset, SpellCheck = spellCheck, BingSpellCheckSubscriptionKey = bingSpellCheckSubscriptionKey, Log = log, Staging = staging, }; #pragma warning disable CS0618 // Type or member is obsolete // Create combined options for assertion taking the test case value if not null or the constructor value if not null. var expectedOptions = new LuisPredictionOptions() { IncludeAllIntents = includeAllIntents ?? constructorOptions.IncludeAllIntents, TimezoneOffset = timezoneOffset ?? constructorOptions.TimezoneOffset, SpellCheck = spellCheck ?? constructorOptions.SpellCheck, BingSpellCheckSubscriptionKey = bingSpellCheckSubscriptionKey ?? constructorOptions.BingSpellCheckSubscriptionKey, Log = log ?? constructorOptions.Log, Staging = staging ?? constructorOptions.Staging, LogPersonalInformation = constructorOptions.LogPersonalInformation, }; var opts = new LuisRecognizerOptionsV2(_luisApp) { PredictionOptions = constructorOptions, TelemetryClient = constructorOptions.TelemetryClient, }; // var sut = new LuisRecognizer(_luisApp, constructorOptions, clientHandler: _mockHttpClientHandler); var sut = new LuisRecognizer(opts, clientHandler: _mockHttpClientHandler); // Act/Assert RecognizeAsync override await sut.RecognizeAsync(BuildTurnContextForUtterance("hi"), overridenOptions, CancellationToken.None); AssertLuisRequest(_mockHttpClientHandler.RequestMessage, expectedOptions); // these values can't be overriden and should stay unchanged. Console.WriteLine(constructorOptions.TelemetryClient == sut.TelemetryClient); Assert.Equal(constructorOptions.TelemetryClient, sut.TelemetryClient); Assert.Equal(constructorOptions.LogPersonalInformation, sut.LogPersonalInformation); // Act/Assert RecognizeAsync<T> override await sut.RecognizeAsync <Contoso_App>(BuildTurnContextForUtterance("hi"), overridenOptions, CancellationToken.None); AssertLuisRequest(_mockHttpClientHandler.RequestMessage, expectedOptions); // these values can't be overriden and should stay unchanged. Assert.Equal(constructorOptions.TelemetryClient, sut.TelemetryClient); Assert.Equal(constructorOptions.LogPersonalInformation, sut.LogPersonalInformation); #pragma warning restore CS0618 // Type or member is obsolete }