Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,27 @@ def order_results(response, combined):


def prepare_result(func):
def _deal_with_too_many_documents(response, obj):
# special case for now if there are too many documents in the request
# they may change id to empty string, but currently it is "All"
too_many_documents_errors = [
error for error in obj.errors
if error.id == "All" and error.error.innererror.code == "InvalidDocumentBatch"
Comment thread
iscai-msft marked this conversation as resolved.
Outdated
Comment thread
iscai-msft marked this conversation as resolved.
Outdated
]
if too_many_documents_errors:
too_many_documents_error = too_many_documents_errors[0]
response.status_code = 400
response.reason = "Bad Request"
raise HttpResponseError(
message="({}) {}".format(
too_many_documents_error.error.innererror.code, too_many_documents_error.error.innererror.message
),
response=response
)

def wrapper(response, obj, response_headers): # pylint: disable=unused-argument
if obj.errors:
_deal_with_too_many_documents(response.http_response, obj)
combined = obj.documents + obj.errors
results = order_results(response, combined)
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[{"text":"One","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"1","entities":[{"text":"Two","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"2","entities":[{"text":"Three","category":"Quantity","subcategory":"Number","offset":0,"length":5,"confidenceScore":0.8}],"warnings":[]},{"id":"3","entities":[{"text":"Four","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"4","entities":[{"text":"Five","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"5","entities":[{"text":"Six","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- 3f938077-141a-48c0-a8dc-45158ca76ca6
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Thu, 30 Apr 2020 18:38:28 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '87'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[{"text":"One","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"1","entities":[{"text":"Two","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"2","entities":[{"text":"Three","category":"Quantity","subcategory":"Number","offset":0,"length":5,"confidenceScore":0.8}],"warnings":[]},{"id":"3","entities":[{"text":"Four","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"4","entities":[{"text":"Five","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"5","entities":[{"text":"Six","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-04-01"}'
headers:
apim-request-id: 1dd2fff9-8681-43db-a4a2-550d2ce86329
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Thu, 30 Apr 2020 18:38:29 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '74'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/linking?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[],"warnings":[]},{"id":"1","entities":[],"warnings":[]},{"id":"2","entities":[],"warnings":[]},{"id":"3","entities":[],"warnings":[]},{"id":"4","entities":[],"warnings":[]},{"id":"5","entities":[],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-02-01"}'
headers:
apim-request-id:
- d66bc012-b3ed-44be-80d2-d837abc671dd
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Thu, 30 Apr 2020 18:38:29 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '21'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/linking?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[],"warnings":[]},{"id":"1","entities":[],"warnings":[]},{"id":"2","entities":[],"warnings":[]},{"id":"3","entities":[],"warnings":[]},{"id":"4","entities":[],"warnings":[]},{"id":"5","entities":[],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-02-01"}'
headers:
apim-request-id: da8df0dd-8966-4c46-808e-7850f5efd6ad
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Thu, 30 Apr 2020 18:38:29 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '32'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/linking?showStats=false
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ def test_input_with_all_errors(self, client):
self.assertTrue(response[1].is_error)
self.assertTrue(response[2].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = client.analyze_sentiment(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
def test_document_warnings(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ async def test_input_with_all_errors(self, client):
self.assertTrue(response[1].is_error)
self.assertTrue(response[2].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
async def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = await client.analyze_sentiment(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
async def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def test_input_with_all_errors(self, client):
for resp in response:
self.assertTrue(resp.is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = client.detect_language(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ async def test_input_with_all_errors(self, client):
for resp in response:
self.assertTrue(resp.is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
async def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = await client.detect_language(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
async def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def test_input_with_all_errors(self, client):
self.assertTrue(response[0].is_error)
self.assertTrue(response[1].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = client.extract_key_phrases(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ async def test_input_with_all_errors(self, client):
self.assertTrue(response[0].is_error)
self.assertTrue(response[1].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
@pytest.mark.xfail
async def test_too_many_documents(self, client):
# marking as xfail since the service hasn't added this error to this endpoint
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = await client.extract_key_phrases(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
async def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def test_input_with_all_errors(self, client):
self.assertTrue(response[1].is_error)
self.assertTrue(response[2].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
def test_too_many_documents(self, client):
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = client.recognize_entities(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ async def test_input_with_all_errors(self, client):
self.assertTrue(response[1].is_error)
self.assertTrue(response[2].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
async def test_too_many_documents(self, client):
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
Comment thread
iscai-msft marked this conversation as resolved.
Outdated
response = await client.recognize_entities(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
async def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def test_input_with_all_errors(self, client):
self.assertTrue(response[0].is_error)
self.assertTrue(response[1].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
def test_too_many_documents(self, client):
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = client.recognize_linked_entities(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
def test_empty_credential_class(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ async def test_input_with_all_errors(self, client):
self.assertTrue(response[0].is_error)
self.assertTrue(response[1].is_error)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
async def test_too_many_documents(self, client):
docs = ["One", "Two", "Three", "Four", "Five", "Six"]

with self.assertRaises(HttpResponseError):
response = await client.recognize_linked_entities(docs)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"text_analytics_account_key": ""})
async def test_empty_credential_class(self, client):
Expand Down