diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md b/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md index 3cf11d0f0450f..cd944a173c6ca 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md @@ -1,12 +1,9 @@ # Release History -## 1.1.0b2 (Unreleased) +## 1.1.0b2 (2022-07-19) ### Features Added - -### Breaking Changes - -### Bugs Fixed +* Added Azure Active Directory (AAD) authentication support ### Other Changes * Python 2.7 is no longer supported. Please use Python version 3.6 or later. diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md b/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md index 71bc4adae852c..016658d31125b 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md @@ -16,16 +16,14 @@ _Azure SDK Python packages support for Python 2.7 ended 01 January 2022. For mor - Python 3.6 or later is required to use this package. - An [Azure subscription][azure_subscription] -- An existing Question Answering resource - -> Note: the new unified Cognitive Language Services are not currently available for deployment. +- A Language Service resource ### Install the package Install the Azure QuestionAnswering client library for Python with [pip][pip_link]: ```bash -pip install azure-ai-language-questionanswering +pip install azure-ai-language-questionanswering --pre ``` ### Authenticate the client @@ -69,6 +67,37 @@ credential = AzureKeyCredential("{api-key}") client = QuestionAnsweringProjectsClient(endpoint, credential) ``` +#### Create a client with an Azure Active Directory Credential + +To use an [Azure Active Directory (AAD) token credential][cognitive_authentication_aad], +provide an instance of the desired credential type obtained from the +[azure-identity][azure_identity_credentials] library. +Note that regional endpoints do not support AAD authentication. Create a [custom subdomain][custom_subdomain] +name for your resource in order to use this type of authentication. + +Authentication with AAD requires some initial setup: + +- [Install azure-identity][install_azure_identity] +- [Register a new AAD application][register_aad_app] +- [Grant access][grant_role_access] to the Language service by assigning the "Cognitive Services Language Reader" role to your service principal. + +After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use. +As an example, [DefaultAzureCredential][default_azure_credential] +can be used to authenticate the client: + +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: +`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` + +Use the returned token credential to authenticate the client: + +```python +from azure.ai.textanalytics import QuestionAnsweringClient +from azure.identity import DefaultAzureCredential + +credential = DefaultAzureCredential() +client = QuestionAnsweringClient(endpoint="https://.cognitiveservices.azure.com/", credential=credential) +``` + ## Key concepts ### QuestionAnsweringClient @@ -317,5 +346,12 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [questionanswering_refdocs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-questionanswering/latest/azure.ai.language.questionanswering.html [questionanswering_rest_docs]: https://docs.microsoft.com/rest/api/cognitiveservices-qnamaker/ [questionanswering_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/README.md +[cognitive_authentication_aad]: https://docs.microsoft.com/azure/cognitive-services/authentication#authenticate-with-azure-active-directory +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials +[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain +[install_azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#install-the-package +[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal +[grant_role_access]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal +[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fsdk%2Ftemplate%2Fazure-template%2FREADME.png) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_patch.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_patch.py index b6f03dd0d37c3..35df1ce90e90a 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_patch.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_patch.py @@ -3,13 +3,32 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------- -from typing import Any - -from azure.core.credentials import AzureKeyCredential +from typing import Union, Any +from azure.core.credentials import AzureKeyCredential, TokenCredential +from azure.core.pipeline.policies import AzureKeyCredentialPolicy, BearerTokenCredentialPolicy from ._question_answering_client import QuestionAnsweringClient as QuestionAnsweringClientGenerated +def _authentication_policy(credential, **kwargs): + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if isinstance(credential, AzureKeyCredential): + authentication_policy = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential, **kwargs + ) + elif hasattr(credential, "get_token"): + authentication_policy = BearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"]), **kwargs + ) + else: + raise TypeError( + "Unsupported credential: {}. Use an instance of AzureKeyCredential " + "or a token credential from azure.identity".format(type(credential)) + ) + return authentication_policy + + class QuestionAnsweringClient(QuestionAnsweringClientGenerated): """The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. @@ -21,12 +40,19 @@ class QuestionAnsweringClient(QuestionAnsweringClientGenerated): https://.api.cognitiveservices.azure.com). :type endpoint: str :param credential: Credential needed for the client to connect to Azure. - :type credential: ~azure.core.credentials.AzureKeyCredential + This can be the an instance of AzureKeyCredential if using a Language API key + or a token credential from :mod:`azure.identity`. + :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential :keyword str default_language: Sets the default language to use for all operations. """ - def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None: - super().__init__(endpoint, credential, **kwargs) + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None: + super().__init__( + endpoint=endpoint, + credential=credential, # type: ignore + authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential, **kwargs)), + **kwargs + ) self._default_language = kwargs.pop("default_language", None) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_patch.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_patch.py index 4f087cecac7f8..6044782ace1c9 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_patch.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_patch.py @@ -6,11 +6,32 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ -from typing import Any, List +from typing import List, Union, Any from azure.core.credentials import AzureKeyCredential +from azure.core.credentials_async import AsyncTokenCredential +from azure.core.pipeline.policies import AzureKeyCredentialPolicy, AsyncBearerTokenCredentialPolicy from ._question_answering_client import QuestionAnsweringClient as QuestionAnsweringClientGenerated +def _authentication_policy(credential, **kwargs): + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if isinstance(credential, AzureKeyCredential): + authentication_policy = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential, **kwargs + ) + elif hasattr(credential, "get_token"): + authentication_policy = AsyncBearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"]), **kwargs + ) + else: + raise TypeError( + "Unsupported credential: {}. Use an instance of AzureKeyCredential " + "or a token credential from azure.identity".format(type(credential)) + ) + return authentication_policy + + class QuestionAnsweringClient(QuestionAnsweringClientGenerated): """The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. @@ -22,12 +43,21 @@ class QuestionAnsweringClient(QuestionAnsweringClientGenerated): https://.api.cognitiveservices.azure.com). :type endpoint: str :param credential: Credential needed for the client to connect to Azure. - :type credential: ~azure.core.credentials.AzureKeyCredential + This can be the an instance of AzureKeyCredential if using a Language API key + or a token credential from :mod:`azure.identity`. + :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials_async.AsyncTokenCredential :keyword str default_language: Sets the default language to use for all operations. """ - def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None: - super().__init__(endpoint, credential, **kwargs) + def __init__( + self, endpoint: str, credential: Union[AzureKeyCredential, AsyncTokenCredential], **kwargs: Any + ) -> None: + super().__init__( + endpoint=endpoint, + credential=credential, # type: ignore + authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)), + **kwargs + ) self._default_language = kwargs.pop("default_language", None) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_patch.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_patch.py index f99e77fef9861..f5af8ffb6ca95 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_patch.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_patch.py @@ -27,5 +27,64 @@ # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md + +import importlib +from typing import Union, Any +from azure.core.credentials import AzureKeyCredential, TokenCredential +from azure.core.pipeline.policies import AzureKeyCredentialPolicy, BearerTokenCredentialPolicy +from ._question_answering_projects_client import QuestionAnsweringProjectsClient \ + as QuestionAnsweringProjectsClientGenerated + + +def _authentication_policy(credential, **kwargs): + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if isinstance(credential, AzureKeyCredential): + authentication_policy = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential, **kwargs + ) + elif hasattr(credential, "get_token"): + authentication_policy = BearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"]), **kwargs + ) + else: + raise TypeError( + "Unsupported credential: {}. Use an instance of AzureKeyCredential " + "or a token credential from azure.identity".format(type(credential)) + ) + return authentication_policy + + +class QuestionAnsweringProjectsClient(QuestionAnsweringProjectsClientGenerated): + """The language service API is a suite of natural language processing (NLP) skills built with + best-in-class Microsoft machine learning algorithms. The API can be used to analyze + unstructured text for tasks such as sentiment analysis, key phrase extraction, language + detection and question answering. Further documentation can be found in :code:`https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview`. + + :param endpoint: Supported Cognitive Services endpoint (e.g., + https://:code:``.api.cognitiveservices.azure.com). + :type endpoint: str + :param credential: Credential needed for the client to connect to Azure. + This can be the an instance of AzureKeyCredential if using a Language API key + or a token credential from :mod:`azure.identity`. + :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential + :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + """ + + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None: + super().__init__( + endpoint=endpoint, + credential=credential, # type: ignore + authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential, **kwargs)), + **kwargs + ) + + def patch_sdk(): - pass + curr_package = importlib.import_module("azure.ai.language.questionanswering.projects") + curr_package.QuestionAnsweringProjectsClient = QuestionAnsweringProjectsClient diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_version.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_version.py index 653b73a4a1994..f1fb63697cf56 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_version.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.1.0b1" +VERSION = "1.1.0b2" diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/aio/_patch.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/aio/_patch.py index f99e77fef9861..90278d044fa07 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/aio/_patch.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/projects/aio/_patch.py @@ -27,5 +27,65 @@ # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md + +import importlib +from typing import Union, Any +from azure.core.credentials import AzureKeyCredential +from azure.core.credentials_async import AsyncTokenCredential +from azure.core.pipeline.policies import AzureKeyCredentialPolicy, AsyncBearerTokenCredentialPolicy +from ._question_answering_projects_client import QuestionAnsweringProjectsClient \ + as QuestionAnsweringProjectsClientGenerated + + +def _authentication_policy(credential, **kwargs): + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if isinstance(credential, AzureKeyCredential): + authentication_policy = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential, **kwargs + ) + elif hasattr(credential, "get_token"): + authentication_policy = AsyncBearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"]), **kwargs + ) + else: + raise TypeError( + "Unsupported credential: {}. Use an instance of AzureKeyCredential " + "or a token credential from azure.identity".format(type(credential)) + ) + return authentication_policy + + +class QuestionAnsweringProjectsClient(QuestionAnsweringProjectsClientGenerated): + """The language service API is a suite of natural language processing (NLP) skills built with + best-in-class Microsoft machine learning algorithms. The API can be used to analyze + unstructured text for tasks such as sentiment analysis, key phrase extraction, language + detection and question answering. Further documentation can be found in :code:`https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview`. + + :param endpoint: Supported Cognitive Services endpoint (e.g., + https://:code:``.api.cognitiveservices.azure.com). + :type endpoint: str + :param credential: Credential needed for the client to connect to Azure. + This can be the an instance of AzureKeyCredential if using a Language API key + or a token credential from :mod:`azure.identity`. + :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials_async.AsyncTokenCredential + :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + """ + + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, AsyncTokenCredential], **kwargs: Any) -> None: + super().__init__( + endpoint=endpoint, + credential=credential, # type: ignore + authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential, **kwargs)), + **kwargs + ) + + def patch_sdk(): - pass + curr_package = importlib.import_module("azure.ai.language.questionanswering.projects.aio") + curr_package.QuestionAnsweringProjectsClient = QuestionAnsweringProjectsClient diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py index aba2d3fade1f0..cc688a50faa66 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py @@ -36,11 +36,10 @@ license='MIT License', # ensure that the development status reflects the status of your package classifiers=[ - "Development Status :: 5 - Production/Stable", + "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -64,7 +63,7 @@ 'pytyped': ['py.typed'], }, install_requires=[ - 'azure-core<2.0.0,>=1.19.1', + "azure-core<2.0.0,>=1.24.0", 'msrest>=0.6.21', ], project_urls={ diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project.py index 767debd0c68db..2a4f3294905cf 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project.py @@ -18,6 +18,33 @@ class CreateAndDeployTests(QuestionAnsweringTest): + @pytest.mark.live_test_only + @GlobalQuestionAnsweringAccountPreparer() + def test_create_project_aad(self, qna_account, qna_key): + token = self.get_credential(QuestionAnsweringProjectsClient) + client = QuestionAnsweringProjectsClient(qna_account, token) + + # 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 + @GlobalQuestionAnsweringAccountPreparer() def test_create_project(self, qna_account, qna_key): client = QuestionAnsweringProjectsClient(qna_account, AzureKeyCredential(qna_key)) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project_async.py index 9827d68f84cfe..980e58b03d845 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_create_and_deploy_project_async.py @@ -19,6 +19,33 @@ class CreateAndDeployTests(AsyncQuestionAnsweringTest): + @pytest.mark.live_test_only + @GlobalQuestionAnsweringAccountPreparer() + async def test_create_project_aad(self, qna_account, qna_key): + token = self.get_credential(QuestionAnsweringProjectsClient, is_async=True) + client = QuestionAnsweringProjectsClient(qna_account, token) + + # 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 + @GlobalQuestionAnsweringAccountPreparer() async def test_create_project(self, qna_account, qna_key): client = QuestionAnsweringProjectsClient(qna_account, AzureKeyCredential(qna_key)) 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 e697aae4c7977..40a976c251649 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 @@ -165,6 +165,49 @@ def test_query_knowledgebase(self, qna_account, qna_key, qna_project): assert prompt.qna_id assert prompt.display_text + @pytest.mark.live_test_only + @GlobalQuestionAnsweringAccountPreparer() + def test_query_knowledgebase_aad(self, qna_account, qna_key, qna_project): + token = self.get_credential(QuestionAnsweringClient) + client = QuestionAnsweringClient(qna_account, token) + query_params = AnswersOptions( + question="Ports and connectors", + top=3, + answer_context=KnowledgeBaseAnswerContext( + previous_question="Meet Surface Pro 4", + previous_qna_id=4 + ) + ) + + with client: + output = client.get_answers( + query_params, + project_name=qna_project, + deployment_name='test' + ) + + assert output.answers + for answer in output.answers: + assert answer.answer + assert answer.confidence + assert answer.qna_id + assert answer.source + assert answer.metadata is not None + assert not answer.short_answer + + assert answer.questions + for question in answer.questions: + assert question + + assert answer.dialog + assert answer.dialog.is_context_only is not None + assert answer.dialog.prompts is not None + if answer.dialog.prompts: + for prompt in answer.dialog.prompts: + assert prompt.display_order is not None + assert prompt.qna_id + assert prompt.display_text + @GlobalQuestionAnsweringAccountPreparer() def test_query_knowledgebase_with_answerspan(self, qna_account, qna_key, qna_project): client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) 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 3879ea3e0081c..26c63a4002805 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 @@ -167,6 +167,49 @@ async def test_query_knowledgebase(self, qna_account, qna_key, qna_project): assert prompt.qna_id assert prompt.display_text + @pytest.mark.live_test_only + @GlobalQuestionAnsweringAccountPreparer() + async def test_query_knowledgebase_aad(self, qna_account, qna_key, qna_project): + token = self.get_credential(QuestionAnsweringClient, is_async=True) + client = QuestionAnsweringClient(qna_account, token) + query_params = AnswersOptions( + question="Ports and connectors", + top=3, + answer_context=KnowledgeBaseAnswerContext( + previous_questiony="Meet Surface Pro 4", + previous_qna_id=4 + ) + ) + + async with client: + output = await client.get_answers( + query_params, + project_name=qna_project, + deployment_name='test' + ) + + assert output.answers + for answer in output.answers: + assert answer.answer + assert answer.confidence + assert answer.qna_id + assert answer.source + assert answer.metadata is not None + assert not answer.short_answer + + assert answer.questions + for question in answer.questions: + assert question + + assert answer.dialog + assert answer.dialog.is_context_only is not None + assert answer.dialog.prompts is not None + if answer.dialog.prompts: + for prompt in answer.dialog.prompts: + assert prompt.display_order is not None + assert prompt.qna_id + assert prompt.display_text + @GlobalQuestionAnsweringAccountPreparer() async def test_query_knowledgebase_with_answerspan(self, qna_account, qna_key, qna_project): client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) diff --git a/shared_requirements.txt b/shared_requirements.txt index 48a31a98b3845..e99f9cb8f887e 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -150,7 +150,7 @@ chardet<5,>=3.0.2 #override azure-identity cryptography>=2.5 #override azure-ai-textanalytics azure-core<2.0.0,>=1.23.0 #override azure-ai-textanalytics typing-extensions>=4.0.1 -#override azure-ai-language-questionanswering azure-core<2.0.0,>=1.19.1 +#override azure-ai-language-questionanswering azure-core<2.0.0,>=1.24.0 #override azure-search-documents azure-core<2.0.0,>=1.19.0 #override azure-ai-formrecognizer azure-core<2.0.0,>=1.23.0 #override azure-storage-blob azure-core<2.0.0,>=1.23.1