Exemple #1
0
        public async Task AnalyzeConversationWithLanguageAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguageAsync

#if SNIPPET
            ConversationsProject       conversationsProject = new ConversationsProject("Menu", "production");
            AnalyzeConversationOptions options = new AnalyzeConversationOptions()
            {
                Language = "es"
            };
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Tendremos 2 platos de nigiri de salmón braseado.",
                conversationsProject,
                options);
#else
            AnalyzeConversationOptions options = new AnalyzeConversationOptions()
            {
                Language = "es"
            };
            Response <AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
                "Tendremos 2 platos de nigiri de salmón braseado.",
                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"));
        }
Exemple #2
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"));
        }
Exemple #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"));
        }
Exemple #4
0
        public void BadArgument()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysisClient_BadRequest
            try
            {
                ConversationsProject conversationsProject         = new ConversationsProject("invalid-project", "production");
                Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation(
                    "Send an email to Carol about the tomorrow's demo",
                    conversationsProject);
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            #endregion
        }
Exemple #5
0
        public void BadArgument()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysisClient_BadRequest
            try
            {
                ConversationsProject conversationsProject     = new ConversationsProject("invalid-project", "production");
                Response <AnalyzeConversationResult> response = client.AnalyzeConversation(
                    "We'll have 2 plates of seared salmon nigiri.",
                    conversationsProject);
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            #endregion
        }
Exemple #6
0
        public void AnalyzeConversationOrchestrationPredictionQuestionAnswering()
        {
            ConversationAnalysisClient client = Client;

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

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA
            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();
                }
            }
            #endregion
            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("ChitChat-QnA"));
        }
Exemple #7
0
        public void AnalyzeConversationOrchestrationPredictionQuestionAnswering()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPrediction

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

            OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction;
            #endregion
            #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA
            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();
                }
            }
            #endregion
            Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering));
            Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("SushiMaking"));
        }
        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 Score:{intent.ConfidenceScore}");
                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 Score: {entity.ConfidenceScore}");
                Console.WriteLine();
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
            Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Order"));
        }
Exemple #9
0
        public void AnalyzeConversationWithOptions()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptions

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

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

            Response <AnalyzeConversationResult> response = client.AnalyzeConversation(
                "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"));
        }
Exemple #10
0
        public async Task AnalyzeConversationAsync()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationAsync

#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

            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"));
        }
        public void AnalyzeConversationWithOptions()
        {
            ConversationAnalysisClient client = Client;

            #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptions
            TextConversationItem input = new TextConversationItem(
                participantId: "1",
                id: "1",
                text: "Send an email to Carol about the tomorrow's demo.");
            AnalyzeConversationOptions options = new AnalyzeConversationOptions(input)
            {
                IsLoggingEnabled = true,
                Verbose          = true
            };

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

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

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

            Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.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("Setup"));
        }
        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"));
        }