Skip to content

Commit 85ce0e9

Browse files
[qna] regen (Azure#19827)
* regen qna * Model renames * Client param order * Updates to docs, samples, tests * Update test trigger * Fix live tests * Fix live samples Co-authored-by: antisch <[email protected]>
1 parent 1cbcc75 commit 85ce0e9

33 files changed

+533
-425
lines changed

sdk/cognitivelanguage/azure-ai-language-questionanswering/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,43 @@ The following examples show common scenarios using the `client` [created above](
7070

7171
### Ask a question
7272

73-
The only input required to ask a question using a knowledgebase is just the question itself:
73+
The only input required to ask a question using a knowledge base is just the question itself:
7474

7575
```python
7676
from azure.ai.language.questionanswering import models as qna
7777

78-
params = qna.KnowledgebaseQueryParameters(
78+
params = qna.KnowledgeBaseQueryOptions(
7979
question="How long should my Surface battery last?"
8080
)
8181

8282
output = client.query_knowledgebase(
8383
project_name="FAQ",
84-
knowledgebase_query_parameters=params
84+
knowledge_base_query_options=params
8585
)
8686
for candidate in output.answers:
8787
print("({}) {}".format(candidate.confidence_score, candidate.answer))
8888
print("Source: {}".format(candidate.source))
8989

9090
```
9191

92-
You can set additional properties on `KnowledgebaseQueryParameters` to limit the number of answers, specify a minimum confidence score, and more.
92+
You can set additional properties on `KnowledgeBaseQueryOptions` to limit the number of answers, specify a minimum confidence score, and more.
9393

9494
### Ask a follow-up question
9595

96-
If your knowledgebase is configured for [chit-chat][questionanswering_docs_chat], you can ask a follow-up question provided the previous question-answering ID and, optionally, the exact question the user asked:
96+
If your knowledge base is configured for [chit-chat][questionanswering_docs_chat], you can ask a follow-up question provided the previous question-answering ID and, optionally, the exact question the user asked:
9797

9898
```python
99-
params = qna.models.KnowledgebaseQueryParameters(
99+
params = qna.models.KnowledgeBaseQueryOptions(
100100
question="How long should charging take?"
101-
context=qna.models.KnowledgebaseAnswerRequestContext(
101+
context=qna.models.KnowledgeBaseAnswerRequestContext(
102102
previous_user_query="How long should my Surface battery last?",
103103
previous_qna_id=previous_answer.id
104104
)
105105
)
106106

107107
output = client.query_knowledgebase(
108108
project_name="FAQ",
109-
knowledgebase_query_parameters=params
109+
knowledge_base_query_options=params
110110
)
111111
for candidate in output.answers:
112112
print("({}) {}".format(candidate.confidence_score, candidate.answer))
@@ -123,13 +123,13 @@ from azure.ai.language.questionanswering import models as qna
123123

124124
client = QuestionAnsweringClient(endpoint, credential)
125125

126-
params = qna.KnowledgebaseQueryParameters(
126+
params = qna.KnowledgeBaseQueryOptions(
127127
question="How long should my Surface battery last?"
128128
)
129129

130130
output = await client.query_knowledgebase(
131131
project_name="FAQ",
132-
knowledgebase_query_parameters=params
132+
knowledge_base_query_options=params
133133
)
134134
```
135135

@@ -149,8 +149,8 @@ from azure.core.exceptions import HttpResponseError
149149

150150
try:
151151
client.query_knowledgebase(
152-
project_name="invalid-knowledgebase",
153-
knowledgebase_query_parameters=params
152+
project_name="invalid-knowledge-base",
153+
knowledge_base_query_options=params
154154
)
155155
except HttpResponseError as error:
156156
print("Query failed: {}".format(error.message))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
from ._version import VERSION
1111

1212
__version__ = VERSION
13-
__all__ = ['QuestionAnsweringClient']
13+
__all__ = ["QuestionAnsweringClient"]
1414

1515
try:
1616
from ._patch import patch_sdk # type: ignore
17+
1718
patch_sdk()
1819
except ImportError:
1920
pass

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_question_answering_client.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
from azure.core import PipelineClient
1313
from msrest import Deserializer, Serializer
1414

15+
from . import models
16+
from ._configuration import QuestionAnsweringClientConfiguration
17+
from .operations import QuestionAnsweringClientOperationsMixin
18+
1519
if TYPE_CHECKING:
1620
# pylint: disable=unused-import,ungrouped-imports
1721
from typing import Any
1822

1923
from azure.core.credentials import AzureKeyCredential
2024
from azure.core.rest import HttpRequest, HttpResponse
2125

22-
from ._configuration import QuestionAnsweringClientConfiguration
23-
from .operations import QuestionAnsweringClientOperationsMixin
24-
from . import models
25-
2626

2727
class QuestionAnsweringClient(QuestionAnsweringClientOperationsMixin):
2828
"""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:`<a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview">https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview</a>`.
2929
30-
:param endpoint: Supported Cognitive Services endpoint (e.g., https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
30+
:param endpoint: Supported Cognitive Services endpoint (e.g.,
31+
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
3132
:type endpoint: str
3233
:param credential: Credential needed for the client to connect to Azure.
3334
:type credential: ~azure.core.credentials.AzureKeyCredential
@@ -49,15 +50,19 @@ def __init__(
4950
self._deserialize = Deserializer(client_models)
5051
self._serialize.client_side_validation = False
5152

52-
def send_request(self, request, **kwargs):
53-
# type: (HttpRequest, Any) -> HttpResponse
53+
def send_request(
54+
self,
55+
request, # type: HttpRequest
56+
**kwargs # type: Any
57+
):
58+
# type: (...) -> HttpResponse
5459
"""Runs the network request through the client's chained policies.
5560
5661
We have helper methods to create requests specific to this service in `azure.ai.language.questionanswering.rest`.
5762
Use these helper methods to create the request you pass to this method. See our example below:
5863
5964
>>> from azure.ai.language.questionanswering.rest import build_query_knowledgebase_request
60-
>>> request = build_query_knowledgebase_request(project_name, json, content, deployment_name)
65+
>>> request = build_query_knowledgebase_request(project_name=project_name, json=json, content=content, deployment_name=deployment_name, **kwargs)
6166
<HttpRequest [POST], url: '/:query-knowledgebases'>
6267
>>> response = client.send_request(request)
6368
<HttpResponse: 200 OK>
@@ -73,6 +78,7 @@ def send_request(self, request, **kwargs):
7378
:return: The response of your network call. Does not do error handling on your response.
7479
:rtype: ~azure.core.rest.HttpResponse
7580
"""
81+
7682
request_copy = deepcopy(request)
7783
path_format_arguments = {
7884
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
from ._question_answering_client import QuestionAnsweringClient
1010

11-
__all__ = ['QuestionAnsweringClient']
11+
__all__ = ["QuestionAnsweringClient"]

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_question_answering_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77
# --------------------------------------------------------------------------
88

99
from copy import deepcopy
10-
from typing import Any
10+
from typing import Any, Awaitable
1111

1212
from azure.core import AsyncPipelineClient
1313
from azure.core.credentials import AzureKeyCredential
1414
from azure.core.rest import AsyncHttpResponse, HttpRequest
1515
from msrest import Deserializer, Serializer
1616

17+
from .. import models
1718
from ._configuration import QuestionAnsweringClientConfiguration
1819
from .operations import QuestionAnsweringClientOperationsMixin
19-
from .. import models
2020

2121

2222
class QuestionAnsweringClient(QuestionAnsweringClientOperationsMixin):
2323
"""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:`<a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview">https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview</a>`.
2424
25-
:param endpoint: Supported Cognitive Services endpoint (e.g., https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
25+
:param endpoint: Supported Cognitive Services endpoint (e.g.,
26+
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
2627
:type endpoint: str
2728
:param credential: Credential needed for the client to connect to Azure.
2829
:type credential: ~azure.core.credentials.AzureKeyCredential
@@ -38,14 +39,14 @@ def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any)
3839
self._deserialize = Deserializer(client_models)
3940
self._serialize.client_side_validation = False
4041

41-
def send_request(self, request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse:
42+
def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]:
4243
"""Runs the network request through the client's chained policies.
4344
4445
We have helper methods to create requests specific to this service in `azure.ai.language.questionanswering.rest`.
4546
Use these helper methods to create the request you pass to this method. See our example below:
4647
4748
>>> from azure.ai.language.questionanswering.rest import build_query_knowledgebase_request
48-
>>> request = build_query_knowledgebase_request(project_name, json, content, deployment_name)
49+
>>> request = build_query_knowledgebase_request(project_name=project_name, json=json, content=content, deployment_name=deployment_name, **kwargs)
4950
<HttpRequest [POST], url: '/:query-knowledgebases'>
5051
>>> response = await client.send_request(request)
5152
<AsyncHttpResponse: 200 OK>
@@ -61,6 +62,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse
6162
:return: The response of your network call. Does not do error handling on your response.
6263
:rtype: ~azure.core.rest.AsyncHttpResponse
6364
"""
65+
6466
request_copy = deepcopy(request)
6567
path_format_arguments = {
6668
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/operations/_question_answering_client_operations.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from azure.core.pipeline.transport import AsyncHttpResponse
2121
from azure.core.rest import HttpRequest
2222

23-
from ... import models as _models, rest
23+
from ... import models as _models, rest as rest
2424

2525
T = TypeVar("T")
2626
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
@@ -29,44 +29,42 @@
2929
class QuestionAnsweringClientOperationsMixin:
3030
async def query_knowledgebase(
3131
self,
32-
knowledgebase_query_parameters: "_models.KnowledgebaseQueryParameters",
32+
knowledge_base_query_options: "_models.KnowledgeBaseQueryOptions",
3333
*,
3434
project_name: str,
3535
deployment_name: Optional[str] = None,
3636
**kwargs: Any
37-
) -> "_models.KnowledgebaseAnswers":
38-
"""Answers the specified question using your knowledgebase.
37+
) -> "_models.KnowledgeBaseAnswers":
38+
"""Answers the specified question using your knowledge base.
3939
40-
Answers the specified question using your knowledgebase.
40+
Answers the specified question using your knowledge base.
4141
42+
:param knowledge_base_query_options: Post body of the request.
43+
:type knowledge_base_query_options:
44+
~azure.ai.language.questionanswering.models.KnowledgeBaseQueryOptions
4245
:keyword project_name: The name of the project to use.
4346
:paramtype project_name: str
44-
:param knowledgebase_query_parameters: Post body of the request.
45-
:type knowledgebase_query_parameters:
46-
~azure.ai.language.questionanswering.models.KnowledgebaseQueryParameters
4747
:keyword deployment_name: The name of the specific deployment of the project to use.
4848
:paramtype deployment_name: str
4949
:keyword callable cls: A custom type or function that will be passed the direct response
50-
:return: KnowledgebaseAnswers, or the result of cls(response)
51-
:rtype: ~azure.ai.language.questionanswering.models.KnowledgebaseAnswers
50+
:return: KnowledgeBaseAnswers, or the result of cls(response)
51+
:rtype: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswers
5252
:raises: ~azure.core.exceptions.HttpResponseError
5353
"""
54-
cls = kwargs.pop("cls", None) # type: ClsType["_models.KnowledgebaseAnswers"]
54+
cls = kwargs.pop("cls", None) # type: ClsType["_models.KnowledgeBaseAnswers"]
5555
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
5656
error_map.update(kwargs.pop("error_map", {}))
57-
5857
content_type = kwargs.pop("content_type", "application/json") # type: Optional[str]
5958

60-
json = self._serialize.body(knowledgebase_query_parameters, "object")
59+
json = self._serialize.body(knowledge_base_query_options, "KnowledgeBaseQueryOptions")
6160

6261
request = rest.build_query_knowledgebase_request(
62+
content_type=content_type,
6363
project_name=project_name,
6464
deployment_name=deployment_name,
6565
json=json,
66-
content_type=content_type,
6766
template_url=self.query_knowledgebase.metadata["url"],
68-
**kwargs
69-
)
67+
)._to_pipeline_transport_request()
7068
path_format_arguments = {
7169
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
7270
}
@@ -82,24 +80,22 @@ async def query_knowledgebase(
8280
error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, response)
8381
raise HttpResponseError(response=response, model=error)
8482

85-
deserialized = self._deserialize("KnowledgebaseAnswers", pipeline_response)
83+
deserialized = self._deserialize("KnowledgeBaseAnswers", pipeline_response)
8684

8785
if cls:
88-
return cls(PipelineResponse._convert(pipeline_response), deserialized, {})
86+
return cls(pipeline_response, deserialized, {})
8987

9088
return deserialized
9189

9290
query_knowledgebase.metadata = {"url": "/:query-knowledgebases"} # type: ignore
9391

94-
async def query_text(
95-
self, text_query_parameters: "_models.TextQueryParameters", **kwargs: Any
96-
) -> "_models.TextAnswers":
92+
async def query_text(self, text_query_options: "_models.TextQueryOptions", **kwargs: Any) -> "_models.TextAnswers":
9793
"""Answers the specified question using the provided text in the body.
9894
9995
Answers the specified question using the provided text in the body.
10096
101-
:param text_query_parameters: Post body of the request.
102-
:type text_query_parameters: ~azure.ai.language.questionanswering.models.TextQueryParameters
97+
:param text_query_options: Post body of the request.
98+
:type text_query_options: ~azure.ai.language.questionanswering.models.TextQueryOptions
10399
:keyword callable cls: A custom type or function that will be passed the direct response
104100
:return: TextAnswers, or the result of cls(response)
105101
:rtype: ~azure.ai.language.questionanswering.models.TextAnswers
@@ -108,14 +104,15 @@ async def query_text(
108104
cls = kwargs.pop("cls", None) # type: ClsType["_models.TextAnswers"]
109105
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
110106
error_map.update(kwargs.pop("error_map", {}))
111-
112107
content_type = kwargs.pop("content_type", "application/json") # type: Optional[str]
113108

114-
json = self._serialize.body(text_query_parameters, "object")
109+
json = self._serialize.body(text_query_options, "TextQueryOptions")
115110

116111
request = rest.build_query_text_request(
117-
json=json, content_type=content_type, template_url=self.query_text.metadata["url"], **kwargs
118-
)
112+
content_type=content_type,
113+
json=json,
114+
template_url=self.query_text.metadata["url"],
115+
)._to_pipeline_transport_request()
119116
path_format_arguments = {
120117
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
121118
}
@@ -134,7 +131,7 @@ async def query_text(
134131
deserialized = self._deserialize("TextAnswers", pipeline_response)
135132

136133
if cls:
137-
return cls(PipelineResponse._convert(pipeline_response), deserialized, {})
134+
return cls(pipeline_response, deserialized, {})
138135

139136
return deserialized
140137

0 commit comments

Comments
 (0)