Reputation: 1910
I have trained and deployed a Custom Named Entity Recognition
model in Language Studio
. The model is successfully deployed and I can test it from Language Studio UI, I can see the detected entities. But when I try to access the endpoint from either Postman or Python I get the message <Response [202]>
, below are the configuration I am using for accessing the endpoint from Python or Postman.
Code
import json
import requests
url = "https://<language_service>.cognitiveservices.azure.com/language/analyze-text/jobs?api-version=2022-10-01-preview"
payload = json.dumps({
"tasks": [
{
"kind": "CustomEntityRecognition",
"parameters": {
"projectName": "<project_name>",
"deploymentName": "<deployment_name>",
"stringIndexType": "TextElement_v8"
}
}
],
"displayName": "CustomTextPortal_CustomEntityRecognition",
"analysisInput": {
"documents": [
{
"id": "1",
"text": "<text>",
"language": "en-us"
},
{
"id": "2",
"text": "<text>",
"language": "en-us"
}
]
}
})
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '<key>'
}
response = requests.post(url, headers=headers, data=payload)
print(response)
Can anyone please tell me what am I missing?
Upvotes: 0
Views: 179
Reputation: 1910
Issue has been resolved, actually I was missing the second part of the code. When the above code runs then we can extract the job id from the response object, then we can make another GET call to the endpoint as follows to get the results.
job_id = response.headers["Operation-Location"].split("/")[-1]
response = requests.get(url+'/jobs/'+job_id, None, headers=header)
dict = json.loads(response.text)
if dict['status'] == 'succeeded':
entities = dict['tasks']['items'][0]['results']['documents'][0]['entities']
print(entities)
Upvotes: 0