1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import pytest
from azure.ai.language.questionanswering.authoring import AuthoringClient
from azure.core.credentials import AzureKeyCredential
from helpers import QnaAuthoringHelper
from testcase import QuestionAnsweringTestCase
class TestSourcesQnasSynonyms(QuestionAnsweringTestCase):
@pytest.mark.live_test_only("Needs re-recording to work with new common sanitizers")
def test_add_source(self, recorded_test, qna_creds):
client = AuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]))
# create project
project_name = "IssacNewton"
QnaAuthoringHelper.create_test_project(client, project_name=project_name, **self.kwargs_for_polling)
# 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
}
}],
**self.kwargs_for_polling
)
sources = sources_poller.result() # wait until done
for source in sources:
assert source["sourceKind"]
# 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_add_qna(self, recorded_test, qna_creds):
client = AuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["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
)
qnas = qna_poller.result()
for qna in qnas:
assert qna["questions"]
assert qna["answer"]
# 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
def test_add_synonym(self, recorded_test, qna_creds):
client = AuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["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
|