コード例 #1
0
        public async Task AnalyzeConversationOrchestrationPredictionQuestionAnsweringAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync
#if SNIPPET
            ConversationsProject orchestrationProject     = new ConversationsProject("DomainOrchestrator", "production");
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "How are you?",
                orchestrationProject);
#else
            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "How are you?",
                TestEnvironment.OrchestrationProject);
#endif
            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            var orchestratorPrediction = customConversationalTaskResult.Result.Prediction as OrchestratorPrediction;
            #endregion

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetProjectKind == TargetProjectKind.QuestionAnswering)
            {
                Console.WriteLine($"Top intent: {respondingProjectName}");

                QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult;

                BinaryData questionAnsweringResponse = qnaTargetIntentResult.Result;
                Console.WriteLine($"Qustion Answering Response: {questionAnsweringResponse.ToString()}");
            }
            Assert.That(targetIntentResult.TargetProjectKind, Is.EqualTo(TargetProjectKind.QuestionAnswering));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("ChitChat-QnA"));
        }
        public async Task AnalyzeConversationWithLanguageAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguageAsync

#if SNIPPET
            AnalyzeConversationOptions options = new AnalyzeConversationOptions(
                "Menu",
                "production",
                "Tendremos 2 platos de nigiri de salmón braseado.")
            {
                Language = "es"
            };
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);
#else
            AnalyzeConversationOptions options = new AnalyzeConversationOptions(
                TestEnvironment.ProjectName,
                TestEnvironment.DeploymentName,
                "Tendremos 2 platos de nigiri de salmón braseado.")
            {
                Language = "es"
            };
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);
#endif

            Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order"));
        }
コード例 #3
0
        public async Task AnalyzeConversationAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationAsync

#if SNIPPET
            ConversationsProject conversationsProject = new ConversationsProject("Menu", "production");

            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "Send an email to Carol about the tomorrow's demo.",
                conversationsProject);
#else
            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "Send an email to Carol about the tomorrow's demo.",
                TestEnvironment.Project);
#endif

            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            ConversationPrediction         conversationPrediction         = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

            Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
            Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

            Console.WriteLine("Intents:");
            foreach (ConversationIntent intent in conversationPrediction.Intents)
            {
                Console.WriteLine($"Category: {intent.Category}");
                Console.WriteLine($"Confidence: {intent.Confidence}");
                Console.WriteLine();
            }

            Console.WriteLine("Entities:");
            foreach (ConversationEntity entity in conversationPrediction.Entities)
            {
                Console.WriteLine($"Category: {entity.Category}");
                Console.WriteLine($"Text: {entity.Text}");
                Console.WriteLine($"Offset: {entity.Offset}");
                Console.WriteLine($"Length: {entity.Length}");
                Console.WriteLine($"Confidence: {entity.Confidence}");
                Console.WriteLine();

                foreach (BaseResolution resolution in entity.Resolutions)
                {
                    if (resolution is DateTimeResolution dateTimeResolution)
                    {
                        Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}");
                        Console.WriteLine($"Timex: {dateTimeResolution.Timex}");
                        Console.WriteLine($"Value: {dateTimeResolution.Value}");
                        Console.WriteLine();
                    }
                }
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Read"));
        }
コード例 #4
0
        public async Task AnalyzeConversationOrchestrationPredictionLuisAsync()
        {
            ConversationAnalysisClient client = Client;

            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "Reserve a table for 2 at the Italian restaurant.",
                TestEnvironment.OrchestrationProject);

            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction;

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.Luis)
            {
                LuisTargetIntentResult luisTargetIntentResult = targetIntentResult as LuisTargetIntentResult;
                BinaryData             luisResponse           = luisTargetIntentResult.Result;

                Console.WriteLine($"LUIS Response: {luisResponse.ToString()}");
            }

            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Luis));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("RestaurantIntent"));
        }
コード例 #5
0
        public async Task AnalyzeConversationOrchestrationPredictionQuestionAnsweringAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync
            string projectName    = "DomainOrchestrator";
            string deploymentName = "production";
#if !SNIPPET
            projectName    = TestEnvironment.OrchestrationProjectName;
            deploymentName = TestEnvironment.OrchestrationDeploymentName;
#endif

            var data = new
            {
                analysisInput = new
                {
                    conversationItem = new
                    {
                        text          = "How are you?",
                        id            = "1",
                        participantId = "1",
                    }
                },
                parameters = new
                {
                    projectName,
                    deploymentName,

                    // Use Utf16CodeUnit for strings in .NET.
                    stringIndexType = "Utf16CodeUnit",
                },
                kind = "Conversation",
            };

            Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));

            using JsonDocument result = await JsonDocument.ParseAsync(response.ContentStream);

            JsonElement conversationalTaskResult = result.RootElement;
            JsonElement orchestrationPrediction  = conversationalTaskResult.GetProperty("result").GetProperty("prediction");
            #endregion

            string      respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString();
            JsonElement targetIntentResult    = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName);

            if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "QuestionAnswering")
            {
                Console.WriteLine($"Top intent: {respondingProjectName}");

                JsonElement questionAnsweringResponse = targetIntentResult.GetProperty("result");
                Console.WriteLine($"Question Answering Response:");
                foreach (JsonElement answer in questionAnsweringResponse.GetProperty("answers").EnumerateArray())
                {
                    Console.WriteLine(answer.GetProperty("answer").GetString());
                }
            }

            Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("QuestionAnswering"));
            Assert.That(respondingProjectName, Is.EqualTo("ChitChat-QnA"));
        }
コード例 #6
0
        public async Task AnalyzeConversationOrchestrationPredictionConversationAsync()
        {
            ConversationAnalysisClient client = Client;

            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "Send an email to Carol about the tomorrow's demo",
                TestEnvironment.OrchestrationProject);

            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction;

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.Conversation)
            {
                ConversationTargetIntentResult cluTargetIntentResult = targetIntentResult as ConversationTargetIntentResult;

                ConversationResult     conversationResult     = cluTargetIntentResult.Result;
                ConversationPrediction conversationPrediction = conversationResult.Prediction;

                Console.WriteLine($"Top Intent: {conversationResult.Prediction.TopIntent}");
                Console.WriteLine($"Intents:");
                foreach (ConversationIntent intent in conversationPrediction.Intents)
                {
                    Console.WriteLine($"Intent Category: {intent.Category}");
                    Console.WriteLine($"Confidence: {intent.Confidence}");
                    Console.WriteLine();
                }

                Console.WriteLine($"Entities:");
                foreach (ConversationEntity entity in conversationPrediction.Entities)
                {
                    Console.WriteLine($"Entity Text: {entity.Text}");
                    Console.WriteLine($"Entity Category: {entity.Category}");
                    Console.WriteLine($"Confidence: {entity.Confidence}");
                    Console.WriteLine($"Starting Position: {entity.Offset}");
                    Console.WriteLine($"Length: {entity.Length}");
                    Console.WriteLine();

                    foreach (BaseResolution resolution in entity.Resolutions)
                    {
                        if (resolution is DateTimeResolution dateTimeResolution)
                        {
                            Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}");
                            Console.WriteLine($"Timex: {dateTimeResolution.Timex}");
                            Console.WriteLine($"Value: {dateTimeResolution.Value}");
                            Console.WriteLine();
                        }
                    }
                }
            }

            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Conversation));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("EmailIntent"));
        }
コード例 #7
0
        public async Task AnalyzeConversationDeepstackAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationDeepstackAsync

#if SNIPPET
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Menu",
                "production",
                "We'll have 2 plates of seared salmon nigiri.");
#else
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                TestEnvironment.ProjectName,
                TestEnvironment.DeploymentName,
                "We'll have 2 plates of seared salmon nigiri.");
#endif

            DeepstackPrediction deepstackPrediction = response.Value.Prediction as DeepstackPrediction;

            Console.WriteLine("Intents:");
            foreach (DeepstackIntent intent in deepstackPrediction.Intents)
            {
                Console.WriteLine($"Category:{intent.Category}");
                Console.WriteLine($"Confidence Score:{intent.ConfidenceScore}");
                Console.WriteLine();
            }

            Console.WriteLine("Entities:");
            foreach (DeepstackEntity entity in deepstackPrediction.Entities)
            {
                Console.WriteLine($"Category: {entity.Category}");
                Console.WriteLine($"Text: {entity.Text}");
                Console.WriteLine($"Offset: {entity.Offset}");
                Console.WriteLine($"Length: {entity.Length}");
                Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}");
                Console.WriteLine();
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(deepstackPrediction.TopIntent, Is.EqualTo("Order"));
        }
コード例 #8
0
        public async Task AnalyzeConversationOrchestrationPredictionQuestionAnsweringAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync
#if SNIPPET
            ConversationsProject orchestrationProject     = new ConversationsProject("DomainOrchestrator", "production");
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "How are you?",
                orchestrationProject);
#else
            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "How are you?",
                TestEnvironment.OrchestrationProject);
#endif
            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction;
            #endregion

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering)
            {
                Console.WriteLine($"Top intent: {respondingProjectName}");

                QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult;

                KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result;

                Console.WriteLine("Answers: \n");
                foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers)
                {
                    Console.WriteLine($"Answer: {answer.Answer}");
                    Console.WriteLine($"Confidence: {answer.Confidence}");
                    Console.WriteLine($"Source: {answer.Source}");
                    Console.WriteLine();
                }
            }
            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("ChitChat-QnA"));
        }
コード例 #9
0
        public async Task AnalyzeConversationWithConversationPredictionResultAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithConversationPredictionAsync

#if SNIPPET
            ConversationsProject conversationsProject     = new ConversationsProject("Menu", "production");
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "We'll have 2 plates of seared salmon nigiri.",
                conversationsProject);
#else
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "We'll have 2 plates of seared salmon nigiri.",
                TestEnvironment.Project);
#endif

            ConversationPrediction conversationPrediction = response.Value.Prediction as ConversationPrediction;

            Console.WriteLine("Intents:");
            foreach (ConversationIntent intent in conversationPrediction.Intents)
            {
                Console.WriteLine($"Category:{intent.Category}");
                Console.WriteLine($"Confidence:{intent.Confidence}");
                Console.WriteLine();
            }

            Console.WriteLine("Entities:");
            foreach (ConversationEntity entity in conversationPrediction.Entities)
            {
                Console.WriteLine($"Category: {entity.Category}");
                Console.WriteLine($"Text: {entity.Text}");
                Console.WriteLine($"Offset: {entity.Offset}");
                Console.WriteLine($"Length: {entity.Length}");
                Console.WriteLine($"Confidence: {entity.Confidence}");
                Console.WriteLine();
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Order"));
        }
コード例 #10
0
        public async Task AnalyzeConversationOrchestrationPredictionQuestionAnsweringAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync

#if SNIPPET
            ConversationsProject orchestrationProject     = new ConversationsProject("DomainOrchestrator", "production");
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Where are the calories per recipe?",
                orchestrationProject);
#else
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Where are the calories per recipe?",
                TestEnvironment.OrchestrationProject);
#endif

            OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction;
            #endregion

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering)
            {
                QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult;

                KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result;

                Console.WriteLine("Answers: \n");
                foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers)
                {
                    Console.WriteLine($"Answer: {answer.Answer}");
                    Console.WriteLine($"Confidence Score: {answer.ConfidenceScore}");
                    Console.WriteLine($"Source: {answer.Source}");
                    Console.WriteLine();
                }
            }
            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("SushiMaking"));
        }
コード例 #11
0
        public async Task AnalyzeConversationWithOptionsAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptionsAsync

#if SNIPPET
            ConversationsProject       conversationsProject = new ConversationsProject("Menu", "production");
            AnalyzeConversationOptions options = new AnalyzeConversationOptions()
            {
                IsLoggingEnabled = true,
                Verbose          = true,
            };

            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "We'll have 2 plates of seared salmon nigiri.",
                conversationsProject,
                options);
#else
            AnalyzeConversationOptions options = new AnalyzeConversationOptions()
            {
                IsLoggingEnabled = true,
                Verbose          = true,
            };

            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "We'll have 2 plates of seared salmon nigiri.",
                TestEnvironment.Project,
                options);
#endif

            Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order"));
        }
コード例 #12
0
        public async Task AnalyzeConversationOrchestrationPredictionConversationAsync()
        {
            ConversationAnalysisClient client = Client;

            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "We'll have 2 plates of seared salmon nigiri.",
                TestEnvironment.OrchestrationProject);

            OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction;

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.Conversation)
            {
                ConversationTargetIntentResult cluTargetIntentResult = targetIntentResult as ConversationTargetIntentResult;

                ConversationResult     conversationResult     = cluTargetIntentResult.Result;
                ConversationPrediction conversationPrediction = conversationResult.Prediction;

                if (!String.IsNullOrEmpty(conversationResult.DetectedLanguage))
                {
                    Console.WriteLine($"Detected Language: {conversationResult.DetectedLanguage}");
                }

                Console.WriteLine($"Top Intent: {conversationResult.Prediction.TopIntent}");
                Console.WriteLine($"Intents:");
                foreach (ConversationIntent intent in conversationPrediction.Intents)
                {
                    Console.WriteLine($"Intent Category: {intent.Category}");
                    Console.WriteLine($"Confidence Score: {intent.ConfidenceScore}");
                    Console.WriteLine();
                }

                Console.WriteLine($"Entities:");
                foreach (ConversationEntity entitiy in conversationPrediction.Entities)
                {
                    Console.WriteLine($"Entity Text: {entitiy.Text}");
                    Console.WriteLine($"Entity Category: {entitiy.Category}");
                    Console.WriteLine($"Confidence Score: {entitiy.ConfidenceScore}");
                    Console.WriteLine($"Starting Position: {entitiy.Offset}");
                    Console.WriteLine($"Length: {entitiy.Length}");
                    Console.WriteLine();
                }
            }

            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Conversation));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("SushiOrder"));
        }
コード例 #13
0
        public async Task AnalyzeConversationAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationAsync

#if SNIPPET
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Menu",
                "production",
                "We'll have 2 plates of seared salmon nigiri.");
#else
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                TestEnvironment.ProjectName,
                TestEnvironment.DeploymentName,
                "We'll have 2 plates of seared salmon nigiri.");
#endif

            Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order"));
        }
コード例 #14
0
        public async Task AnalyzeConversationOrchestrationPredictionLuisAsync()
        {
            ConversationAnalysisClient client = Client;
            var data = new
            {
                analysisInput = new
                {
                    conversationItem = new
                    {
                        text          = "Reserve a table for 2 at the Italian restaurant.",
                        id            = "1",
                        participantId = "1",
                    }
                },
                parameters = new
                {
                    projectName    = TestEnvironment.OrchestrationProjectName,
                    deploymentName = TestEnvironment.OrchestrationDeploymentName,

                    // Use Utf16CodeUnit for strings in .NET.
                    stringIndexType = "Utf16CodeUnit",
                },
                kind = "Conversation",
            };

            Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));

            using JsonDocument result = await JsonDocument.ParseAsync(response.ContentStream);

            JsonElement conversationalTaskResult = result.RootElement;
            JsonElement orchestrationPrediction  = conversationalTaskResult.GetProperty("result").GetProperty("prediction");

            string      respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString();
            JsonElement targetIntentResult    = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName);

            if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "Luis")
            {
                JsonElement luisResponse = targetIntentResult.GetProperty("result");
                Console.WriteLine($"LUIS Response: {luisResponse.GetRawText()}");
            }

            Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("Luis"));
            Assert.That(orchestrationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("RestaurantIntent"));
        }
        private async Task <(IEnumerable <string> jobId, IEnumerable <string> errors)> SubmitConversationsAsync(IEnumerable <AnalyzeConversationsRequest> data)
        {
            var errors = new List <string>();
            var jobs   = new List <string>();

            try
            {
                Log.LogInformation($"Sending language conversation requests.");

                foreach (var request in data)
                {
                    using var input = RequestContent.Create(JsonConvert.SerializeObject(request));
                    var operation = await ConversationAnalysisClient.AnalyzeConversationAsync(WaitUntil.Started, input).ConfigureAwait(false);

                    var response = await operation.UpdateStatusAsync().ConfigureAwait(false);

                    using JsonDocument result = JsonDocument.Parse(response.ContentStream);
                    var jobResults = result.RootElement;
                    var jobId      = jobResults.GetProperty("jobId");
                    Log.LogInformation($"Submitting TA job: {jobId}");
                    jobs.Add(jobId.ToString());
                }

                return(jobs, errors);
            }
            catch (OperationCanceledException)
            {
                throw new TimeoutException($"The operation has timed out after {RequestTimeout.TotalSeconds} seconds.");
            }

            // do not catch throttling errors, rather throw and retry
            catch (RequestFailedException e) when(e.Status != 429)
            {
                errors.Add($"Conversation analytics request failed with error: {e.Message}");
            }

            return(jobs, errors);
        }
コード例 #16
0
        public async Task AnalyzeConversationOrchestrationPredictionLuisAsync()
        {
            ConversationAnalysisClient client = Client;

            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Book me flight from London to Paris",
                TestEnvironment.OrchestrationProject);

            OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction;

            string             respondingProjectName = orchestratorPrediction.TopIntent;
            TargetIntentResult targetIntentResult    = orchestratorPrediction.Intents[respondingProjectName];

            if (targetIntentResult.TargetKind == TargetKind.Luis)
            {
                LuisTargetIntentResult luisTargetIntentResult = targetIntentResult as LuisTargetIntentResult;
                BinaryData             luisResponse           = luisTargetIntentResult.Result;

                Console.WriteLine($"LUIS Response: {luisResponse.ToString()}");
            }

            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Luis));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("FlightBooking"));
        }
コード例 #17
0
        public async Task AnalyzeConversationOrchestrationPredictionConversationAsync()
        {
            ConversationAnalysisClient client = Client;
            var data = new
            {
                analysisInput = new
                {
                    conversationItem = new
                    {
                        text          = "Send an email to Carol about tomorrow's demo",
                        id            = "1",
                        participantId = "1",
                    }
                },
                parameters = new
                {
                    projectName    = TestEnvironment.OrchestrationProjectName,
                    deploymentName = TestEnvironment.OrchestrationDeploymentName,

                    // Use Utf16CodeUnit for strings in .NET.
                    stringIndexType = "Utf16CodeUnit",
                },
                kind = "Conversation",
            };

            Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));

            using JsonDocument result = await JsonDocument.ParseAsync(response.ContentStream);

            JsonElement conversationalTaskResult = result.RootElement;
            JsonElement orchestrationPrediction  = conversationalTaskResult.GetProperty("result").GetProperty("prediction");

            string      respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString();
            JsonElement targetIntentResult    = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName);

            if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "Conversation")
            {
                JsonElement conversationResult     = targetIntentResult.GetProperty("result");
                JsonElement conversationPrediction = conversationResult.GetProperty("prediction");

                Console.WriteLine($"Top Intent: {conversationPrediction.GetProperty("topIntent").GetString()}");
                Console.WriteLine($"Intents:");
                foreach (JsonElement intent in conversationPrediction.GetProperty("intents").EnumerateArray())
                {
                    Console.WriteLine($"Intent Category: {intent.GetProperty("category").GetString()}");
                    Console.WriteLine($"Confidence: {intent.GetProperty("confidenceScore").GetSingle()}");
                    Console.WriteLine();
                }

                Console.WriteLine($"Entities:");
                foreach (JsonElement entity in conversationPrediction.GetProperty("entities").EnumerateArray())
                {
                    Console.WriteLine($"Entity Text: {entity.GetProperty("text").GetString()}");
                    Console.WriteLine($"Entity Category: {entity.GetProperty("category").GetString()}");
                    Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}");
                    Console.WriteLine($"Starting Position: {entity.GetProperty("offset").GetInt32()}");
                    Console.WriteLine($"Length: {entity.GetProperty("length").GetInt32()}");
                    Console.WriteLine();

                    if (!entity.TryGetProperty("resolutions", out JsonElement resolutions))
                    {
                        continue;
                    }

                    foreach (JsonElement resolution in resolutions.EnumerateArray())
                    {
                        if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
                        {
                            Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
                            Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
                            Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
                            Console.WriteLine();
                        }
                    }
                }
            }

            Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("Conversation"));
            Assert.That(orchestrationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("EmailIntent"));
        }
        public async Task AnalyzeConversationWithLanguageAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguageAsync
            TextConversationItem input = new TextConversationItem(
                participantId: "1",
                id: "1",
                text: "Tendremos 2 platos de nigiri de salmón braseado.")
            {
                Language = "es"
            };
            AnalyzeConversationOptions options = new AnalyzeConversationOptions(input);

#if SNIPPET
            ConversationsProject conversationsProject = new ConversationsProject("Menu", "production");

            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                textConversationItem,
                conversationsProject,
                options);
#else
            Response <AnalyzeConversationTaskResult> response = await client.AnalyzeConversationAsync(
                "Tendremos 2 platos de nigiri de salmón braseado.",
                TestEnvironment.Project,
                options);
#endif

            CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
            ConversationPrediction         conversationPrediction         = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

            Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
            Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

            Console.WriteLine("Intents:");
            foreach (ConversationIntent intent in conversationPrediction.Intents)
            {
                Console.WriteLine($"Category: {intent.Category}");
                Console.WriteLine($"Confidence: {intent.Confidence}");
                Console.WriteLine();
            }

            Console.WriteLine("Entities:");
            foreach (ConversationEntity entity in conversationPrediction.Entities)
            {
                Console.WriteLine($"Category: {entity.Category}");
                Console.WriteLine($"Text: {entity.Text}");
                Console.WriteLine($"Offset: {entity.Offset}");
                Console.WriteLine($"Length: {entity.Length}");
                Console.WriteLine($"Confidence: {entity.Confidence}");
                Console.WriteLine();

                foreach (BaseResolution resolution in entity.Resolutions)
                {
                    if (resolution is DateTimeResolution dateTimeResolution)
                    {
                        Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}");
                        Console.WriteLine($"Timex: {dateTimeResolution.Timex}");
                        Console.WriteLine($"Value: {dateTimeResolution.Value}");
                        Console.WriteLine();
                    }
                }
            }

            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Read"));
        }
コード例 #19
0
        public async Task AnalyzeConversationWithOptionsAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptionsAsync
            string projectName    = "Menu";
            string deploymentName = "production";
#if !SNIPPET
            projectName    = TestEnvironment.ProjectName;
            deploymentName = TestEnvironment.DeploymentName;
#endif

            var data = new
            {
                analysisInput = new
                {
                    conversationItem = new
                    {
                        text          = "Send an email to Carol about tomorrow's demo",
                        id            = "1",
                        participantId = "1",
                    }
                },
                parameters = new
                {
                    projectName,
                    deploymentName,
                    verbose = true,

                    // Use Utf16CodeUnit for strings in .NET.
                    stringIndexType = "Utf16CodeUnit",
                },
                kind = "Conversation",
            };

            Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));

            #endregion

            using JsonDocument result = await JsonDocument.ParseAsync(response.ContentStream);

            JsonElement conversationalTaskResult = result.RootElement;
            JsonElement conversationPrediction   = conversationalTaskResult.GetProperty("result").GetProperty("prediction");

            Console.WriteLine($"Project Kind: {conversationPrediction.GetProperty("projectKind").GetString()}");
            Console.WriteLine($"Top intent: {conversationPrediction.GetProperty("topIntent").GetString()}");

            Console.WriteLine("Intents:");
            foreach (JsonElement intent in conversationPrediction.GetProperty("intents").EnumerateArray())
            {
                Console.WriteLine($"Category: {intent.GetProperty("category").GetString()}");
                Console.WriteLine($"Confidence: {intent.GetProperty("confidenceScore").GetSingle()}");
                Console.WriteLine();
            }

            Console.WriteLine("Entities:");
            foreach (JsonElement entity in conversationPrediction.GetProperty("entities").EnumerateArray())
            {
                Console.WriteLine($"Category: {entity.GetProperty("category").GetString()}");
                Console.WriteLine($"Text: {entity.GetProperty("text").GetString()}");
                Console.WriteLine($"Offset: {entity.GetProperty("offset").GetInt32()}");
                Console.WriteLine($"Length: {entity.GetProperty("length").GetInt32()}");
                Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}");
                Console.WriteLine();

                if (!entity.TryGetProperty("resolutions", out JsonElement resolutions))
                {
                    continue;
                }

                foreach (JsonElement resolution in resolutions.EnumerateArray())
                {
                    if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
                    {
                        Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
                        Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
                        Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
                        Console.WriteLine();
                    }
                }
            }

            Assert.That(response.Status, Is.EqualTo(200));
            Assert.That(conversationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("Send"));
        }