def test_add_synonym(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

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

        # add synonyms
        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)
        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
Ejemplo n.º 2
0
    def test_import_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        export_url = QnaAuthoringHelper.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 = client.begin_import_assets(project_name=project_name,
                                                   options=project)
        import_poller.result()

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

        # create project
        project_name = "IssacNewton"
        QnaAuthoringHelper.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 = client.begin_update_qnas(project_name=project_name,
                                              qnas=[{
                                                  "op": "add",
                                                  "value": {
                                                      "questions": [question],
                                                      "answer": answer
                                                  }
                                              }],
                                              **self.kwargs_for_polling)
        qna_poller.result()

        # assert
        qnas = client.list_qnas(project_name=project_name)
        qna_added = False
        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
Ejemplo n.º 4
0
    def test_add_source(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account, AzureKeyCredential(qna_key))

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

        # add sources
        source_display_name = "MicrosoftFAQ"
        sources_poller = 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
                }
            }]
        )
        sources_poller.result() # wait until done

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

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

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

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

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

        # export project
        export_poller = client.begin_export(project_name=project_name,
                                            format="json")
        result = export_poller.result()
        assert result["status"] == "succeeded"
        assert result["resultUrl"] is not None
    def test_create_project(self, qna_account, qna_key):
        client = QuestionAnsweringProjectsClient(qna_account,
                                                 AzureKeyCredential(qna_key))

        # create project
        project_name = "IssacNewton"
        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
        for p in qna_projects:
            if ("projectName" in p) and p["projectName"] == project_name:
                found = True
        assert found
Ejemplo n.º 8
0
def sample_export_import_project():
    # [START export_import_project]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects import QuestionAnsweringProjectsClient

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

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

        # create project
        project_name = "IssacNewton"
        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 = client.begin_export(project_name=project_name,
                                            format="json")
        export_result = export_poller.result()
        export_url = export_result["resultUrl"]

        # delete old project
        delete_poller = client.begin_delete_project(project_name=project_name)
        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 = client.begin_import_assets(project_name=project_name,
                                                   options=project)
        import_poller.result()

        # list projects
        print("view all qna projects:")
        qna_projects = client.list_projects()
        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"]))
Ejemplo n.º 9
0
def sample_create_and_deploy_project():
    # [START create_and_deploy_project]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects import QuestionAnsweringProjectsClient

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

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

        # create project
        project_name = "IssacNewton"
        project = 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()
        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 = 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"
                }
            }])
        update_sources_poller.result()

        # list sources
        print("list project sources")
        sources = client.list_sources(project_name=project_name)
        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 = client.begin_deploy_project(
            project_name=project_name, deployment_name="production")
        deployment_poller.result()

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

        print("view project deployments")
        for d in deployments:
            print(d)
def sample_update_knowledge_sources():
    # [START update_knowledge_sources]
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.questionanswering.projects import QuestionAnsweringProjectsClient

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

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

        # create project
        project_name = "Microsoft"
        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 = 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
                }
            }])
        sources_poller.result()  # wait until done

        sources = client.list_sources(project_name=project_name)
        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 = 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"
                }
            }])
        qna_poller.result()

        qnas = client.list_qnas(project_name=project_name)
        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
        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)
        for item in synonyms:
            print("synonyms:")
            print("\talterations:")
            for alt in item["alterations"]:
                print("\t\t{}".format(alt))
            print('')