/// <summary> /// Initializes a new instance of the <see cref="CustomQuestionAnswering"/> class. /// </summary> /// <param name="endpoint">The <see cref="QnAMakerEndpoint"/> of the knowledge base to query.</param> /// <param name="options">The <see cref="QnAMakerOptions"/> for the Custom Question Answering Knowledge Base.</param> /// <param name="httpClient">An alternate client with which to talk to Language Service. /// If null, a default client is used for this instance.</param> /// <param name="telemetryClient">The IBotTelemetryClient used for logging telemetry events.</param> /// <param name="logPersonalInformation">Set to true to include personally identifiable information in telemetry events.</param> public CustomQuestionAnswering(QnAMakerEndpoint endpoint, QnAMakerOptions options, HttpClient httpClient, IBotTelemetryClient telemetryClient, bool logPersonalInformation = false) { _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint)); if (string.IsNullOrEmpty(endpoint.KnowledgeBaseId)) { throw new ArgumentException(nameof(endpoint.KnowledgeBaseId)); } if (string.IsNullOrEmpty(endpoint.Host)) { throw new ArgumentException(nameof(endpoint.Host)); } if (string.IsNullOrEmpty(endpoint.EndpointKey)) { throw new ArgumentException(nameof(endpoint.EndpointKey)); } if (_endpoint.Host.EndsWith("v2.0", StringComparison.Ordinal) || _endpoint.Host.EndsWith("v3.0", StringComparison.Ordinal)) { throw new NotSupportedException("v2.0 and v3.0 of QnA Maker service is no longer supported in the QnA Maker."); } _httpClient = httpClient ?? DefaultHttpClient; TelemetryClient = telemetryClient ?? new NullBotTelemetryClient(); LogPersonalInformation = logPersonalInformation; _languageServiceHelper = new LanguageServiceUtils(TelemetryClient, _httpClient, endpoint, options); }
/// <summary> /// Combines QnAMakerOptions passed into the QnAMaker constructor with the options passed as arguments into GetAnswersAsync(). /// </summary> /// <param name="queryOptions">The options for the QnA Maker knowledge base.</param> /// <returns>Return modified options for the QnA Maker knowledge base.</returns> private QnAMakerOptions HydrateOptions(QnAMakerOptions queryOptions) { var hydratedOptions = JsonConvert.DeserializeObject <QnAMakerOptions>(JsonConvert.SerializeObject(Options)); if (queryOptions != null) { if (queryOptions.ScoreThreshold != hydratedOptions.ScoreThreshold && queryOptions.ScoreThreshold != 0) { hydratedOptions.ScoreThreshold = queryOptions.ScoreThreshold; } if (queryOptions.Top != hydratedOptions.Top && queryOptions.Top != 0) { hydratedOptions.Top = queryOptions.Top; } // For backward compatibility of legacy bot code with this SDK if (queryOptions.StrictFilters?.Length > 0) { queryOptions.Filters = LanguageServiceUtils.GetFilters(queryOptions.StrictFilters, queryOptions.StrictFiltersJoinOperator.ToString()); } if (queryOptions.Filters?.MetadataFilter?.Metadata != null) { hydratedOptions.Filters = queryOptions.Filters; } hydratedOptions.Context = queryOptions.Context; hydratedOptions.QnAId = queryOptions.QnAId; hydratedOptions.IsTest = queryOptions.IsTest; hydratedOptions.RankerType = queryOptions.RankerType != null ? queryOptions.RankerType : RankerTypes.DefaultRankerType; hydratedOptions.StrictFiltersJoinOperator = queryOptions.StrictFiltersJoinOperator; } return(hydratedOptions); }