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)); }
public async Task QueryKnowledgeBaseAsync() { QuestionAnsweringClient client = Client; #region Snippet:QuestionAnsweringClient_QueryKnowledgeBaseAsync #if SNIPPET string projectName = "FAQ"; #endif QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should my Surface battery last?"); #if SNIPPET Response <KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync(projectName, options); #else Response <KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync(TestEnvironment.ProjectName, options, TestEnvironment.DeploymentName); #endif foreach (KnowledgeBaseAnswer answer in response.Value.Answers) { Console.WriteLine($"({answer.ConfidenceScore:P2}) {answer.Answer}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); }
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 }
public void Chat() { QuestionAnsweringClient client = Client; KnowledgeBaseAnswer previousAnswer = QuestionAnsweringModelFactory.KnowledgeBaseAnswer(id: 27); #region Snippet:QuestionAnsweringClient_Chat string projectName = "FAQ"; string deploymentName = "prod"; #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 QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should charging take?") { Context = new KnowledgeBaseAnswerRequestContext(previousAnswer.Id.Value) }; Response <KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options); foreach (KnowledgeBaseAnswer answer in response.Value.Answers) { Console.WriteLine($"({answer.ConfidenceScore:P2}) {answer.Answer}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); }
/* uncomment when we have authoring * [Ignore("Used only for the migration guide")] * private async Task MigrationGuide_Authoring() * { #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateClient * IQnAMakerClient client = new QnAMakerClient(new ApiKeyServiceClientCredentials("<QnAMakerSubscriptionKey>"), new HttpClient(), false) * { * Endpoint = "https://westus.api.cognitive.microsoft.com" * }; #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateClient * #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateKnowledgeBase * var createOp = await client.Knowledgebase.CreateAsync(new CreateKbDTO * { * Name = "testqna", QnaList = new List<QnADTO> * { * new QnADTO * { * Questions = new List<string> * { * "hi" * }, * Answer = "hello" * } * } * }); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateKnowledgeBase * #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledeBase * var updateOp = await client.Knowledgebase.UpdateAsync("<KnowledgeBaseID>", * new UpdateKbOperationDTO * { * Add = new UpdateKbOperationDTOAdd * { * QnaList = new List<QnADTO> * { * new QnADTO * { * Questions = new List<string> * { * "bye" * }, * Answer = "goodbye" * } * } * } * }); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledeBase * #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_DownloadKnowledeBase * var kbdata = await client.Knowledgebase.DownloadAsync("<KnowledgeBaseID>", EnvironmentType.Test); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledeBase * #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_DeleteKnowledeBase * await client.Knowledgebase.DeleteAsync("<KnowledgeBaseID>"); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_DeleteKnowledeBase * * }*/ private async Task Language_QnA_MigrationGuide_Runtime() { #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient var endpoint = new Uri("{endpoint}"); var credential = new AzureKeyCredential("{api-key}"); var client = new QuestionAnsweringClient(endpoint, credential); #endregion #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase var response = await client.QueryKnowledgeBaseAsync( "{project-name}", "{deployment-name}", "{question}"); #endregion #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_Chat var options = new QueryKnowledgeBaseOptions( "{project-name}", "{deployment-name}", "{question}"); options.Context = new KnowledgeBaseAnswerRequestContext(1); var responseFollowUp = await client.QueryKnowledgeBaseAsync(options); #endregion }
public async Task ChatAsync() { QuestionAnsweringClient client = Client; KnowledgebaseAnswer previousAnswer = QuestionAnsweringModelFactory.KnowledgebaseAnswer(id: 27); #region Snippet:QuestionAnsweringClient_ChatAsync #if SNIPPET // Answers are ordered by their ConfidenceScore so assume the user choose the first answer below: KnowledgebaseAnswer previousAnswer = answers.Answers.First(); #endif KnowledgebaseQueryOptions options = new KnowledgebaseQueryOptions("How long should charging take?") { Context = new KnowledgebaseAnswerRequestContext(previousAnswer.Id.Value) }; #if SNIPPET Response <KnowledgebaseAnswers> response = await client.QueryKnowledgebaseAsync("FAQ", options); #else Response <KnowledgebaseAnswers> response = await client.QueryKnowledgebaseAsync(TestEnvironment.ProjectName, options, TestEnvironment.DeploymentName); #endif foreach (KnowledgebaseAnswer answer in response.Value.Answers) { Console.WriteLine($"({answer.ConfidenceScore:P2}) {answer.Answer}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); }
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); } }
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)); }
public void QueryKnowledgeBase() { QuestionAnsweringClient client = Client; #region Snippet:QuestionAnsweringClient_QueryKnowledgeBase string projectName = "FAQ"; string deploymentName = "prod"; #if !SNIPPET projectName = TestEnvironment.ProjectName; deploymentName = TestEnvironment.DeploymentName; #endif QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should my Surface battery last?"); Response <KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options); foreach (KnowledgeBaseAnswer answer in response.Value.Answers) { Console.WriteLine($"({answer.ConfidenceScore:P2}) {answer.Answer}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); }