Skip to content

Commit

Permalink
[textanalytics] only allow one action per type (#19550)
Browse files Browse the repository at this point in the history
* add validation to allow for only one action per type

* update changelog
  • Loading branch information
kristapratico authored Jun 29, 2021
1 parent e3b53e8 commit 9b90f6e
Show file tree
Hide file tree
Showing 7 changed files with 908 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Note: this version will be the last to officially support Python 3.5, future ver
### Breaking Changes

- 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.
- Changed: `begin_analyze_actions` now accepts a single action per type. A `ValueError` is raised if duplicate actions are passed.
- Removed: `AnalyzeActionsType`
- Removed: `AnalyzeActionsResult`
- Removed: `AnalyzeActionsError`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ def begin_analyze_actions( # type: ignore

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

try:
analyze_tasks = self._client.models(api_version='v3.1').JobManifestTasks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ async def begin_analyze_actions( # type: ignore

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

try:
analyze_tasks = self._client.models(api_version='v3.1').JobManifestTasks(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
interactions:
- request:
body: '{"tasks": {"entityRecognitionTasks": [], "entityRecognitionPiiTasks": [{"parameters":
{"model-version": "latest", "loggingOptOut": false, "stringIndexType": "UnicodeCodePoint"}}],
"keyPhraseExtractionTasks": [], "entityLinkingTasks": [], "sentimentAnalysisTasks":
[{"parameters": {"model-version": "latest", "loggingOptOut": false, "opinionMining":
false}}]}, "analysisInput": {"documents": [{"id": "1", "text": "I did not like
the hotel we stayed at.", "language": "tr"}, {"id": "2", "text": "I did not
like the hotel we stayed at.", "language": "en"}]}}'
headers:
Accept:
- application/json, text/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '555'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze
response:
body:
string: ''
headers:
apim-request-id:
- abcffc21-b367-4e89-bda5-6ada712289f5
date:
- Mon, 28 Jun 2021 19:23:31 GMT
operation-location:
- https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '2883'
status:
code: 202
message: Accepted
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- ad8a2cca-552d-41ed-9e0f-c8aa841e3959
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:23:37 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '10'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- 0816a32e-6e41-45b4-9712-35847668d9a4
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:23:45 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '2584'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- e0ced991-ee08-4ae1-8419-becd4c1eb608
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:23:57 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '7535'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- c0ec87bb-67dd-4d0e-8246-df4c100e6389
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:24:03 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '11'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- 4a534831-af55-48ab-9276-b9a940d434e5
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:24:07 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '11'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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}}'
headers:
apim-request-id:
- 00846de9-ef34-4288-bc1d-e9d4bd390dbb
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:24:13 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '10'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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
did not like the hotel we stayed at.","id":"2","entities":[],"warnings":[]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
Language Code.","innererror":{"code":"UnsupportedLanguageCode","message":"Invalid
language code. Supported languages: ja,ko,zh-Hans,de,en,es,fr,it,pt-BR,pt-PT.
For additional details see https://aka.ms/text-analytics/language-support?tabs=named-entity-recognition"}}}],"modelVersion":"2021-01-15"}}]}}'
headers:
apim-request-id:
- 0b9ac807-8b1c-49e8-8db2-5f2e7f228785
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:24:25 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '7597'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-textanalytics/5.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1/analyze/jobs/7c0f4350-b4dd-4c26-ba9e-f7655428c5d8
response:
body:
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
did not like the hotel we stayed at.","id":"2","entities":[],"warnings":[]}],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
Language Code.","innererror":{"code":"UnsupportedLanguageCode","message":"Invalid
language code. Supported languages: ja,ko,zh-Hans,de,en,es,fr,it,pt-BR,pt-PT.
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
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
did not like the hotel we stayed at."}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}}]}}'
headers:
apim-request-id:
- fddfbd8f-ea98-4f9d-be0d-2cb941c6a46f
content-type:
- application/json; charset=utf-8
date:
- Mon, 28 Jun 2021 19:24:31 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '119'
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 9b90f6e

Please sign in to comment.