Example #1
0
        public async Task <Response <KnowledgeBaseAnswers> > QueryAsync(string projectName, string deploymentName, QueryKnowledgeBaseOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default)
        {
            if (projectName == null)
            {
                throw new ArgumentNullException(nameof(projectName));
            }
            if (deploymentName == null)
            {
                throw new ArgumentNullException(nameof(deploymentName));
            }
            if (knowledgeBaseQueryOptions == null)
            {
                throw new ArgumentNullException(nameof(knowledgeBaseQueryOptions));
            }

            using var message = CreateQueryRequest(projectName, deploymentName, knowledgeBaseQueryOptions);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                KnowledgeBaseAnswers value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = KnowledgeBaseAnswers.DeserializeKnowledgeBaseAnswers(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
Example #2
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"));
        }
Example #3
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"));
        }
 internal QuestionAnsweringTargetIntentResult(TargetKind targetKind, string apiVersion, double confidenceScore, KnowledgeBaseAnswers result) : base(targetKind, apiVersion, confidenceScore)
 {
     Result     = result;
     TargetKind = targetKind;
 }