diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md b/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md index d0b11136cae8..e9f0408f0f86 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/CHANGELOG.md @@ -1,5 +1,14 @@ # Release History +## 1.0.0b2 (unreleased) + +### Breaking changes +* The method `QuestionAnsweringClient.query_knowledgebase` has been renamed to `query_knowledge_base`. + +### Features Added +* The method `QuestionAnsweringClient.query_text` now supports a list of records as strings, where the ID value will be automatically populated. + + ## 1.0.0b1 (2021-07-27) ### Features Added diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md b/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md index 740c535acdc1..a3e4f543c1dd 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md @@ -79,7 +79,7 @@ params = qna.KnowledgeBaseQueryOptions( question="How long should my Surface battery last?" ) -output = client.query_knowledgebase( +output = client.query_knowledge_base( params, project_name="FAQ", ) @@ -104,7 +104,7 @@ params = qna.models.KnowledgeBaseQueryOptions( ) ) -output = client.query_knowledgebase( +output = client.query_knowledge_base( params, project_name="FAQ" ) @@ -127,7 +127,7 @@ params = qna.KnowledgeBaseQueryOptions( question="How long should my Surface battery last?" ) -output = await client.query_knowledgebase( +output = await client.query_knowledge_base( params, project_name="FAQ" ) @@ -148,7 +148,7 @@ For example, if you submit a question to a non-existant knowledge base, a `400` from azure.core.exceptions import HttpResponseError try: - client.query_knowledgebase( + client.query_knowledge_base( params, project_name="invalid-knowledge-base" ) 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 new file mode 100644 index 000000000000..7308492dcdab --- /dev/null +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_patch.py @@ -0,0 +1,38 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------- + +import six + +from .models import TextRecord + + +def _validate_text_records(records): + if not records: + raise ValueError("Input records can not be empty or None") + + if isinstance(records, six.string_types): + raise TypeError("Input records cannot be a string.") + + if isinstance(records, dict): + raise TypeError("Input records cannot be a dict") + + if not all(isinstance(x, six.string_types) for x in records): + if not all( + isinstance(x, (dict, TextRecord)) + for x in records + ): + raise TypeError( + "Mixing string and dictionary/object record input unsupported." + ) + + request_batch = [] + for idx, doc in enumerate(records): + if isinstance(doc, six.string_types): + record = {"id": str(idx), "text": doc} + request_batch.append(record) + else: + request_batch.append(doc) + return request_batch diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/__init__.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/__init__.py index 4edb3526786a..bb4c4f612106 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/__init__.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/__init__.py @@ -7,13 +7,13 @@ # -------------------------------------------------------------------------- try: - from ._request_builders_py3 import build_query_knowledgebase_request + from ._request_builders_py3 import build_query_knowledge_base_request from ._request_builders_py3 import build_query_text_request except (SyntaxError, ImportError): - from ._request_builders import build_query_knowledgebase_request # type: ignore + from ._request_builders import build_query_knowledge_base_request # type: ignore from ._request_builders import build_query_text_request # type: ignore __all__ = [ - "build_query_knowledgebase_request", + "build_query_knowledge_base_request", "build_query_text_request", ] diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders.py index 981287ff61f4..2d9863dd1c85 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders.py @@ -18,7 +18,7 @@ # fmt: off -def build_query_knowledgebase_request( +def build_query_knowledge_base_request( **kwargs # type: Any ): # type: (...) -> HttpRequest diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders_py3.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders_py3.py index 283d2d36e45b..77bb3c947abe 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders_py3.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_rest/_request_builders_py3.py @@ -13,7 +13,7 @@ _SERIALIZER = Serializer() -def build_query_knowledgebase_request( +def build_query_knowledge_base_request( *, project_name: str, json: Any = None, content: Any = None, deployment_name: Optional[str] = None, **kwargs: Any ) -> HttpRequest: """Answers the specified question using your knowledge base. diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/operations/_question_answering_client_operations.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/operations/_question_answering_client_operations.py index fdee9098cb24..00d91b45f212 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/operations/_question_answering_client_operations.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/operations/_question_answering_client_operations.py @@ -21,6 +21,7 @@ from azure.core.rest import HttpRequest from ... import models as _models, _rest as rest +from ..._patch import _validate_text_records T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -28,7 +29,7 @@ class QuestionAnsweringClientOperationsMixin: @overload - async def query_knowledgebase( + async def query_knowledge_base( self, knowledge_base_query_options: "_models.KnowledgeBaseQueryOptions", *, @@ -53,7 +54,7 @@ async def query_knowledgebase( ... @overload - async def query_knowledgebase( + async def query_knowledge_base( self, *, project_name: str, @@ -106,7 +107,7 @@ async def query_knowledgebase( """ ... - async def query_knowledgebase( + async def query_knowledge_base( self, *args, **kwargs: Any @@ -172,12 +173,12 @@ async def query_knowledgebase( json = self._serialize.body(knowledge_base_query_options, "KnowledgeBaseQueryOptions") - request = rest.build_query_knowledgebase_request( + request = rest.build_query_knowledge_base_request( content_type=content_type, project_name=project_name, deployment_name=deployment_name, json=json, - template_url=self.query_knowledgebase.metadata["url"], + template_url=self.query_knowledge_base.metadata["url"], )._to_pipeline_transport_request() path_format_arguments = { "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), @@ -201,7 +202,7 @@ async def query_knowledgebase( return deserialized - query_knowledgebase.metadata = {"url": "/:query-knowledgebases"} # type: ignore + query_knowledge_base.metadata = {"url": "/:query-knowledgebases"} # type: ignore @overload async def query_text( @@ -286,6 +287,11 @@ async def query_text( language=kwargs.pop("language", None), string_index_type=kwargs.pop("string_index_type", "TextElements_v8") ) + try: + text_query_options['records'] = _validate_text_records(text_query_options['records']) + except TypeError: + text_query_options.records = _validate_text_records(text_query_options.records) + cls = kwargs.pop("cls", None) # type: ClsType["_models.TextAnswers"] error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop("error_map", {})) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/operations/_question_answering_client_operations.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/operations/_question_answering_client_operations.py index 7f76c69ab66f..0d415602e1c9 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/operations/_question_answering_client_operations.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/operations/_question_answering_client_operations.py @@ -21,6 +21,7 @@ from azure.core.rest import HttpRequest from .. import models as _models, _rest as rest +from .._patch import _validate_text_records if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -32,7 +33,7 @@ class QuestionAnsweringClientOperationsMixin(object): @overload - def query_knowledgebase( + def query_knowledge_base( self, knowledge_base_query_options, # type: "_models.KnowledgeBaseQueryOptions" **kwargs # type: Any @@ -55,7 +56,7 @@ def query_knowledgebase( pass @overload - def query_knowledgebase( + def query_knowledge_base( self, **kwargs # type: Any ): @@ -96,7 +97,7 @@ def query_knowledgebase( """ pass - def query_knowledgebase( + def query_knowledge_base( self, *args, # type: "_models.KnowledgeBaseQueryOptions" **kwargs # type: Any @@ -163,12 +164,12 @@ def query_knowledgebase( json = self._serialize.body(knowledge_base_query_options, "KnowledgeBaseQueryOptions") - request = rest.build_query_knowledgebase_request( + request = rest.build_query_knowledge_base_request( content_type=content_type, project_name=project_name, deployment_name=deployment_name, json=json, - template_url=self.query_knowledgebase.metadata["url"], + template_url=self.query_knowledge_base.metadata["url"], )._to_pipeline_transport_request() path_format_arguments = { "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), @@ -190,7 +191,7 @@ def query_knowledgebase( return deserialized - query_knowledgebase.metadata = {"url": "/:query-knowledgebases"} # type: ignore + query_knowledge_base.metadata = {"url": "/:query-knowledgebases"} # type: ignore @overload def query_text( @@ -221,7 +222,7 @@ def query_text( :keyword question: Required. User question to query against the given text records. :paramtype question: str :keyword records: Required. Text records to be searched for given question. - :paramtype records: list[~azure.ai.language.questionanswering.models.TextInput] + :paramtype records: list[str or ~azure.ai.language.questionanswering.models.TextRecord] :keyword language: Language of the text records. This is BCP-47 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default. @@ -254,7 +255,7 @@ def query_text( :paramtype question: str :keyword records: Text records to be searched for given question. Provide either `text_query_options`, OR individual keyword arguments. If both are provided, only the options object will be used. - :paramtype records: list[~azure.ai.language.questionanswering.models.TextInput] + :paramtype records: list[str or ~azure.ai.language.questionanswering.models.TextRecord] :keyword language: Language of the text records. This is BCP-47 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default. :paramtype language: str @@ -277,6 +278,11 @@ def query_text( language=kwargs.pop("language", None), string_index_type=kwargs.pop("string_index_type", "TextElements_v8") ) + try: + text_query_options['records'] = _validate_text_records(text_query_options['records']) + except TypeError: + text_query_options.records = _validate_text_records(text_query_options.records) + cls = kwargs.pop("cls", None) # type: ClsType["_models.TextAnswers"] error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop("error_map", {})) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_chat_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_chat_async.py index 059bf3e17e73..483e68f85705 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_chat_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_chat_async.py @@ -31,7 +31,7 @@ async def sample_chit_chat(): endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"] key = os.environ["AZURE_QUESTIONANSWERING_KEY"] - knowledgebase_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] + knowledge_base_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] client = QuestionAnsweringClient(endpoint, AzureKeyCredential(key)) async with client: @@ -47,9 +47,9 @@ async def sample_chit_chat(): ), ) - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( first_question, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) best_candidate = [a for a in output.answers if a.confidence_score > 0.9][0] @@ -72,9 +72,9 @@ async def sample_chit_chat(): include_unstructured_sources=True ) - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( followup_question, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) print("Q: {}".format(followup_question.question)) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_query_knowledgebase_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_query_knowledgebase_async.py index fdaee2ee65e5..2f5b0ef1f2e5 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_query_knowledgebase_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/async_samples/sample_query_knowledgebase_async.py @@ -31,7 +31,7 @@ async def sample_query_knowledgebase(): endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"] key = os.environ["AZURE_QUESTIONANSWERING_KEY"] - knowledgebase_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] + knowledge_base_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] client = QuestionAnsweringClient(endpoint, AzureKeyCredential(key)) async with client: @@ -47,9 +47,9 @@ async def sample_query_knowledgebase(): ), ) - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( input, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) best_candidate = [a for a in output.answers if a.confidence_score > 0.9][0] diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_chat.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_chat.py index 48c7be634897..68077ff16f05 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_chat.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_chat.py @@ -29,7 +29,7 @@ def sample_chit_chat(): endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"] key = os.environ["AZURE_QUESTIONANSWERING_KEY"] - knowledgebase_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] + knowledge_base_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] client = QuestionAnsweringClient(endpoint, AzureKeyCredential(key)) with client: @@ -45,9 +45,9 @@ def sample_chit_chat(): ), ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( first_question, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) best_candidate = [a for a in output.answers if a.confidence_score > 0.9][0] @@ -70,9 +70,9 @@ def sample_chit_chat(): include_unstructured_sources=True ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( followup_question, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) print("Q: {}".format(followup_question.question)) diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_query_knowledgebase.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_query_knowledgebase.py index da25074b7ace..21599649b602 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_query_knowledgebase.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/sample_query_knowledgebase.py @@ -29,7 +29,7 @@ def sample_query_knowledgebase(): endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"] key = os.environ["AZURE_QUESTIONANSWERING_KEY"] - knowledgebase_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] + knowledge_base_project = os.environ["AZURE_QUESTIONANSWERING_PROJECT"] client = QuestionAnsweringClient(endpoint, AzureKeyCredential(key)) with client: @@ -45,9 +45,9 @@ def sample_query_knowledgebase(): ), ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( input, - project_name=knowledgebase_project, + project_name=knowledge_base_project, deployment_name="test" ) best_candidate = [a for a in output.answers if a.confidence_score > 0.9][0] diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py index c5c359fe8608..976409977724 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/setup.py @@ -68,11 +68,10 @@ install_requires=[ 'azure-core<2.0.0,>=1.16.0', 'msrest>=0.6.21', - 'chardet>=3.0.2,<5' ], extras_require={ ":python_version<'3.0'": ['futures', 'azure-ai-language-nspkg'], - ":python_version<'3.5'": ["typing"] + ":python_version<'3.5'": ["typing"], }, project_urls={ 'Bug Reports': 'https://github.com/Azure/azure-sdk-for-python/issues', diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_overload.yaml b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_overload.yaml index 74e875f88e16..bae034dbea31 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_overload.yaml +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_overload.yaml @@ -1,99 +1,14 @@ interactions: - request: - body: '{"question": "What is the meaning of life?", "records": [{"id": "doc1", - "text": "abc Graphics Surprise, surprise -- our 4K "}, {"id": "doc2", "text": - "e graphics card. While the Nvidia GeForce MX250 GPU isn''t meant for demanding - gaming, it is a step up from integrated graphics as proven by comparing it to - the UHD 620 GPU in the FHD model. The MX250-equipped Envy 13 scored a 116,575 - on the Ice Storm Unlimited benchmark while the base model scored a 82,270. Upgrading - to the discrete graphics gives the Envy 13 better performance than the Notebook - 9 Pro (61,662; UHD 620), Surface Laptop 2 (71,647; UHD 620) and the premium - laptop average (86,937). While the Nvidia GeForce MX250 GPU isn''t meant for - demanding gaming, it is a step up from integrated graphics as proven by comparing - it to the UHD 620 GPU in the FHD model. We played the racing game Dirt 3 at - 92 frames per second on "}, {"id": "doc3", "text": "Graphics Surprise, surprise - -- our 4K Envy 13 came with a discrete graphics card. While the Nvidia GeForce - MX250 GPU isn''t meant for demanding gaming, it is a step up from integrated - graphics as proven by comparing it to the UHD 620 GPU in the FHD model. The - MX250-equipped Envy 13 scored a 116,575 on the Ice Storm Unlimited benchmark - while the base model scored a 82,270. Upgrading to the discrete graphics gives - the Envy 13 better performance than the Notebook 9 Pro (61,662; UHD 620), Surface - Laptop 2 (71,647; UHD 620) and the premium laptop average (86,937). While - the Nvidia GeForce MX250 GPU isn''t meant for demanding gaming, it is a step - up from integrated graphics as proven by comparing it to the UHD 620 GPU in - the FHD model. We played the racing game Dirt 3 at 92 frames per second on - the MX250 model, which is well above our 30-fps playability, the category average - (69 fps) and what the Surface Laptop 2 (82 fps) achieved. The ZenBook S UX391UA - (45 fps) fell flat on this real-world test but ran better than the base model - Envy 13 (31 fps). Audio I had a good ol'' time groovin'' to the sound of the - Envy 13''s crisp speakers. HP went all out with the Envy, placing dual speakers - on the underside of the chassis along with a third, top-firing driver above - the keyboard. Devon Gilfillian''s funky jam \"Here and Now\" boomed smooth, - soulful tunes throughout my small apartment. The twang of the electric guitar - played nicely with the thudding percussion but never overshadowed Gilfillian - or the female backup vocals. Bang & Olufsen software comes preinstalled on - the Envy 13, with equalizer controls so you can adjust the bass, midrange and - treble to your liking. But even out of the box, you''ll enjoy great sound without - having to bust out your headphones. Battery Life Get an Envy 13 with the 1080p - non-touch display if battery life is important to you. The FHD model endured - for 11 hours and 11 minutes whereas the 4K model lasted only 4 hours and 36 - minutes on our battery test, which involves continuous web browsing over Wi-Fi - at 150 nits of brightness. MORE: Laptops with Best Battery Life - Longest - Lasting Laptop Batteries Competing laptops like the ZenBook S UX391UA (7:05), - Surface Laptop 2 (9:22) and Notebook 9 Pro (8:53) outstayed the 4K Envy 13 but - powered down long before the 1080p version. Webcam The 720p webcam on the - Envy 13 is nothing to write home about. A selfie I snapped in my dimly lit room - was covered in a haze of visual noise. My beard and hair were unkempt blobs, - while my eyes looked like they were drawn on by a pointillist painter. If there''s - one positive, it''s that the lens captures natural colors and even extracted - the different shades of gray in my T-shirt. On the right edge of the Envy - 13 is a physical kill switch that cuts the power to the webcam so you can feel - reassured that nobody is snooping on you. Heat Leave the lapdesk at home - - you don''t have to worry about the Envy 13 overheating. After I played - a 15-minute, full-HD video in full screen, the touchpad on the HP Envy 13 with - a Core i7 CPU rose to only 83 degrees Fahrenheit while the keyboard (87 degrees) - and underside (90 degrees) also remained well below our 95-degree comfort threshold. - Even the toastiest part of the machine, the lower-left edge on the underside, - topped out at 94 degrees. Software and Warranty It''s a shame that a laptop - with such beautiful hardware ships with such ugly software. Pre-installed on - this machine are entirely too many programs that could either be packaged together - or omitted altogether. HP provides an app called Audio Switch, which simply - lets you switch your audio input/output between the internal speakers and headphones. - As the same implies, HP''s Command Center is where you can get information about - your Envy 13 but also switch the thermal profiles between comfort and performance. - Along with support documentation, HP also bundles in a setup program called - JumpStart, a program for connecting printers and a redundant system-info app - called Event Utility. Also installed on the Envy 13''s Windows 10 Home OS - are several Microsoft apps, including Simple Solitaire, Candy Crush Friends - and Your Phone. Other third-party apps include Booking.com, Netflix and McAfee - Security. HP ships the Envy 13 with a one-year warranty. See how HP did on - our Tech Support Showdown and Best and Worst Brands ranking. Bottom Line The - Envy 13 has cemented its standing as the ultimate laptop for college students - or travelers. Along with 11-plus hours of battery life (on the FHD model), the - Envy 13 has a sleek, ultraportable chassis, fast performance, and powerful speakers. - Best of all, the Envy 13 starts at a reasonable $799, which is hundreds less - than the competition. In many ways, the Envy 13 is what we wanted the new MacBook - Air to be. The new HP Envy 13 is everything I was hoping the new MacBook Air - would be: fast, attractive and affordable. Just be sure to buy the right model. - We strongly recommend the 1080p version over the 4K model because it lasts several - hours longer on a charge and costs less. In fact, if we were reviewing the 4K - model separately, we''d only give it a 3.5 rating. You should also consider - the Envy 13 with a 10th Gen CPU, although we haven''t gotten the chance to review - it yet. If you absolutely need a high-res display, the 4K Envy 13 is one of - many good options. We also recommend the Samsung Notebook 9 Pro, which has a - similarly premium design but much better battery life than the 4K Envy. The - Microsoft Surface Laptop 2 is another recommended alternative, though you might - want to wait a few months for the rumored Surface Laptop 3. Overall, the HP - Envy 13 is a fantastic laptop that checks all the right boxes --- as long as - you buy the 1080p model. Credit: Laptop Mag HP Envy 13 (2019) Specs BluetoothBluetooth - 5.0 BrandHP CPUIntel Core i7-8565U Card SlotsmicroSD Company Websitehttps://www8.hp.com/us/en/home.html - Display Size13.3 Graphics CardNvidia GeForce MX250 Hard Drive Size512GB Hard - Drive TypePCIe NVMe M.2 Highest Available Resolution3840 x 2160 Native Resolution3840 - x 2160 Operating SystemWindows 10 Home Ports (excluding USB)USB 3.1 with Type-C, - USB 3.1 Always-On, USB 3.1, Headphone/Mic, microSD RAM16GB RAM Upgradable to16GB - Size12.1 x 8.3 x .57 inches Touchpad Size4.3 x 2.2 inches USB Ports3 Video Memory2GB - Warranty/Supportone-year warranty. Weight2.8 pounds Wi-Fi802.11ac Wi-Fi ModelIntel - Wireless-AC 9560 "}], "language": "en", "stringIndexType": "TextElements_v8"}' + body: '{"question": "How long it takes to charge surface?", "records": [{"id": + "0", "text": "Power and charging. It takes two to four hours to charge the Surface + Pro 4 battery fully from an empty state. It can take longer if you\u2019re using + your Surface for power-intensive activities like gaming or video streaming while + you\u2019re charging it."}, {"id": "1", "text": "You can use the USB port on + your Surface Pro 4 power supply to charge other devices, like a phone, while + your Surface charges. The USB port on the power supply is only for charging, + not for data transfer. If you want to use a USB device, plug it into the USB + port on your Surface."}], "stringIndexType": "TextElements_v8"}' headers: Accept: - application/json @@ -102,7 +17,7 @@ interactions: Connection: - keep-alive Content-Length: - - '7447' + - '688' Content-Type: - application/json User-Agent: @@ -111,50 +26,41 @@ interactions: uri: https://test-resource.api.cognitive.microsoft.com/language/:query-text?api-version=2021-05-01-preview response: body: - string: "{\n \"answers\": [\n {\n \"answer\": \"Battery Life Get an - Envy 13 with the 1080p non-touch display if battery life is important to you. - \ The FHD model endured for 11 hours and 11 minutes whereas the 4K model - lasted only 4 hours and 36 minutes on our battery test, which involves continuous - web browsing over Wi-Fi at 150 nits of brightness. MORE: Laptops with Best - Battery Life - Longest Lasting Laptop Batteries Competing laptops like the - ZenBook S UX391UA (7:05), Surface Laptop 2 (9:22) and Notebook 9 Pro (8:53) - outstayed the 4K Envy 13 but powered down long before the 1080p version.\",\n - \ \"confidenceScore\": 0.017458289861679077,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"Battery Life\",\n \"confidenceScore\": - 0.26247412,\n \"offset\": 0,\n \"length\": 12\n },\n \"offset\": - 1779,\n \"length\": 555\n },\n {\n \"answer\": \"Along with - 11-plus hours of battery life (on the FHD model), the Envy 13 has a sleek, - ultraportable chassis, fast performance, and powerful speakers. Best of all, - the Envy 13 starts at a reasonable $799, which is hundreds less than the competition. - In many ways, the Envy 13 is what we wanted the new MacBook Air to be.\",\n - \ \"confidenceScore\": 0.00940172653645277,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"battery life\",\n \"confidenceScore\": - 0.35305238,\n \"offset\": 27,\n \"length\": 13\n },\n \"offset\": - 4508,\n \"length\": 319\n },\n {\n \"answer\": \"We also recommend - the Samsung Notebook 9 Pro, which has a similarly premium design but much - better battery life than the 4K Envy. The Microsoft Surface Laptop 2 is another - recommended alternative, though you might want to wait a few months for the - rumored Surface Laptop 3. Overall, the HP Envy 13 is a fantastic laptop - that checks all the right boxes --- as long as you buy the 1080p model.\",\n - \ \"confidenceScore\": 0.0070572528056800365,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"battery life\",\n \"confidenceScore\": - 0.5914322,\n \"offset\": 98,\n \"length\": 13\n },\n \"offset\": - 5391,\n \"length\": 393\n }\n ]\n}" + string: "{\n \"answers\": [\n {\n \"answer\": \"Power and charging. + It takes two to four hours to charge the Surface Pro 4 battery fully from + an empty state. It can take longer if you\u2019re using your Surface for power-intensive + activities like gaming or video streaming while you\u2019re charging it.\",\n + \ \"confidenceScore\": 0.9298818707466125,\n \"id\": \"0\",\n \"answerSpan\": + {\n \"text\": \"two to four hours\",\n \"confidenceScore\": + 0.98579097,\n \"offset\": 28,\n \"length\": 18\n },\n \"offset\": + 0,\n \"length\": 245\n },\n {\n \"answer\": \"It takes two + to four hours to charge the Surface Pro 4 battery fully from an empty state. + It can take longer if you\u2019re using your Surface for power-intensive activities + like gaming or video streaming while you\u2019re charging it.\",\n \"confidenceScore\": + 0.9254360198974609,\n \"id\": \"0\",\n \"answerSpan\": {\n \"text\": + \"two to four hours\",\n \"confidenceScore\": 0.98562825,\n \"offset\": + 8,\n \"length\": 18\n },\n \"offset\": 20,\n \"length\": + 225\n },\n {\n \"answer\": \"It can take longer if you\u2019re + using your Surface for power-intensive activities like gaming or video streaming + while you\u2019re charging it.\",\n \"confidenceScore\": 0.05503516271710396,\n + \ \"id\": \"0\",\n \"answerSpan\": {\n \"text\": \"longer\",\n + \ \"confidenceScore\": 0.624118,\n \"offset\": 11,\n \"length\": + 7\n },\n \"offset\": 110,\n \"length\": 135\n }\n ]\n}" headers: apim-request-id: - - 1166df47-3640-4276-ba1b-8352467aabde + - 0859996e-48ab-42f9-9d67-04d21bc14fba content-length: - - '2147' + - '1479' content-type: - application/json; charset=utf-8 date: - - Tue, 13 Jul 2021 17:24:16 GMT + - Fri, 06 Aug 2021 18:14:29 GMT strict-transport-security: - max-age=31536000; includeSubDomains; preload x-content-type-options: - nosniff x-envoy-upstream-service-time: - - '263' + - '1084' status: code: 200 message: OK diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_with_str_records.yaml b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_with_str_records.yaml new file mode 100644 index 000000000000..1f40ef745ff9 --- /dev/null +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text.test_query_text_with_str_records.yaml @@ -0,0 +1,67 @@ +interactions: +- request: + body: '{"question": "How long it takes to charge surface?", "records": [{"id": + "0", "text": "Power and charging. It takes two to four hours to charge the Surface + Pro 4 battery fully from an empty state. It can take longer if you\u2019re using + your Surface for power-intensive activities like gaming or video streaming while + you\u2019re charging it."}, {"id": "1", "text": "You can use the USB port on + your Surface Pro 4 power supply to charge other devices, like a phone, while + your Surface charges. The USB port on the power supply is only for charging, + not for data transfer. If you want to use a USB device, plug it into the USB + port on your Surface."}], "language": "en"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '668' + Content-Type: + - application/json + User-Agent: + - azsdk-python-ai-language-questionanswering/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://test-resource.api.cognitive.microsoft.com/language/:query-text?api-version=2021-05-01-preview + response: + body: + string: "{\n \"answers\": [\n {\n \"answer\": \"Power and charging. + It takes two to four hours to charge the Surface Pro 4 battery fully from + an empty state. It can take longer if you\u2019re using your Surface for power-intensive + activities like gaming or video streaming while you\u2019re charging it.\",\n + \ \"confidenceScore\": 0.9298818111419678,\n \"id\": \"0\",\n \"answerSpan\": + {\n \"text\": \"two to four hours\",\n \"confidenceScore\": + 0.98579097,\n \"offset\": 28,\n \"length\": 18\n },\n \"offset\": + 0,\n \"length\": 245\n },\n {\n \"answer\": \"It takes two + to four hours to charge the Surface Pro 4 battery fully from an empty state. + It can take longer if you\u2019re using your Surface for power-intensive activities + like gaming or video streaming while you\u2019re charging it.\",\n \"confidenceScore\": + 0.9254360198974609,\n \"id\": \"0\",\n \"answerSpan\": {\n \"text\": + \"two to four hours\",\n \"confidenceScore\": 0.98562825,\n \"offset\": + 8,\n \"length\": 18\n },\n \"offset\": 20,\n \"length\": + 225\n },\n {\n \"answer\": \"It can take longer if you\u2019re + using your Surface for power-intensive activities like gaming or video streaming + while you\u2019re charging it.\",\n \"confidenceScore\": 0.05503518134355545,\n + \ \"id\": \"0\",\n \"answerSpan\": {\n \"text\": \"longer\",\n + \ \"confidenceScore\": 0.624118,\n \"offset\": 11,\n \"length\": + 7\n },\n \"offset\": 110,\n \"length\": 135\n }\n ]\n}" + headers: + apim-request-id: + - c103d09b-72cd-489c-8d4a-e077a5526e70 + content-length: + - '1479' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 06 Aug 2021 18:18:43 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '491' + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_overload.yaml b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_overload.yaml index 45124a7a4e5b..564793648d31 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_overload.yaml +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_overload.yaml @@ -1,104 +1,19 @@ interactions: - request: - body: '{"question": "What is the meaning of life?", "records": [{"id": "doc1", - "text": "abc Graphics Surprise, surprise -- our 4K "}, {"id": "doc2", "text": - "e graphics card. While the Nvidia GeForce MX250 GPU isn''t meant for demanding - gaming, it is a step up from integrated graphics as proven by comparing it to - the UHD 620 GPU in the FHD model. The MX250-equipped Envy 13 scored a 116,575 - on the Ice Storm Unlimited benchmark while the base model scored a 82,270. Upgrading - to the discrete graphics gives the Envy 13 better performance than the Notebook - 9 Pro (61,662; UHD 620), Surface Laptop 2 (71,647; UHD 620) and the premium - laptop average (86,937). While the Nvidia GeForce MX250 GPU isn''t meant for - demanding gaming, it is a step up from integrated graphics as proven by comparing - it to the UHD 620 GPU in the FHD model. We played the racing game Dirt 3 at - 92 frames per second on "}, {"id": "doc3", "text": "Graphics Surprise, surprise - -- our 4K Envy 13 came with a discrete graphics card. While the Nvidia GeForce - MX250 GPU isn''t meant for demanding gaming, it is a step up from integrated - graphics as proven by comparing it to the UHD 620 GPU in the FHD model. The - MX250-equipped Envy 13 scored a 116,575 on the Ice Storm Unlimited benchmark - while the base model scored a 82,270. Upgrading to the discrete graphics gives - the Envy 13 better performance than the Notebook 9 Pro (61,662; UHD 620), Surface - Laptop 2 (71,647; UHD 620) and the premium laptop average (86,937). While - the Nvidia GeForce MX250 GPU isn''t meant for demanding gaming, it is a step - up from integrated graphics as proven by comparing it to the UHD 620 GPU in - the FHD model. We played the racing game Dirt 3 at 92 frames per second on - the MX250 model, which is well above our 30-fps playability, the category average - (69 fps) and what the Surface Laptop 2 (82 fps) achieved. The ZenBook S UX391UA - (45 fps) fell flat on this real-world test but ran better than the base model - Envy 13 (31 fps). Audio I had a good ol'' time groovin'' to the sound of the - Envy 13''s crisp speakers. HP went all out with the Envy, placing dual speakers - on the underside of the chassis along with a third, top-firing driver above - the keyboard. Devon Gilfillian''s funky jam \"Here and Now\" boomed smooth, - soulful tunes throughout my small apartment. The twang of the electric guitar - played nicely with the thudding percussion but never overshadowed Gilfillian - or the female backup vocals. Bang & Olufsen software comes preinstalled on - the Envy 13, with equalizer controls so you can adjust the bass, midrange and - treble to your liking. But even out of the box, you''ll enjoy great sound without - having to bust out your headphones. Battery Life Get an Envy 13 with the 1080p - non-touch display if battery life is important to you. The FHD model endured - for 11 hours and 11 minutes whereas the 4K model lasted only 4 hours and 36 - minutes on our battery test, which involves continuous web browsing over Wi-Fi - at 150 nits of brightness. MORE: Laptops with Best Battery Life - Longest - Lasting Laptop Batteries Competing laptops like the ZenBook S UX391UA (7:05), - Surface Laptop 2 (9:22) and Notebook 9 Pro (8:53) outstayed the 4K Envy 13 but - powered down long before the 1080p version. Webcam The 720p webcam on the - Envy 13 is nothing to write home about. A selfie I snapped in my dimly lit room - was covered in a haze of visual noise. My beard and hair were unkempt blobs, - while my eyes looked like they were drawn on by a pointillist painter. If there''s - one positive, it''s that the lens captures natural colors and even extracted - the different shades of gray in my T-shirt. On the right edge of the Envy - 13 is a physical kill switch that cuts the power to the webcam so you can feel - reassured that nobody is snooping on you. Heat Leave the lapdesk at home - - you don''t have to worry about the Envy 13 overheating. After I played - a 15-minute, full-HD video in full screen, the touchpad on the HP Envy 13 with - a Core i7 CPU rose to only 83 degrees Fahrenheit while the keyboard (87 degrees) - and underside (90 degrees) also remained well below our 95-degree comfort threshold. - Even the toastiest part of the machine, the lower-left edge on the underside, - topped out at 94 degrees. Software and Warranty It''s a shame that a laptop - with such beautiful hardware ships with such ugly software. Pre-installed on - this machine are entirely too many programs that could either be packaged together - or omitted altogether. HP provides an app called Audio Switch, which simply - lets you switch your audio input/output between the internal speakers and headphones. - As the same implies, HP''s Command Center is where you can get information about - your Envy 13 but also switch the thermal profiles between comfort and performance. - Along with support documentation, HP also bundles in a setup program called - JumpStart, a program for connecting printers and a redundant system-info app - called Event Utility. Also installed on the Envy 13''s Windows 10 Home OS - are several Microsoft apps, including Simple Solitaire, Candy Crush Friends - and Your Phone. Other third-party apps include Booking.com, Netflix and McAfee - Security. HP ships the Envy 13 with a one-year warranty. See how HP did on - our Tech Support Showdown and Best and Worst Brands ranking. Bottom Line The - Envy 13 has cemented its standing as the ultimate laptop for college students - or travelers. Along with 11-plus hours of battery life (on the FHD model), the - Envy 13 has a sleek, ultraportable chassis, fast performance, and powerful speakers. - Best of all, the Envy 13 starts at a reasonable $799, which is hundreds less - than the competition. In many ways, the Envy 13 is what we wanted the new MacBook - Air to be. The new HP Envy 13 is everything I was hoping the new MacBook Air - would be: fast, attractive and affordable. Just be sure to buy the right model. - We strongly recommend the 1080p version over the 4K model because it lasts several - hours longer on a charge and costs less. In fact, if we were reviewing the 4K - model separately, we''d only give it a 3.5 rating. You should also consider - the Envy 13 with a 10th Gen CPU, although we haven''t gotten the chance to review - it yet. If you absolutely need a high-res display, the 4K Envy 13 is one of - many good options. We also recommend the Samsung Notebook 9 Pro, which has a - similarly premium design but much better battery life than the 4K Envy. The - Microsoft Surface Laptop 2 is another recommended alternative, though you might - want to wait a few months for the rumored Surface Laptop 3. Overall, the HP - Envy 13 is a fantastic laptop that checks all the right boxes --- as long as - you buy the 1080p model. Credit: Laptop Mag HP Envy 13 (2019) Specs BluetoothBluetooth - 5.0 BrandHP CPUIntel Core i7-8565U Card SlotsmicroSD Company Websitehttps://www8.hp.com/us/en/home.html - Display Size13.3 Graphics CardNvidia GeForce MX250 Hard Drive Size512GB Hard - Drive TypePCIe NVMe M.2 Highest Available Resolution3840 x 2160 Native Resolution3840 - x 2160 Operating SystemWindows 10 Home Ports (excluding USB)USB 3.1 with Type-C, - USB 3.1 Always-On, USB 3.1, Headphone/Mic, microSD RAM16GB RAM Upgradable to16GB - Size12.1 x 8.3 x .57 inches Touchpad Size4.3 x 2.2 inches USB Ports3 Video Memory2GB - Warranty/Supportone-year warranty. Weight2.8 pounds Wi-Fi802.11ac Wi-Fi ModelIntel - Wireless-AC 9560 "}], "language": "en", "stringIndexType": "TextElements_v8"}' + body: '{"question": "How long it takes to charge surface?", "records": [{"id": + "0", "text": "Power and charging. It takes two to four hours to charge the Surface + Pro 4 battery fully from an empty state. It can take longer if you\u2019re using + your Surface for power-intensive activities like gaming or video streaming while + you\u2019re charging it."}, {"id": "1", "text": "You can use the USB port on + your Surface Pro 4 power supply to charge other devices, like a phone, while + your Surface charges. The USB port on the power supply is only for charging, + not for data transfer. If you want to use a USB device, plug it into the USB + port on your Surface."}], "stringIndexType": "TextElements_v8"}' headers: Accept: - application/json Content-Length: - - '7447' + - '688' Content-Type: - application/json User-Agent: @@ -107,43 +22,34 @@ interactions: uri: https://test-resource.api.cognitive.microsoft.com/language/:query-text?api-version=2021-05-01-preview response: body: - string: "{\n \"answers\": [\n {\n \"answer\": \"Battery Life Get an - Envy 13 with the 1080p non-touch display if battery life is important to you. - \ The FHD model endured for 11 hours and 11 minutes whereas the 4K model - lasted only 4 hours and 36 minutes on our battery test, which involves continuous - web browsing over Wi-Fi at 150 nits of brightness. MORE: Laptops with Best - Battery Life - Longest Lasting Laptop Batteries Competing laptops like the - ZenBook S UX391UA (7:05), Surface Laptop 2 (9:22) and Notebook 9 Pro (8:53) - outstayed the 4K Envy 13 but powered down long before the 1080p version.\",\n - \ \"confidenceScore\": 0.017458289861679077,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"Battery Life\",\n \"confidenceScore\": - 0.26247412,\n \"offset\": 0,\n \"length\": 12\n },\n \"offset\": - 1779,\n \"length\": 555\n },\n {\n \"answer\": \"Along with - 11-plus hours of battery life (on the FHD model), the Envy 13 has a sleek, - ultraportable chassis, fast performance, and powerful speakers. Best of all, - the Envy 13 starts at a reasonable $799, which is hundreds less than the competition. - In many ways, the Envy 13 is what we wanted the new MacBook Air to be.\",\n - \ \"confidenceScore\": 0.009401722811162472,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"battery life\",\n \"confidenceScore\": - 0.3530523,\n \"offset\": 27,\n \"length\": 13\n },\n \"offset\": - 4508,\n \"length\": 319\n },\n {\n \"answer\": \"We also recommend - the Samsung Notebook 9 Pro, which has a similarly premium design but much - better battery life than the 4K Envy. The Microsoft Surface Laptop 2 is another - recommended alternative, though you might want to wait a few months for the - rumored Surface Laptop 3. Overall, the HP Envy 13 is a fantastic laptop - that checks all the right boxes --- as long as you buy the 1080p model.\",\n - \ \"confidenceScore\": 0.007057250943034887,\n \"id\": \"doc3\",\n - \ \"answerSpan\": {\n \"text\": \"battery life\",\n \"confidenceScore\": - 0.5914322,\n \"offset\": 98,\n \"length\": 13\n },\n \"offset\": - 5391,\n \"length\": 393\n }\n ]\n}" + string: "{\n \"answers\": [\n {\n \"answer\": \"Power and charging. + It takes two to four hours to charge the Surface Pro 4 battery fully from + an empty state. It can take longer if you\u2019re using your Surface for power-intensive + activities like gaming or video streaming while you\u2019re charging it.\",\n + \ \"confidenceScore\": 0.9298818707466125,\n \"id\": \"0\",\n \"answerSpan\": + {\n \"text\": \"two to four hours\",\n \"confidenceScore\": + 0.98579097,\n \"offset\": 28,\n \"length\": 18\n },\n \"offset\": + 0,\n \"length\": 245\n },\n {\n \"answer\": \"It takes two + to four hours to charge the Surface Pro 4 battery fully from an empty state. + It can take longer if you\u2019re using your Surface for power-intensive activities + like gaming or video streaming while you\u2019re charging it.\",\n \"confidenceScore\": + 0.9254360198974609,\n \"id\": \"0\",\n \"answerSpan\": {\n \"text\": + \"two to four hours\",\n \"confidenceScore\": 0.98562825,\n \"offset\": + 8,\n \"length\": 18\n },\n \"offset\": 20,\n \"length\": + 225\n },\n {\n \"answer\": \"It can take longer if you\u2019re + using your Surface for power-intensive activities like gaming or video streaming + while you\u2019re charging it.\",\n \"confidenceScore\": 0.05503516271710396,\n + \ \"id\": \"0\",\n \"answerSpan\": {\n \"text\": \"longer\",\n + \ \"confidenceScore\": 0.624118,\n \"offset\": 11,\n \"length\": + 7\n },\n \"offset\": 110,\n \"length\": 135\n }\n ]\n}" headers: - apim-request-id: 82332b85-228b-41c2-b65d-a7b893a52dff - content-length: '2146' + apim-request-id: 05642021-6f95-4a4c-a641-9dd5f3a6762f + content-length: '1479' content-type: application/json; charset=utf-8 - date: Tue, 13 Jul 2021 17:24:19 GMT + date: Fri, 06 Aug 2021 18:14:30 GMT strict-transport-security: max-age=31536000; includeSubDomains; preload x-content-type-options: nosniff - x-envoy-upstream-service-time: '254' + x-envoy-upstream-service-time: '862' status: code: 200 message: OK diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_with_str_records.yaml b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_with_str_records.yaml new file mode 100644 index 000000000000..f95eec132700 --- /dev/null +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/recordings/test_query_text_async.test_query_text_with_str_records.yaml @@ -0,0 +1,57 @@ +interactions: +- request: + body: '{"question": "How long it takes to charge surface?", "records": [{"id": + "0", "text": "Power and charging. It takes two to four hours to charge the Surface + Pro 4 battery fully from an empty state. It can take longer if you\u2019re using + your Surface for power-intensive activities like gaming or video streaming while + you\u2019re charging it."}, {"id": "1", "text": "You can use the USB port on + your Surface Pro 4 power supply to charge other devices, like a phone, while + your Surface charges. The USB port on the power supply is only for charging, + not for data transfer. If you want to use a USB device, plug it into the USB + port on your Surface."}], "language": "en"}' + headers: + Accept: + - application/json + Content-Length: + - '668' + Content-Type: + - application/json + User-Agent: + - azsdk-python-ai-language-questionanswering/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://test-resource.api.cognitive.microsoft.com/language/:query-text?api-version=2021-05-01-preview + response: + body: + string: "{\n \"answers\": [\n {\n \"answer\": \"Power and charging. + It takes two to four hours to charge the Surface Pro 4 battery fully from + an empty state. It can take longer if you\u2019re using your Surface for power-intensive + activities like gaming or video streaming while you\u2019re charging it.\",\n + \ \"confidenceScore\": 0.9298818707466125,\n \"id\": \"0\",\n \"answerSpan\": + {\n \"text\": \"two to four hours\",\n \"confidenceScore\": + 0.98579097,\n \"offset\": 28,\n \"length\": 18\n },\n \"offset\": + 0,\n \"length\": 245\n },\n {\n \"answer\": \"It takes two + to four hours to charge the Surface Pro 4 battery fully from an empty state. + It can take longer if you\u2019re using your Surface for power-intensive activities + like gaming or video streaming while you\u2019re charging it.\",\n \"confidenceScore\": + 0.9254359602928162,\n \"id\": \"0\",\n \"answerSpan\": {\n \"text\": + \"two to four hours\",\n \"confidenceScore\": 0.98562825,\n \"offset\": + 8,\n \"length\": 18\n },\n \"offset\": 20,\n \"length\": + 225\n },\n {\n \"answer\": \"It can take longer if you\u2019re + using your Surface for power-intensive activities like gaming or video streaming + while you\u2019re charging it.\",\n \"confidenceScore\": 0.05503518134355545,\n + \ \"id\": \"0\",\n \"answerSpan\": {\n \"text\": \"longer\",\n + \ \"confidenceScore\": 0.624118,\n \"offset\": 11,\n \"length\": + 7\n },\n \"offset\": 110,\n \"length\": 135\n }\n ]\n}" + headers: + apim-request-id: 0b3e9e81-ead6-45fa-83ab-9c04b41a14cf + content-length: '1479' + content-type: application/json; charset=utf-8 + date: Fri, 06 Aug 2021 18:18:44 GMT + strict-transport-security: max-age=31536000; includeSubDomains; preload + x-content-type-options: nosniff + x-envoy-upstream-service-time: '376' + status: + code: 200 + message: OK + url: https://wuppe.api.cognitive.microsoft.com/language/:query-text?api-version=2021-05-01-preview +version: 1 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 e48e4dc00b82..260340e20756 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 @@ -35,7 +35,7 @@ def test_query_knowledgebase_llc(self, qna_account, qna_key, qna_project): "previousQnAId": 4 } } - request = build_query_knowledgebase_request( + request = build_query_knowledge_base_request( json=json_content, project_name=qna_project, deployment_name='test' @@ -84,7 +84,7 @@ def test_query_knowledgebase_llc_with_answerspan(self, qna_account, qna_key, qna "topAnswersWithSpan": 1 } } - request = build_query_knowledgebase_request( + request = build_query_knowledge_base_request( json=json_content, project_name=qna_project, deployment_name='test' @@ -135,7 +135,7 @@ def test_query_knowledgebase(self, qna_account, qna_key, qna_project): ) with client: - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -181,7 +181,7 @@ def test_query_knowledgebase_with_answerspan(self, qna_account, qna_key, qna_pro ) with client: - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -232,7 +232,7 @@ def test_query_knowledgebase_with_dictparams(self, qna_account, qna_key, qna_pro } with client: - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -247,7 +247,7 @@ def test_query_knowledgebase_with_dictparams(self, qna_account, qna_key, qna_pro def test_query_knowledgebase_overload(self, qna_account, qna_key, qna_project): client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) with client: - output = client.query_knowledgebase( + output = client.query_knowledge_base( project_name=qna_project, deployment_name='test', question="How long should my Surface battery last?", @@ -284,7 +284,7 @@ def test_query_knowledgebase_with_followup(self, qna_account, qna_key, qna_proje include_unstructured_sources=True ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -309,7 +309,7 @@ def test_query_knowledgebase_with_followup(self, qna_account, qna_key, qna_proje ), include_unstructured_sources=True ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -329,7 +329,7 @@ def test_query_knowledgebase_only_id(self, qna_account, qna_key, qna_project): qna_id=19 ) - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -343,7 +343,7 @@ def test_query_knowledgebase_python_dict(self, qna_account, qna_key, qna_project with client: query_params = {"qna_id": 19} - output = client.query_knowledgebase( + output = client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' 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 d3aa12ca20c1..32ea2bab5e7f 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 @@ -37,7 +37,7 @@ async def test_query_knowledgebase_llc(self, qna_account, qna_key, qna_project): "previousQnAId": 4 } } - request = build_query_knowledgebase_request( + request = build_query_knowledge_base_request( json=json_content, project_name=qna_project, deployment_name='test' @@ -86,7 +86,7 @@ async def test_query_knowledgebase_llc_with_answerspan(self, qna_account, qna_ke "topAnswersWithSpan": 2 } } - request = build_query_knowledgebase_request( + request = build_query_knowledge_base_request( json=json_content, project_name=qna_project, deployment_name='test' @@ -137,7 +137,7 @@ async def test_query_knowledgebase(self, qna_account, qna_key, qna_project): ) async with client: - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -183,7 +183,7 @@ async def test_query_knowledgebase_with_answerspan(self, qna_account, qna_key, q ) async with client: - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -233,7 +233,7 @@ async def test_query_knowledgebase_with_dictparams(self, qna_account, qna_key, q } async with client: - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -248,7 +248,7 @@ async def test_query_knowledgebase_with_dictparams(self, qna_account, qna_key, q async def test_query_knowledgebase_overload(self, qna_account, qna_key, qna_project): client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) async with client: - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( project_name=qna_project, deployment_name='test', question="How long should my Surface battery last?", @@ -285,7 +285,7 @@ async def test_query_knowledgebase_with_followup(self, qna_account, qna_key, qna include_unstructured_sources=True ) - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -310,7 +310,7 @@ async def test_query_knowledgebase_with_followup(self, qna_account, qna_key, qna ), include_unstructured_sources=True ) - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -327,7 +327,7 @@ async def test_query_knowledgebase_only_id(self, qna_account, qna_key, qna_proje async with client: query_params = {"qnaId": 19} - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' @@ -341,7 +341,7 @@ async def test_query_knowledgebase_python_dict(self, qna_account, qna_key, qna_p async with client: query_params = {"qna_id": 19} - output = await client.query_knowledgebase( + output = await client.query_knowledge_base( query_params, project_name=qna_project, deployment_name='test' diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text.py index 488306fa2510..2bfc61fd58b8 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text.py @@ -4,6 +4,8 @@ # Licensed under the MIT License. # ------------------------------------ +import pytest + from azure.core.exceptions import HttpResponseError, ClientAuthenticationError from azure.core.credentials import AzureKeyCredential @@ -124,3 +126,57 @@ def test_query_text_with_dictparams(self, qna_account, qna_key): confident_answers = [a for a in output.answers if a.confidence_score > 0.9] assert len(confident_answers) == 2 assert confident_answers[0].answer_span.text == "two to four hours" + + + @GlobalQuestionAnsweringAccountPreparer() + def test_query_text_with_str_records(self, qna_account, qna_key): + client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) + params = { + "question": "How long it takes to charge surface?", + "records": [ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + ], + "language": "en" + } + + with client: + output = client.query_text(params) + assert len(output.answers) == 3 + confident_answers = [a for a in output.answers if a.confidence_score > 0.9] + assert len(confident_answers) == 2 + assert confident_answers[0].answer_span.text == "two to four hours" + + @GlobalQuestionAnsweringAccountPreparer() + def test_query_text_overload(self, qna_account, qna_key): + client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) + + with client: + with pytest.raises(TypeError): + client.query_text( + question="How long it takes to charge surface?", + records=[ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + { + "text": "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + "id": "2" + } + ] + ) + output = client.query_text( + question="How long it takes to charge surface?", + records=[ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + ] + ) + assert len(output.answers) == 3 + confident_answers = [a for a in output.answers if a.confidence_score > 0.9] + assert len(confident_answers) == 2 + assert confident_answers[0].answer_span.text == "two to four hours" diff --git a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text_async.py b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text_async.py index 9f1cfa1f6e10..1eee19633ec7 100644 --- a/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text_async.py +++ b/sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/test_query_text_async.py @@ -4,6 +4,8 @@ # Licensed under the MIT License. # ------------------------------------ +import pytest + from azure.core.exceptions import HttpResponseError, ClientAuthenticationError from azure.core.credentials import AzureKeyCredential @@ -126,3 +128,56 @@ async def test_query_text_with_dictparams(self, qna_account, qna_key): confident_answers = [a for a in output.answers if a.confidence_score > 0.9] assert len(confident_answers) == 2 assert confident_answers[0].answer_span.text == "two to four hours" + + @GlobalQuestionAnsweringAccountPreparer() + async def test_query_text_with_str_records(self, qna_account, qna_key): + client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) + params = { + "question": "How long it takes to charge surface?", + "records": [ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + ], + "language": "en" + } + + async with client: + output = await client.query_text(params) + assert len(output.answers) == 3 + confident_answers = [a for a in output.answers if a.confidence_score > 0.9] + assert len(confident_answers) == 2 + assert confident_answers[0].answer_span.text == "two to four hours" + + @GlobalQuestionAnsweringAccountPreparer() + async def test_query_text_overload(self, qna_account, qna_key): + client = QuestionAnsweringClient(qna_account, AzureKeyCredential(qna_key)) + + async with client: + with pytest.raises(TypeError): + await client.query_text( + question="How long it takes to charge surface?", + records=[ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + { + "text": "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + "id": "2" + } + ] + ) + output = await client.query_text( + question="How long it takes to charge surface?", + records=[ + "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. " + + "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.", + "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. "+ + "The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.", + ] + ) + assert len(output.answers) == 3 + confident_answers = [a for a in output.answers if a.confidence_score > 0.9] + assert len(confident_answers) == 2 + assert confident_answers[0].answer_span.text == "two to four hours"