public async Task ChatAsync()
        {
            QuestionAnsweringClient client         = Client;
            KnowledgeBaseAnswer     previousAnswer = QuestionAnsweringModelFactory.KnowledgeBaseAnswer(qnaId: 27);

            #region Snippet:QuestionAnsweringClient_ChatAsync
            string projectName    = "{ProjectName}";
            string deploymentName = "{DeploymentName}";
#if SNIPPET
            // Answers are ordered by their ConfidenceScore so assume the user choose the first answer below:
            KnowledgeBaseAnswer previousAnswer = answers.Answers.First();
#else
            projectName    = TestEnvironment.ProjectName;
            deploymentName = TestEnvironment.DeploymentName;
#endif
            QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
            AnswersOptions           options = new AnswersOptions
            {
                AnswerContext = new KnowledgeBaseAnswerContext(previousAnswer.QnaId.Value)
            };

            Response <AnswersResult> response = await client.GetAnswersAsync("How long should charging take?", project, options);

            foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
            {
                Console.WriteLine($"({answer.Confidence:P2}) {answer.Answer}");
                Console.WriteLine($"Source: {answer.Source}");
                Console.WriteLine();
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
        }
Exemplo n.º 2
0
        private async Task Language_QnA_MigrationGuide_Runtime()
        {
            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient
            Uri endpoint = new Uri("{LanguageQnaEndpoint}");
            AzureKeyCredential credential = new AzureKeyCredential("{ApiKey}");

            QuestionAnsweringClient client = new QuestionAnsweringClient(endpoint, credential);
            #endregion

#pragma warning disable SA1509 // Opening braces should not be preceded by blank line
            {
                #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase
                QuestionAnsweringProject project  = new QuestionAnsweringProject("{ProjectName}", "{DeploymentName}");
                Response <AnswersResult> response = await client.GetAnswersAsync("{Question}", project);

                #endregion
            }

            {
                #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_Chat
                QuestionAnsweringProject project = new QuestionAnsweringProject("{ProjectName}", "{DeploymentName}");
                AnswersOptions           options = new AnswersOptions
                {
                    AnswerContext = new KnowledgeBaseAnswerContext(1)
                };

                Response <AnswersResult> responseFollowUp = await client.GetAnswersAsync("{Question}", project, options);

                #endregion
            }
#pragma warning restore SA1509 // Opening braces should not be preceded by blank line
        }
Exemplo n.º 3
0
        public void BadArgument()
        {
            QuestionAnsweringClient client = Client;

            #region Snippet:QuestionAnsweringClient_BadRequest
            try
            {
                QuestionAnsweringProject project  = new QuestionAnsweringProject("invalid-knowledgebase", "test");
                Response <AnswersResult> response = client.GetAnswers("Does this knowledge base exist?", project);
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            #endregion
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            const string KEY             = "PON AQUI TU CLAVE DEL RECURSO DE LENGUAJE";
            const string ENDPOINT        = "PON AQUI TU URL DEL RECURSO DE LENGUAJE";
            const string PROJECT_NAME    = "PON AQUI EL NOMBRE DE TU PROYECTO EN LANGUAGE STUDIO";
            const string DEPLOYMENT_NAME = "production";

            QuestionAnsweringClient  cliente  = new QuestionAnsweringClient(new Uri(ENDPOINT), new AzureKeyCredential(KEY));
            QuestionAnsweringProject proyecto = new QuestionAnsweringProject(PROJECT_NAME, DEPLOYMENT_NAME);

            //Bucle de conversación
            while (true)
            {
                //Leemos la pregunta
                Console.Write("Escribe tu pregunta:");
                string pregunta = Console.ReadLine();

                //Invocamos a la API para obtener la respuesta
                Response <AnswersResult> respuesta = cliente.GetAnswers(pregunta, proyecto);

                //Mostramos la respuesta
                Console.WriteLine("Respuesta: {0}\n", respuesta.Value.Answers[0].Answer);
            }
        }
Exemplo n.º 5
0
        public async Task GetAnswersAsync()
        {
            QuestionAnsweringClient client = Client;

            #region Snippet:QuestionAnsweringClient_GetAnswersAsync
            string projectName    = "{ProjectName}";
            string deploymentName = "{DeploymentName}";
#if !SNIPPET
            projectName    = TestEnvironment.ProjectName;
            deploymentName = TestEnvironment.DeploymentName;
#endif
            QuestionAnsweringProject project  = new QuestionAnsweringProject(projectName, deploymentName);
            Response <AnswersResult> response = await client.GetAnswersAsync("How long should my Surface battery last?", project);

            foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
            {
                Console.WriteLine($"({answer.Confidence:P2}) {answer.Answer}");
                Console.WriteLine($"Source: {answer.Source}");
                Console.WriteLine();
            }
            #endregion

            Assert.That(response.GetRawResponse().Status, Is.EqualTo(200));
        }