Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/cognitivelanguage/azure-ai-language-questionanswering-authoring",
"Tag": "python/cognitivelanguage/azure-ai-language-questionanswering-authoring_401205f3a4"
"Tag": "python/cognitivelanguage/azure-ai-language-questionanswering-authoring_ab8ff6ade9"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@


class TestSourcesQnasSynonyms(QuestionAnsweringAuthoringTestCase):
def test_add_source(self, recorded_test, qna_authoring_creds): # type: ignore[name-defined] # pylint: disable=unused-argument
def test_add_chitchat(self, recorded_test, qna_authoring_creds): # type: ignore[name-defined] # pylint: disable=unused-argument
client = QuestionAnsweringAuthoringClient(
qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"])
)
project_name = "IsaacNewton"
AuthoringTestHelper.create_test_project(client, project_name=project_name)
source_display_name = "MicrosoftFAQ"
update_source_ops = [
_models.UpdateSourceRecord(
question = "Hello"
answer = "Hi! How can I help you today?"
update_qna_ops = [
_models.UpdateQnaRecord(
{
"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,
"id": 0,
"answer": answer,
"questions": [question],
},
}
)
]
poller = client.begin_update_sources( # pylint: disable=no-value-for-parameter
poller = client.begin_update_qnas( # pylint: disable=no-value-for-parameter
project_name=project_name,
sources=cast(list[_models.UpdateSourceRecord], update_source_ops),
qnas=cast(list[_models.UpdateQnaRecord], update_qna_ops),
content_type="application/json",
polling_interval=0 if self.is_playback else None, # type: ignore[arg-type] # pylint: disable=using-constant-test
)
poller.result()
assert any(s.get("displayName") == source_display_name for s in client.list_sources(project_name=project_name))
assert any(
(q.get("answer") == answer and question in q.get("questions", []))
for q in client.list_qnas(project_name=project_name)
)

def test_add_qna(self, recorded_test, qna_authoring_creds): # type: ignore[name-defined] # pylint: disable=unused-argument
client = QuestionAnsweringAuthoringClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class TestSourcesQnasSynonymsAsync(QuestionAnsweringAuthoringTestCase):
@pytest.mark.asyncio
async def test_add_source(self, recorded_test, qna_authoring_creds): # type: ignore[name-defined] # pylint: disable=unused-argument
async def test_add_chitchat(self, recorded_test, qna_authoring_creds): # type: ignore[name-defined] # pylint: disable=unused-argument
client = QuestionAnsweringAuthoringClient(
qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"])
)
Expand All @@ -20,31 +20,30 @@ async def test_add_source(self, recorded_test, qna_authoring_creds): # type: ig
await AuthoringAsyncTestHelper.create_test_project(
client, project_name=project_name, polling_interval=0 if self.is_playback else None # pylint: disable=using-constant-test
)
update_source_ops = [
_models.UpdateSourceRecord(
question = "Hello"
answer = "Hi! How can I help you today?"
update_qna_ops = [
_models.UpdateQnaRecord(
{
"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,
"id": 0,
"answer": answer,
"questions": [question],
},
}
)
]
poller = await client.begin_update_sources( # pylint: disable=no-value-for-parameter
poller = await client.begin_update_qnas( # pylint: disable=no-value-for-parameter
project_name=project_name,
sources=cast(list[_models.UpdateSourceRecord], update_source_ops),
qnas=cast(list[_models.UpdateQnaRecord], update_qna_ops),
content_type="application/json",
polling_interval=0 if self.is_playback else None, # type: ignore[arg-type] # pylint: disable=using-constant-test
)
await poller.result()
found = False
async for s in client.list_sources(project_name=project_name):
if s.get("displayName") == "MicrosoftFAQ":
async for qna in client.list_qnas(project_name=project_name):
if qna.get("answer") == answer and question in qna.get("questions", []):
found = True
assert found

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/cognitivelanguage/azure-ai-language-questionanswering",
"Tag": "python/cognitivelanguage/azure-ai-language-questionanswering_4cf6afbd99"
"Tag": "python/cognitivelanguage/azure-ai-language-questionanswering_ce9b04d392"
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@ def test_query_knowledgebase_with_answerspan(self, recorded_test, qna_creds): #
assert answer.short_answer.text
assert answer.short_answer.confidence is not None

def test_query_knowledgebase_filter(self, recorded_test, qna_creds): # pylint: disable=unused-argument
filters = QueryFilters(
metadata_filter=MetadataFilter(
metadata=[
MetadataRecord(key="explicitlytaggedheading", value="check the battery level"),
MetadataRecord(key="explicitlytaggedheading", value="make your battery last"),
],
logical_operation="OR",
),
)
with QuestionAnsweringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"])) as client:
query_params = AnswersOptions(
question="Battery life",
filters=filters,
top=3,
)
response = client.get_answers(
query_params,
project_name=qna_creds["qna_project"],
deployment_name="test",
)
assert response.answers

def test_query_knowledgebase_only_id(self, recorded_test, qna_creds): # pylint: disable=unused-argument
client = QuestionAnsweringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]))
with client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,6 @@ async def test_query_knowledgebase_with_short_answer(self, recorded_test, qna_cr
assert answer.short_answer.text
assert answer.short_answer.confidence is not None

@pytest.mark.asyncio
async def test_query_knowledgebase_filter(self, recorded_test, qna_creds): # pylint: disable=unused-argument
filters = QueryFilters(
metadata_filter=MetadataFilter(
metadata=[
MetadataRecord(key="explicitlytaggedheading", value="check the battery level"),
MetadataRecord(key="explicitlytaggedheading", value="make your battery last"),
],
logical_operation="OR",
)
)
async with QuestionAnsweringClient(
qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"])
) as client:
params = AnswersOptions(
question="Battery life",
top=3,
filters=filters,
)
response = await client.get_answers(
params,
project_name=qna_creds["qna_project"],
deployment_name="production",
)
assert response.answers
assert any( # pylint: disable=use-a-generator
[
a
for a in response.answers
if (a.metadata or {}).get("explicitlytaggedheading") == "check the battery level"
]
)
assert any( # pylint: disable=use-a-generator
[
a
for a in response.answers
if (a.metadata or {}).get("explicitlytaggedheading") == "make your battery last"
]
)

@pytest.mark.asyncio
async def test_query_knowledgebase_overload_errors(self): # negative parameter validation
async with QuestionAnsweringClient("http://fake.com", AzureKeyCredential("123")) as client:
Expand Down
Loading