azure-ai-textanalytics 5.3.0b1__py3-none-any.whl → 6.0.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of azure-ai-textanalytics might be problematic. Click here for more details.

Files changed (128) hide show
  1. azure/ai/textanalytics/__init__.py +26 -197
  2. azure/ai/textanalytics/_client.py +111 -0
  3. azure/ai/textanalytics/_configuration.py +73 -0
  4. azure/ai/textanalytics/{_generated/v2022_05_01/operations → _operations}/__init__.py +13 -8
  5. azure/ai/textanalytics/_operations/_operations.py +716 -0
  6. azure/ai/textanalytics/{_generated/v2022_05_01/models → _operations}/_patch.py +8 -6
  7. azure/ai/textanalytics/_patch.py +350 -0
  8. azure/ai/textanalytics/{_generated/aio → _utils}/__init__.py +1 -5
  9. azure/ai/textanalytics/_utils/model_base.py +1237 -0
  10. azure/ai/textanalytics/{_generated/_serialization.py → _utils/serialization.py} +640 -616
  11. azure/ai/textanalytics/{_generated/v2022_05_01/aio/_vendor.py → _utils/utils.py} +10 -12
  12. azure/ai/textanalytics/_version.py +8 -7
  13. azure/ai/textanalytics/aio/__init__.py +25 -14
  14. azure/ai/textanalytics/aio/_client.py +115 -0
  15. azure/ai/textanalytics/aio/_configuration.py +75 -0
  16. azure/ai/textanalytics/{_generated/v2022_10_01_preview/aio/operations → aio/_operations}/__init__.py +13 -8
  17. azure/ai/textanalytics/aio/_operations/_operations.py +623 -0
  18. azure/ai/textanalytics/{_generated/v2022_05_01 → aio/_operations}/_patch.py +8 -6
  19. azure/ai/textanalytics/aio/_patch.py +344 -0
  20. azure/ai/textanalytics/models/__init__.py +402 -0
  21. azure/ai/textanalytics/models/_enums.py +1979 -0
  22. azure/ai/textanalytics/models/_models.py +6641 -0
  23. azure/ai/textanalytics/{_generated/v2022_05_01/aio → models}/_patch.py +8 -6
  24. azure/ai/textanalytics/py.typed +1 -0
  25. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/METADATA +755 -319
  26. azure_ai_textanalytics-6.0.0b1.dist-info/RECORD +29 -0
  27. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/WHEEL +1 -1
  28. azure/ai/textanalytics/_base_client.py +0 -111
  29. azure/ai/textanalytics/_check.py +0 -22
  30. azure/ai/textanalytics/_dict_mixin.py +0 -54
  31. azure/ai/textanalytics/_generated/__init__.py +0 -16
  32. azure/ai/textanalytics/_generated/_configuration.py +0 -70
  33. azure/ai/textanalytics/_generated/_operations_mixin.py +0 -795
  34. azure/ai/textanalytics/_generated/_text_analytics_client.py +0 -126
  35. azure/ai/textanalytics/_generated/_version.py +0 -8
  36. azure/ai/textanalytics/_generated/aio/_configuration.py +0 -66
  37. azure/ai/textanalytics/_generated/aio/_operations_mixin.py +0 -776
  38. azure/ai/textanalytics/_generated/aio/_text_analytics_client.py +0 -124
  39. azure/ai/textanalytics/_generated/models.py +0 -8
  40. azure/ai/textanalytics/_generated/v2022_05_01/__init__.py +0 -20
  41. azure/ai/textanalytics/_generated/v2022_05_01/_configuration.py +0 -72
  42. azure/ai/textanalytics/_generated/v2022_05_01/_text_analytics_client.py +0 -100
  43. azure/ai/textanalytics/_generated/v2022_05_01/_vendor.py +0 -45
  44. azure/ai/textanalytics/_generated/v2022_05_01/aio/__init__.py +0 -20
  45. azure/ai/textanalytics/_generated/v2022_05_01/aio/_configuration.py +0 -71
  46. azure/ai/textanalytics/_generated/v2022_05_01/aio/_text_analytics_client.py +0 -97
  47. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/__init__.py +0 -18
  48. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_patch.py +0 -121
  49. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_text_analytics_client_operations.py +0 -603
  50. azure/ai/textanalytics/_generated/v2022_05_01/models/__init__.py +0 -281
  51. azure/ai/textanalytics/_generated/v2022_05_01/models/_models_py3.py +0 -5722
  52. azure/ai/textanalytics/_generated/v2022_05_01/models/_text_analytics_client_enums.py +0 -439
  53. azure/ai/textanalytics/_generated/v2022_05_01/operations/_patch.py +0 -120
  54. azure/ai/textanalytics/_generated/v2022_05_01/operations/_text_analytics_client_operations.py +0 -744
  55. azure/ai/textanalytics/_generated/v2022_10_01_preview/__init__.py +0 -20
  56. azure/ai/textanalytics/_generated/v2022_10_01_preview/_configuration.py +0 -72
  57. azure/ai/textanalytics/_generated/v2022_10_01_preview/_patch.py +0 -19
  58. azure/ai/textanalytics/_generated/v2022_10_01_preview/_text_analytics_client.py +0 -100
  59. azure/ai/textanalytics/_generated/v2022_10_01_preview/_vendor.py +0 -45
  60. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/__init__.py +0 -20
  61. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_configuration.py +0 -71
  62. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_patch.py +0 -19
  63. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_text_analytics_client.py +0 -97
  64. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_vendor.py +0 -27
  65. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_patch.py +0 -121
  66. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_text_analytics_client_operations.py +0 -603
  67. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/__init__.py +0 -407
  68. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_models_py3.py +0 -8462
  69. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_patch.py +0 -72
  70. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_text_analytics_client_enums.py +0 -730
  71. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/__init__.py +0 -18
  72. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_patch.py +0 -120
  73. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_text_analytics_client_operations.py +0 -744
  74. azure/ai/textanalytics/_generated/v3_0/__init__.py +0 -20
  75. azure/ai/textanalytics/_generated/v3_0/_configuration.py +0 -66
  76. azure/ai/textanalytics/_generated/v3_0/_patch.py +0 -31
  77. azure/ai/textanalytics/_generated/v3_0/_text_analytics_client.py +0 -96
  78. azure/ai/textanalytics/_generated/v3_0/_vendor.py +0 -33
  79. azure/ai/textanalytics/_generated/v3_0/aio/__init__.py +0 -20
  80. azure/ai/textanalytics/_generated/v3_0/aio/_configuration.py +0 -65
  81. azure/ai/textanalytics/_generated/v3_0/aio/_patch.py +0 -31
  82. azure/ai/textanalytics/_generated/v3_0/aio/_text_analytics_client.py +0 -93
  83. azure/ai/textanalytics/_generated/v3_0/aio/_vendor.py +0 -27
  84. azure/ai/textanalytics/_generated/v3_0/aio/operations/__init__.py +0 -18
  85. azure/ai/textanalytics/_generated/v3_0/aio/operations/_patch.py +0 -19
  86. azure/ai/textanalytics/_generated/v3_0/aio/operations/_text_analytics_client_operations.py +0 -428
  87. azure/ai/textanalytics/_generated/v3_0/models/__init__.py +0 -81
  88. azure/ai/textanalytics/_generated/v3_0/models/_models_py3.py +0 -1467
  89. azure/ai/textanalytics/_generated/v3_0/models/_patch.py +0 -19
  90. azure/ai/textanalytics/_generated/v3_0/models/_text_analytics_client_enums.py +0 -58
  91. azure/ai/textanalytics/_generated/v3_0/operations/__init__.py +0 -18
  92. azure/ai/textanalytics/_generated/v3_0/operations/_patch.py +0 -19
  93. azure/ai/textanalytics/_generated/v3_0/operations/_text_analytics_client_operations.py +0 -604
  94. azure/ai/textanalytics/_generated/v3_1/__init__.py +0 -20
  95. azure/ai/textanalytics/_generated/v3_1/_configuration.py +0 -66
  96. azure/ai/textanalytics/_generated/v3_1/_patch.py +0 -31
  97. azure/ai/textanalytics/_generated/v3_1/_text_analytics_client.py +0 -98
  98. azure/ai/textanalytics/_generated/v3_1/_vendor.py +0 -45
  99. azure/ai/textanalytics/_generated/v3_1/aio/__init__.py +0 -20
  100. azure/ai/textanalytics/_generated/v3_1/aio/_configuration.py +0 -65
  101. azure/ai/textanalytics/_generated/v3_1/aio/_patch.py +0 -31
  102. azure/ai/textanalytics/_generated/v3_1/aio/_text_analytics_client.py +0 -95
  103. azure/ai/textanalytics/_generated/v3_1/aio/_vendor.py +0 -27
  104. azure/ai/textanalytics/_generated/v3_1/aio/operations/__init__.py +0 -18
  105. azure/ai/textanalytics/_generated/v3_1/aio/operations/_patch.py +0 -19
  106. azure/ai/textanalytics/_generated/v3_1/aio/operations/_text_analytics_client_operations.py +0 -1291
  107. azure/ai/textanalytics/_generated/v3_1/models/__init__.py +0 -205
  108. azure/ai/textanalytics/_generated/v3_1/models/_models_py3.py +0 -3976
  109. azure/ai/textanalytics/_generated/v3_1/models/_patch.py +0 -19
  110. azure/ai/textanalytics/_generated/v3_1/models/_text_analytics_client_enums.py +0 -367
  111. azure/ai/textanalytics/_generated/v3_1/operations/__init__.py +0 -18
  112. azure/ai/textanalytics/_generated/v3_1/operations/_patch.py +0 -19
  113. azure/ai/textanalytics/_generated/v3_1/operations/_text_analytics_client_operations.py +0 -1709
  114. azure/ai/textanalytics/_lro.py +0 -552
  115. azure/ai/textanalytics/_models.py +0 -3142
  116. azure/ai/textanalytics/_policies.py +0 -66
  117. azure/ai/textanalytics/_request_handlers.py +0 -104
  118. azure/ai/textanalytics/_response_handlers.py +0 -580
  119. azure/ai/textanalytics/_text_analytics_client.py +0 -1802
  120. azure/ai/textanalytics/_user_agent.py +0 -8
  121. azure/ai/textanalytics/_validate.py +0 -113
  122. azure/ai/textanalytics/aio/_base_client_async.py +0 -95
  123. azure/ai/textanalytics/aio/_lro_async.py +0 -501
  124. azure/ai/textanalytics/aio/_response_handlers_async.py +0 -94
  125. azure/ai/textanalytics/aio/_text_analytics_client_async.py +0 -1800
  126. azure_ai_textanalytics-5.3.0b1.dist-info/RECORD +0 -115
  127. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info/licenses}/LICENSE +0 -0
  128. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,623 @@
1
+ # pylint: disable=line-too-long,useless-suppression
2
+ # coding=utf-8
3
+ # --------------------------------------------------------------------------
4
+ # Copyright (c) Microsoft Corporation. All rights reserved.
5
+ # Licensed under the MIT License. See License.txt in the project root for license information.
6
+ # Code generated by Microsoft (R) Python Code Generator.
7
+ # Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
+ # --------------------------------------------------------------------------
9
+ from collections.abc import MutableMapping # pylint:disable=import-error
10
+ from io import IOBase
11
+ import json
12
+ from typing import Any, AsyncIterator, Callable, IO, Optional, TypeVar, Union, cast, overload
13
+
14
+ from azure.core import AsyncPipelineClient
15
+ from azure.core.exceptions import (
16
+ ClientAuthenticationError,
17
+ HttpResponseError,
18
+ ResourceExistsError,
19
+ ResourceNotFoundError,
20
+ ResourceNotModifiedError,
21
+ StreamClosedError,
22
+ StreamConsumedError,
23
+ map_error,
24
+ )
25
+ from azure.core.pipeline import PipelineResponse
26
+ from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
27
+ from azure.core.polling.async_base_polling import AsyncLROBasePolling
28
+ from azure.core.rest import AsyncHttpResponse, HttpRequest
29
+ from azure.core.tracing.decorator_async import distributed_trace_async
30
+ from azure.core.utils import case_insensitive_dict
31
+
32
+ from ... import models as _models
33
+ from ..._operations._operations import (
34
+ build_text_analysis_analyze_text_job_request,
35
+ build_text_analysis_analyze_text_request,
36
+ build_text_analysis_cancel_job_request,
37
+ build_text_analysis_get_job_status_request,
38
+ )
39
+ from ..._utils.model_base import SdkJSONEncoder, _deserialize, _failsafe_deserialize
40
+ from ..._utils.utils import ClientMixinABC
41
+ from .._configuration import TextAnalysisClientConfiguration
42
+
43
+ JSON = MutableMapping[str, Any]
44
+ _Unset: Any = object()
45
+ T = TypeVar("T")
46
+ ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
47
+
48
+
49
+ class _TextAnalysisClientOperationsMixin(
50
+ ClientMixinABC[AsyncPipelineClient[HttpRequest, AsyncHttpResponse], TextAnalysisClientConfiguration]
51
+ ):
52
+
53
+ @overload
54
+ async def analyze_text(
55
+ self,
56
+ body: _models.AnalyzeTextInput,
57
+ *,
58
+ show_stats: Optional[bool] = None,
59
+ content_type: str = "application/json",
60
+ **kwargs: Any
61
+ ) -> _models.AnalyzeTextResult:
62
+ """Request text analysis over a collection of documents.
63
+
64
+ :param body: The input documents to analyze. Required.
65
+ :type body: ~azure.ai.textanalytics.models.AnalyzeTextInput
66
+ :keyword show_stats: (Optional) if set to true, response will contain request and document
67
+ level statistics. Default value is None.
68
+ :paramtype show_stats: bool
69
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
70
+ Default value is "application/json".
71
+ :paramtype content_type: str
72
+ :return: AnalyzeTextResult. The AnalyzeTextResult is compatible with MutableMapping
73
+ :rtype: ~azure.ai.textanalytics.models.AnalyzeTextResult
74
+ :raises ~azure.core.exceptions.HttpResponseError:
75
+ """
76
+
77
+ @overload
78
+ async def analyze_text(
79
+ self, body: JSON, *, show_stats: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any
80
+ ) -> _models.AnalyzeTextResult:
81
+ """Request text analysis over a collection of documents.
82
+
83
+ :param body: The input documents to analyze. Required.
84
+ :type body: JSON
85
+ :keyword show_stats: (Optional) if set to true, response will contain request and document
86
+ level statistics. Default value is None.
87
+ :paramtype show_stats: bool
88
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
89
+ Default value is "application/json".
90
+ :paramtype content_type: str
91
+ :return: AnalyzeTextResult. The AnalyzeTextResult is compatible with MutableMapping
92
+ :rtype: ~azure.ai.textanalytics.models.AnalyzeTextResult
93
+ :raises ~azure.core.exceptions.HttpResponseError:
94
+ """
95
+
96
+ @overload
97
+ async def analyze_text(
98
+ self,
99
+ body: IO[bytes],
100
+ *,
101
+ show_stats: Optional[bool] = None,
102
+ content_type: str = "application/json",
103
+ **kwargs: Any
104
+ ) -> _models.AnalyzeTextResult:
105
+ """Request text analysis over a collection of documents.
106
+
107
+ :param body: The input documents to analyze. Required.
108
+ :type body: IO[bytes]
109
+ :keyword show_stats: (Optional) if set to true, response will contain request and document
110
+ level statistics. Default value is None.
111
+ :paramtype show_stats: bool
112
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
113
+ Default value is "application/json".
114
+ :paramtype content_type: str
115
+ :return: AnalyzeTextResult. The AnalyzeTextResult is compatible with MutableMapping
116
+ :rtype: ~azure.ai.textanalytics.models.AnalyzeTextResult
117
+ :raises ~azure.core.exceptions.HttpResponseError:
118
+ """
119
+
120
+ @distributed_trace_async
121
+ async def analyze_text(
122
+ self,
123
+ body: Union[_models.AnalyzeTextInput, JSON, IO[bytes]],
124
+ *,
125
+ show_stats: Optional[bool] = None,
126
+ **kwargs: Any
127
+ ) -> _models.AnalyzeTextResult:
128
+ """Request text analysis over a collection of documents.
129
+
130
+ :param body: The input documents to analyze. Is one of the following types: AnalyzeTextInput,
131
+ JSON, IO[bytes] Required.
132
+ :type body: ~azure.ai.textanalytics.models.AnalyzeTextInput or JSON or IO[bytes]
133
+ :keyword show_stats: (Optional) if set to true, response will contain request and document
134
+ level statistics. Default value is None.
135
+ :paramtype show_stats: bool
136
+ :return: AnalyzeTextResult. The AnalyzeTextResult is compatible with MutableMapping
137
+ :rtype: ~azure.ai.textanalytics.models.AnalyzeTextResult
138
+ :raises ~azure.core.exceptions.HttpResponseError:
139
+ """
140
+ error_map: MutableMapping = {
141
+ 401: ClientAuthenticationError,
142
+ 404: ResourceNotFoundError,
143
+ 409: ResourceExistsError,
144
+ 304: ResourceNotModifiedError,
145
+ }
146
+ error_map.update(kwargs.pop("error_map", {}) or {})
147
+
148
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
149
+ _params = kwargs.pop("params", {}) or {}
150
+
151
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
152
+ cls: ClsType[_models.AnalyzeTextResult] = kwargs.pop("cls", None)
153
+
154
+ content_type = content_type or "application/json"
155
+ _content = None
156
+ if isinstance(body, (IOBase, bytes)):
157
+ _content = body
158
+ else:
159
+ _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
160
+
161
+ _request = build_text_analysis_analyze_text_request(
162
+ show_stats=show_stats,
163
+ content_type=content_type,
164
+ api_version=self._config.api_version,
165
+ content=_content,
166
+ headers=_headers,
167
+ params=_params,
168
+ )
169
+ path_format_arguments = {
170
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
171
+ }
172
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
173
+
174
+ _stream = kwargs.pop("stream", False)
175
+ pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
176
+ _request, stream=_stream, **kwargs
177
+ )
178
+
179
+ response = pipeline_response.http_response
180
+
181
+ if response.status_code not in [200]:
182
+ if _stream:
183
+ try:
184
+ await response.read() # Load the body in memory and close the socket
185
+ except (StreamConsumedError, StreamClosedError):
186
+ pass
187
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
188
+ error = _failsafe_deserialize(_models.ErrorResponse, response)
189
+ raise HttpResponseError(response=response, model=error)
190
+
191
+ if _stream:
192
+ deserialized = response.iter_bytes()
193
+ else:
194
+ deserialized = _deserialize(_models.AnalyzeTextResult, response.json())
195
+
196
+ if cls:
197
+ return cls(pipeline_response, deserialized, {}) # type: ignore
198
+
199
+ return deserialized # type: ignore
200
+
201
+ @distributed_trace_async
202
+ async def get_job_status(
203
+ self,
204
+ job_id: str,
205
+ *,
206
+ show_stats: Optional[bool] = None,
207
+ top: Optional[int] = None,
208
+ skip: Optional[int] = None,
209
+ **kwargs: Any
210
+ ) -> _models.AnalyzeTextOperationState:
211
+ """Get analysis status and results.
212
+
213
+ Get the status of an analysis job. A job can consist of one or more tasks. After all tasks
214
+ succeed, the job transitions to the succeeded state and results are available for each task.
215
+
216
+ :param job_id: job ID. Required.
217
+ :type job_id: str
218
+ :keyword show_stats: (Optional) if set to true, response will contain request and document
219
+ level statistics. Default value is None.
220
+ :paramtype show_stats: bool
221
+ :keyword top: The maximum number of resources to return from the collection. Default value is
222
+ None.
223
+ :paramtype top: int
224
+ :keyword skip: An offset into the collection of the first resource to be returned. Default
225
+ value is None.
226
+ :paramtype skip: int
227
+ :return: AnalyzeTextOperationState. The AnalyzeTextOperationState is compatible with
228
+ MutableMapping
229
+ :rtype: ~azure.ai.textanalytics.models.AnalyzeTextOperationState
230
+ :raises ~azure.core.exceptions.HttpResponseError:
231
+ """
232
+ error_map: MutableMapping = {
233
+ 401: ClientAuthenticationError,
234
+ 404: ResourceNotFoundError,
235
+ 409: ResourceExistsError,
236
+ 304: ResourceNotModifiedError,
237
+ }
238
+ error_map.update(kwargs.pop("error_map", {}) or {})
239
+
240
+ _headers = kwargs.pop("headers", {}) or {}
241
+ _params = kwargs.pop("params", {}) or {}
242
+
243
+ cls: ClsType[_models.AnalyzeTextOperationState] = kwargs.pop("cls", None)
244
+
245
+ _request = build_text_analysis_get_job_status_request(
246
+ job_id=job_id,
247
+ show_stats=show_stats,
248
+ top=top,
249
+ skip=skip,
250
+ api_version=self._config.api_version,
251
+ headers=_headers,
252
+ params=_params,
253
+ )
254
+ path_format_arguments = {
255
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
256
+ }
257
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
258
+
259
+ _stream = kwargs.pop("stream", False)
260
+ pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
261
+ _request, stream=_stream, **kwargs
262
+ )
263
+
264
+ response = pipeline_response.http_response
265
+
266
+ if response.status_code not in [200]:
267
+ if _stream:
268
+ try:
269
+ await response.read() # Load the body in memory and close the socket
270
+ except (StreamConsumedError, StreamClosedError):
271
+ pass
272
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
273
+ error = _failsafe_deserialize(_models.ErrorResponse, response)
274
+ raise HttpResponseError(response=response, model=error)
275
+
276
+ if _stream:
277
+ deserialized = response.iter_bytes()
278
+ else:
279
+ deserialized = _deserialize(_models.AnalyzeTextOperationState, response.json())
280
+
281
+ if cls:
282
+ return cls(pipeline_response, deserialized, {}) # type: ignore
283
+
284
+ return deserialized # type: ignore
285
+
286
+ async def _analyze_text_job_initial(
287
+ self,
288
+ body: Union[JSON, IO[bytes]] = _Unset,
289
+ *,
290
+ text_input: _models.MultiLanguageTextInput = _Unset,
291
+ actions: list[_models.AnalyzeTextOperationAction] = _Unset,
292
+ display_name: Optional[str] = None,
293
+ default_language: Optional[str] = None,
294
+ cancel_after: Optional[float] = None,
295
+ **kwargs: Any
296
+ ) -> AsyncIterator[bytes]:
297
+ error_map: MutableMapping = {
298
+ 401: ClientAuthenticationError,
299
+ 404: ResourceNotFoundError,
300
+ 409: ResourceExistsError,
301
+ 304: ResourceNotModifiedError,
302
+ }
303
+ error_map.update(kwargs.pop("error_map", {}) or {})
304
+
305
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
306
+ _params = kwargs.pop("params", {}) or {}
307
+
308
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
309
+ cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None)
310
+
311
+ if body is _Unset:
312
+ if text_input is _Unset:
313
+ raise TypeError("missing required argument: text_input")
314
+ if actions is _Unset:
315
+ raise TypeError("missing required argument: actions")
316
+ body = {
317
+ "analysisInput": text_input,
318
+ "cancelAfter": cancel_after,
319
+ "defaultLanguage": default_language,
320
+ "displayName": display_name,
321
+ "tasks": actions,
322
+ }
323
+ body = {k: v for k, v in body.items() if v is not None}
324
+ content_type = content_type or "application/json"
325
+ _content = None
326
+ if isinstance(body, (IOBase, bytes)):
327
+ _content = body
328
+ else:
329
+ _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
330
+
331
+ _request = build_text_analysis_analyze_text_job_request(
332
+ content_type=content_type,
333
+ api_version=self._config.api_version,
334
+ content=_content,
335
+ headers=_headers,
336
+ params=_params,
337
+ )
338
+ path_format_arguments = {
339
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
340
+ }
341
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
342
+
343
+ _stream = True
344
+ pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
345
+ _request, stream=_stream, **kwargs
346
+ )
347
+
348
+ response = pipeline_response.http_response
349
+
350
+ if response.status_code not in [202]:
351
+ try:
352
+ await response.read() # Load the body in memory and close the socket
353
+ except (StreamConsumedError, StreamClosedError):
354
+ pass
355
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
356
+ error = _failsafe_deserialize(_models.ErrorResponse, response)
357
+ raise HttpResponseError(response=response, model=error)
358
+
359
+ response_headers = {}
360
+ response_headers["Operation-Location"] = self._deserialize("str", response.headers.get("Operation-Location"))
361
+
362
+ deserialized = response.iter_bytes()
363
+
364
+ if cls:
365
+ return cls(pipeline_response, deserialized, response_headers) # type: ignore
366
+
367
+ return deserialized # type: ignore
368
+
369
+ @overload
370
+ async def _begin_analyze_text_job(
371
+ self,
372
+ *,
373
+ text_input: _models.MultiLanguageTextInput,
374
+ actions: list[_models.AnalyzeTextOperationAction],
375
+ content_type: str = "application/json",
376
+ display_name: Optional[str] = None,
377
+ default_language: Optional[str] = None,
378
+ cancel_after: Optional[float] = None,
379
+ **kwargs: Any
380
+ ) -> AsyncLROPoller[None]:
381
+ """Submit a collection of text documents for analysis. Specify one or more unique tasks to be
382
+ executed as a long-running operation.
383
+
384
+ :keyword text_input: Contains the input to be analyzed. Required.
385
+ :paramtype text_input: ~azure.ai.textanalytics.models.MultiLanguageTextInput
386
+ :keyword actions: List of tasks to be performed as part of the LRO. Required.
387
+ :paramtype actions: list[~azure.ai.textanalytics.models.AnalyzeTextOperationAction]
388
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
389
+ Default value is "application/json".
390
+ :paramtype content_type: str
391
+ :keyword display_name: Name for the task. Default value is None.
392
+ :paramtype display_name: str
393
+ :keyword default_language: Default language to use for records requesting automatic language
394
+ detection. Default value is None.
395
+ :paramtype default_language: str
396
+ :keyword cancel_after: Optional duration in seconds after which the job will be canceled if not
397
+ completed. Default value is None.
398
+ :paramtype cancel_after: float
399
+ :return: An instance of AsyncLROPoller that returns None
400
+ :rtype: ~azure.core.polling.AsyncLROPoller[None]
401
+ :raises ~azure.core.exceptions.HttpResponseError:
402
+ """
403
+
404
+ @overload
405
+ async def _begin_analyze_text_job(
406
+ self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
407
+ ) -> AsyncLROPoller[None]:
408
+ """Submit a collection of text documents for analysis. Specify one or more unique tasks to be
409
+ executed as a long-running operation.
410
+
411
+ :param body: Required.
412
+ :type body: JSON
413
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
414
+ Default value is "application/json".
415
+ :paramtype content_type: str
416
+ :return: An instance of AsyncLROPoller that returns None
417
+ :rtype: ~azure.core.polling.AsyncLROPoller[None]
418
+ :raises ~azure.core.exceptions.HttpResponseError:
419
+ """
420
+
421
+ @overload
422
+ async def _begin_analyze_text_job(
423
+ self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
424
+ ) -> AsyncLROPoller[None]:
425
+ """Submit a collection of text documents for analysis. Specify one or more unique tasks to be
426
+ executed as a long-running operation.
427
+
428
+ :param body: Required.
429
+ :type body: IO[bytes]
430
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
431
+ Default value is "application/json".
432
+ :paramtype content_type: str
433
+ :return: An instance of AsyncLROPoller that returns None
434
+ :rtype: ~azure.core.polling.AsyncLROPoller[None]
435
+ :raises ~azure.core.exceptions.HttpResponseError:
436
+ """
437
+
438
+ @distributed_trace_async
439
+ async def _begin_analyze_text_job(
440
+ self,
441
+ body: Union[JSON, IO[bytes]] = _Unset,
442
+ *,
443
+ text_input: _models.MultiLanguageTextInput = _Unset,
444
+ actions: list[_models.AnalyzeTextOperationAction] = _Unset,
445
+ display_name: Optional[str] = None,
446
+ default_language: Optional[str] = None,
447
+ cancel_after: Optional[float] = None,
448
+ **kwargs: Any
449
+ ) -> AsyncLROPoller[None]:
450
+ """Submit a collection of text documents for analysis. Specify one or more unique tasks to be
451
+ executed as a long-running operation.
452
+
453
+ :param body: Is either a JSON type or a IO[bytes] type. Required.
454
+ :type body: JSON or IO[bytes]
455
+ :keyword text_input: Contains the input to be analyzed. Required.
456
+ :paramtype text_input: ~azure.ai.textanalytics.models.MultiLanguageTextInput
457
+ :keyword actions: List of tasks to be performed as part of the LRO. Required.
458
+ :paramtype actions: list[~azure.ai.textanalytics.models.AnalyzeTextOperationAction]
459
+ :keyword display_name: Name for the task. Default value is None.
460
+ :paramtype display_name: str
461
+ :keyword default_language: Default language to use for records requesting automatic language
462
+ detection. Default value is None.
463
+ :paramtype default_language: str
464
+ :keyword cancel_after: Optional duration in seconds after which the job will be canceled if not
465
+ completed. Default value is None.
466
+ :paramtype cancel_after: float
467
+ :return: An instance of AsyncLROPoller that returns None
468
+ :rtype: ~azure.core.polling.AsyncLROPoller[None]
469
+ :raises ~azure.core.exceptions.HttpResponseError:
470
+ """
471
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
472
+ _params = kwargs.pop("params", {}) or {}
473
+
474
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
475
+ cls: ClsType[None] = kwargs.pop("cls", None)
476
+ polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
477
+ lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
478
+ cont_token: Optional[str] = kwargs.pop("continuation_token", None)
479
+ if cont_token is None:
480
+ raw_result = await self._analyze_text_job_initial(
481
+ body=body,
482
+ text_input=text_input,
483
+ actions=actions,
484
+ display_name=display_name,
485
+ default_language=default_language,
486
+ cancel_after=cancel_after,
487
+ content_type=content_type,
488
+ cls=lambda x, y, z: x,
489
+ headers=_headers,
490
+ params=_params,
491
+ **kwargs
492
+ )
493
+ await raw_result.http_response.read() # type: ignore
494
+ kwargs.pop("error_map", None)
495
+
496
+ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements
497
+ if cls:
498
+ return cls(pipeline_response, None, {}) # type: ignore
499
+
500
+ path_format_arguments = {
501
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
502
+ }
503
+
504
+ if polling is True:
505
+ polling_method: AsyncPollingMethod = cast(
506
+ AsyncPollingMethod,
507
+ AsyncLROBasePolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs),
508
+ )
509
+ elif polling is False:
510
+ polling_method = cast(AsyncPollingMethod, AsyncNoPolling())
511
+ else:
512
+ polling_method = polling
513
+ if cont_token:
514
+ return AsyncLROPoller[None].from_continuation_token(
515
+ polling_method=polling_method,
516
+ continuation_token=cont_token,
517
+ client=self._client,
518
+ deserialization_callback=get_long_running_output,
519
+ )
520
+ return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore
521
+
522
+ async def _cancel_job_initial(self, job_id: str, **kwargs: Any) -> AsyncIterator[bytes]:
523
+ error_map: MutableMapping = {
524
+ 401: ClientAuthenticationError,
525
+ 404: ResourceNotFoundError,
526
+ 409: ResourceExistsError,
527
+ 304: ResourceNotModifiedError,
528
+ }
529
+ error_map.update(kwargs.pop("error_map", {}) or {})
530
+
531
+ _headers = kwargs.pop("headers", {}) or {}
532
+ _params = kwargs.pop("params", {}) or {}
533
+
534
+ cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None)
535
+
536
+ _request = build_text_analysis_cancel_job_request(
537
+ job_id=job_id,
538
+ api_version=self._config.api_version,
539
+ headers=_headers,
540
+ params=_params,
541
+ )
542
+ path_format_arguments = {
543
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
544
+ }
545
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
546
+
547
+ _stream = True
548
+ pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
549
+ _request, stream=_stream, **kwargs
550
+ )
551
+
552
+ response = pipeline_response.http_response
553
+
554
+ if response.status_code not in [202]:
555
+ try:
556
+ await response.read() # Load the body in memory and close the socket
557
+ except (StreamConsumedError, StreamClosedError):
558
+ pass
559
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
560
+ error = _failsafe_deserialize(_models.ErrorResponse, response)
561
+ raise HttpResponseError(response=response, model=error)
562
+
563
+ response_headers = {}
564
+ response_headers["Operation-Location"] = self._deserialize("str", response.headers.get("Operation-Location"))
565
+
566
+ deserialized = response.iter_bytes()
567
+
568
+ if cls:
569
+ return cls(pipeline_response, deserialized, response_headers) # type: ignore
570
+
571
+ return deserialized # type: ignore
572
+
573
+ @distributed_trace_async
574
+ async def begin_cancel_job(self, job_id: str, **kwargs: Any) -> AsyncLROPoller[None]:
575
+ """Cancel a long-running Text Analysis job.
576
+
577
+ Cancel a long-running Text Analysis job.
578
+
579
+ :param job_id: The job ID to cancel. Required.
580
+ :type job_id: str
581
+ :return: An instance of AsyncLROPoller that returns None
582
+ :rtype: ~azure.core.polling.AsyncLROPoller[None]
583
+ :raises ~azure.core.exceptions.HttpResponseError:
584
+ """
585
+ _headers = kwargs.pop("headers", {}) or {}
586
+ _params = kwargs.pop("params", {}) or {}
587
+
588
+ cls: ClsType[None] = kwargs.pop("cls", None)
589
+ polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
590
+ lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
591
+ cont_token: Optional[str] = kwargs.pop("continuation_token", None)
592
+ if cont_token is None:
593
+ raw_result = await self._cancel_job_initial(
594
+ job_id=job_id, cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs
595
+ )
596
+ await raw_result.http_response.read() # type: ignore
597
+ kwargs.pop("error_map", None)
598
+
599
+ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements
600
+ if cls:
601
+ return cls(pipeline_response, None, {}) # type: ignore
602
+
603
+ path_format_arguments = {
604
+ "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
605
+ }
606
+
607
+ if polling is True:
608
+ polling_method: AsyncPollingMethod = cast(
609
+ AsyncPollingMethod,
610
+ AsyncLROBasePolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs),
611
+ )
612
+ elif polling is False:
613
+ polling_method = cast(AsyncPollingMethod, AsyncNoPolling())
614
+ else:
615
+ polling_method = polling
616
+ if cont_token:
617
+ return AsyncLROPoller[None].from_continuation_token(
618
+ polling_method=polling_method,
619
+ continuation_token=cont_token,
620
+ client=self._client,
621
+ deserialization_callback=get_long_running_output,
622
+ )
623
+ return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore
@@ -1,14 +1,16 @@
1
- # ------------------------------------
2
- # Copyright (c) Microsoft Corporation.
3
- # Licensed under the MIT License.
4
- # ------------------------------------
1
+ # coding=utf-8
2
+ # --------------------------------------------------------------------------
3
+ # Copyright (c) Microsoft Corporation. All rights reserved.
4
+ # Licensed under the MIT License. See License.txt in the project root for license information.
5
+ # --------------------------------------------------------------------------
5
6
  """Customize generated code here.
6
7
 
7
8
  Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
8
9
  """
9
- from typing import List
10
10
 
11
- __all__: List[str] = [] # Add all objects you want publicly available to users at this package level
11
+
12
+ __all__: list[str] = [] # Add all objects you want publicly available to users at this package level
13
+
12
14
 
13
15
  def patch_sdk():
14
16
  """Do not remove from this file.