From dd22c89e0a456dcddf4d9bdd0e7dd509300122e7 Mon Sep 17 00:00:00 2001 From: Chris McConnell Date: Fri, 19 Jul 2019 10:49:27 -0700 Subject: [PATCH] Simplify recognizer signature by moving constructor args into LuisRecognizerOptions. Fix all style warnings. --- .../LuisPredictionOptions.cs | 7 ++++ .../LuisRecognizer.cs | 27 +++++-------- .../LuisRecognizerOptions.cs | 9 +++++ .../LuisUtil.cs | 12 +++--- .../LuisOracleTests.cs | 2 +- .../TelemetryOverrideRecognizer.cs | 2 +- .../TestData/Composite1.json | 1 + .../TestData/Composite2.json | 1 + .../TestData/Composite3.json | 1 + .../TestData/DynamicListsAndList.json | 1 + .../TestData/ExternalEntitiesAndBuiltin.json | 1 + .../ExternalEntitiesAndComposite.json | 1 + .../TestData/ExternalEntitiesAndList.json | 1 + .../TestData/ExternalEntitiesAndRegex.json | 1 + .../TestData/ExternalEntitiesAndSimple.json | 1 + .../ExternalEntitiesAndSimpleOverride.json | 1 + .../TestData/GeoPeopleOrdinal.json | 1 + .../TestData/Minimal.json | 1 + .../TestData/Patterns.json | 1 + .../TestData/Prebuilt.json | 1 + .../TestData/TraceActivity.json | 1 + .../TestData/Typed.json | 1 + .../TestData/TypedPrebuilt.json | 1 + .../TestData/roles.json | 1 + .../LuisV3OracleTests.cs | 40 +++++++++++-------- .../OverrideFillRecognizer.cs | 9 ++--- .../TelemetryConvertResult.cs | 5 +-- .../TelemetryOverrideRecognizer.cs | 8 ++-- 28 files changed, 85 insertions(+), 54 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisPredictionOptions.cs b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisPredictionOptions.cs index 3a0745a4ca..2a7c8a62a9 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisPredictionOptions.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisPredictionOptions.cs @@ -25,6 +25,13 @@ public class LuisPredictionOptions /// public bool IncludeInstanceData { get; set; } = false; + /// + /// Gets or sets a value indicating whether API results should be included. + /// + /// True to include API results. + /// This is mainly useful for testing or getting access to LUIS features not yet in the SDK. + public bool IncludeAPIResults { get; set; } = false; + /// /// Gets or sets a value indicating whether queries should be logged in LUIS. /// diff --git a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizer.cs index 9e39552d1e..52d112979b 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizer.cs @@ -33,7 +33,6 @@ public class LuisRecognizer : ITelemetryRecognizer private readonly LuisApplication _application; private readonly LuisPredictionOptions _predictionOptions; - private readonly bool _includeApiResults; /// /// Initializes a new instance of the class. @@ -41,20 +40,18 @@ public class LuisRecognizer : ITelemetryRecognizer /// The LUIS application to use to recognize text. /// (Optional) Options for the created recognizer. /// (Optional) The default LUIS prediction options to use. - /// (Optional) TRUE to include raw LUIS API response. /// (Optional) Custom handler for LUIS API calls to allow mocking. - public LuisRecognizer(LuisApplication application, LuisRecognizerOptions recognizerOptions = null, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, HttpClientHandler clientHandler = null) + public LuisRecognizer(LuisApplication application, LuisRecognizerOptions recognizerOptions = null, LuisPredictionOptions predictionOptions = null) { recognizerOptions = recognizerOptions ?? new LuisRecognizerOptions(); _application = application ?? throw new ArgumentNullException(nameof(application)); _predictionOptions = predictionOptions ?? new LuisPredictionOptions(); - _includeApiResults = includeApiResults; TelemetryClient = recognizerOptions.TelemetryClient; LogPersonalInformation = recognizerOptions.LogPersonalInformation; var delegatingHandler = new LuisDelegatingHandler(); - var httpClientHandler = clientHandler ?? CreateRootHandler(); + var httpClientHandler = recognizerOptions.HttpClient ?? CreateRootHandler(); var currentHandler = CreateHttpHandlerPipeline(httpClientHandler, delegatingHandler); DefaultHttpClient = new HttpClient(currentHandler, false) @@ -221,11 +218,9 @@ public virtual async Task RecognizeAsync(ITurnContext turnContext, Diction /// Context object containing information for a single turn of conversation with a user. /// Additional properties to be logged to telemetry with the LuisResult event. /// Additional metrics to be logged to telemetry with the LuisResult event. - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// . - protected virtual async Task OnRecognizerResultAsync(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null, CancellationToken cancellationToken = default) + protected virtual void OnRecognizerResult(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null) { - var properties = await FillLuisEventPropertiesAsync(recognizerResult, turnContext, telemetryProperties, cancellationToken).ConfigureAwait(false); + var properties = FillLuisEventProperties(recognizerResult, turnContext, telemetryProperties); // Track the event TelemetryClient.TrackEvent(LuisTelemetryConstants.LuisResult, properties, telemetryMetrics); @@ -238,10 +233,8 @@ protected virtual async Task OnRecognizerResultAsync(RecognizerResult recognizer /// Last activity sent from user. /// Context object containing information for a single turn of conversation with a user. /// Additional properties to be logged to telemetry with the LuisResult event. - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// additionalProperties /// A dictionary that is sent as "Properties" to IBotTelemetryClient.TrackEvent method for the BotMessageSend event. - protected Task> FillLuisEventPropertiesAsync(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null, CancellationToken cancellationToken = default) + protected Dictionary FillLuisEventProperties(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null) { var topTwoIntents = (recognizerResult.Intents.Count > 0) ? recognizerResult.Intents.OrderByDescending(x => x.Value.Score).Take(2).ToArray() : null; @@ -281,12 +274,12 @@ protected virtual async Task OnRecognizerResultAsync(RecognizerResult recognizer // Additional Properties can override "stock" properties. if (telemetryProperties != null) { - return Task.FromResult(telemetryProperties.Concat(properties) + properties = telemetryProperties.Concat(properties) .GroupBy(kv => kv.Key) - .ToDictionary(g => g.Key, g => g.First().Value)); + .ToDictionary(g => g.Key, g => g.First().Value); } - return Task.FromResult(properties); + return properties; } private string AddParam(string query, string prop, bool? val) @@ -394,14 +387,14 @@ private async Task RecognizeInternalAsync(ITurnContext turnCon Entities = LuisUtil.ExtractEntitiesAndMetadata(prediction), }; LuisUtil.AddProperties(prediction, recognizerResult); - if (_includeApiResults) + if (options.IncludeAPIResults) { recognizerResult.Properties.Add("luisResult", luisResponse); } } // Log telemetry - await OnRecognizerResultAsync(recognizerResult, turnContext, telemetryProperties, telemetryMetrics, cancellationToken).ConfigureAwait(false); + OnRecognizerResult(recognizerResult, turnContext, telemetryProperties, telemetryMetrics); var traceInfo = JObject.FromObject( new diff --git a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizerOptions.cs b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizerOptions.cs index 6e518fee85..95c24b4682 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizerOptions.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisRecognizerOptions.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. +using System.Net.Http; using Newtonsoft.Json; namespace Microsoft.Bot.Builder.AI.Luis @@ -31,5 +32,13 @@ public class LuisRecognizerOptions /// /// If true, personal information is logged to Telemetry; otherwise the properties will be filtered. public bool LogPersonalInformation { get; set; } = false; + + /// + /// Gets or sets the handler for sending http calls. + /// + /// + /// Handler for intercepting http calls for logging or testing. + /// + public HttpClientHandler HttpClient { get; set; } } } diff --git a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisUtil.cs b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisUtil.cs index 8e4cf7a0b6..7d220208c8 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisUtil.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LuisV3/LuisUtil.cs @@ -10,8 +10,8 @@ namespace Microsoft.Bot.Builder.AI.Luis // Utility functions used to extract and transform data from Luis SDK internal static class LuisUtil { - internal const string _metadataKey = "$instance"; - internal const string _geoV2 = "builtin.geographyV2."; + internal const string MetadataKey = "$instance"; + internal const string GeoV2 = "builtin.geographyV2."; internal static readonly HashSet _dateSubtypes = new HashSet { "date", "daterange", "datetime", "datetimerange", "duration", "set", "time", "timerange" }; internal static string NormalizedIntent(string intent) => intent.Replace('.', '_').Replace(' ', '_'); @@ -48,11 +48,11 @@ internal static void FindGeographyTypes(JToken source, Dictionary().StartsWith(_geoV2)) + if (obj.TryGetValue("type", out var type) && type.Type == JTokenType.String && type.Value().StartsWith(GeoV2)) { - var path = type.Path.Replace(_metadataKey + ".", string.Empty); + var path = type.Path.Replace(MetadataKey + ".", string.Empty); path = path.Substring(0, path.LastIndexOf('.')); - geoTypes.Add(path, type.Value().Substring(_geoV2.Length)); + geoTypes.Add(path, type.Value().Substring(GeoV2.Length)); } else { @@ -112,7 +112,7 @@ internal static JToken MapProperties(JToken source, bool inInstance, Dictionary< var isArr = property.Value.Type == JTokenType.Array; var isStr = property.Value.Type == JTokenType.String; var isInt = property.Value.Type == JTokenType.Integer; - var val = MapProperties(property.Value, inInstance || property.Name == _metadataKey, geoTypes); + var val = MapProperties(property.Value, inInstance || property.Name == MetadataKey, geoTypes); if (name == "datetime" && isArr) { nobj.Add("datetimeV1", val); diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/LuisOracleTests.cs b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/LuisOracleTests.cs index 54285d3eba..4b67f820b8 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/LuisOracleTests.cs +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/LuisOracleTests.cs @@ -579,7 +579,7 @@ public async Task Telemetry_OverrideOnDeriveAsync() TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, }; - var recognizer = new TelemetryOverrideRecognizer(telemetryClient.Object, luisApp, options, false, false, clientHandler); + var recognizer = new TelemetryOverrideRecognizer(luisApp, options, false, false, clientHandler); var additionalProperties = new Dictionary { diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TelemetryOverrideRecognizer.cs b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TelemetryOverrideRecognizer.cs index dccd565249..5b6b95fabe 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TelemetryOverrideRecognizer.cs +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TelemetryOverrideRecognizer.cs @@ -10,7 +10,7 @@ namespace Microsoft.Bot.Builder.AI.Luis.Tests { public class TelemetryOverrideRecognizer : LuisRecognizer { - public TelemetryOverrideRecognizer(IBotTelemetryClient telemetryClient, LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, bool logPersonalInformation = false, HttpClientHandler clientHandler = null) + public TelemetryOverrideRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, bool logPersonalInformation = false, HttpClientHandler clientHandler = null) : base(application, predictionOptions, includeApiResults, clientHandler) { LogPersonalInformation = logPersonalInformation; diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite1.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite1.json index fa56683b0a..24906e11e8 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite1.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite1.json @@ -1275,6 +1275,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite2.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite2.json index c03896986b..c38bf61dac 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite2.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite2.json @@ -280,6 +280,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite3.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite3.json index b151943de6..fc5da0f0ea 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite3.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Composite3.json @@ -295,6 +295,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/DynamicListsAndList.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/DynamicListsAndList.json index c6a094c31c..efe446c7e1 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/DynamicListsAndList.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/DynamicListsAndList.json @@ -113,6 +113,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndBuiltin.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndBuiltin.json index 4c171e1838..c39f3a636c 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndBuiltin.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndBuiltin.json @@ -80,6 +80,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndComposite.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndComposite.json index 9703da87a8..f2da059e1f 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndComposite.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndComposite.json @@ -129,6 +129,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndList.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndList.json index 5b93970227..80a6051ef2 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndList.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndList.json @@ -86,6 +86,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndRegex.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndRegex.json index d6da9fd4d7..b90c0e876d 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndRegex.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndRegex.json @@ -79,6 +79,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimple.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimple.json index b8fc058084..11396631a7 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimple.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimple.json @@ -144,6 +144,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimpleOverride.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimpleOverride.json index d2b241737c..97dda7ece7 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimpleOverride.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/ExternalEntitiesAndSimpleOverride.json @@ -149,6 +149,7 @@ } ], "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/GeoPeopleOrdinal.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/GeoPeopleOrdinal.json index 91f513cde6..2162ff1e40 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/GeoPeopleOrdinal.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/GeoPeopleOrdinal.json @@ -264,6 +264,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Minimal.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Minimal.json index 9ae2259fa0..d27f03e835 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Minimal.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Minimal.json @@ -90,6 +90,7 @@ "v3": { "options": { "IncludeAllIntents": false, + "IncludeAPIResults": true, "IncludeInstanceData": false, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Patterns.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Patterns.json index d94e5ec533..1fb350d944 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Patterns.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Patterns.json @@ -221,6 +221,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Prebuilt.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Prebuilt.json index 345feeefc6..999108a0ec 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Prebuilt.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Prebuilt.json @@ -226,6 +226,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TraceActivity.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TraceActivity.json index 54648e9d8f..84963fb6ca 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TraceActivity.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TraceActivity.json @@ -157,6 +157,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Typed.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Typed.json index 8d5e51fb6d..377d699c14 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Typed.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/Typed.json @@ -1275,6 +1275,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TypedPrebuilt.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TypedPrebuilt.json index 345feeefc6..999108a0ec 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TypedPrebuilt.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/TypedPrebuilt.json @@ -226,6 +226,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/roles.json b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/roles.json index 451357152d..79ade1aeb9 100644 --- a/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/roles.json +++ b/tests/Microsoft.Bot.Builder.AI.LUIS.Tests/TestData/roles.json @@ -1504,6 +1504,7 @@ "v3": { "options": { "IncludeAllIntents": true, + "IncludeAPIResults": true, "IncludeInstanceData": true, "Log": true, "PreferExternalEntities": true, diff --git a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/LuisV3OracleTests.cs b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/LuisV3OracleTests.cs index ef044f7738..e35650d0ad 100644 --- a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/LuisV3OracleTests.cs +++ b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/LuisV3OracleTests.cs @@ -105,7 +105,7 @@ public async Task NullUtterance() GetEnvironmentVars(); var mockHttp = GetMockHttpClientHandlerObject(utterance, responsePath); - var luisRecognizer = GetLuisRecognizer(mockHttp, verbose: true); + var luisRecognizer = GetLuisRecognizer(mockHttp); var context = GetContext(utterance); var result = await luisRecognizer.RecognizeAsync(context, CancellationToken.None); @@ -167,11 +167,11 @@ public async Task TestJson(string file, ITurnContext turnContext = null) var mockHttp = GetMockHttpClientHandlerObject((string)oracle["text"], mockResponse); var oracleOptions = response["options"]; var options = (oracleOptions == null || oracleOptions.Type == JTokenType.Null) - ? new LuisPredictionOptions { IncludeAllIntents = true, IncludeInstanceData = true } + ? new LuisPredictionOptions { IncludeAllIntents = true, IncludeInstanceData = true, IncludeAPIResults = true } : oracleOptions.ToObject(); var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; response["options"] = (JObject)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(options, settings)); - var luisRecognizer = GetLuisRecognizer(mockHttp, true, options); + var luisRecognizer = GetLuisRecognizer(mockHttp, options); var typedResult = await luisRecognizer.RecognizeAsync(context, CancellationToken.None); var typedJson = Utils.Json(typedResult, version, oracle); @@ -340,7 +340,7 @@ public void UserAgentContainsProductVersion() var clientHandler = new EmptyLuisResponseClientHandler(); - var recognizer = new LuisRecognizer(application, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(application, new LuisRecognizerOptions { HttpClient = clientHandler }); var adapter = new NullAdapter(); var activity = new Activity @@ -398,6 +398,7 @@ public async Task Telemetry_OverrideOnLogAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; var activity = new Activity @@ -410,7 +411,7 @@ public async Task Telemetry_OverrideOnLogAsync() }; var turnContext = new TurnContext(adapter, activity); - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act var additionalProperties = new Dictionary @@ -461,8 +462,9 @@ public async Task Telemetry_PiiLoggedAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = true, + HttpClient = clientHandler, }; - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act var result = await recognizer.RecognizeAsync(turnContext).ConfigureAwait(false); @@ -508,8 +510,9 @@ public async Task Telemetry_NoPiiLoggedAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act var result = await recognizer.RecognizeAsync(turnContext).ConfigureAwait(false); @@ -556,8 +559,9 @@ public async Task Telemetry_OverrideOnDeriveAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new TelemetryOverrideRecognizer(telemetryClient.Object, luisApp, options, false, false, clientHandler); + var recognizer = new TelemetryOverrideRecognizer(luisApp, options); var additionalProperties = new Dictionary { @@ -608,8 +612,9 @@ public async Task Telemetry_OverrideFillAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new OverrideFillRecognizer(telemetryClient.Object, luisApp, options, false, false, clientHandler); + var recognizer = new OverrideFillRecognizer(luisApp, options); var additionalProperties = new Dictionary { @@ -670,9 +675,10 @@ public async Task Telemetry_NoOverrideAsync() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act var result = await recognizer.RecognizeAsync(turnContext, CancellationToken.None).ConfigureAwait(false); @@ -714,12 +720,13 @@ public async Task Telemetry_Convert() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act // Use a class the converts the Recognizer Result.. - var result = await recognizer.RecognizeAsync(turnContext, CancellationToken.None).ConfigureAwait(false); + var result = await recognizer.RecognizeAsync(turnContext, CancellationToken.None).ConfigureAwait(false); // Assert Assert.IsNotNull(result); @@ -759,8 +766,9 @@ public async Task Telemetry_ConvertParms() { TelemetryClient = telemetryClient.Object, LogPersonalInformation = false, + HttpClient = clientHandler, }; - var recognizer = new LuisRecognizer(luisApp, options, clientHandler: clientHandler); + var recognizer = new LuisRecognizer(luisApp, options); // Act var additionalProperties = new Dictionary @@ -774,7 +782,7 @@ public async Task Telemetry_ConvertParms() { "luis", 1.0001 }, }; - var result = await recognizer.RecognizeAsync(turnContext, additionalProperties, additionalMetrics, CancellationToken.None).ConfigureAwait(false); + var result = await recognizer.RecognizeAsync(turnContext, additionalProperties, additionalMetrics, CancellationToken.None).ConfigureAwait(false); // Assert Assert.IsNotNull(result); @@ -795,10 +803,10 @@ public async Task Telemetry_ConvertParms() Assert.AreEqual(((Dictionary)telemetryClient.Invocations[0].Arguments[2])["luis"], 1.0001); } - private IRecognizer GetLuisRecognizer(MockedHttpClientHandler httpClientHandler, bool verbose = false, LuisPredictionOptions options = null) + private IRecognizer GetLuisRecognizer(MockedHttpClientHandler httpClientHandler, LuisPredictionOptions options = null) { var luisApp = new LuisApplication(AppId, Key, Endpoint); - return new LuisRecognizer(luisApp, null, options, verbose, httpClientHandler); + return new LuisRecognizer(luisApp, new LuisRecognizerOptions { HttpClient = httpClientHandler }, options); } private MockedHttpClientHandler GetMockHttpClientHandlerObject(string example, string responsePath) diff --git a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/OverrideFillRecognizer.cs b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/OverrideFillRecognizer.cs index 56adc2c916..c20fbbf843 100644 --- a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/OverrideFillRecognizer.cs +++ b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/OverrideFillRecognizer.cs @@ -11,15 +11,14 @@ namespace Microsoft.Bot.Builder.AI.LuisV3.Tests { public class OverrideFillRecognizer : LuisRecognizer { - public OverrideFillRecognizer(IBotTelemetryClient telemetryClient, LuisApplication application, LuisRecognizerOptions recognizerOptions = null, bool includeApiResults = false, bool logPersonalInformation = false, HttpClientHandler clientHandler = null) - : base(application, recognizerOptions, null, includeApiResults, clientHandler) + public OverrideFillRecognizer(LuisApplication application, LuisRecognizerOptions recognizerOptions = null) + : base(application, recognizerOptions) { - LogPersonalInformation = logPersonalInformation; } - protected override async Task OnRecognizerResultAsync(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null, CancellationToken cancellationToken = default) + protected override void OnRecognizerResult(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null) { - var properties = await FillLuisEventPropertiesAsync(recognizerResult, turnContext, telemetryProperties, cancellationToken).ConfigureAwait(false); + var properties = FillLuisEventProperties(recognizerResult, turnContext, telemetryProperties); properties.TryAdd("MyImportantProperty", "myImportantValue"); diff --git a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryConvertResult.cs b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryConvertResult.cs index 9b012e84fa..4c3afa96ea 100644 --- a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryConvertResult.cs +++ b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryConvertResult.cs @@ -7,8 +7,6 @@ namespace Microsoft.Bot.Builder.AI.LuisV3.Tests { public class TelemetryConvertResult : IRecognizerConvert { - private RecognizerResult _result; - public TelemetryConvertResult() { } @@ -17,6 +15,7 @@ public TelemetryConvertResult() /// Convert recognizer result. /// /// Result to convert. - public void Convert(dynamic result) => _result = result as RecognizerResult; + public void Convert(dynamic _) + { } } } diff --git a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryOverrideRecognizer.cs b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryOverrideRecognizer.cs index ad2c694b93..b88c2eec5b 100644 --- a/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryOverrideRecognizer.cs +++ b/tests/Microsoft.Bot.Builder.Ai.LUISV3.tests/TelemetryOverrideRecognizer.cs @@ -11,13 +11,12 @@ namespace Microsoft.Bot.Builder.AI.LuisV3.Tests { public class TelemetryOverrideRecognizer : LuisRecognizer { - public TelemetryOverrideRecognizer(IBotTelemetryClient telemetryClient, LuisApplication application, LuisRecognizerOptions recognizerOptions = null, bool includeApiResults = false, bool logPersonalInformation = false, HttpClientHandler clientHandler = null) - : base(application, recognizerOptions, null, includeApiResults, clientHandler) + public TelemetryOverrideRecognizer(LuisApplication application, LuisRecognizerOptions recognizerOptions = null) + : base(application, recognizerOptions) { - LogPersonalInformation = logPersonalInformation; } - protected override Task OnRecognizerResultAsync(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary properties = null, Dictionary metrics = null, CancellationToken cancellationToken = default) + protected override void OnRecognizerResult(RecognizerResult recognizerResult, ITurnContext turnContext, Dictionary properties = null, Dictionary metrics = null) { properties.TryAdd("MyImportantProperty", "myImportantValue"); @@ -38,7 +37,6 @@ protected override Task OnRecognizerResultAsync(RecognizerResult recognizerResul TelemetryClient.TrackEvent( "MySecondEvent", secondEventProperties); - return Task.CompletedTask; } } }