Skip to content

Commit 9b90f6e

Browse files
[textanalytics] only allow one action per type (Azure#19550)
* add validation to allow for only one action per type * update changelog
1 parent e3b53e8 commit 9b90f6e

File tree

7 files changed

+908
-0
lines changed

7 files changed

+908
-0
lines changed

sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Note: this version will be the last to officially support Python 3.5, future ver
1515
### Breaking Changes
1616

1717
- Changed: the response structure of `being_analyze_actions`. Now, we return a list of results, where each result is a list of the action results for the document, in the order the documents and actions were passed.
18+
- Changed: `begin_analyze_actions` now accepts a single action per type. A `ValueError` is raised if duplicate actions are passed.
1819
- Removed: `AnalyzeActionsType`
1920
- Removed: `AnalyzeActionsResult`
2021
- Removed: `AnalyzeActionsError`

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ def begin_analyze_actions( # type: ignore
893893

894894
doc_id_order = [doc.get("id") for doc in docs.documents]
895895
task_order = [_determine_action_type(action) for action in actions]
896+
if len(task_order) != len(set(task_order)):
897+
raise ValueError("Multiple of the same action is not currently supported.")
896898

897899
try:
898900
analyze_tasks = self._client.models(api_version='v3.1').JobManifestTasks(

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ async def begin_analyze_actions( # type: ignore
877877

878878
doc_id_order = [doc.get("id") for doc in docs.documents]
879879
task_order = [_determine_action_type(action) for action in actions]
880+
if len(task_order) != len(set(task_order)):
881+
raise ValueError("Multiple of the same action is not currently supported.")
880882

881883
try:
882884
analyze_tasks = self._client.models(api_version='v3.1').JobManifestTasks(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
interactions:
2+
- request:
3+
body: '{"tasks": {"entityRecognitionTasks": [], "entityRecognitionPiiTasks": [{"parameters":
4+
{"model-version": "latest", "loggingOptOut": false, "stringIndexType": "UnicodeCodePoint"}}],
5+
"keyPhraseExtractionTasks": [], "entityLinkingTasks": [], "sentimentAnalysisTasks":
6+
[{"parameters": {"model-version": "latest", "loggingOptOut": false, "opinionMining":
7+
false}}]}, "analysisInput": {"documents": [{"id": "1", "text": "I did not like
8+
the hotel we stayed at.", "language": "tr"}, {"id": "2", "text": "I did not
9+
like the hotel we stayed at.", "language": "en"}]}}'
10+
headers:
11+
Accept:
12+
- application/json, text/json
13+
Accept-Encoding:
14+
- gzip, deflate
15+
Connection:
16+
- keep-alive
17+
Content-Length:
18+
- '555'
19+
Content-Type:
20+
- application/json
21+
User-Agent:
22+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
23+
method: POST
24+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze
25+
response:
26+
body:
27+
string: ''
28+
headers:
29+
apim-request-id:
30+
- abcffc21-b367-4e89-bda5-6ada712289f5
31+
date:
32+
- Mon, 28 Jun 2021 19:23:31 GMT
33+
operation-location:
34+
- https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
35+
strict-transport-security:
36+
- max-age=31536000; includeSubDomains; preload
37+
transfer-encoding:
38+
- chunked
39+
x-content-type-options:
40+
- nosniff
41+
x-envoy-upstream-service-time:
42+
- '2883'
43+
status:
44+
code: 202
45+
message: Accepted
46+
- request:
47+
body: null
48+
headers:
49+
Accept:
50+
- '*/*'
51+
Accept-Encoding:
52+
- gzip, deflate
53+
Connection:
54+
- keep-alive
55+
User-Agent:
56+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
57+
method: GET
58+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
59+
response:
60+
body:
61+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:32Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"notStarted","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
62+
headers:
63+
apim-request-id:
64+
- ad8a2cca-552d-41ed-9e0f-c8aa841e3959
65+
content-type:
66+
- application/json; charset=utf-8
67+
date:
68+
- Mon, 28 Jun 2021 19:23:37 GMT
69+
strict-transport-security:
70+
- max-age=31536000; includeSubDomains; preload
71+
transfer-encoding:
72+
- chunked
73+
x-content-type-options:
74+
- nosniff
75+
x-envoy-upstream-service-time:
76+
- '10'
77+
status:
78+
code: 200
79+
message: OK
80+
- request:
81+
body: null
82+
headers:
83+
Accept:
84+
- '*/*'
85+
Accept-Encoding:
86+
- gzip, deflate
87+
Connection:
88+
- keep-alive
89+
User-Agent:
90+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
91+
method: GET
92+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
93+
response:
94+
body:
95+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:45Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
96+
headers:
97+
apim-request-id:
98+
- 0816a32e-6e41-45b4-9712-35847668d9a4
99+
content-type:
100+
- application/json; charset=utf-8
101+
date:
102+
- Mon, 28 Jun 2021 19:23:45 GMT
103+
strict-transport-security:
104+
- max-age=31536000; includeSubDomains; preload
105+
transfer-encoding:
106+
- chunked
107+
x-content-type-options:
108+
- nosniff
109+
x-envoy-upstream-service-time:
110+
- '2584'
111+
status:
112+
code: 200
113+
message: OK
114+
- request:
115+
body: null
116+
headers:
117+
Accept:
118+
- '*/*'
119+
Accept-Encoding:
120+
- gzip, deflate
121+
Connection:
122+
- keep-alive
123+
User-Agent:
124+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
125+
method: GET
126+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
127+
response:
128+
body:
129+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:45Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
130+
headers:
131+
apim-request-id:
132+
- e0ced991-ee08-4ae1-8419-becd4c1eb608
133+
content-type:
134+
- application/json; charset=utf-8
135+
date:
136+
- Mon, 28 Jun 2021 19:23:57 GMT
137+
strict-transport-security:
138+
- max-age=31536000; includeSubDomains; preload
139+
transfer-encoding:
140+
- chunked
141+
x-content-type-options:
142+
- nosniff
143+
x-envoy-upstream-service-time:
144+
- '7535'
145+
status:
146+
code: 200
147+
message: OK
148+
- request:
149+
body: null
150+
headers:
151+
Accept:
152+
- '*/*'
153+
Accept-Encoding:
154+
- gzip, deflate
155+
Connection:
156+
- keep-alive
157+
User-Agent:
158+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
159+
method: GET
160+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
161+
response:
162+
body:
163+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:45Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
164+
headers:
165+
apim-request-id:
166+
- c0ec87bb-67dd-4d0e-8246-df4c100e6389
167+
content-type:
168+
- application/json; charset=utf-8
169+
date:
170+
- Mon, 28 Jun 2021 19:24:03 GMT
171+
strict-transport-security:
172+
- max-age=31536000; includeSubDomains; preload
173+
transfer-encoding:
174+
- chunked
175+
x-content-type-options:
176+
- nosniff
177+
x-envoy-upstream-service-time:
178+
- '11'
179+
status:
180+
code: 200
181+
message: OK
182+
- request:
183+
body: null
184+
headers:
185+
Accept:
186+
- '*/*'
187+
Accept-Encoding:
188+
- gzip, deflate
189+
Connection:
190+
- keep-alive
191+
User-Agent:
192+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
193+
method: GET
194+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
195+
response:
196+
body:
197+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:45Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
198+
headers:
199+
apim-request-id:
200+
- 4a534831-af55-48ab-9276-b9a940d434e5
201+
content-type:
202+
- application/json; charset=utf-8
203+
date:
204+
- Mon, 28 Jun 2021 19:24:07 GMT
205+
strict-transport-security:
206+
- max-age=31536000; includeSubDomains; preload
207+
transfer-encoding:
208+
- chunked
209+
x-content-type-options:
210+
- nosniff
211+
x-envoy-upstream-service-time:
212+
- '11'
213+
status:
214+
code: 200
215+
message: OK
216+
- request:
217+
body: null
218+
headers:
219+
Accept:
220+
- '*/*'
221+
Accept-Encoding:
222+
- gzip, deflate
223+
Connection:
224+
- keep-alive
225+
User-Agent:
226+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
227+
method: GET
228+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
229+
response:
230+
body:
231+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:23:45Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":0,"failed":0,"inProgress":2,"total":2}}'
232+
headers:
233+
apim-request-id:
234+
- 00846de9-ef34-4288-bc1d-e9d4bd390dbb
235+
content-type:
236+
- application/json; charset=utf-8
237+
date:
238+
- Mon, 28 Jun 2021 19:24:13 GMT
239+
strict-transport-security:
240+
- max-age=31536000; includeSubDomains; preload
241+
transfer-encoding:
242+
- chunked
243+
x-content-type-options:
244+
- nosniff
245+
x-envoy-upstream-service-time:
246+
- '10'
247+
status:
248+
code: 200
249+
message: OK
250+
- request:
251+
body: null
252+
headers:
253+
Accept:
254+
- '*/*'
255+
Accept-Encoding:
256+
- gzip, deflate
257+
Connection:
258+
- keep-alive
259+
User-Agent:
260+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
261+
method: GET
262+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
263+
response:
264+
body:
265+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:24:18Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"running","errors":[],"displayName":"NA","tasks":{"completed":1,"failed":0,"inProgress":1,"total":2,"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-28T19:24:18.1203059Z","taskName":"PersonallyIdentifiableInformation_latest","state":"succeeded","results":{"documents":[{"redactedText":"I
266+
did not like the hotel we stayed at.","id":"2","entities":[],"warnings":[]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
267+
Language Code.","innererror":{"code":"UnsupportedLanguageCode","message":"Invalid
268+
language code. Supported languages: ja,ko,zh-Hans,de,en,es,fr,it,pt-BR,pt-PT.
269+
For additional details see https://aka.ms/text-analytics/language-support?tabs=named-entity-recognition"}}}],"modelVersion":"2021-01-15"}}]}}'
270+
headers:
271+
apim-request-id:
272+
- 0b9ac807-8b1c-49e8-8db2-5f2e7f228785
273+
content-type:
274+
- application/json; charset=utf-8
275+
date:
276+
- Mon, 28 Jun 2021 19:24:25 GMT
277+
strict-transport-security:
278+
- max-age=31536000; includeSubDomains; preload
279+
transfer-encoding:
280+
- chunked
281+
x-content-type-options:
282+
- nosniff
283+
x-envoy-upstream-service-time:
284+
- '7597'
285+
status:
286+
code: 200
287+
message: OK
288+
- request:
289+
body: null
290+
headers:
291+
Accept:
292+
- '*/*'
293+
Accept-Encoding:
294+
- gzip, deflate
295+
Connection:
296+
- keep-alive
297+
User-Agent:
298+
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
299+
method: GET
300+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
301+
response:
302+
body:
303+
string: '{"jobId":"7c0f4350-b4dd-4c26-ba9e-f7655428c5d8","lastUpdateDateTime":"2021-06-28T19:24:24Z","createdDateTime":"2021-06-28T19:23:29Z","expirationDateTime":"2021-06-29T19:23:29Z","status":"succeeded","errors":[],"displayName":"NA","tasks":{"completed":2,"failed":0,"inProgress":0,"total":2,"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-28T19:24:18.1203059Z","taskName":"PersonallyIdentifiableInformation_latest","state":"succeeded","results":{"documents":[{"redactedText":"I
304+
did not like the hotel we stayed at.","id":"2","entities":[],"warnings":[]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
305+
Language Code.","innererror":{"code":"UnsupportedLanguageCode","message":"Invalid
306+
language code. Supported languages: ja,ko,zh-Hans,de,en,es,fr,it,pt-BR,pt-PT.
307+
For additional details see https://aka.ms/text-analytics/language-support?tabs=named-entity-recognition"}}}],"modelVersion":"2021-01-15"}}],"sentimentAnalysisTasks":[{"lastUpdateDateTime":"2021-06-28T19:24:24.9467046Z","taskName":"SentimentAnalysis_latest","state":"succeeded","results":{"documents":[{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.55,"negative":0.39},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.55,"negative":0.39},"offset":0,"length":38,"text":"I
308+
did not like the hotel we stayed at."}],"warnings":[]},{"id":"2","sentiment":"negative","confidenceScores":{"positive":0.01,"neutral":0.45,"negative":0.54},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.01,"neutral":0.45,"negative":0.54},"offset":0,"length":38,"text":"I
309+
did not like the hotel we stayed at."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}}]}}'
310+
headers:
311+
apim-request-id:
312+
- fddfbd8f-ea98-4f9d-be0d-2cb941c6a46f
313+
content-type:
314+
- application/json; charset=utf-8
315+
date:
316+
- Mon, 28 Jun 2021 19:24:31 GMT
317+
strict-transport-security:
318+
- max-age=31536000; includeSubDomains; preload
319+
transfer-encoding:
320+
- chunked
321+
x-content-type-options:
322+
- nosniff
323+
x-envoy-upstream-service-time:
324+
- '119'
325+
status:
326+
code: 200
327+
message: OK
328+
version: 1

0 commit comments

Comments
 (0)