public async Task ExportAndImportAsync() { QuestionAnsweringProjectsClient client = Client; string exportedProjectName = CreateTestProjectName(); await CreateProjectAsync(exportedProjectName); #region Snippet:QuestionAnsweringProjectsClient_ExportProjectAsync Operation <BinaryData> exportOperation = await client.ExportAsync(waitForCompletion : true, exportedProjectName, format : "json"); // retrieve export operation response, and extract url of exported file JsonDocument operationValueJson = JsonDocument.Parse(exportOperation.Value); string exportedFileUrl = operationValueJson.RootElement.GetProperty("resultUrl").ToString(); #endregion Assert.True(exportOperation.HasCompleted); Assert.True(!String.IsNullOrEmpty(exportedFileUrl)); #region Snippet:QuestionAnsweringProjectsClient_ImportProjectAsync // Set import project name and request content string importedProjectName = "{ProjectNameToBeImported}"; #if !SNIPPET importedProjectName = "importedProject"; #endif RequestContent importRequestContent = RequestContent.Create(new { Metadata = new { ProjectName = "NewProjectForExport", Description = "This is the description for a test project", Language = "en", DefaultAnswer = "No answer found for your question.", MultilingualResource = false, CreatedDateTime = "2021-11-25T09=35=33Z", LastModifiedDateTime = "2021-11-25T09=35=33Z", Settings = new { DefaultAnswer = "No answer found for your question." } } }); Operation <BinaryData> importOperation = await client.ImportAsync(waitForCompletion : true, importedProjectName, importRequestContent, format : "json"); Console.WriteLine($"Operation status: {importOperation.GetRawResponse().Status}"); #endregion Assert.True(importOperation.HasCompleted); Assert.AreEqual(200, importOperation.GetRawResponse().Status); #region Snippet:QuestionAnsweringProjectsClient_GetProjectDetailsAsync Response projectDetails = await client.GetProjectDetailsAsync(importedProjectName); Console.WriteLine(projectDetails.Content); #endregion Assert.AreEqual(200, projectDetails.Status); await DeleteProjectAsync(importedProjectName); }
public void CreateQuestionAnsweringProjectsClient() { #region Snippet:QuestionAnsweringProjectsClient_Create Uri endpoint = new Uri("{LanguageEndpoint}"); AzureKeyCredential credential = new AzureKeyCredential("{ApiKey}"); QuestionAnsweringProjectsClient client = new QuestionAnsweringProjectsClient(endpoint, credential); #endregion }
// TODO: Make this test Sync once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696 public async Task KnowledgeSources() { QuestionAnsweringProjectsClient client = Client; #region Snippet:QuestionAnsweringProjectsClient_UpdateSources_UpdateSample // Set request content parameters for updating our new project's sources string sourceUri = "{KnowledgeSourceUri}"; string testProjectName = "{ProjectName}"; #if !SNIPPET sourceUri = "https://www.microsoft.com/en-in/software-download/faq"; testProjectName = CreateTestProjectName(); CreateProject(testProjectName); #endif RequestContent updateSourcesRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { displayName = "MicrosoftFAQ", source = sourceUri, sourceUri = sourceUri, sourceKind = "url", contentStructureKind = "unstructured", refresh = false } } }); #if SNIPPET Operation <BinaryData> updateSourcesOperation = client.UpdateSources(waitForCompletion: false, testProjectName, updateSourcesRequestContent); updateSourcesOperation.WaitForCompletion(); #else // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696 Operation <BinaryData> updateSourcesOperation = InstrumentOperation(client.UpdateSources(WaitUntil.Started, testProjectName, updateSourcesRequestContent)); await updateSourcesOperation.WaitForCompletionAsync(); #endif // Knowledge Sources can be retrieved as follows Pageable <BinaryData> sources = client.GetSources(testProjectName); Console.WriteLine("Sources: "); foreach (BinaryData source in sources) { Console.WriteLine(source); } #endregion Assert.True(updateSourcesOperation.HasCompleted); Assert.That(sources.Any(source => source.ToString().Contains(sourceUri))); #region Snippet:QuestionAnsweringProjectsClient_UpdateQnas string question = "{NewQuestion}"; string answer = "{NewAnswer}"; #if !SNIPPET question = "What is the easiest way to use azure services in my .NET project?"; answer = "Using Microsoft's Azure SDKs"; #endif RequestContent updateQnasRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { questions = new[] { question }, answer = answer } } }); Operation <BinaryData> updateQnasOperation = Client.UpdateQnas(WaitUntil.Completed, testProjectName, updateQnasRequestContent); // QnAs can be retrieved as follows Pageable <BinaryData> qnas = Client.GetQnas(testProjectName); Console.WriteLine("Qnas: "); foreach (var qna in qnas) { Console.WriteLine(qna); } #endregion Assert.True(updateQnasOperation.HasCompleted); Assert.AreEqual(200, updateQnasOperation.GetRawResponse().Status); Assert.That(qnas.Any(qna => qna.ToString().Contains(question))); Assert.That(qnas.Any(qna => qna.ToString().Contains(answer))); #region Snippet:QuestionAnsweringProjectsClient_UpdateSynonyms RequestContent updateSynonymsRequestContent = RequestContent.Create( new { value = new[] { new { alterations = new[] { "qnamaker", "qna maker", } }, new { alterations = new[] { "qna", "question and answer", } } } }); Response updateSynonymsResponse = Client.UpdateSynonyms(testProjectName, updateSynonymsRequestContent); // Synonyms can be retrieved as follows Pageable <BinaryData> synonyms = Client.GetSynonyms(testProjectName); Console.WriteLine("Synonyms: "); foreach (BinaryData synonym in synonyms) { Console.WriteLine(synonym); } #endregion Assert.AreEqual(204, updateSynonymsResponse.Status); Assert.That(synonyms.Any(synonym => synonym.ToString().Contains("qnamaker"))); Assert.That(synonyms.Any(synonym => synonym.ToString().Contains("qna maker"))); #region Snippet:QuestionAnsweringProjectsClient_AddFeedback RequestContent addFeedbackRequestContent = RequestContent.Create( new { records = new[] { new { userId = "userX", userQuestion = "{Follow-up Question}", qnaId = 1 } } }); Response addFeedbackResponse = Client.AddFeedback(testProjectName, addFeedbackRequestContent); #endregion Assert.AreEqual(204, addFeedbackResponse.Status); DeleteProject(testProjectName); }
// TODO: Make this test Sync once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696 public async Task CreateAndDeploy() { QuestionAnsweringProjectsClient client = Client; #region Snippet:QuestionAnsweringProjectsClient_CreateProject // Set project name and request content parameters string newProjectName = "{ProjectName}"; #if !SNIPPET newProjectName = "newFAQ"; #endif RequestContent creationRequestContent = RequestContent.Create( new { description = "This is the description for a test project", language = "en", multilingualResource = false, settings = new { defaultAnswer = "No answer found for your question." } } ); Response creationResponse = client.CreateProject(newProjectName, creationRequestContent); // Projects can be retrieved as follows Pageable <BinaryData> projects = client.GetProjects(); Console.WriteLine("Projects: "); foreach (BinaryData project in projects) { Console.WriteLine(project); } #endregion Assert.AreEqual(201, creationResponse.Status); Assert.That(projects.Any(project => project.ToString().Contains(newProjectName))); #region Snippet:QuestionAnsweringProjectsClient_UpdateSources // Set request content parameters for updating our new project's sources string sourceUri = "{KnowledgeSourceUri}"; #if !SNIPPET sourceUri = "https://www.microsoft.com/en-in/software-download/faq"; #endif RequestContent updateSourcesRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { displayName = "MicrosoftFAQ", source = sourceUri, sourceUri = sourceUri, sourceKind = "url", contentStructureKind = "unstructured", refresh = false } } }); #if SNIPPET Operation <BinaryData> updateSourcesOperation = client.UpdateSources(waitForCompletion: true, newProjectName, updateSourcesRequestContent); #else // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696 Operation <BinaryData> updateSourcesOperation = await client.UpdateSourcesAsync(waitForCompletion : false, newProjectName, updateSourcesRequestContent); await updateSourcesOperation.WaitForCompletionAsync(); #endif // Knowledge Sources can be retrieved as follows Pageable <BinaryData> sources = client.GetSources(newProjectName); Console.WriteLine("Sources: "); foreach (BinaryData source in sources) { Console.WriteLine(source); } #endregion Assert.True(updateSourcesOperation.HasCompleted); Assert.That(sources.Any(source => source.ToString().Contains(sourceUri))); #region Snippet:QuestionAnsweringProjectsClient_DeployProject // Set deployment name and start operation string newDeploymentName = "{DeploymentName}"; #if !SNIPPET newDeploymentName = "production"; #endif #if SNIPPET Operation <BinaryData> deploymentOperation = client.DeployProject(waitForCompletion: true, newProjectName, newDeploymentName); #else // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696 Operation <BinaryData> deploymentOperation = await client.DeployProjectAsync(waitForCompletion : false, newProjectName, newDeploymentName); await deploymentOperation.WaitForCompletionAsync(); #endif // Deployments can be retrieved as follows Pageable <BinaryData> deployments = client.GetDeployments(newProjectName); Console.WriteLine("Deployments: "); foreach (BinaryData deployment in deployments) { Console.WriteLine(deployment); } #endregion Assert.True(deploymentOperation.HasCompleted); Assert.That(deployments.Any(deployment => deployment.ToString().Contains(newDeploymentName))); DeleteProject(newProjectName); }
public async Task KnowledgeSourcesAsync() { QuestionAnsweringProjectsClient client = Client; #region Snippet:QuestionAnsweringProjectsClient_UpdateSourcesAsync_UpdateSample // Set request content parameters for updating our new project's sources string sourceUri = "{KnowledgeSourceUri}"; string testProjectName = "{ProjectName}"; #if !SNIPPET sourceUri = "https://www.microsoft.com/en-in/software-download/faq"; testProjectName = CreateTestProjectName(); await CreateProjectAsync(testProjectName); #endif RequestContent updateSourcesRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { displayName = "MicrosoftFAQ", source = sourceUri, sourceUri = sourceUri, sourceKind = "url", contentStructureKind = "unstructured", refresh = false } } }); Operation <BinaryData> updateSourcesOperation = await client.UpdateSourcesAsync(waitForCompletion : false, testProjectName, updateSourcesRequestContent); await updateSourcesOperation.WaitForCompletionAsync(); // Wait for operation completion Response <BinaryData> updateSourcesOperationResult = await updateSourcesOperation.WaitForCompletionAsync(); Console.WriteLine($"Update Sources operation result: \n{updateSourcesOperationResult}"); // Knowledge Sources can be retrieved as follows AsyncPageable <BinaryData> sources = client.GetSourcesAsync(testProjectName); Console.WriteLine("Sources: "); await foreach (BinaryData source in sources) { Console.WriteLine(source); } #endregion Assert.True(updateSourcesOperation.HasCompleted); Assert.That((await sources.ToEnumerableAsync()).Any(source => source.ToString().Contains(sourceUri))); #region Snippet:QuestionAnsweringProjectsClient_UpdateQnasAsync string question = "{NewQuestion}"; string answer = "{NewAnswer}"; #if !SNIPPET question = "What is the easiest way to use azure services in my .NET project?"; answer = "Using Microsoft's Azure SDKs"; #endif RequestContent updateQnasRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { questions = new[] { question }, answer = answer } } }); Operation <BinaryData> updateQnasOperation = await Client.UpdateQnasAsync(waitForCompletion : true, testProjectName, updateQnasRequestContent); await updateQnasOperation.WaitForCompletionAsync(); // QnAs can be retrieved as follows AsyncPageable <BinaryData> qnas = Client.GetQnasAsync(testProjectName); Console.WriteLine("Qnas: "); await foreach (var qna in qnas) { Console.WriteLine(qna); } #endregion Assert.True(updateQnasOperation.HasCompleted); Assert.AreEqual(200, updateQnasOperation.GetRawResponse().Status); Assert.That((await qnas.ToEnumerableAsync()).Any(source => source.ToString().Contains(question))); Assert.That((await qnas.ToEnumerableAsync()).Any(source => source.ToString().Contains(answer))); #region Snippet:QuestionAnsweringProjectsClient_UpdateSynonymsAsync RequestContent updateSynonymsRequestContent = RequestContent.Create( new { value = new[] { new { alterations = new[] { "qnamaker", "qna maker", } }, new { alterations = new[] { "qna", "question and answer", } } } }); Response updateSynonymsResponse = await Client.UpdateSynonymsAsync(testProjectName, updateSynonymsRequestContent); // Synonyms can be retrieved as follows AsyncPageable <BinaryData> synonyms = Client.GetSynonymsAsync(testProjectName); Console.WriteLine("Synonyms: "); await foreach (BinaryData synonym in synonyms) { Console.WriteLine(synonym); } #endregion Assert.AreEqual(204, updateSynonymsResponse.Status); Assert.That((await synonyms.ToEnumerableAsync()).Any(synonym => synonym.ToString().Contains("qnamaker"))); Assert.That((await synonyms.ToEnumerableAsync()).Any(synonym => synonym.ToString().Contains("qna maker"))); #region Snippet:QuestionAnsweringProjectsClient_AddFeedbackAsync RequestContent addFeedbackRequestContent = RequestContent.Create( new { records = new[] { new { userId = "userX", userQuestion = "{Follow-up question}", qnaId = 1 } } }); Response addFeedbackResponse = await Client.AddFeedbackAsync(testProjectName, addFeedbackRequestContent); #endregion Assert.AreEqual(204, addFeedbackResponse.Status); await DeleteProjectAsync(testProjectName); }
private async Task Language_QnA_MigrationGuide_Authoring() { #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateClient Uri endpoint = new Uri("{LanguageQnaEndpoint}"); AzureKeyCredential credential = new AzureKeyCredential("{ApiKey}"); QuestionAnsweringProjectsClient client = new QuestionAnsweringProjectsClient(endpoint, credential); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateClient #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateProject string newProjectName = "{ProjectName}"; RequestContent creationRequestContent = RequestContent.Create( new { description = "This is the description for a test project", language = "en", multilingualResource = false, settings = new { defaultAnswer = "No answer found for your question." } } ); Response creationResponse = await client.CreateProjectAsync(newProjectName, creationRequestContent); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateProject #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledgeSource string sourceUri = "{SourceURI}"; RequestContent updateSourcesRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { displayName = "MicrosoftFAQ", source = sourceUri, sourceUri = sourceUri, sourceKind = "url", contentStructureKind = "unstructured", refresh = false } } }); Operation <BinaryData> updateSourcesOperation = await client.UpdateSourcesAsync(WaitUntil.Completed, "{ProjectName}", updateSourcesRequestContent); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledgeSource #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateQnas RequestContent updateQnasRequestContent = RequestContent.Create( new[] { new { op = "add", value = new { questions = new[] { "What is the easiest way to use Azure services in my .NET project?" }, answer = "Refer to the Azure SDKs" } } }); Operation <BinaryData> updateQnasOperation = await client.UpdateQnasAsync(WaitUntil.Completed, "{ProjectName}", updateQnasRequestContent); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateQnas #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_ExportProject Operation <BinaryData> exportOperation = client.Export(WaitUntil.Completed, "{ProjectName}", "{ExportFormat}"); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_ExportProject #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_DeleteProject Operation <BinaryData> deletionOperation = await client.DeleteProjectAsync(WaitUntil.Completed, "{ProjectName}"); #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_DeleteProject }