Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QnAMaker"/> class.
        /// </summary>
        /// <param name="endpoint">The endpoint of the knowledge base to query.</param>
        /// <param name="options">The options for the QnA Maker knowledge base.</param>
        /// <param name="customHttpClient">An alternate client with which to talk to QnAMaker.
        /// If null, a default client is used for this instance.</param>
        public QnAMaker(QnAMakerEndpoint endpoint, QnAMakerOptions options = null, HttpClient customHttpClient = null)
        {
            _httpClient = customHttpClient ?? DefaultHttpClient;

            _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));
            }

            _options = options ?? new QnAMakerOptions();

            if (_options.ScoreThreshold == 0)
            {
                _options.ScoreThreshold = 0.3F;
            }

            if (_options.Top == 0)
            {
                _options.Top = 1;
            }

            if (_options.ScoreThreshold < 0 || _options.ScoreThreshold > 1)
            {
                throw new ArgumentOutOfRangeException(nameof(_options.ScoreThreshold), "Score threshold should be a value between 0 and 1");
            }

            if (_options.Top < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(_options.Top), "Top should be an integer greater than 0");
            }

            if (_options.StrictFilters == null)
            {
                _options.StrictFilters = new Metadata[] { };
            }

            if (_options.MetadataBoost == null)
            {
                _options.MetadataBoost = new Metadata[] { };
            }
        }
 /// <summary>
 /// Creates a new <see cref="QnAMakerMiddleware"/> instance.
 /// </summary>
 /// <param name="endpoint">Endpoint details to connect to the QnA service.</param>
 /// <param name="options">Options to control the behavior of the middleware.</param>
 /// <param name="httpClient">A client with which to talk to QnAMaker.
 /// If null, a default client is used for this instance.</param>
 public QnAMakerMiddleware(QnAMakerEndpoint endpoint, QnAMakerMiddlewareOptions options = null, HttpClient httpClient = null)
 {
     _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     _options  = options ?? new QnAMakerMiddlewareOptions();
     _qnaMaker = new QnAMaker(endpoint, options, httpClient);
 }