From 8aa54625091597e8d1e4085f809f611e401307de Mon Sep 17 00:00:00 2001 From: Gary Pretty Date: Mon, 22 Jun 2020 18:36:04 +0100 Subject: [PATCH 1/3] Add missing code docs for the AI libraries (LUIS / QnA) --- .../Generator/GeographyV2.cs | 19 ++++++++ .../Generator/OrdinalV2.cs | 11 +++++ .../ITelemetryRecognizer.cs | 9 ++++ .../LuisAdaptiveRecognizer.cs | 11 +++++ .../LuisApplication.cs | 3 ++ .../LuisComponentRegistration.cs | 11 +++++ .../LuisExtensions.cs | 3 ++ .../LuisRecognizer.cs | 9 ++++ .../LuisRecognizerOptions.cs | 8 ++++ .../LuisRecognizerOptionsV2.cs | 3 ++ .../LuisRecognizerOptionsV3.cs | 3 ++ .../LuisTelemetryConstants.cs | 47 +++++++++++++++++++ .../Microsoft.Bot.Builder.AI.Luis.csproj | 7 +-- .../V3/LuisApplication.cs | 3 ++ .../Dialogs/QnAMakerDialog.cs | 2 + .../ITelemetryQnAMaker.cs | 3 ++ .../Microsoft.Bot.Builder.AI.QnA.csproj | 5 -- .../Models/FeedbackRecords.cs | 9 ++-- .../Models/Metadata.cs | 11 +++++ .../Models/QnAMakerTraceInfo.cs | 6 +++ .../Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs | 26 ++++++++++ .../QnAMakerEndpoint.cs | 3 ++ .../QnAMakerOptions.cs | 19 +++++++- .../QnAMakerRecognizer.cs | 29 ++++++++++++ .../Utils/QnATelemetryConstants.cs | 39 +++++++++++++++ 25 files changed, 283 insertions(+), 16 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/GeographyV2.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/GeographyV2.cs index f8f20037ff..90af68c343 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/GeographyV2.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/GeographyV2.cs @@ -47,10 +47,29 @@ public GeographyV2(string type, string location) /// public static class Types { + /// + /// Constant for LUIS geographic location type of POI. + /// public const string POI = "poi"; + + /// + /// Constant for LUIS geographic location type of City. + /// public const string City = "city"; + + /// + /// Constant for LUIS geographic location type Country or Region. + /// public const string CountryRegion = "countryRegion"; + + /// + /// Constant for LUIS geographic location type of Continent. + /// public const string Continent = "continent"; + + /// + /// Constant for LUIS geographic location type of State. + /// public const string State = "state"; } } diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/OrdinalV2.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/OrdinalV2.cs index f2112b94db..982637d71f 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/OrdinalV2.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/Generator/OrdinalV2.cs @@ -47,8 +47,19 @@ public OrdinalV2(string relativeTo, long offset) /// public static class Anchor { + /// + /// Constant for Offset anchor type of Current. + /// public const string Current = "current"; + + /// + /// Constant for Offset anchor type of End. + /// public const string End = "end"; + + /// + /// Constant for Offset anchor type of Start. + /// public const string Start = "start"; } } diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/ITelemetryRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/ITelemetryRecognizer.cs index 5aad3e4df0..5d39c738cf 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/ITelemetryRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/ITelemetryRecognizer.cs @@ -34,6 +34,15 @@ public interface ITelemetryRecognizer : IRecognizer /// The LUIS results of the analysis of the current message text in the current turn's context activity. Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default); + /// + /// Runs an utterance through a recognizer and returns a strongly-typed recognizer result. + /// + /// The recognition result type. + /// Turn context. + /// Dictionary containing additional properties to be attached to the outgoing telemetry item. + /// Dictionary containing additional metrics to be attached to the outgoing telemetry item. + /// Cancellation token. + /// Analysis of utterance. Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default) where T : IRecognizerConvert, new(); diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisAdaptiveRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisAdaptiveRecognizer.cs index 0e95fa023b..59260e2ad6 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisAdaptiveRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisAdaptiveRecognizer.cs @@ -19,6 +19,9 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public class LuisAdaptiveRecognizer : Recognizer { + /// + /// The Kind name for this recognizer. + /// [JsonProperty("$kind")] public const string Kind = "Microsoft.LuisRecognizer"; @@ -136,6 +139,14 @@ public LuisRecognizerOptionsV3 RecognizerOptions(DialogContext dialogContext) }; } + /// + /// Uses the returned from the and populates a dictionary of string + /// with properties to be logged into telemetry. Including any additional properties that were passed into the method. + /// + /// An instance of to extract the telemetry properties from. + /// A collection of additional properties to be added to the returned dictionary of properties. + /// An instance of . + /// The dictionary of properties to be logged with telemetry for the recongizer result. protected override Dictionary FillRecognizerResultTelemetryProperties(RecognizerResult recognizerResult, Dictionary telemetryProperties, DialogContext dc) { var (logPersonalInfo, error) = this.LogPersonalInformation.TryGetValue(dc.State); diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisApplication.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisApplication.cs index 29949a1d8a..7dad7d8535 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisApplication.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisApplication.cs @@ -12,6 +12,9 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public class LuisApplication { + /// + /// Initializes a new instance of the class. + /// public LuisApplication() { } diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisComponentRegistration.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisComponentRegistration.cs index fbd779f223..43836c6267 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisComponentRegistration.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisComponentRegistration.cs @@ -15,11 +15,22 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public class LuisComponentRegistration : ComponentRegistration, IComponentDeclarativeTypes { + /// + /// Gets a list of declarative type objects. + /// + /// An instance of . + /// A collection of of . public IEnumerable GetDeclarativeTypes(ResourceExplorer resourceExplorer) { yield return new DeclarativeType(LuisAdaptiveRecognizer.Kind); } + /// + /// Gets a list of declarative type objects. + /// + /// An instance of . + /// An instance of . + /// A collection of of . public IEnumerable GetConverters(ResourceExplorer resourceExplorer, SourceContext sourceContext) { yield return new ArrayExpressionConverter(); diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisExtensions.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisExtensions.cs index 190f2846d0..c35dbafedc 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisExtensions.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisExtensions.cs @@ -10,6 +10,9 @@ namespace Microsoft.Bot.Builder.AI.Luis { + /// + /// Extension methods for LUIS. + /// public static class LuisExtensions { /// diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizer.cs index 16954ad55e..f37e4b0a97 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizer.cs @@ -22,6 +22,9 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public class LuisRecognizer : ITelemetryRecognizer { + /// + /// The declarative type for this recognizer. + /// [JsonProperty("$kind")] public const string DeclarativeType = "Microsoft.LuisRecognizer"; @@ -123,6 +126,12 @@ public LuisRecognizer(string applicationEndpoint, LuisPredictionOptions predicti { } + /// + /// Gets the default HttpClient to be used when calling the LUIS API. + /// + /// + /// A . + /// public static HttpClient DefaultHttpClient { get; private set; } /// diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptions.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptions.cs index ba42629b8d..19e8a1ff5a 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptions.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptions.cs @@ -14,6 +14,10 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public abstract class LuisRecognizerOptions { + /// + /// Initializes a new instance of the class. + /// + /// An instance of . protected LuisRecognizerOptions(LuisApplication application) { Application = application ?? throw new ArgumentNullException(nameof(application)); @@ -49,6 +53,10 @@ protected LuisRecognizerOptions(LuisApplication application) /// If true, personal information is logged to Telemetry; otherwise the properties will be filtered. public bool LogPersonalInformation { get; set; } = false; + /// + /// Gets or sets a value indicating whether flag to indicate if full results from the LUIS API should be returned with the recognizer result. + /// + /// A value indicating whether full results from the LUIS API should be returned with the recognizer result. public bool IncludeAPIResults { get; set; } = false; // Support original ITurnContext diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV2.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV2.cs index 3bb0486a38..25e3bbf550 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV2.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV2.cs @@ -15,6 +15,9 @@ namespace Microsoft.Bot.Builder.AI.Luis { + /// + /// Options for . + /// public class LuisRecognizerOptionsV2 : LuisRecognizerOptions { /// diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV3.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV3.cs index 9ee8ac98c3..9bf2164bd6 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV3.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisRecognizerOptionsV3.cs @@ -16,6 +16,9 @@ namespace Microsoft.Bot.Builder.AI.Luis { + /// + /// Options for . + /// public class LuisRecognizerOptionsV3 : LuisRecognizerOptions { /// diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisTelemetryConstants.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisTelemetryConstants.cs index e878856c56..e00816bef3 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisTelemetryConstants.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/LuisTelemetryConstants.cs @@ -8,17 +8,64 @@ namespace Microsoft.Bot.Builder.AI.Luis /// public static class LuisTelemetryConstants { + /// + /// The Key used when storing a LUIS Result in a custom event within telemetry. + /// public static readonly string LuisResult = "LuisResult"; // Event name + + /// + /// The Key used when storing a LUIS app ID in a custom event within telemetry. + /// public static readonly string ApplicationIdProperty = "applicationId"; + + /// + /// The Key used when storing a LUIS intent in a custom event within telemetry. + /// public static readonly string IntentProperty = "intent"; + + /// + /// The Key used when storing a LUIS intent score in a custom event within telemetry. + /// public static readonly string IntentScoreProperty = "intentScore"; + + /// + /// The Key used when storing a LUIS intent in a custom event within telemetry. + /// public static readonly string Intent2Property = "intent2"; + + /// + /// The Key used when storing a LUIS intent score in a custom event within telemetry. + /// public static readonly string IntentScore2Property = "intentScore2"; + + /// + /// The Key used when storing LUIS entities in a custom event within telemetry. + /// public static readonly string EntitiesProperty = "entities"; + + /// + /// The Key used when storing the LUIS query in a custom event within telemetry. + /// public static readonly string QuestionProperty = "question"; + + /// + /// The Key used when storing an Activity ID in a custom event within telemetry. + /// public static readonly string ActivityIdProperty = "activityId"; + + /// + /// The Key used when storing a sentiment label in a custom event within telemetry. + /// public static readonly string SentimentLabelProperty = "sentimentLabel"; + + /// + /// The Key used when storing a LUIS sentiment score in a custom event within telemetry. + /// public static readonly string SentimentScoreProperty = "sentimentScore"; + + /// + /// The Key used when storing the FromId in a custom event within telemetry. + /// public static readonly string FromIdProperty = "fromId"; } } diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj index cfaf785696..bf3fe3aa7c 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj @@ -23,12 +23,7 @@ true - - - $(NoWarn);CS1591 - - - + diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/V3/LuisApplication.cs b/libraries/Microsoft.Bot.Builder.AI.LUIS/V3/LuisApplication.cs index e26d67f0a1..9c468a3f5c 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/V3/LuisApplication.cs +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/V3/LuisApplication.cs @@ -13,6 +13,9 @@ namespace Microsoft.Bot.Builder.AI.LuisV3 /// public class LuisApplication { + /// + /// Initializes a new instance of the class. + /// public LuisApplication() { } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs index b07bc39293..097ed1516c 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs @@ -351,6 +351,7 @@ public QnAMakerDialog([CallerFilePath] string sourceFilePath = "", [CallerLineNu return await base.BeginDialogAsync(dc, dialogOptions, cancellationToken).ConfigureAwait(false); } + /// public override Task ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default) { var interrupted = dc.State.GetValue(TurnPath.Interrupted, () => false); @@ -363,6 +364,7 @@ public override Task ContinueDialogAsync(DialogContext dc, Can return base.ContinueDialogAsync(dc, cancellationToken); } + /// protected override async Task OnPreBubbleEventAsync(DialogContext dc, DialogEvent e, CancellationToken cancellationToken) { if (dc.Context.Activity.Type == ActivityTypes.Message) diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/ITelemetryQnAMaker.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/ITelemetryQnAMaker.cs index 1b32720bf9..f49edf28d3 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/ITelemetryQnAMaker.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/ITelemetryQnAMaker.cs @@ -6,6 +6,9 @@ namespace Microsoft.Bot.Builder.AI.QnA { + /// + /// Interface for adding telemetry logging capabilities to . + /// public interface ITelemetryQnAMaker { /// diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj b/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj index 1406c9056b..9114ab030a 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj @@ -21,11 +21,6 @@ Full true - - - - $(NoWarn);CS1591 - diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/FeedbackRecords.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/FeedbackRecords.cs index fe30a538cb..5d832eee46 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/FeedbackRecords.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/FeedbackRecords.cs @@ -10,9 +10,12 @@ namespace Microsoft.Bot.Builder.AI.QnA /// public class FeedbackRecords { - // - // List of feedback records - // + /// + /// Gets or sets the list of feedback records. + /// + /// + /// List of feedback records. + /// [JsonProperty("feedbackRecords")] public FeedbackRecord[] Records { get; set; } } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/Metadata.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/Metadata.cs index 87b91e2320..3a2c4df49b 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/Metadata.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/Metadata.cs @@ -6,12 +6,23 @@ namespace Microsoft.Bot.Builder.AI.QnA { + /// + /// Represents the Metadata object sent as part of QnA Maker requests. + /// [Serializable] public class Metadata { + /// + /// Gets or sets the name for the Metadata property. + /// + /// A string. [JsonProperty(PropertyName = "name")] public string Name { get; set; } + /// + /// Gets or sets the value for the Metadata property. + /// + /// A string. [JsonProperty(PropertyName = "value")] public string Value { get; set; } } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs index 3bb7b817be..a9c6b5b760 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs @@ -104,6 +104,12 @@ public class QnAMakerTraceInfo [JsonProperty("rankerType")] public string RankerType { get; set; } + /// + /// Gets or sets the collection to be sent when calling QnA Maker to boost results. + /// + /// + /// An array of . + /// [Obsolete("This property is no longer used and will be ignored")] [JsonIgnore] public Metadata[] MetadataBoost { get; set; } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs index 7a7467f250..7b7c27eae2 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs @@ -17,8 +17,19 @@ namespace Microsoft.Bot.Builder.AI.QnA /// public class QnAMaker : IQnAMakerClient, ITelemetryQnAMaker { + /// + /// The name of the QnAMaker class. + /// public static readonly string QnAMakerName = nameof(QnAMaker); + + /// + /// The type used when logging QnA Maker trace. + /// public static readonly string QnAMakerTraceType = "https://www.qnamaker.ai/schemas/trace"; + + /// + /// The label used when logging QnA Maker trace. + /// public static readonly string QnAMakerTraceLabel = "QnAMaker Trace"; private readonly HttpClient _httpClient; @@ -115,6 +126,12 @@ public QnAMaker(QnAMakerService service, QnAMakerOptions options = null, HttpCli { } + /// + /// Gets the to be used when calling the QnA Maker API. + /// + /// + /// A instance of . + /// public static HttpClient DefaultHttpClient { get; } = new HttpClient(); /// @@ -222,6 +239,15 @@ public async Task CallTrainAsync(FeedbackRecords feedbackRecords) await this.activeLearningTrainHelper.CallTrainAsync(feedbackRecords).ConfigureAwait(false); } + /// + /// Executed when a result is returned from QnA Maker. + /// + /// An array of . + /// The . + /// Additional properties to be logged to telemetry with the LuisResult event. + /// Additional metrics to be logged to telemetry with the LuisResult event. + /// A . + /// A Task representing the work to be executed. protected virtual async Task OnQnaResultsAsync( QueryResult[] queryResults, ITurnContext turnContext, diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerEndpoint.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerEndpoint.cs index e17d265234..72403196a8 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerEndpoint.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerEndpoint.cs @@ -11,6 +11,9 @@ namespace Microsoft.Bot.Builder.AI.QnA /// public class QnAMakerEndpoint { + /// + /// Initializes a new instance of the class. + /// public QnAMakerEndpoint() { } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerOptions.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerOptions.cs index e7b8e0d70f..22a27883f4 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerOptions.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerOptions.cs @@ -11,6 +11,9 @@ namespace Microsoft.Bot.Builder.AI.QnA /// public class QnAMakerOptions { + /// + /// Initializes a new instance of the class. + /// public QnAMakerOptions() { ScoreThreshold = 0.3f; @@ -67,9 +70,21 @@ public QnAMakerOptions() [JsonProperty("qnAId")] public int QnAId { get; set; } + /// + /// Gets or sets the collection to be sent when calling QnA Maker to filter results. + /// + /// + /// An array of . + /// [JsonProperty("strictFilters")] - public Metadata[] StrictFilters { get; set; } - + public Metadata[] StrictFilters { get; set; } + + /// + /// Gets or sets the collection to be sent when calling QnA Maker to boost results. + /// + /// + /// An array of . + /// [Obsolete("This property is no longer used and will be ignored")] [JsonIgnore] public Metadata[] MetadataBoost { get; set; } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs index a54ba96dde..cfb1f0a951 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs @@ -21,13 +21,22 @@ namespace Microsoft.Bot.Builder.AI.QnA.Recognizers /// public class QnAMakerRecognizer : Recognizer { + /// + /// The declarative type for this recognizer. + /// [JsonProperty("$kind")] public const string Kind = "Microsoft.QnAMakerRecognizer"; + /// + /// Key used when adding the intent to the intents collection. + /// public const string QnAMatchIntent = "QnAMatch"; private const string IntentPrefix = "intent="; + /// + /// Initializes a new instance of the class. + /// public QnAMakerRecognizer() { } @@ -128,6 +137,12 @@ public QnAMakerRecognizer() [JsonProperty("qnaId")] public IntExpression QnAId { get; set; } = 0; + /// + /// Gets or sets the to be used when calling the QnA Maker API. + /// + /// + /// A instance of . + /// [JsonIgnore] public HttpClient HttpClient { get; set; } @@ -149,6 +164,15 @@ public QnAMakerRecognizer() [JsonProperty("enablePreciseAnswer")] public BoolExpression EnablePreciseAnswer { get; set; } = false; + /// + /// Return results of the call to QnA Maker. + /// + /// Context object containing information for a single turn of conversation with a user. + /// The incoming activity received from the user. The Text property value is used as the query text for QnA Maker. + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Additional properties to be logged to telemetry with the LuisResult event. + /// Additional metrics to be logged to telemetry with the LuisResult event. + /// A containing the QnA Maker result. public override async Task RecognizeAsync(DialogContext dialogContext, Activity activity, CancellationToken cancellationToken, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null) { // Identify matched intents @@ -241,6 +265,11 @@ public override async Task RecognizeAsync(DialogContext dialog return recognizerResult; } + /// + /// Gets an instance of . + /// + /// The used to access state. + /// An instance of . protected virtual Task GetQnAMakerClientAsync(DialogContext dc) { var qnaClient = dc.Context.TurnState.Get(); diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/QnATelemetryConstants.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/QnATelemetryConstants.cs index 530abc81f9..b35f158762 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/QnATelemetryConstants.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/QnATelemetryConstants.cs @@ -8,15 +8,54 @@ namespace Microsoft.Bot.Builder.AI.QnA /// public static class QnATelemetryConstants { + /// + /// The Key used for the custom event type within telemetry. + /// public static readonly string QnaMsgEvent = "QnaMessage"; // Event name + + /// + /// The Key used when storing a QnA Knowledge Base ID in a custom event within telemetry. + /// public static readonly string KnowledgeBaseIdProperty = "knowledgeBaseId"; + + /// + /// The Key used when storing a QnA Answer in a custom event within telemetry. + /// public static readonly string AnswerProperty = "answer"; + + /// + /// The Key used when storing a flag indicating if a QnA article was found in a custom event within telemetry. + /// public static readonly string ArticleFoundProperty = "articleFound"; + + /// + /// The Key used when storing the Channel ID in a custom event within telemetry. + /// public static readonly string ChannelIdProperty = "channelId"; + + /// + /// The Key used when storing a matched question ID in a custom event within telemetry. + /// public static readonly string MatchedQuestionProperty = "matchedQuestion"; + + /// + /// The Key used when storing the identified question text in a custom event within telemetry. + /// public static readonly string QuestionProperty = "question"; + + /// + /// The Key used when storing the identified question ID in a custom event within telemetry. + /// public static readonly string QuestionIdProperty = "questionId"; + + /// + /// The Key used when storing a QnA Maker result score in a custom event within telemetry. + /// public static readonly string ScoreProperty = "score"; + + /// + /// The Key used when storing a username in a custom event within telemetry. + /// public static readonly string UsernameProperty = "username"; } } From f7641dc04e7a4640917ab7756bbef9415ae3863e Mon Sep 17 00:00:00 2001 From: Gabo Gilabert Date: Tue, 30 Jun 2020 21:41:22 -0400 Subject: [PATCH 2/3] Manually fixed some merge conflicts to match master --- .../Microsoft.Bot.Builder.AI.Luis.csproj | 4 +- .../Models/QnAMakerTraceInfo.cs | 10 --- .../QnAMakerRecognizer.cs | 71 ++++++++----------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj index bf3fe3aa7c..67f5b82651 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj @@ -23,7 +23,7 @@ true - + @@ -47,4 +47,4 @@ - + \ No newline at end of file diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs index a9c6b5b760..19f2900daf 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Models/QnAMakerTraceInfo.cs @@ -113,15 +113,5 @@ public class QnAMakerTraceInfo [Obsolete("This property is no longer used and will be ignored")] [JsonIgnore] public Metadata[] MetadataBoost { get; set; } - - /// - /// Gets or sets AnswerSpanRequest. - /// Users can request PreciseAnswer from QnAMaker using this configuration. - /// - /// - /// AnswerSpanRequest for requesting PreciseAnswer. - /// - [JsonProperty("answerSpanRequest")] - public AnswerSpanRequest AnswerSpanRequest { get; set; } } } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs index cfb1f0a951..1334e76693 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMakerRecognizer.cs @@ -1,5 +1,5 @@ -// Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. using System; using System.Collections.Generic; @@ -155,15 +155,6 @@ public QnAMakerRecognizer() [JsonProperty("logPersonalInformation")] public BoolExpression LogPersonalInformation { get; set; } = "=settings.telemetry.logPersonalInformation"; - /// - /// Gets or sets a value indicating whether to enable PreciseAnswer generation. - /// - /// - /// Choice whether to generate precise answer or not. - /// - [JsonProperty("enablePreciseAnswer")] - public BoolExpression EnablePreciseAnswer { get; set; } = false; - /// /// Return results of the call to QnA Maker. /// @@ -176,7 +167,7 @@ public QnAMakerRecognizer() public override async Task RecognizeAsync(DialogContext dialogContext, Activity activity, CancellationToken cancellationToken, Dictionary telemetryProperties = null, Dictionary telemetryMetrics = null) { // Identify matched intents - var recognizerResult = new RecognizerResult() + var recognizerResult = new RecognizerResult { Text = activity.Text, Intents = new Dictionary(), @@ -188,14 +179,18 @@ public override async Task RecognizeAsync(DialogContext dialog return recognizerResult; } - List filters = new List(); + var filters = new List(); if (IncludeDialogNameInMetadata.GetValue(dialogContext.State)) { - filters.Add(new Metadata() { Name = "dialogName", Value = dialogContext.ActiveDialog.Id }); + filters.Add(new Metadata + { + Name = "dialogName", + Value = dialogContext.ActiveDialog.Id + }); } // if there is $qna.metadata set add to filters - var externalMetadata = this.Metadata?.GetValue(dialogContext.State); + var externalMetadata = Metadata?.GetValue(dialogContext.State); if (externalMetadata != null) { filters.AddRange(externalMetadata); @@ -207,14 +202,13 @@ public override async Task RecognizeAsync(DialogContext dialog dialogContext.Context, new QnAMakerOptions { - Context = this.Context?.GetValue(dialogContext.State), - ScoreThreshold = this.Threshold.GetValue(dialogContext.State), + Context = Context?.GetValue(dialogContext.State), + ScoreThreshold = Threshold.GetValue(dialogContext.State), StrictFilters = filters.ToArray(), - Top = this.Top.GetValue(dialogContext.State), - QnAId = this.QnAId.GetValue(dialogContext.State), - RankerType = this.RankerType.GetValue(dialogContext.State), - IsTest = this.IsTest, - EnablePreciseAnswer = this.EnablePreciseAnswer.GetValue(dialogContext.State) + Top = Top.GetValue(dialogContext.State), + QnAId = QnAId.GetValue(dialogContext.State), + RankerType = RankerType.GetValue(dialogContext.State), + IsTest = IsTest }, null).ConfigureAwait(false); @@ -223,7 +217,7 @@ public override async Task RecognizeAsync(DialogContext dialog QueryResult topAnswer = null; foreach (var answer in answers) { - if ((topAnswer == null) || (answer.Score > topAnswer.Score)) + if (topAnswer == null || answer.Score > topAnswer.Score) { topAnswer = answer; } @@ -231,24 +225,17 @@ public override async Task RecognizeAsync(DialogContext dialog if (topAnswer.Answer.Trim().ToLower().StartsWith(IntentPrefix)) { - recognizerResult.Intents.Add(topAnswer.Answer.Trim().Substring(IntentPrefix.Length).Trim(), new IntentScore() { Score = topAnswer.Score }); + recognizerResult.Intents.Add(topAnswer.Answer.Trim().Substring(IntentPrefix.Length).Trim(), new IntentScore { Score = topAnswer.Score }); } else { - recognizerResult.Intents.Add(QnAMatchIntent, new IntentScore() { Score = topAnswer.Score }); + recognizerResult.Intents.Add(QnAMatchIntent, new IntentScore { Score = topAnswer.Score }); } var answerArray = new JArray(); answerArray.Add(topAnswer.Answer); ObjectPath.SetPathValue(recognizerResult, "entities.answer", answerArray); - if (!string.IsNullOrEmpty(topAnswer.AnswerSpan?.Text)) - { - var answerSpanArray = new JArray(); - answerSpanArray.Add(topAnswer.AnswerSpan.Text); - ObjectPath.SetPathValue(recognizerResult, "entities.answerspan", answerSpanArray); - } - var instance = new JArray(); instance.Add(JObject.FromObject(topAnswer)); ObjectPath.SetPathValue(recognizerResult, "entities.$instance.answer", instance); @@ -257,10 +244,10 @@ public override async Task RecognizeAsync(DialogContext dialog } else { - recognizerResult.Intents.Add("None", new IntentScore() { Score = 1.0f }); + recognizerResult.Intents.Add("None", new IntentScore { Score = 1.0f }); } - this.TrackRecognizerResult(dialogContext, "QnAMakerRecognizerResult", this.FillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties), telemetryMetrics); + TrackRecognizerResult(dialogContext, "QnAMakerRecognizerResult", FillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties), telemetryMetrics); return recognizerResult; } @@ -279,19 +266,19 @@ protected virtual Task GetQnAMakerClientAsync(DialogContext dc) return Task.FromResult(qnaClient); } - var (epKey, error) = this.EndpointKey.TryGetValue(dc.State); - var (hn, error2) = this.HostName.TryGetValue(dc.State); - var (kbId, error3) = this.KnowledgeBaseId.TryGetValue(dc.State); - var (logPersonalInfo, error4) = this.LogPersonalInformation.TryGetValue(dc.State); + var (epKey, error) = EndpointKey.TryGetValue(dc.State); + var (hn, error2) = HostName.TryGetValue(dc.State); + var (kbId, error3) = KnowledgeBaseId.TryGetValue(dc.State); + var (logPersonalInfo, error4) = LogPersonalInformation.TryGetValue(dc.State); var endpoint = new QnAMakerEndpoint { - EndpointKey = (string)epKey ?? throw new ArgumentNullException(nameof(EndpointKey), error), - Host = (string)hn ?? throw new ArgumentNullException(nameof(HostName), error2), - KnowledgeBaseId = (string)kbId ?? throw new ArgumentNullException(nameof(KnowledgeBaseId), error3) + EndpointKey = epKey ?? throw new ArgumentNullException(nameof(EndpointKey), error), + Host = hn ?? throw new ArgumentNullException(nameof(HostName), error2), + KnowledgeBaseId = kbId ?? throw new ArgumentNullException(nameof(KnowledgeBaseId), error3) }; - return Task.FromResult(new QnAMaker(endpoint, new QnAMakerOptions(), this.HttpClient, this.TelemetryClient, (bool)logPersonalInfo)); + return Task.FromResult(new QnAMaker(endpoint, new QnAMakerOptions(), HttpClient, TelemetryClient, logPersonalInfo)); } } } From 447347afa1c2943452f5f70097e73564d9aa1c02 Mon Sep 17 00:00:00 2001 From: Gabo Gilabert Date: Tue, 30 Jun 2020 21:45:11 -0400 Subject: [PATCH 3/3] Fixed other naming errors for new variables that came with the merge --- .../Dialogs/QnAMakerDialog.cs | 6 ++-- .../Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs | 12 +++---- .../Utils/BindToActivity.cs | 9 +++--- .../Utils/GenerateAnswerUtils.cs | 32 +++++++++---------- .../Utils/TrainUtils.cs | 12 +++---- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs index abdc70bdbe..bc21ae98b0 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs @@ -74,7 +74,7 @@ public class QnAMakerDialog : WaterfallDialog private const string DefaultCardNoMatchText = "None of the above."; private const string DefaultCardNoMatchResponse = "Thanks for the feedback."; - private float maximumScoreForLowScoreVariation = 0.95F; + private float _maximumScoreForLowScoreVariation = 0.95F; /// /// Initializes a new instance of the class. @@ -479,8 +479,8 @@ private async Task CallGenerateAnswerAsync(WaterfallStepContex stepContext.Values[ValueProperty.QnAData] = new List(response.Answers); // Check if active learning is enabled. - // maximumScoreForLowScoreVariation is the score above which no need to check for feedback. - if (response.Answers.Any() && response.Answers.First().Score <= maximumScoreForLowScoreVariation) + // _maximumScoreForLowScoreVariation is the score above which no need to check for feedback. + if (response.Answers.Any() && response.Answers.First().Score <= _maximumScoreForLowScoreVariation) { // Get filtered list of the response that support low score variation criteria. response.Answers = qnaClient.GetLowScoreVariation(response.Answers); diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs index 7b7c27eae2..eff3e93b47 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs @@ -36,8 +36,8 @@ public class QnAMaker : IQnAMakerClient, ITelemetryQnAMaker private readonly QnAMakerEndpoint _endpoint; - private GenerateAnswerUtils generateAnswerHelper; - private TrainUtils activeLearningTrainHelper; + private readonly GenerateAnswerUtils _generateAnswerHelper; + private readonly TrainUtils _activeLearningTrainHelper; /// /// Initializes a new instance of the class. @@ -84,8 +84,8 @@ public QnAMaker(QnAMakerEndpoint endpoint, QnAMakerOptions options, HttpClient h TelemetryClient = telemetryClient ?? new NullBotTelemetryClient(); LogPersonalInformation = logPersonalInformation; - this.generateAnswerHelper = new GenerateAnswerUtils(TelemetryClient, _endpoint, options, _httpClient); - this.activeLearningTrainHelper = new TrainUtils(_endpoint, _httpClient); + this._generateAnswerHelper = new GenerateAnswerUtils(TelemetryClient, _endpoint, options, _httpClient); + this._activeLearningTrainHelper = new TrainUtils(_endpoint, _httpClient); } /// @@ -212,7 +212,7 @@ public async Task GetAnswersRawAsync( throw new ArgumentException("Null or empty text"); } - var result = await this.generateAnswerHelper.GetAnswersRawAsync(turnContext, messageActivity, options).ConfigureAwait(false); + var result = await this._generateAnswerHelper.GetAnswersRawAsync(turnContext, messageActivity, options).ConfigureAwait(false); await OnQnaResultsAsync(result.Answers, turnContext, telemetryProperties, telemetryMetrics, CancellationToken.None).ConfigureAwait(false); @@ -236,7 +236,7 @@ public QueryResult[] GetLowScoreVariation(QueryResult[] queryResult) /// A representing the asynchronous operation. public async Task CallTrainAsync(FeedbackRecords feedbackRecords) { - await this.activeLearningTrainHelper.CallTrainAsync(feedbackRecords).ConfigureAwait(false); + await this._activeLearningTrainHelper.CallTrainAsync(feedbackRecords).ConfigureAwait(false); } /// diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/BindToActivity.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/BindToActivity.cs index 9946bf390c..f70dbfa5fc 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/BindToActivity.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/BindToActivity.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. + using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.Builder.Dialogs; @@ -9,21 +10,21 @@ namespace Microsoft.Bot.Builder.AI.QnA.Utils { internal class BindToActivity : ITemplate { - private Activity activity; + private readonly Activity _activity; public BindToActivity(Activity activity) { - this.activity = activity; + _activity = activity; } public Task BindAsync(DialogContext context, object data = null, CancellationToken cancellationToken = default) { - return Task.FromResult(activity); + return Task.FromResult(_activity); } public override string ToString() { - return $"{this.activity.Text}"; + return $"{_activity.Text}"; } } } diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/GenerateAnswerUtils.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/GenerateAnswerUtils.cs index 5312ed5521..1cc93be2d0 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/GenerateAnswerUtils.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/GenerateAnswerUtils.cs @@ -15,9 +15,9 @@ namespace Microsoft.Bot.Builder.AI.QnA /// internal class GenerateAnswerUtils { - private readonly IBotTelemetryClient telemetryClient; - private QnAMakerEndpoint _endpoint; - private readonly HttpClient httpClient; + private readonly HttpClient _httpClient; + private readonly IBotTelemetryClient _telemetryClient; + private readonly QnAMakerEndpoint _endpoint; /// /// Initializes a new instance of the class. @@ -28,12 +28,12 @@ internal class GenerateAnswerUtils /// Http client. public GenerateAnswerUtils(IBotTelemetryClient telemetryClient, QnAMakerEndpoint endpoint, QnAMakerOptions options, HttpClient httpClient) { - this.telemetryClient = telemetryClient; - this._endpoint = endpoint; + _telemetryClient = telemetryClient; + _endpoint = endpoint; - this.Options = options ?? new QnAMakerOptions(); - ValidateOptions(this.Options); - this.httpClient = httpClient; + Options = options ?? new QnAMakerOptions(); + ValidateOptions(Options); + _httpClient = httpClient; } /// @@ -52,7 +52,7 @@ public GenerateAnswerUtils(IBotTelemetryClient telemetryClient, QnAMakerEndpoint [Obsolete] public async Task GetAnswersAsync(ITurnContext turnContext, IMessageActivity messageActivity, QnAMakerOptions options) { - var result = await this.GetAnswersRawAsync(turnContext, messageActivity, options).ConfigureAwait(false); + var result = await GetAnswersRawAsync(turnContext, messageActivity, options).ConfigureAwait(false); return result.Answers; } @@ -138,7 +138,7 @@ private static void ValidateOptions(QnAMakerOptions options) { options.StrictFilters = new Metadata[] { }; } - + if (options.RankerType == null) { options.RankerType = RankerTypes.DefaultRankerType; @@ -152,7 +152,7 @@ private static void ValidateOptions(QnAMakerOptions options) /// Return modified options for the QnA Maker knowledge base. private QnAMakerOptions HydrateOptions(QnAMakerOptions queryOptions) { - var hydratedOptions = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(this.Options)); + var hydratedOptions = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(Options)); if (queryOptions != null) { @@ -169,7 +169,7 @@ private QnAMakerOptions HydrateOptions(QnAMakerOptions queryOptions) if (queryOptions.StrictFilters?.Length > 0) { hydratedOptions.StrictFilters = queryOptions.StrictFilters; - } + } hydratedOptions.Context = queryOptions.Context; hydratedOptions.QnAId = queryOptions.QnAId; @@ -188,7 +188,7 @@ private async Task QueryQnaServiceAsync(Activity messageActivity, { question = messageActivity.Text, top = options.Top, - strictFilters = options.StrictFilters, + strictFilters = options.StrictFilters, scoreThreshold = options.ScoreThreshold, context = options.Context, qnaId = options.QnAId, @@ -196,7 +196,7 @@ private async Task QueryQnaServiceAsync(Activity messageActivity, rankerType = options.RankerType }, Formatting.None); - var httpRequestHelper = new HttpRequestUtils(httpClient); + var httpRequestHelper = new HttpRequestUtils(_httpClient); var response = await httpRequestHelper.ExecuteHttpRequestAsync(requestUrl, jsonRequest, _endpoint).ConfigureAwait(false); var result = await FormatQnaResultAsync(response, options).ConfigureAwait(false); @@ -208,12 +208,12 @@ private async Task EmitTraceInfoAsync(ITurnContext turnContext, Activity message { var traceInfo = new QnAMakerTraceInfo { - Message = (Activity)messageActivity, + Message = messageActivity, QueryResults = result, KnowledgeBaseId = _endpoint.KnowledgeBaseId, ScoreThreshold = options.ScoreThreshold, Top = options.Top, - StrictFilters = options.StrictFilters, + StrictFilters = options.StrictFilters, Context = options.Context, QnAId = options.QnAId, IsTest = options.IsTest, diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/TrainUtils.cs b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/TrainUtils.cs index a2e7124223..c13cf62411 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/TrainUtils.cs +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Utils/TrainUtils.cs @@ -13,8 +13,8 @@ namespace Microsoft.Bot.Builder.AI.QnA /// internal class TrainUtils { - private QnAMakerEndpoint _endpoint; - private readonly HttpClient httpClient; + private readonly HttpClient _httpClient; + private readonly QnAMakerEndpoint _endpoint; /// /// Initializes a new instance of the class. @@ -23,8 +23,8 @@ internal class TrainUtils /// Http client. public TrainUtils(QnAMakerEndpoint endpoint, HttpClient httpClient) { - this._endpoint = endpoint; - this.httpClient = httpClient; + _endpoint = endpoint; + _httpClient = httpClient; } /// @@ -45,7 +45,7 @@ public async Task CallTrainAsync(FeedbackRecords feedbackRecords) } // Call train - await this.QueryTrainAsync(feedbackRecords).ConfigureAwait(false); + await QueryTrainAsync(feedbackRecords).ConfigureAwait(false); } private async Task QueryTrainAsync(FeedbackRecords feedbackRecords) @@ -53,7 +53,7 @@ private async Task QueryTrainAsync(FeedbackRecords feedbackRecords) var requestUrl = $"{_endpoint.Host}/knowledgebases/{_endpoint.KnowledgeBaseId}/train"; var jsonRequest = JsonConvert.SerializeObject(feedbackRecords, Formatting.None); - var httpRequestHelper = new HttpRequestUtils(httpClient); + var httpRequestHelper = new HttpRequestUtils(_httpClient); var response = await httpRequestHelper.ExecuteHttpRequestAsync(requestUrl, jsonRequest, _endpoint).ConfigureAwait(false); } }