public async Task <ActionResult> Text([FromBody] InputModel inputModel)
        {
            if (inputModel.Document.HasContent())
            {
                // Get settings from cache
                var settingHelper = new SettingHelper(_memoryCache);
                var keys          = $"{SettingKeys.TextAnalyticsEndpoint},{SettingKeys.TextAnalyticsSecret}";
                Dictionary <string, string> settings = settingHelper.GetCachedSettingValuesByKeys(keys);

                // Text analytics
                var textAnalytics = new TextAnalytics(settings[SettingKeys.TextAnalyticsEndpoint], settings[SettingKeys.TextAnalyticsSecret]);
                var response      = await textAnalytics.ProcessText(inputModel.Document);

                return(Ok(response));
            }

            // If it reaches here document has no content return HTTP 400 Bad Request
            return(BadRequest(new { Message = "Document cannot be empty" }));
        }
Example #2
0
        public TextAnalyticsTest()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            SQLHelperConfig.ConnectionConfig = configuration.GetConnectionString("ContentderAIConnection");

            var provider = new ServiceCollection()
                           .AddMemoryCache()
                           .BuildServiceProvider();
            var memoryCache   = provider.GetService <IMemoryCache>();
            var settingHelper = new SettingHelper(memoryCache);

            settingHelper.CacheAllSettings();

            var keys = $"{SettingKeys.TextAnalyticsEndpoint},{SettingKeys.TextAnalyticsSecret}";
            Dictionary <string, string> settings = settingHelper.GetCachedSettingValuesByKeys(keys);

            _textAnalytics = new TextAnalytics(settings[SettingKeys.TextAnalyticsEndpoint], settings[SettingKeys.TextAnalyticsSecret]);
        }