Exemple #1
0
        // 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);
        }
Exemple #2
0
        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(WaitUntil.Started, 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(WaitUntil.Completed, 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
        }