public void Chat()
        {
            QuestionAnsweringClient client         = Client;
            KnowledgeBaseAnswer     previousAnswer = QuestionAnsweringModelFactory.KnowledgeBaseAnswer(qnaId: 27);

            #region Snippet:QuestionAnsweringClient_Chat
            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 = client.GetAnswers("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
        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.º 3
0
        public void GetAnswers()
        {
            QuestionAnsweringClient client = Client;

            #region Snippet:QuestionAnsweringClient_GetAnswers
            string projectName    = "{ProjectName}";
            string deploymentName = "{DeploymentName}";
#if !SNIPPET
            projectName    = TestEnvironment.ProjectName;
            deploymentName = TestEnvironment.DeploymentName;
#endif
            QuestionAnsweringProject project  = new QuestionAnsweringProject(projectName, deploymentName);
            Response <AnswersResult> response = client.GetAnswers("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));
        }