GET Request Output
Once POST Compute Request has been submitted on different models, the computed metadata is stored and can be accessed by using
requestId.
The time taken to compute metadata from different models is dependant on the time duration of the Conversation and the number of models enabled.A 60 minute long conversation should take around 15-20 minutes to get to
processed
status.To track the status of requested models the Get Processing State route can be used. This route can be integrated with your code by using long-polling to check the state periodically until the processing of the all the requestId are in
processed
state. For more information refer to the Example given below.The state of a particular
request ID
can take the following values.State | Description |
uploaded | When the model processing request has been acknowledged by Marsview and the request is either queued or being processed. |
error | When there was an error processing the model. This could either be a configuration issue or an Internal Server error. In case of a failure, more information can be found from the metadata section or by referring to the Error Code given in the JSON response. |
processed | When the model processing request has completed successfully. |
get
https://api.marsview.ai
/cb/v1/conversation/get_txn/:txnId
Get Processing State
get
https://api.marsview.ai
/cb/v1/conversation/fetch_metadata/:txnId
Get Request Metadata
This example will demonstrate how to long-poll for
Speech-to-text
model processing to complete and fetch the Speech-to-text
model metadata once the model.state.status
is in processed
state.For more information on how to send a compute request on a Particular
Transaction ID
refer to the Compute Metadata section of the documentation. Using your
'API Key
' and 'API Secret'
you can generate the token as shown below.Curl
curl --location --request POST 'https://api.marsview.ai/cb/v1/auth/create_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
"apiKey": "{{Insert API Key}}",
"apiSecret": "{{Insert API Secret}}",
"userId": "[email protected]"
}'
Using the Get Processing State method the Processing request status can be fetched periodically (every 300 seconds in this case).
- If the process is in
uploaded
state we continue to poll until the process is in either processed orerror
state. - If the process is in
processed
state orerror
state we can move to Step 3.
Step 3: Fetching metadata
Once a particular request is in processed state Metadata for that model can be fetched using the Get Request Metadata method.
Shown below is an example Python code snippet for step 2 and step 3
Python
import requests
txn_id = "replace this with your Transaction ID"
auth_token = "Bearer <API TOKEN>"
processing_state_url = "https://api.marsview.ai/cb/v1/conversation/get_txn/{txn_id}"
metadata_url = "https://api.marsview.aicb/v1/conversation/fetch_metadata/{txnId}"
def get_speech_to_text_state():
payload={}
headers = {
'authorization': '{}'.format(auth_token)
}
response = requests.request("GET", processing_state_url.format(txn_id=user_id), headers=headers, json=payload)
print(response.text)
if response.status_code == 200 and response.json()["status"] == "true":
return response.json()["data"]["enableModels"]["state"]["status"]
else:
raise Exception("Custom exception")
def get_speech_to_text_metadata():
payload={}
headers = {
'authorization': '{}'.format(auth_token)
}
response = requests.request("GET", metadata_url.format(txn_id=user_id), headers=headers, json=payload)
if response.status_code == 200 and response.json()["status"] == "true":
return response.json()["data"]["transcript"]
else:
raise Exception("Custom exception")
def long_poll_results():
while True:
state = get_speech_to_text_state()
if state == "processed":
return get_speech_to_text_metadata()
elif state == "uploaded":
time.sleep(300)
elif state == "error":
raise Exception("An error has occured during the processing of this request")
if __name__ == "__main__":
long_poll_results()
Last modified 1yr ago