/// <summary>
        /// Initializes a new instance of the <see cref="LuisRecognizer"/> class.
        /// </summary>
        /// <param name="application">The LUIS application to use to recognize text.</param>
        /// <param name="predictionOptions">(Optional) The LUIS prediction options to use.</param>
        /// <param name="includeApiResults">(Optional) TRUE to include raw LUIS API response.</param>
        /// <param name="clientHandler">(Optional) Custom handler for LUIS API calls to allow mocking.</param>
        public LuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, HttpClientHandler clientHandler = null)
        {
            _application       = application ?? throw new ArgumentNullException(nameof(application));
            _options           = predictionOptions ?? new LuisPredictionOptions();
            _includeApiResults = includeApiResults;

            TelemetryClient        = _options.TelemetryClient;
            LogPersonalInformation = _options.LogPersonalInformation;

            var credentials       = new ApiKeyServiceClientCredentials(application.EndpointKey);
            var delegatingHandler = new LuisDelegatingHandler();
            var httpClientHandler = clientHandler ?? CreateRootHandler();
            var currentHandler    = CreateHttpHandlerPipeline(httpClientHandler, delegatingHandler);

            DefaultHttpClient = new HttpClient(currentHandler, false)
            {
                Timeout = TimeSpan.FromMilliseconds(_options.Timeout),
            };

            // assign DefaultHttpClient to _httpClient to expose Timeout in unit tests
            // and keep HttpClient usage as a singleton
            _httpClient = DefaultHttpClient;

            _runtime = new LUISRuntimeClient(credentials, _httpClient, false)
            {
                Endpoint = application.Endpoint,
            };
        }
 public LanguageUnderstandingController()
 {
     _luisClient = new LUISRuntimeClient(new MockCredentials())
     {
         // Ensure the sdk client makes requests to your cognitive service containers instead of the cloud API
         Endpoint = ServiceEndpoint
     };
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuisRecognizer"/> class.
 /// </summary>
 /// <param name="application">The LUIS application to use to recognize text.</param>
 /// <param name="predictionOptions">(Optional) The LUIS prediction options to use.</param>
 /// <param name="includeApiResults">(Optional) TRUE to include raw LUIS API response.</param>
 /// <param name="clientHandler">(Optional) Custom handler for LUIS API calls to allow mocking.</param>
 public LuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, HttpClientHandler clientHandler = null)
 {
     _application       = application ?? throw new ArgumentNullException(nameof(application));
     _options           = predictionOptions ?? new LuisPredictionOptions();
     _includeApiResults = includeApiResults;
     _runtime           = new LUISRuntimeClient(new ApiKeyServiceClientCredentials(application.EndpointKey), clientHandler)
     {
         Endpoint = application.Endpoint,
     };
 }
예제 #4
0
        protected async void UseClientFor(Func <ILUISRuntimeClient, Task> doTest, string className = null, [CallerMemberName] string methodName = "")
        {
            using (MockContext context = MockContext.Start(className ?? ClassName, methodName))
            {
                HttpMockServer.Initialize(className ?? ClassName, methodName, mode);
                ILUISRuntimeClient client = GetClient(HttpMockServer.CreateInstance());
                await doTest(client);

                context.Stop();
            }
        }
예제 #5
0
 public VoiceController(ILogger <VoiceController> logger, ILUISRuntimeClient luisRuntimeClient,
                        IDictionary <string, CallState> callStates, VoiceConfig voiceConfig, LuisSettings luisSettings,
                        IHubContext <CallActivityHub> hubContext)
 {
     _logger            = logger;
     _luisRuntimeClient = luisRuntimeClient;
     _callStates        = callStates;
     _voiceConfig       = voiceConfig;
     _luisSettings      = luisSettings;
     _hubContext        = hubContext;
 }
예제 #6
0
        public LuisService(IOptions <LuisSettings> options,
                           ILUISAuthoringClient luisAuthoringClient,
                           ILUISRuntimeClient luisRuntimeClient,
                           IRedisCacheService redisCache,
                           HttpClient httpClient,
                           ILogger <LuisService> logger)
        {
            _redisCache   = redisCache;
            _luisSettings = options?.Value ?? throw new ArgumentNullException(nameof(options));
            _logger       = logger;
            _httpClient   = httpClient;

            _luisRuntimeClient   = luisRuntimeClient;
            _luisAuthoringClient = luisAuthoringClient;
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LuisRecognizer"/> class.
        /// </summary>
        /// <param name="application">The LUIS application to use to recognize text.</param>
        /// <param name="predictionOptions">(Optional) The LUIS prediction options to use.</param>
        /// <param name="includeApiResults">(Optional) TRUE to include raw LUIS API response.</param>
        /// <param name="clientHandler">(Optional) Custom handler for LUIS API calls to allow mocking.</param>
        public LuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, HttpClientHandler clientHandler = null)
        {
            _application       = application ?? throw new ArgumentNullException(nameof(application));
            _options           = predictionOptions ?? new LuisPredictionOptions();
            _includeApiResults = includeApiResults;

            var credentials       = new ApiKeyServiceClientCredentials(application.EndpointKey);
            var delegatingHandler = new LuisDelegatingHandler();

            // LUISRuntimeClient requires that we explicitly bind to the appropriate constructor.
            _runtime = clientHandler == null
                    ?
                       new LUISRuntimeClient(credentials, delegatingHandler)
                    :
                       new LUISRuntimeClient(credentials, clientHandler, delegatingHandler);

            _runtime.Endpoint = application.Endpoint;
        }