public async Task <Screen> ModerateTextAsync(string textToModerate, IAzureTextModerationOptions options)
        {
            // Convert string to a byte[], then into a stream (for parameter in ScreenText()).
            byte[]       textBytes = Encoding.UTF8.GetBytes(textToModerate);
            MemoryStream stream    = new MemoryStream(textBytes);

            using (var client = GetNewClient())
            {
                return(await client.TextModeration.ScreenTextAsync(options.ContentType, stream, options.Language,
                                                                   options.AutoCorrect, options.DetectPII, options.KeyWordListId, options.Classify));
            }
        }
Example #2
0
        /// <summary>
        /// Moderates the given text using Azure services
        /// </summary>
        /// <remarks>
        /// https://westus.dev.cognitive.microsoft.com/docs/services/57cf753a3f9b070c105bd2c1/operations/57cf753a3f9b070868a1f66f
        /// </remarks>
        private async Task <BlogPostModerationResult> ModerateTextUsingAzureAsync(string txt, IAzureTextModerationOptions options)
        {
            if (txt.Length >= 1024)
            {
                throw new ArgumentException("Text can only be 1024 chars");
            }

            var azureReturnVal = await AzureAPI.ModerateTextAsync(txt, options);

            return(InterpretAzureResult(azureReturnVal));
        }