Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,29 @@ def order_results(response, combined):


def prepare_result(func):
def _get_error_code_and_message(error):
if hasattr(error.error, 'innererror') and error.error.innererror:
return error.error.innererror.code, error.error.innererror.message
return error.error.code, error.error.message

def _deal_with_too_many_documents(response, obj):
# special case for now if there are too many documents in the request
too_many_documents_errors = [
error for error in obj.errors if error.id == ""
]
if too_many_documents_errors:
too_many_documents_error = too_many_documents_errors[0]
response.status_code = 400
response.reason = "Bad Request"
code, message = _get_error_code_and_message(too_many_documents_error)
raise HttpResponseError(
message="({}) {}".format(code, 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,46 @@
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/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"0","sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"offset":0,"length":3,"text":"One"}],"warnings":[]},{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"offset":0,"length":3,"text":"Two"}],"warnings":[]},{"id":"2","sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":5,"text":"Three"}],"warnings":[]},{"id":"3","sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"offset":0,"length":4,"text":"Four"}],"warnings":[]},{"id":"4","sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":4,"text":"Five"}],"warnings":[]},{"id":"5","sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.98,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.98,"negative":0.01},"offset":0,"length":3,"text":"Six"}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- f7829392-4511-4f67-9d87-bf68daefdf14
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Wed, 06 May 2020 17:49:55 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '786'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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/sentiment?showStats=false
response:
body:
string: '{"documents":[{"id":"0","sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"offset":0,"length":3,"text":"One"}],"warnings":[]},{"id":"1","sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"offset":0,"length":3,"text":"Two"}],"warnings":[]},{"id":"2","sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":5,"text":"Three"}],"warnings":[]},{"id":"3","sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"offset":0,"length":4,"text":"Four"}],"warnings":[]},{"id":"4","sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":4,"text":"Five"}],"warnings":[]},{"id":"5","sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.98,"negative":0.01},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.01,"neutral":0.98,"negative":0.01},"offset":0,"length":3,"text":"Six"}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
headers:
apim-request-id: 907d38c7-507c-4d8c-ab66-7ba7b902396c
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Wed, 06 May 2020 17:49:59 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '447'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/sentiment?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "countryHint": "US"}, {"id":
"1", "text": "Two", "countryHint": "US"}, {"id": "2", "text": "Three", "countryHint":
"US"}, {"id": "3", "text": "Four", "countryHint": "US"}, {"id": "4", "text":
"Five", "countryHint": "US"}, {"id": "5", "text": "Six", "countryHint": "US"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '313'
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/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"0","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"1","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"2","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"3","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"4","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"5","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 665f34a6-d0d7-4e1e-836a-0022b2e7c355
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Wed, 06 May 2020 17:50:00 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '17'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "countryHint": "US"}, {"id":
"1", "text": "Two", "countryHint": "US"}, {"id": "2", "text": "Three", "countryHint":
"US"}, {"id": "3", "text": "Four", "countryHint": "US"}, {"id": "4", "text":
"Five", "countryHint": "US"}, {"id": "5", "text": "Six", "countryHint": "US"}]}'
headers:
Accept:
- application/json
Content-Length:
- '313'
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/languages?showStats=false
response:
body:
string: '{"documents":[{"id":"0","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"1","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"2","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"3","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"4","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]},{"id":"5","detectedLanguage":{"name":"English","iso6391Name":"en","confidenceScore":1.0},"warnings":[]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id: ac9a9b12-9398-417b-b38a-1a33b7f27398
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Wed, 06 May 2020 17:50:00 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '4'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/languages?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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/keyPhrases?showStats=false
response:
body:
string: '{"documents":[{"id":"0","keyPhrases":[],"warnings":[]},{"id":"1","keyPhrases":[],"warnings":[]},{"id":"2","keyPhrases":[],"warnings":[]},{"id":"3","keyPhrases":[],"warnings":[]},{"id":"4","keyPhrases":[],"warnings":[]},{"id":"5","keyPhrases":[],"warnings":[]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id:
- 43f39a4a-18f5-4c05-b5a2-b3404123cc86
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Wed, 06 May 2020 17:50:01 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '9'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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/keyPhrases?showStats=false
response:
body:
string: '{"documents":[{"id":"0","keyPhrases":[],"warnings":[]},{"id":"1","keyPhrases":[],"warnings":[]},{"id":"2","keyPhrases":[],"warnings":[]},{"id":"3","keyPhrases":[],"warnings":[]},{"id":"4","keyPhrases":[],"warnings":[]},{"id":"5","keyPhrases":[],"warnings":[]}],"errors":[],"modelVersion":"2019-10-01"}'
headers:
apim-request-id: fdc1b5e3-6da7-4fa1-b190-a3b3ff2b1289
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Wed, 06 May 2020 17:50:01 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '4'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/keyPhrases?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/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":"","error":{"code":"InvalidRequest","message":"The
request has exceeded the allowed document limits.","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:
- c59e450a-a78e-4bb5-aac2-b6da434585d1
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Wed, 06 May 2020 17:50:02 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '957'
status:
code: 200
message: OK
version: 1
Loading