diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/assets.json b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/assets.json index ebe4f9908e7d..7005c0541281 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/assets.json +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/assets.json @@ -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" } diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources.py index f104a87f739e..d80d8ba16077 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources.py @@ -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( diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources_async.py index 39a485f54a79..01b5a7449585 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering-authoring/tests/test_update_knowledge_sources_async.py @@ -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"]) ) @@ -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 diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/assets.json b/sdk/cognitivelanguage/azure-ai-language-questionanswering/assets.json index 17f266b9de4c..2a7e198ae6e1 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/assets.json +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/assets.json @@ -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" } diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase.py index 62fbcad45a80..5a4e6ed83629 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase.py @@ -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: diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase_async.py index b8e38dd7134f..a05df9f79afb 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_knowledgebase_async.py @@ -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: