Esempio n. 1
0
    async def test_deploy_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create deployable project
        project_name = "IssacNewton"
        await QnaAuthoringAsyncHelper.create_test_project(
            client,
            project_name=project_name,
            is_deployable=True,
            **self.kwargs_for_polling)

        # test deploy
        deployment_name = "production"
        deployment_poller = await client.begin_deploy_project(
            project_name=project_name,
            deployment_name=deployment_name,
            **self.kwargs_for_polling)
        await deployment_poller.result()

        # assert
        deployments = client.list_deployments(project_name=project_name)
        deployment_found = False
        async for d in deployments:
            if ("deploymentName"
                    in d) and d["deploymentName"] == deployment_name:
                deployment_found = True
        assert deployment_found
Esempio n. 2
0
    async def test_add_qna(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        await QnaAuthoringAsyncHelper.create_test_project(
            client, project_name=project_name, **self.kwargs_for_polling)

        # add qnas
        question = "What is the easiest way to use azure services in my .NET project?"
        answer = "Using Microsoft's Azure SDKs"
        qna_poller = await client.begin_update_qnas(project_name=project_name,
                                                    qnas=[{
                                                        "op": "add",
                                                        "value": {
                                                            "questions":
                                                            [question],
                                                            "answer": answer
                                                        }
                                                    }],
                                                    **self.kwargs_for_polling)
        await qna_poller.result()

        # assert
        qnas = client.list_qnas(project_name=project_name)
        qna_added = False
        async for qna in qnas:
            if ("answer" in qna and "questions" in qna) and (
                    qna["answer"] == answer and question in qna["questions"]):
                qna_added = True
        assert qna_added
    async def test_import_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account, AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        export_url = await QnaAuthoringAsyncHelper.create_test_project(client, project_name=project_name, get_export_url=True, delete_old_project=True)

        # import project
        project = {
            "Metadata": {
                "ProjectName": project_name,
                "Description": "biography of Sir Issac Newton",
                "Language": "en",
                "MultilingualResource": False,
                "Settings": {
                    "DefaultAnswer": "no answer"
                }
            }
        }
        import_poller = await client.begin_import_assets(
            project_name=project_name,
            options=project
        )
        await import_poller.result()

        # assert
        project_found = False
        projects = client.list_projects()
        async for p in projects:
            if ("projectName" in p) and p["projectName"] == project_name:
                project_found = True
        assert project_found
Esempio n. 4
0
    async def test_add_source(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        await QnaAuthoringAsyncHelper.create_test_project(
            client, project_name=project_name, **self.kwargs_for_polling)

        # add sources
        source_display_name = "MicrosoftFAQ"
        sources_poller = await client.begin_update_sources(
            project_name=project_name,
            sources=[{
                "op": "add",
                "value": {
                    "displayName": source_display_name,
                    "source":
                    "https://www.microsoft.com/en-in/software-download/faq",
                    "sourceUri":
                    "https://www.microsoft.com/en-in/software-download/faq",
                    "sourceKind": "url",
                    "contentStructureKind": "unstructured",
                    "refresh": False
                }
            }],
            **self.kwargs_for_polling)
        await sources_poller.result()  # wait until done

        # assert
        sources = client.list_sources(project_name=project_name)
        source_added = False
        async for s in sources:
            if ("displayName"
                    in s) and s["displayName"] == source_display_name:
                source_added = True
        assert source_added
Esempio n. 5
0
    async def test_add_synonym(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        await QnaAuthoringAsyncHelper.create_test_project(
            client, project_name=project_name, **self.kwargs_for_polling)

        # add synonyms
        await client.update_synonyms(
            project_name=project_name,
            synonyms={"value": [{
                "alterations": ["qnamaker", "qna maker"]
            }]})

        # assert
        synonym_added = False
        synonyms = client.list_synonyms(project_name=project_name)
        async for s in synonyms:
            if ("alterations" in s) and ("qnamaker" in s["alterations"]
                                         and "qna maker" in s["alterations"]):
                synonym_added = True
        assert synonym_added
Esempio n. 6
0
    async def test_create_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        await client.create_project(project_name=project_name,
                                    options={
                                        "description":
                                        "biography of Sir Issac Newton",
                                        "language": "en",
                                        "multilingualResource": True,
                                        "settings": {
                                            "defaultAnswer": "no answer"
                                        }
                                    })

        # list projects
        qna_projects = client.list_projects()
        found = False
        async for p in qna_projects:
            if ("projectName" in p) and p["projectName"] == project_name:
                found = True
        assert found
    async def test_export_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account, AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        await QnaAuthoringAsyncHelper.create_test_project(client, project_name=project_name)

        # export project
        export_poller = await client.begin_export(
            project_name=project_name,
            format="json"
        )
        result = await export_poller.result()
        assert result["status"] == "succeeded"
        assert result["resultUrl"] is not None
async def sample_create_and_deploy_project_async():
    # [START create_and_deploy_project]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects.aio import QuestionAnsweringProjectsClient

    # get service secrets
    endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"]
    key = os.environ["AZURE_QUESTIONANSWERING_KEY"]

    # create client
    client = QuestionAnsweringProjectsClient(endpoint, AzureKeyCredential(key))
    async with client:

        # create project
        project_name = "IssacNewton"
        project = await client.create_project(
            project_name=project_name,
            options={
                "description": "biography of Sir Issac Newton",
                "language": "en",
                "multilingualResource": True,
                "settings": {
                    "defaultAnswer": "no answer"
                }
            })

        print("view created project info:")
        print("\tname: {}".format(project["projectName"]))
        print("\tlanguage: {}".format(project["language"]))
        print("\tdescription: {}".format(project["description"]))

        # list projects
        print("find created project ..")
        qna_projects = client.list_projects()
        async for p in qna_projects:
            if p["projectName"] == project_name:
                print("project: {}".format(p["projectName"]))
                print("\tlanguage: {}".format(p["language"]))
                print("\tdescription: {}".format(p["description"]))

        # update sources (REQUIRED TO DEPLOY PROJECT)
        update_sources_poller = await client.begin_update_sources(
            project_name=project_name,
            sources=[{
                "op": "add",
                "value": {
                    "displayName": "Issac Newton Bio",
                    "sourceUri": "https://wikipedia.org/wiki/Isaac_Newton",
                    "sourceKind": "url"
                }
            }])
        await update_sources_poller.result()

        # list sources
        print("list project sources")
        sources = client.list_sources(project_name=project_name)
        async for source in sources:
            print("project: {}".format(source["displayName"]))
            print("\tsource: {}".format(source["source"]))
            print("\tsource Uri: {}".format(source["sourceUri"]))
            print("\tsource kind: {}".format(source["sourceKind"]))

        # deploy project
        deployment_poller = await client.begin_deploy_project(
            project_name=project_name, deployment_name="production")
        await deployment_poller.result()

        # list all deployments
        deployments = client.list_deployments(project_name=project_name)

        print("view project deployments")
        async for d in deployments:
            print(d)
Esempio n. 9
0
async def sample_update_knowledge_sources_async():
    # [START update_knowledge_sources]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects.aio import QuestionAnsweringProjectsClient

    # get service secrets
    endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"]
    key = os.environ["AZURE_QUESTIONANSWERING_KEY"]

    # create client
    client = QuestionAnsweringProjectsClient(endpoint, AzureKeyCredential(key))
    async with client:

        # create project
        project_name = "Microsoft"
        await client.create_project(project_name=project_name,
                                    options={
                                        "description":
                                        "test project for some Microsoft QnAs",
                                        "language": "en",
                                        "multilingualResource": True,
                                        "settings": {
                                            "defaultAnswer": "no answer"
                                        }
                                    })

        # sources
        sources_poller = await client.begin_update_sources(
            project_name=project_name,
            sources=[{
                "op": "add",
                "value": {
                    "displayName": "MicrosoftFAQ",
                    "source":
                    "https://www.microsoft.com/en-in/software-download/faq",
                    "sourceUri":
                    "https://www.microsoft.com/en-in/software-download/faq",
                    "sourceKind": "url",
                    "contentStructureKind": "unstructured",
                    "refresh": False
                }
            }])
        await sources_poller.result()  # wait until done

        sources = client.list_sources(project_name=project_name)
        async for item in sources:
            print("source name: {}".format(item["displayName"]))
            print("\tsource: {}".format(item["source"]))
            print("\tsource uri: {}".format(item["sourceUri"]))
            print("\tsource kind: {}".format(item["sourceKind"]))

        # qnas
        qna_poller = await client.begin_update_qnas(
            project_name=project_name,
            qnas=[{
                "op": "add",
                "value": {
                    "questions": [
                        "What is the easiest way to use azure services in my .NET project?"
                    ],
                    "answer":
                    "Using Microsoft's Azure SDKs"
                }
            }])
        await qna_poller.result()

        qnas = client.list_qnas(project_name=project_name)
        async for item in qnas:
            print("qna: {}".format(item["id"]))
            print("\tquestions:")
            for question in item["questions"]:
                print("\t\t{}".format(question))
            print("\tanswer: {}".format(item["answer"]))

        # synonyms
        await client.update_synonyms(project_name=project_name,
                                     synonyms={
                                         "value": [{
                                             "alterations":
                                             ["qnamaker", "qna maker"]
                                         }, {
                                             "alterations":
                                             ["qna", "question and answer"]
                                         }]
                                     })
        synonyms = client.list_synonyms(project_name=project_name)
        async for item in synonyms:
            print("synonyms:")
            print("\talterations:")
            for alt in item["alterations"]:
                print("\t\t{}".format(alt))
            print('')
Esempio n. 10
0
async def sample_export_import_project_async():
    # [START export_import_project]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects.aio import QuestionAnsweringProjectsClient

    # get service secrets
    endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"]
    key = os.environ["AZURE_QUESTIONANSWERING_KEY"]

    # create client
    client = QuestionAnsweringProjectsClient(endpoint, AzureKeyCredential(key))
    async with client:

        # create project
        project_name = "IssacNewton"
        await client.create_project(
            project_name=project_name,
            options={
                "description": "biography of Sir Issac Newton",
                "language": "en",
                "multilingualResource": True,
                "settings": {
                    "defaultAnswer": "no answer"
                }
            })

        # export
        export_poller = await client.begin_export(
            project_name=project_name,
            format="json"
        )
        export_result = await export_poller.result()
        export_url = export_result["resultUrl"]

        # delete old project
        delete_poller = await client.begin_delete_project(
            project_name=project_name
        )
        await delete_poller.result()

        # import project
        project = {
            "Metadata": {
                "ProjectName": "IssacNewton",
                "Description": "biography of Sir Issac Newton",
                "Language": "en",
                "DefaultAnswer": None,
                "MultilingualResource": False,
                "CreatedDateTime": "2022-01-25T13:10:08Z",
                "LastModifiedDateTime": "2022-01-25T13:10:08Z",
                "LastDeployedDateTime": None,
                "Settings": {
                    "DefaultAnswer": "no answer",
                    "EnableHierarchicalExtraction": None,
                    "DefaultAnswerUsedForExtraction": None
                }
            }
        }
        import_poller = await client.begin_import_assets(
            project_name=project_name,
            options=project
        )
        await import_poller.result()

        # list projects
        print("view all qna projects:")
        qna_projects = client.list_projects()
        async for p in qna_projects:
            if p["projectName"] == project_name:
                print("project: {}".format(p["projectName"]))
                print("\tlanguage: {}".format(p["language"]))
                print("\tdescription: {}".format(p["description"]))